Skip to main content
summaryrefslogtreecommitdiffstats
blob: 93574db5fea94237daafc6460c05a1cc3447d289 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*******************************************************************************
 * Copyright (c) 2001, 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
 *******************************************************************************/
package org.eclipse.jem.internal.adapters.jdom;
/*


 */
import java.util.*;

import org.eclipse.emf.common.notify.*;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.jdt.core.*;
import org.eclipse.jem.internal.java.adapters.*;
import org.eclipse.jem.internal.java.adapters.JavaReflectionAdapterFactory;
import org.eclipse.jem.internal.java.adapters.ReflectionAdaptor;
/**
 * Insert the type's description here.
 * Creation date: (6/13/2000 1:20:31 PM)
 * @author: Administrator
 */
public class JavaJDOMAdapterFactory extends JavaReflectionAdapterFactory {
	
	protected JavaReflectionSynchronizer synchronizer;
	protected IJavaProject javaProject;
/**
 * JavaJDOMAdapterFactory constructor comment.
 */
public JavaJDOMAdapterFactory() {
	super();
}
/**
 * JavaJDOMAdapterFactory constructor comment.
 */
public JavaJDOMAdapterFactory(IJavaProject aJavaProject) {
	this();
	setJavaProject(aJavaProject);
}
protected ReflectionAdaptor createJavaClassAdaptor(Notifier target) {
	return new JavaClassJDOMAdaptor(target, getJavaProject(), this);
}
protected ReflectionAdaptor createJavaFieldAdaptor(Notifier target) {
	return new JavaFieldJDOMAdaptor(target, getJavaProject());
}
protected ReflectionAdaptor createJavaMethodAdaptor(Notifier target) {
	return new JavaMethodJDOMAdaptor(target, getJavaProject());
}
/**
 *  Flush ALL adapters, worst case
 * We also want to ensure that the source types are also cleared
 * in this worst case scenario.
 */
public void flushAll() {
	doFlush(reflected.values(),true, true);
}

public List flushAllNoNotification() {
	return doFlush(reflected.values(),true, false);
}

public void flushPackage(String packageName, boolean noFlushIfSourceFound) {
	List adaptors = getReflectedForPackage(packageName, noFlushIfSourceFound);
	doFlush(adaptors, true, true);
}
public List flushPackageNoNotification(String packageName, boolean noFlushIfSourceFound) {
	List adaptors = getReflectedForPackage(packageName, noFlushIfSourceFound);
	return doFlush(adaptors, true, false);
}
/**
 * Return a List of reflection adaptors that belong to 
 * the packageName.
 * @param packageName
 * @return
 */
private List getReflectedForPackage(String packageName, boolean filterFoundTypes) {
	if (packageName != null && !reflected.isEmpty()) {
		isBusyIteratingReflected = true;
		List result = null;
		try {
			Iterator it = reflected.entrySet().iterator();
			Map.Entry entry;
			String key;
			JavaClassJDOMAdaptor adaptor;
			while (it.hasNext()) {
				entry = (Map.Entry) it.next();
				adaptor = (JavaClassJDOMAdaptor) entry.getValue();
				/*
				 * Ensure that the the adaptor is only filtered out if it has
				 * actually reflected the content.  It is not good enough just
				 * to test for the sourceType.
				 */
				if (filterFoundTypes && adaptor.hasValidReflection())
					continue;
				key = (String) entry.getKey();
				if (key.startsWith(packageName) && key.indexOf('.', packageName.length() + 1) < 0) {
					if (result == null)
						result = new ArrayList();
					result.add(entry.getValue());
				}	
			}
		} finally {
			finishedIteratingReflected();
		}
		if (result != null)
			return result;
	}
	return Collections.EMPTY_LIST;
}
private List doFlush(Collection adaptors, boolean clearSourceType, boolean doNotify) {
	if (!adaptors.isEmpty()) {
		isBusyIteratingReflected = true;
		List notifications = doNotify ? null : new ArrayList(adaptors.size());
		try {
			Notification notification;
			Iterator i = adaptors.iterator();
			JDOMAdaptor adaptor;
			while (i.hasNext()) {
				adaptor = (JDOMAdaptor) i.next();
				if (doNotify)
					adaptor.flushReflectedValuesIfNecessary(clearSourceType);
				else {
					notification = adaptor.flushReflectedValuesIfNecessaryNoNotification(clearSourceType);
					if (notification != null)
						notifications.add(notification);
				}
			}
		} finally {
			finishedIteratingReflected();
		}
		return notifications;
	}
	return Collections.EMPTY_LIST;
}
// Flush the adapter for a source object
public void flushReflection(String source) {
	JDOMAdaptor a = (JDOMAdaptor) reflected.get(source);
	if (a != null)
		a.flushReflectedValuesIfNecessary();
}
public Notification flushReflectionNoNotification(String source) {
	JDOMAdaptor a = (JDOMAdaptor) reflected.get(source);
	if (a != null)
		return a.flushReflectedValuesIfNecessaryNoNotification(false);
	return null;
}

public Notification flushReflectionPlusInnerNoNotification(String source) {
	isBusyIteratingReflected = true;
	Notification notification = null;
	try {
		String innerName = source + '$';
		Iterator it = reflected.entrySet().iterator();
		Map.Entry entry;
		String key;
		JavaReflectionAdaptor adaptor;
		while (it.hasNext()) {
			entry = (Map.Entry) it.next();
			key = (String) entry.getKey();
			if (key.equals(source) || key.startsWith(innerName)) {
				adaptor = (JavaReflectionAdaptor) reflected.get(key);
				if (adaptor != null) {
					if (notification == null)
						notification = adaptor.flushReflectedValuesIfNecessaryNoNotification(false);
					else
						((NotificationChain) notification).add(adaptor.flushReflectedValuesIfNecessaryNoNotification(false));
				}
			}
		}
	} finally {
		finishedIteratingReflected();
	}
	return notification;

}
/**
 * Insert the method's description here.
 * Creation date: (11/2/2000 3:02:31 PM)
 * @return org.eclipse.jdt.core.api.IJavaProject
 */
public IJavaProject getJavaProject() {
	return javaProject;
}
/**
 * Create a Java Model listener which will flush invalidated adaptors.
 * This will cause those adapters to re-reflect their target object's contents.
 */
protected void initializeSynchronizer() {
	synchronizer = new JavaReflectionSynchronizer(this);
}
/**
 * Notify all JDOMAdapters which use the same target ICompilationUnit
 * Creation date: (8/17/2001 4:45:43 PM)
 */
public void notifyContentChanged(ICompilationUnit targetCU) {

	if (targetCU == null || reflected.values()==null) return ;
	isBusyIteratingReflected = true;
	try {
		Iterator i = reflected.values().iterator();
		while (i.hasNext()) {
			Object a = i.next() ;
			if (a instanceof JDOMAdaptor) {
				JDOMAdaptor adaptor = (JDOMAdaptor) a;
				IMember reflectionSource = (IMember) adaptor.getReflectionSource();
				ICompilationUnit adapterCU = null ;
				if (reflectionSource != null) {
					try {
					   adapterCU = reflectionSource.getCompilationUnit();
					} catch (Exception e) {} 
				}
				if (adapterCU != null && targetCU.equals(adapterCU)) {
			       adaptor.contentChanged();
				}
			}
		}
	} finally {
		finishedIteratingReflected();  	
	}
}
/**
 * Insert the method's description here.
 * Creation date: (11/2/2000 3:02:31 PM)
 * @param newJavaProject org.eclipse.jdt.core.IJavaProject
 */
public void setJavaProject(IJavaProject newJavaProject) {
	javaProject = newJavaProject;
	if (newJavaProject != null && synchronizer == null)
		initializeSynchronizer();
}
}

Back to the top