Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6bb9db52e0cefaf6bf9ed31ca1b3d5ce5c06e30a (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
/*
 * Copyright (c) 2008 Borland Software Corporation
 * 
 * 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:
 *    Artem Tikhomirov (Borland) - initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»

«EXTENSION Facility»

«DEFINE Main FOR gmfgen::DynamicModelAccess-»
package «packageName»;

public class «className» {

	«EXPAND field(self) FOREACH editorGen.getAllDomainGenPackages(false)-»

	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.emf.ecore.EPackage ePackage;

	«EXPAND xpt::Common::generatedMemberComment»
	private «className»(org.eclipse.emf.ecore.EPackage ePackage) {
		this.ePackage = ePackage;
	}

	«EXPAND getMethod(self) FOREACH editorGen.getAllDomainGenPackages(false)-»

	«EXPAND getRegistryMethod»

	«EXPAND xpt::Common::generatedMemberComment»
	public boolean isInstance(Object obj, String metaClassName) {
		org.eclipse.emf.ecore.EClass metaClass = getEClass(metaClassName);
		return obj instanceof org.eclipse.emf.ecore.EObject && metaClass.isSuperTypeOf(((org.eclipse.emf.ecore.EObject) obj).eClass());
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EObject newInstance(String metaClassName) {
		return this.ePackage.getEFactoryInstance().create(getEClass(metaClassName));
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EClass getEClass(String metaClassName) {
		«EXPAND xpt::Common::_assert('metaClassName != null')-»
		org.eclipse.emf.ecore.EClass metaClass = findMetaClass(metaClassName);
		assertMetaClass(metaClass, metaClassName);
		return metaClass;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EStructuralFeature getEFeature(String metaClassName, String metaFeatureName) {
		«EXPAND xpt::Common::_assert('metaFeatureName != null')-»
		org.eclipse.emf.ecore.EClass metaClass = getEClass(metaClassName);
		org.eclipse.emf.ecore.EStructuralFeature f = metaClass.getEStructuralFeature(metaFeatureName);
		assertMetaFeature(f, metaClass, metaFeatureName);
		return f;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EAttribute getEAttribute(String metaClassName, String metaFeatureName) {
		return (org.eclipse.emf.ecore.EAttribute) getEFeature(metaClassName, metaFeatureName);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EReference getEReference(String metaClassName, String metaFeatureName) {
		return (org.eclipse.emf.ecore.EReference) getEFeature(metaClassName, metaFeatureName);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EDataType getEDataType(String metaClassName) {
		«EXPAND xpt::Common::_assert('metaClassName != null')-»
		org.eclipse.emf.ecore.EClassifier c = this.ePackage.getEClassifier(metaClassName);
		if (false == c instanceof org.eclipse.emf.ecore.EDataType) {
			return null;
		}
		return (org.eclipse.emf.ecore.EDataType) c;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EEnum getEEnum(String metaClassName) {
		«EXPAND xpt::Common::_assert('metaClassName != null')-»
		org.eclipse.emf.ecore.EClassifier c = this.ePackage.getEClassifier(metaClassName);
		if (false == c instanceof org.eclipse.emf.ecore.EEnum) {
			return null;
		}
		return (org.eclipse.emf.ecore.EEnum) c;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.emf.ecore.EClass findMetaClass(String name) {
		org.eclipse.emf.ecore.EClassifier c = this.ePackage.getEClassifier(name);
		if (false == c instanceof org.eclipse.emf.ecore.EClass) {
			return null;
		}
		return (org.eclipse.emf.ecore.EClass) c;
	}

	«EXPAND xpt::Common::generatedMemberComment('Default implementation throws IllegalStateException if metaclass is null')»
	private void assertMetaClass(org.eclipse.emf.ecore.EClass metaClass, String metaClassName) {
		if (metaClass == null) {
			throw new IllegalStateException(java.text.MessageFormat.format("Can't find class {0} in the package {1}", new Object[] {metaClassName, this.ePackage.getName()}));
		}
	}

	«EXPAND xpt::Common::generatedMemberComment('Default implementation throws IllegalStateException if meta-feature is null')»
	private void assertMetaFeature(org.eclipse.emf.ecore.EStructuralFeature metaFeature, org.eclipse.emf.ecore.EClass metaClass, String featureName) {
		if (metaFeature == null) {
			throw new IllegalStateException(java.text.MessageFormat.format("Can't find feature {0} of class {1} in the package {2}", new Object[] {featureName, metaClass.getName(), this.ePackage.getName()}));
		}
	}

	«EXPAND initMethod FOREACH editorGen.getAllDomainGenPackages(false)-»
«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::DynamicModelAccess»«ENDDEFINE»

«DEFINE field(dma : gmfgen::DynamicModelAccess) FOR genmodel::GenPackage-»
«EXPAND xpt::Common::generatedMemberComment»
private static «dma.className» «fieldName(self)»;
«ENDDEFINE»

«DEFINE getMethod(dma : gmfgen::DynamicModelAccess) FOR genmodel::GenPackage-»
	«EXPAND xpt::Common::generatedMemberComment('@throws IllegalStateException if no EPackage with given URI is registered.')»
	public static «dma.className» get«getNameToken(self)»() {
		if («fieldName(self)» == null) {
			org.eclipse.emf.ecore.EPackage pkg = getRegistry().getEPackage("«ecorePackage.nsURI»");
			if (pkg == null) {
				throw new IllegalStateException("Package «ecorePackage.name»(«ecorePackage.nsURI») not found");
			}
			«fieldName(self)» = new «dma.className»(pkg);
			«fieldName(self)».init«getNameToken(self)»();
		}
		return «fieldName(self)»;
	}
«ENDDEFINE»

«DEFINE initMethod FOR genmodel::GenPackage-»
	«EXPAND xpt::Common::generatedMemberComment»
	private void init«getNameToken(self)»() {
	}
«ENDDEFINE»

«DEFINE getRegistryMethod FOR gmfgen::DynamicModelAccess»
	«EXPAND xpt::Common::generatedMemberComment('Default implementation returns global registry, clients that need another may redefine.')»
	private static org.eclipse.emf.ecore.EPackage.Registry getRegistry() {
		return org.eclipse.emf.ecore.EPackage.Registry.INSTANCE;
	}
«ENDDEFINE»

Back to the top