Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java131
1 files changed, 7 insertions, 124 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java b/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java
index 8c2dc378506..0c2aa4964ec 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/ExtendedElementTypeSetRegistry.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2015 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,24 +8,20 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) - Initial API and implementation
- * Christian W. Damus - bug 459174
- * Christian W. Damus - bug 459825
+ * Christian W. Damus - bugs 459174, 459825, 485220
*
*****************************************************************************/
package org.eclipse.papyrus.infra.extendedtypes;
+import static org.eclipse.papyrus.infra.extendedtypes.util.InternalUtils.loadClass;
+
import java.io.IOException;
-import java.lang.ref.WeakReference;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Dictionary;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.StringTokenizer;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
@@ -43,7 +39,6 @@ import org.eclipse.gmf.runtime.emf.type.core.internal.descriptors.IEditHelperAdv
import org.eclipse.gmf.runtime.emf.type.core.internal.impl.SpecializationTypeRegistry;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.elementtypesconfigurations.registries.ElementTypeSetConfigurationRegistry;
-import org.eclipse.papyrus.infra.extendedtypes.preferences.ExtendedTypesPreferences;
import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
import org.osgi.framework.Bundle;
@@ -131,7 +126,7 @@ public class ExtendedElementTypeSetRegistry {
}
// retrieve the path from the identifier
- String path = ExtendedTypesPreferences.getLocalExtendedTypesDefinitions().get(identifier);
+ String path = UserExtendedTypesRegistry.getInstance().getLocalExtendedTypesDefinitions().get(identifier);
if (path == null) {
return;
}
@@ -312,7 +307,7 @@ public class ExtendedElementTypeSetRegistry {
* @return
*/
protected Map<String, ExtendedElementTypeSet> loadExtendedTypeSetsFromWorkspace() {
- Map<String, String> localFilesPath = ExtendedTypesPreferences.getLocalExtendedTypesDefinitions();
+ Map<String, String> localFilesPath = UserExtendedTypesRegistry.getInstance().getLocalExtendedTypesDefinitions();
Map<String, ExtendedElementTypeSet> workspaceElementTypeSets = new HashMap<String, ExtendedElementTypeSet>();
if (localFilesPath != null && !localFilesPath.isEmpty()) {
for (Entry<String, String> idToPath : localFilesPath.entrySet()) {
@@ -381,7 +376,7 @@ public class ExtendedElementTypeSetRegistry {
*/
protected ExtendedElementTypeSet getExtendedElementTypeSet(String extendedTypesID, String modelPath, String bundleId) {
// 1. look in preferences.
- String filePath = ExtendedTypesPreferences.getExtendedTypesRedefinition(extendedTypesID);
+ String filePath = UserExtendedTypesRegistry.getInstance().getExtendedTypesRedefinition(extendedTypesID);
if (filePath != null) {
getExtendedElementTypeSetInPluginStateArea(extendedTypesID);
}
@@ -467,118 +462,6 @@ public class ExtendedElementTypeSetRegistry {
return set;
}
- // /////////////////////////////////////////////////////////////////////////
- // loading resource
- // /////////////////////////////////////////////////////////////////////////
- /** A map of classes that have been successfully loaded, keyed on the class name optionally prepended by the plugin ID, if specified. */
- private static Map<String, WeakReference<Class<?>>> successLookupTable = new HashMap<String, WeakReference<Class<?>>>();
-
- /** A map of classes that could not be loaded, keyed on the class name, optionally prepended by the plugin ID if specified. */
- private static Set<String> failureLookupTable = new HashSet<String>();
-
- /** A map to hold the bundle to exception list */
- private static Map<Bundle, Set<String>> bundleToExceptionsSetMap = new HashMap<Bundle, Set<String>>();
-
- /**
- * A utility method to load a class using its name and a given class loader.
- *
- * @param className
- * The class name
- * @param bundle
- * The class loader
- * @return The loaded class or <code>null</code> if could not be loaded
- */
- protected static Class<?> loadClass(String className, String pluginId) {
- StringBuffer keyStringBuf = new StringBuffer(className.length() + pluginId.length() + 2); // 2 is for . and extra.
- keyStringBuf.append(pluginId);
- keyStringBuf.append('.');
- keyStringBuf.append(className);
- String keyString = keyStringBuf.toString();
- WeakReference<Class<?>> ref = successLookupTable.get(keyString);
- Class<?> found = (ref != null) ? ref.get() : null;
- if (found == null) {
- if (ref != null) {
- successLookupTable.remove(keyString);
- }
- if (!failureLookupTable.contains(keyString)) {
- try {
- Bundle bundle = basicGetPluginBundle(pluginId);
- if (bundle != null) {
- // never load the class if the bundle is not active other wise
- // we will cause the plugin to load
- // unless the class is in the exception list
- int state = bundle.getState();
- if (state == org.osgi.framework.Bundle.ACTIVE || isInExceptionList(bundle, className)) {
- found = bundle.loadClass(className);
- successLookupTable.put(keyString, new WeakReference<Class<?>>(found));
- if (state == org.osgi.framework.Bundle.ACTIVE) {
- bundleToExceptionsSetMap.remove(bundle);
- }
- }
- } else {
- failureLookupTable.add(keyString);
- }
- } catch (ClassNotFoundException e) {
- failureLookupTable.add(keyString);
- }
- }
- }
- return found;
- }
-
- /**
- * Given a bundle id, it checks if the bundle is found and activated. If it
- * is, the method returns the bundle, otherwise it returns <code>null</code>.
- *
- * @param pluginId
- * the bundle ID
- * @return the bundle, if found
- */
- protected static Bundle getPluginBundle(String pluginId) {
- Bundle bundle = basicGetPluginBundle(pluginId);
- if (null != bundle && bundle.getState() == org.osgi.framework.Bundle.ACTIVE) {
- return bundle;
- }
- return null;
- }
-
- private static Bundle basicGetPluginBundle(String pluginId) {
- return Platform.getBundle(pluginId);
- }
-
- private static boolean isInExceptionList(Bundle bundle, String className) {
- String packageName = className.substring(0, className.lastIndexOf('.'));
- Set<String> exceptionSet = bundleToExceptionsSetMap.get(bundle);
- if (exceptionSet == null) {
- Dictionary<String, String> dict = bundle.getHeaders();
- String value = dict.get("Eclipse-LazyStart"); //$NON-NLS-1$
- if (value != null) {
- int index = value.indexOf("exceptions"); //$NON-NLS-1$
- if (index != -1) {
- try {
- int start = value.indexOf('"', index + 1);
- int end = value.indexOf('"', start + 1);
- String exceptions = value.substring(start + 1, end);
- exceptionSet = new HashSet<String>(2);
- StringTokenizer tokenizer = new StringTokenizer(exceptions, ","); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- exceptionSet.add(tokenizer.nextToken().trim());
- }
- } catch (IndexOutOfBoundsException exception) {
- // this means the MF did not follow the documented format for the exceptions list so i'll consider it empty
- exceptionSet = Collections.emptySet();
- }
- } else {
- exceptionSet = Collections.emptySet();
- }
- } else {
- exceptionSet = Collections.emptySet();
- }
- bundleToExceptionsSetMap.put(bundle, exceptionSet);
- }
- return exceptionSet.contains(packageName);
- }
-
/**
* @return the extendedTypeSets
*/

Back to the top