|
Lines 12-27
Link Here
|
| 12 |
|
12 |
|
| 13 |
package org.eclipse.emf.validation.service; |
13 |
package org.eclipse.emf.validation.service; |
| 14 |
|
14 |
|
|
|
15 |
import java.io.IOException; |
| 16 |
import java.io.InputStream; |
| 17 |
import java.net.URL; |
| 18 |
import java.net.URLClassLoader; |
| 15 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
| 16 |
import java.util.Collection; |
20 |
import java.util.Collection; |
| 17 |
import java.util.Iterator; |
21 |
import java.util.Iterator; |
| 18 |
import java.util.List; |
22 |
import java.util.List; |
| 19 |
import java.util.Map; |
23 |
import java.util.Map; |
| 20 |
|
24 |
|
|
|
25 |
import org.eclipse.core.internal.registry.RegistryProviderFactory; |
| 21 |
import org.eclipse.core.runtime.CoreException; |
26 |
import org.eclipse.core.runtime.CoreException; |
| 22 |
import org.eclipse.core.runtime.IConfigurationElement; |
27 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
|
28 |
import org.eclipse.core.runtime.IContributor; |
| 29 |
import org.eclipse.core.runtime.IExtensionRegistry; |
| 23 |
import org.eclipse.core.runtime.IStatus; |
30 |
import org.eclipse.core.runtime.IStatus; |
| 24 |
import org.eclipse.core.runtime.Platform; |
31 |
import org.eclipse.core.runtime.Platform; |
|
|
32 |
import org.eclipse.core.runtime.RegistryFactory; |
| 33 |
import org.eclipse.core.runtime.spi.IRegistryProvider; |
| 34 |
import org.eclipse.core.runtime.spi.RegistryContributor; |
| 35 |
import org.eclipse.core.runtime.spi.RegistryStrategy; |
| 36 |
import org.eclipse.emf.common.EMFPlugin; |
| 25 |
import org.eclipse.emf.ecore.EClass; |
37 |
import org.eclipse.emf.ecore.EClass; |
| 26 |
import org.eclipse.emf.ecore.EClassifier; |
38 |
import org.eclipse.emf.ecore.EClassifier; |
| 27 |
import org.eclipse.emf.ecore.EPackage; |
39 |
import org.eclipse.emf.ecore.EPackage; |
|
Lines 89-98
Link Here
|
| 89 |
private ModelValidationService() { |
101 |
private ModelValidationService() { |
| 90 |
super(); |
102 |
super(); |
| 91 |
|
103 |
|
|
|
104 |
configureStandaloneRegistry(); |
| 105 |
|
| 92 |
configureConstraints(); |
106 |
configureConstraints(); |
| 93 |
configureListeners(); |
107 |
configureListeners(); |
| 94 |
} |
108 |
} |
|
|
109 |
|
| 110 |
/** |
| 111 |
* Sets up the registry when running in stand alone mode. It populates the registry with |
| 112 |
* every plugin descriptor in the classpath (jar or directory) |
| 113 |
*/ |
| 114 |
@SuppressWarnings("restriction") |
| 115 |
private void configureStandaloneRegistry() { |
| 116 |
if (EMFPlugin.IS_ECLIPSE_RUNNING == false) { |
| 117 |
// Standalone mode |
| 118 |
RegistryStrategy strategy = new RegistryStrategy(null, null); |
| 119 |
final IExtensionRegistry registry = RegistryFactory.createRegistry(strategy, null, null); |
| 120 |
// Locate all plugins in the path |
| 121 |
ClassLoader classLoader = ModelValidationService.class.getClassLoader(); |
| 122 |
if (classLoader instanceof URLClassLoader) { |
| 123 |
URL[] urls = ((URLClassLoader) classLoader).getURLs(); |
| 124 |
for (int i = 0; i < urls.length; i++) { |
| 125 |
String pluginLocation = urls[i].toExternalForm(); |
| 126 |
if (pluginLocation.endsWith(".jar")) { |
| 127 |
pluginLocation = "jar:" + pluginLocation + "!/plugin.xml"; |
| 128 |
} |
| 129 |
else if (pluginLocation.endsWith("/bin/")){ |
| 130 |
pluginLocation += "../plugin.xml"; |
| 131 |
} |
| 132 |
else { |
| 133 |
pluginLocation += "plugin.xml"; |
| 134 |
} |
| 135 |
try { |
| 136 |
URL pluginURL = new URL(pluginLocation); |
| 137 |
InputStream is = pluginURL.openStream(); |
| 138 |
IContributor contribution = new RegistryContributor(String.valueOf(i), EMFModelValidationPlugin.getPluginId(), |
| 139 |
null, null); |
| 140 |
registry.addContribution(is, contribution, false, null, null, null); |
| 141 |
} |
| 142 |
catch (IOException io) { |
| 143 |
// pluginLocation is not valid, ignore |
| 144 |
} |
| 145 |
catch (Exception e) { |
| 146 |
e.printStackTrace(); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
// Register standalone registry provider |
| 151 |
IRegistryProvider standaloneProvider = new IRegistryProvider() { |
| 95 |
|
152 |
|
|
|
153 |
public IExtensionRegistry getRegistry() { |
| 154 |
return registry; |
| 155 |
} |
| 156 |
|
| 157 |
}; |
| 158 |
try { |
| 159 |
RegistryProviderFactory.setDefault(standaloneProvider); |
| 160 |
} |
| 161 |
catch (Exception e) { |
| 162 |
e.printStackTrace(); |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 96 |
/** |
167 |
/** |
| 97 |
* Configures validation constraint providers based on the |
168 |
* Configures validation constraint providers based on the |
| 98 |
* <tt>constraintProviders</tt> extension configurations. |
169 |
* <tt>constraintProviders</tt> extension configurations. |
|
Lines 102-110
Link Here
|
| 102 |
Platform.getExtensionRegistry().getConfigurationElementsFor( |
173 |
Platform.getExtensionRegistry().getConfigurationElementsFor( |
| 103 |
EMFModelValidationPlugin.getPluginId(), |
174 |
EMFModelValidationPlugin.getPluginId(), |
| 104 |
EMFModelValidationPlugin.CONSTRAINT_PROVIDERS_EXT_P_NAME); |
175 |
EMFModelValidationPlugin.CONSTRAINT_PROVIDERS_EXT_P_NAME); |
| 105 |
|
176 |
|
| 106 |
constraintCache = new ConstraintCache(); |
177 |
constraintCache = new ConstraintCache(); |
| 107 |
|
178 |
|
| 108 |
Collection<IProviderDescriptor> providers = getProviders(); |
179 |
Collection<IProviderDescriptor> providers = getProviders(); |
| 109 |
|
180 |
|
| 110 |
// include the cache in my collection of providers |
181 |
// include the cache in my collection of providers |