Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8f26cf3bf377ef27803873875e065dd5446c92bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
/*
 * Created on Dec 3, 2003
 * 
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipse.wst.common.internal.emfworkbench.edit;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.jem.util.logger.proxy.Logger;

/**
 * @author schacher
 * 
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class ExtendedComposedAdapterFactory extends ComposedAdapterFactory {

	/**
	 * @param adapterFactory
	 */
	public ExtendedComposedAdapterFactory(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	/**
	 * @param adapterFactories
	 */
	public ExtendedComposedAdapterFactory(AdapterFactory[] adapterFactories) {
		super(adapterFactories);
	}

	/**
	 * @param adapterFactories
	 */
	public ExtendedComposedAdapterFactory(Collection adapterFactories) {
		super(adapterFactories);
	}

	/*
	 * overrode from the super class, changed not to check supertypes of the EObject, because that
	 * will be handled by the DynamicAdapterFactory
	 * 
	 * @see org.eclipse.emf.common.notify.AdapterFactory#adapt(org.eclipse.emf.common.notify.Notifier,
	 *      java.lang.Object)
	 */
	public Adapter adapt(Notifier target, Object type) {
		Adapter result = null;

		if (target instanceof EObject) {
			EObject eObject = (EObject) target;
			EClass eClass = eObject.eClass();
			if (eClass != null) {
				EPackage ePackage = eClass.getEPackage();
				Collection types = new ArrayList();
				types.add(ePackage);
				if (type != null) {
					types.add(type);
				}
				/* when an error occurs, remove the delegate and try again */
				boolean attemptAdaptAgain = true;
				while (result == null && attemptAdaptAgain) {
					attemptAdaptAgain = false;
					AdapterFactory delegateAdapterFactory = getFactoryForTypes(types);
					if (delegateAdapterFactory != null) {
						try {
							result = delegateAdapterFactory.adapt(target, type);
						} catch (RuntimeException re) {
							Logger.getLogger().logError(re);
							adapterFactories.remove(delegateAdapterFactory);
							attemptAdaptAgain = true;
						}
					}
				}
			}
		} else {
			result = adapt(target, type, new HashSet(), target.getClass());
		}

		return result;
	}
}

Back to the top