Skip to content

Package: PlatformGenModel

PlatformGenModel

nameinstructionbranchcomplexitylinemethod
PlatformGenModel(IPlatformBundle, String, String, String)
M: 67 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
PlatformGenModel(IPlatformBundle, String, String, int, String, String)
M: 65 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 48 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getBasePackage()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBasePackage(IPlatformGenModel)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getEPackage()
M: 66 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
getEPackageNsURI(URI)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getEPackageNsURI(URI, Map)
M: 51 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getGenModel()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getGenModelURI()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getGeneratedPackage()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIProxyEPackage()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIProxyEPackage(Map)
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getIProxyERoot()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIProxyERoot(Map)
M: 43 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getNsURI()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPlatformGenModelLocationMap()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getPlatformGenModels()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getWorkspaceGenModelLocationMap()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getWorkspacePlatformGenModels()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setPlatformBundle(IPlatformBundle)
M: 57 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: * <copyright>
3: *
4: * Copyright (c) 2009-2010 Thales Corporate Services S.A.S.
5: * This program and the accompanying materials
6: * are made available under the terms of the Eclipse Public License v2.0
7: * which accompanies this distribution, and is available at
8: * https://www.eclipse.org/legal/epl-v2.0
9: *
10: * SPDX-License-Identifier: EPL-2.0
11: *
12: * Contributors:
13: * Thales Corporate Services S.A.S - initial API and implementation
14: *
15: * </copyright>
16: *
17: */
18: package org.eclipse.egf.core.internal.genmodel;
19:
20: import java.lang.reflect.Field;
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: import org.eclipse.core.runtime.Assert;
25: import org.eclipse.egf.common.helper.EMFHelper;
26: import org.eclipse.egf.common.helper.URIHelper;
27: import org.eclipse.egf.common.loader.IClassLoader;
28: import org.eclipse.egf.core.EGFCorePlugin;
29: import org.eclipse.egf.core.epackage.IProxyEPackage;
30: import org.eclipse.egf.core.epackage.IProxyERoot;
31: import org.eclipse.egf.core.epackage.ProxyFactory;
32: import org.eclipse.egf.core.genmodel.IPlatformGenModel;
33: import org.eclipse.egf.core.platform.loader.BundleClassLoaderFactory;
34: import org.eclipse.egf.core.platform.pde.IPlatformBundle;
35: import org.eclipse.egf.core.platform.pde.PlatformExtensionPointURI;
36: import org.eclipse.emf.common.util.URI;
37: import org.eclipse.emf.common.util.WrappedException;
38: import org.eclipse.emf.ecore.EPackage;
39: import org.eclipse.emf.ecore.plugin.EcorePlugin;
40: import org.eclipse.osgi.util.NLS;
41: import org.eclipse.pde.core.plugin.IPluginModelBase;
42:
43: public final class PlatformGenModel extends PlatformExtensionPointURI implements IPlatformGenModel {
44:
45: private String _generatedPackage;
46:
47: private String _genModel;
48:
49: private URI _genModelURI;
50:
51: private static Map<URI, URI> workspaceGenModelLocationMap;
52:
53: private static Map<URI, IPlatformGenModel> nsURIToWorkspaceGenModel;
54:
55: private static Map<URI, URI> platformGenModelLocationMap;
56:
57: private static Map<URI, IPlatformGenModel> nsURIToPlatformGenModel;
58:
59: /**
60: * Returns a map from {@link EPackage#getNsURI() package namespace URI} (represented as a String)
61: * to the location of the GenModel containing a GenPackage for the package (represented as a {@link URI URI}).
62: *
63: * @return a map from package namespace to GenModel location.
64: */
65: public static Map<URI, URI> getWorkspaceGenModelLocationMap() {
66:• if (workspaceGenModelLocationMap == null) {
67: workspaceGenModelLocationMap = new HashMap<URI, URI>();
68: }
69: return workspaceGenModelLocationMap;
70: }
71:
72: public static Map<URI, IPlatformGenModel> getWorkspacePlatformGenModels() {
73:• if (nsURIToWorkspaceGenModel == null) {
74: nsURIToWorkspaceGenModel = new HashMap<URI, IPlatformGenModel>();
75: }
76: return nsURIToWorkspaceGenModel;
77: }
78:
79: /**
80: * Returns a map from {@link EPackage#getNsURI() package namespace URI} (represented as a String)
81: * to the location of the GenModel containing a GenPackage for the package (represented as a {@link URI URI}).
82: *
83: * @return a map from package namespace to GenModel location.
84: */
85: public static Map<URI, URI> getPlatformGenModelLocationMap() {
86:• if (platformGenModelLocationMap == null) {
87: platformGenModelLocationMap = new HashMap<URI, URI>();
88: }
89: return platformGenModelLocationMap;
90: }
91:
92: public static Map<URI, IPlatformGenModel> getPlatformGenModels() {
93:• if (nsURIToPlatformGenModel == null) {
94: nsURIToPlatformGenModel = new HashMap<URI, IPlatformGenModel>();
95: }
96: return nsURIToPlatformGenModel;
97: }
98:
99: public URI getEPackageNsURI(URI uri) {
100: return getEPackageNsURI(uri, null);
101: }
102:
103: public URI getEPackageNsURI(URI uri, Map<IPluginModelBase, IClassLoader> loaders) {
104:• if (uri == null) {
105: return null;
106: }
107: // Load the static resource
108: try {
109:• if (getBundle() == null) {
110: IClassLoader loader = null;
111:• if (loaders != null) {
112: loader = loaders.get(getPluginModelBase());
113:• if (loader == null) {
114: loader = BundleClassLoaderFactory.getBundleClassLoader(getPluginModelBase());
115: loaders.put(getPluginModelBase(), loader);
116: }
117: } else {
118: loader = BundleClassLoaderFactory.getBundleClassLoader(getPluginModelBase());
119: }
120: return EMFHelper.getEPackageNsURI(loader, getGeneratedPackage(), uri);
121: }
122: return EMFHelper.getEPackageNsURI(getEPackage(), uri);
123: } catch (Throwable t) {
124: EGFCorePlugin.getDefault().logError(t);
125: }
126: return null;
127: }
128:
129: public static String getBasePackage(IPlatformGenModel genModel) {
130: String classname = genModel.getGeneratedPackage();
131: int index = classname.lastIndexOf("."); //$NON-NLS-1$
132:• if (index == -1 || index == 0) {
133: return null;
134: }
135: return classname.substring(0, index);
136: }
137:
138: public PlatformGenModel(IPlatformBundle bundle, String uri, String className, String genModel) {
139: super(bundle, uri);
140: _uri = URI.createURI(URI.decode(getId()));
141: Assert.isNotNull(className);
142:• Assert.isLegal(className.trim().length() != 0);
143:• Assert.isLegal(bundle.isRuntime() == false);
144: _generatedPackage = className.trim();
145:• if (genModel != null && genModel.trim().length() != 0) {
146: _genModel = genModel.trim();
147: _genModelURI = URIHelper.getPlatformPluginURI(getPlatformBundle().getBundleId(), URI.decode(_genModel), false);
148: getWorkspaceGenModelLocationMap().put(getNsURI(), _genModelURI);
149: }
150: getWorkspacePlatformGenModels().put(getNsURI(), this);
151: }
152:
153: public PlatformGenModel(IPlatformBundle bundle, String uri, String uniqueIdentifier, int handleId, String className, String genModel) {
154: super(bundle, uri, uniqueIdentifier, handleId);
155: _uri = URI.createURI(URI.decode(getId()));
156: Assert.isNotNull(className);
157:• Assert.isLegal(className.trim().length() != 0);
158: Assert.isLegal(bundle.isRuntime());
159: _generatedPackage = className.trim();
160:• if (genModel != null && genModel.trim().length() != 0) {
161: _genModel = genModel.trim();
162: _genModelURI = URIHelper.getPlatformPluginURI(getPlatformBundle().getBundleId(), URI.decode(_genModel), false);
163: getPlatformGenModelLocationMap().put(getNsURI(), _genModelURI);
164: }
165: getPlatformGenModels().put(getNsURI(), this);
166: }
167:
168: @Override
169: protected void setPlatformBundle(IPlatformBundle bundle) {
170: super.setPlatformBundle(bundle);
171: // when merged, the previous discarded one could clean the registry
172:• if (_genModelURI != null) {
173:• if (isRuntime()) {
174: getPlatformGenModelLocationMap().put(getNsURI(), _genModelURI);
175: EcorePlugin.getEPackageNsURIToGenModelLocationMap().put(getNsURI().toString(), _genModelURI);
176: } else {
177: getWorkspaceGenModelLocationMap().put(getNsURI(), _genModelURI);
178: }
179: }
180:• if (isRuntime()) {
181: getPlatformGenModels().put(getNsURI(), this);
182: EPackage.Registry.INSTANCE.put(getNsURI().toString(), getEPackage());
183: } else {
184: getWorkspacePlatformGenModels().put(getNsURI(), this);
185: }
186: }
187:
188: public URI getNsURI() {
189: return getURI();
190: }
191:
192: public String getGeneratedPackage() {
193: return _generatedPackage;
194: }
195:
196: public String getGenModel() {
197: return _genModel;
198: }
199:
200: public URI getGenModelURI() {
201: return _genModelURI;
202: }
203:
204: @Override
205: public boolean equals(Object object) {
206:• if (super.equals(object) == false) {
207: return false;
208: }
209:• if (object instanceof IPlatformGenModel == false) {
210: return false;
211: }
212: IPlatformGenModel platformGenModel = (IPlatformGenModel) object;
213:• if (platformGenModel.getGeneratedPackage().equals(getGeneratedPackage()) == false) {
214: return false;
215: }
216:• if (platformGenModel.getGenModel() == null && getGenModel() == null) {
217: return true;
218: }
219:• if (platformGenModel.getGenModel() == null || getGenModel() == null) {
220: return false;
221: }
222:• if (platformGenModel.getGenModel().equals(getGenModel()) == false) {
223: return false;
224: }
225: return true;
226: }
227:
228: public String getBasePackage() {
229: return getBasePackage(this);
230: }
231:
232: public IProxyEPackage getIProxyEPackage() {
233: return getIProxyEPackage(null);
234: }
235:
236: public IProxyEPackage getIProxyEPackage(Map<IPluginModelBase, IClassLoader> loaders) {
237: IProxyERoot wrapper = getIProxyERoot(loaders);
238:• if (wrapper != null && wrapper.getChildren().length == 1) {
239: return wrapper.getChildren()[0];
240: }
241: return null;
242: }
243:
244: public IProxyERoot getIProxyERoot() {
245: return getIProxyERoot(null);
246: }
247:
248: public IProxyERoot getIProxyERoot(Map<IPluginModelBase, IClassLoader> loaders) {
249: // Load the static resource
250: try {
251:• if (getBundle() == null) {
252: IClassLoader loader = null;
253:• if (loaders != null) {
254: loader = loaders.get(getPluginModelBase());
255:• if (loader == null) {
256: loader = BundleClassLoaderFactory.getBundleClassLoader(getPluginModelBase());
257: loaders.put(getPluginModelBase(), loader);
258: }
259: } else {
260: loader = BundleClassLoaderFactory.getBundleClassLoader(getPluginModelBase());
261: }
262: return ProxyFactory.buildIProxyERoot(loader, this);
263: }
264: return ProxyFactory.buildIProxyERoot(this);
265: } catch (Throwable t) {
266: EGFCorePlugin.getDefault().logError(t);
267: }
268: return null;
269: }
270:
271: public EPackage getEPackage() {
272:• if (getBundle() != null) {
273: EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(getNsURI().toString());
274:• if (ePackage == null) {
275: try {
276: Class<?> javaClass = getBundle().loadClass(_generatedPackage);
277: Field field = javaClass.getField("eINSTANCE"); //$NON-NLS-1$
278: Object result = field.get(null);
279: ePackage = (EPackage) result;
280:• if (ePackage != null) {
281: EPackage.Registry.INSTANCE.put(getNsURI().toString(), ePackage);
282: }
283: } catch (ClassNotFoundException e) {
284: throw new WrappedException(e);
285: } catch (IllegalAccessException e) {
286: throw new WrappedException(e);
287: } catch (NoSuchFieldException e) {
288: throw new WrappedException(e);
289: }
290: }
291: return ePackage;
292: }
293: throw new UnsupportedOperationException(NLS.bind("EPackage couldn't be resolved ''{0}''", getNsURI())); //$NON-NLS-1$
294: }
295:
296: @Override
297: protected void dispose() {
298:• if (isRuntime()) {
299: // Clean local registry
300: getPlatformGenModelLocationMap().remove(getNsURI());
301: getPlatformGenModels().remove(getNsURI());
302: } else {
303: getWorkspaceGenModelLocationMap().remove(getNsURI());
304: getWorkspacePlatformGenModels().remove(getNsURI());
305: }
306: }
307:
308: }