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
|
/***************************************************************************************************
* Copyright (c) 2003, 2004 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
**************************************************************************************************/
package org.eclipse.jst.j2ee.internal.webservice.provider;
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.common.notify.impl.AdapterFactoryImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.jst.j2ee.internal.webservice.adapter.AdapterViewerItem;
public class ATKUIAdapterFactory extends AdapterFactoryImpl {
private AdapterFactory[] adapterFactories_;
public ATKUIAdapterFactory() {
adapterFactories_ = new AdapterFactory[4];
adapterFactories_[0] = new WsddItemProviderAdapterFactory();
adapterFactories_[1] = new ATKUIWscddAdapterFactory();
adapterFactories_[2] = new ATKUIWscommonAdapterFactory();
adapterFactories_[3] = new ATKUICommonAdapterFactory();
}
@Override
public Object adapt(Object target, Object type) {
if (target instanceof Notifier) {
for (int i = 0; i < adapterFactories_.length; i++) {
Object object = adapterFactories_[i].adapt(target, type);
if (object != null) {
return object;
}
}
return null;
}
return resolve(target, type);
}
@Override
public Adapter adapt(Notifier target, Object type) {
Object object = adapt((Object) target, type);
if (object instanceof Adapter) {
return (Adapter) object;
}
return null;
}
/**
* This is called by {@link #adapt(Object,Object) adapt(Object, Object)}for objects that aren't
* notifiers.
*
* @param an
* arbitrary object to adapt.
* @param type
* the key indicating the type of adapter required.
* @return the object itself.
* @see #adapt(Object,Object)
*/
@Override
protected Object resolve(Object object, Object type) {
if (object instanceof EList)
return resolveEList((EList) object, type);
else if (object instanceof AdapterViewerItem)
return resolveAdapterViewerItem((AdapterViewerItem) object, type);
else
return null;
}
private Object resolveEList(EList eList, Object type) {
if (eList.size() > 0)
return adapt(eList.get(0), type);
return null;
}
private Object resolveAdapterViewerItem(AdapterViewerItem adapterViewerItem, Object type) {
return resolveEList(adapterViewerItem.getEObjectList(), type);
}
public void addListener(INotifyChangedListener listener) {
((WsddItemProviderAdapterFactory) adapterFactories_[0]).addListener(listener);
((ATKUIWscddAdapterFactory) adapterFactories_[1]).addListener(listener);
((ATKUIWscommonAdapterFactory) adapterFactories_[2]).addListener(listener);
((ATKUICommonAdapterFactory) adapterFactories_[3]).addListener(listener);
}
}
|