Debian Codegraph @

plugins/org.eclipse.emf.codegen.ecore/templates/model/ResourceClass.javajet

raw
1 <%@ jet package="org.eclipse.emf.codegen.ecore.templates.model" imports="org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.codegen.ecore.genmodel.impl.* java.util.* org.eclipse.emf.ecore.EStructuralFeature org.eclipse.emf.ecore.util.*" class="ResourceClass"%>
2 <%
3 /**
4 * Copyright (c) 2002-2006 IBM Corporation and others.
5 * All rights reserved. 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 * http://www.eclipse.org/legal/epl-v20.html
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 */
13 %>
14 <%GenPackage genPackage = (GenPackage)argument; GenModel genModel=genPackage.getGenModel(); ExtendedMetaData extendedMetaData= genModel.getExtendedMetaData();%>
15 <%final boolean isJDK50 = genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50;%>
16 <%@ include file="../Header.javajetinc"%>
17 package <%=genPackage.getUtilitiesPackageName()%>;
18
19 <%genModel.getImportedName("org.eclipse.emf.common.util.URI");%>
20 <%genModel.markImportLocation(stringBuffer);%>
21
22 /**
23 * <!-- begin-user-doc -->
24 * The <b>Resource </b> associated with the package.
25 * <!-- end-user-doc -->
26 * @see <%=genPackage.getQualifiedResourceFactoryClassName()%>
27 <%if (genPackage.hasAPITags()) {%>
28 * <%=genPackage.getAPITags(genModel.getIndentation(stringBuffer))%>
29 <%}%>
30 * @generated
31 */
32 <%if (isJDK50 && genPackage.hasAPIDeprecatedTag()) {%>
33 @Deprecated
34 <%}%>
35 public class <%=genPackage.getResourceClassName()%> extends <%=genPackage.getImportedResourceBaseClassName()%>
36 {
37 <%if (genModel.hasCopyrightField()) {%>
38 /**
39 * <!-- begin-user-doc -->
40 * <!-- end-user-doc -->
41 * @generated
42 */
43 public static final <%=genModel.getImportedName("java.lang.String")%> copyright = <%=genModel.getCopyrightFieldLiteral()%>;<%=genModel.getNonNLS()%>
44
45 <%}%>
46 /**
47 * Creates an instance of the resource.
48 * <!-- begin-user-doc -->
49 * <!-- end-user-doc -->
50 * @param uri the URI of the new resource.
51 * @generated
52 */
53 public <%=genPackage.getResourceClassName()%>(URI uri)
54 {
55 super(uri);
56 <%if (genPackage.getResource() == GenResourceKind.XML_LITERAL) { // Do nothing%>
57 <%}%>
58 }
59
60 <%if (genPackage.isDataTypeConverters() && (genPackage.hasDocumentRoot() || org.eclipse.emf.ecore.xml.type.XMLTypePackage.eNS_URI.equals(genPackage.getNSURI()))) { boolean isXMLTypePackage = org.eclipse.emf.ecore.xml.type.XMLTypePackage.eNS_URI.equals(genPackage.getNSURI());%>
61 <%final String _Map = genModel.useGenerics() ? "Map<?, ?>" : "Map";%>
62 <%final String _MapStringBoolean = genModel.useGenerics() ? "Map<String, Boolean>" : "Map";%>
63 <%final String _MapStringWildcard = genModel.useGenerics() ? "Map<String, ?>" : "Map";%>
64 <%if (!isXMLTypePackage) {%>
65 <%genModel.getImportedName("org.eclipse.emf.ecore.xmi.XMLResource");%>
66 <%genModel.getImportedName("org.eclipse.emf.ecore.xmi.XMLParserPool");%>
67 <%genModel.getImportedName("org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl");%>
68 <%genModel.getImportedName("java.io.InputStream");%>
69 <%genModel.getImportedName("java.io.IOException");%>
70 <%genModel.getImportedName("org.eclipse.emf.ecore.EObject");%>
71 <%genModel.getImportedName("java.util.Collections");%>
72 <%genModel.getImportedName("java.util.HashMap");%>
73 <%genModel.getImportedName("java.util.Map");%>
74 <%genModel.getImportedName("org.xml.sax.InputSource");%>
75 <%genModel.getImportedName("javax.xml.parsers.SAXParser");%>
76 <%}%>
77 <%genModel.getImportedName("org.xml.sax.Attributes");%>
78 <%genModel.getImportedName("org.xml.sax.SAXException");%>
79 <%String _StackFrame = genModel.getImportedName("org.eclipse.emf.ecore.xml.type.util.XMLTypeResourceImpl")+".StackFrame";%>
80 <%String _DataFrame = genModel.getImportedName("org.eclipse.emf.ecore.xml.type.util.XMLTypeResourceImpl")+".DataFrame";%>
81 <%if (!isXMLTypePackage) {%>
82 /**
83 * A load option that turns of the use of the generate data converters.
84 * <!-- begin-user-doc -->
85 * <!-- end-user-doc -->
86 * @generated
87 */
88 public static final String OPTION_USE_DATA_CONVERTER = "USE_DATA_CONVERTER";
89
90 /**
91 * <!-- begin-user-doc -->
92 * <!-- end-user-doc -->
93 * @generated
94 */
95 <%if (genModel.useClassOverrideAnnotation()) {%>
96 @Override
97 <%}%>
98 public void doLoad(InputStream inputStream, <%=_Map%> options) throws IOException
99 {
100 if (options != null && Boolean.TRUE.equals(options.get(OPTION_USE_DATA_CONVERTER)))
101 {
102 getContents().add
103 (load
104 (new InputSource(inputStream),
105 (<%=_MapStringBoolean%>)options.get(XMLResource.OPTION_PARSER_FEATURES),
106 (<%=_MapStringWildcard%>)options.get(XMLResource.OPTION_PARSER_PROPERTIES),
107 Boolean.TRUE.equals(options.get(XMLResource.OPTION_USE_LEXICAL_HANDLER))).eContainer());
108 }
109 else
110 {
111 super.doLoad(inputStream, options);
112 }
113 }
114
115 /**
116 * <!-- begin-user-doc -->
117 * <!-- end-user-doc -->
118 * @generated
119 */
120 <%if (genModel.useClassOverrideAnnotation()) {%>
121 @Override
122 <%}%>
123 public void doLoad(InputSource inputSource, <%=_Map%> options) throws IOException
124 {
125 if (options != null && Boolean.TRUE.equals(options.get(OPTION_USE_DATA_CONVERTER)))
126 {
127 getContents().add
128 (load
129 (inputSource,
130 (<%=_MapStringBoolean%>)options.get(XMLResource.OPTION_PARSER_FEATURES),
131 (<%=_MapStringWildcard%>)options.get(XMLResource.OPTION_PARSER_PROPERTIES),
132 Boolean.TRUE.equals(options.get(XMLResource.OPTION_USE_LEXICAL_HANDLER))).eContainer());
133 }
134 else
135 {
136 super.doLoad(inputSource, options);
137 }
138 }
139
140 /**
141 * <!-- begin-user-doc -->
142 * <!-- end-user-doc -->
143 * @generated
144 */
145 protected static final XMLParserPool parserPool = new XMLParserPoolImpl();
146
147 /**
148 * Loads an instance from the input.
149 * <!-- begin-user-doc -->
150 * <!-- end-user-doc -->
151 * @param inputSource the input from which to load.
152 * @param features a map of the parser features and their values.
153 * @param properties a map of a parser properties and their values.
154 * @param useLexicalHandler whether a lexical handler should be used during loading.
155 * @return the root object; for the case of a document root, the child of that document root is return.
156 * @throws ParserConfigurationException
157 * @throws SAXException
158 * @generated
159 */
160 public static EObject load(InputSource inputSource, <%=_MapStringBoolean%> features, <%=_MapStringWildcard%> properties, boolean useLexicalHandler) throws IOException
161 {
162 <%=_MapStringBoolean%> requiredFeatures = new <%=_MapStringBoolean.replace("Map","HashMap")%>();
163 requiredFeatures.put("http://xml.org/sax/features/namespaces", Boolean.TRUE);
164 if (features != null)
165 {
166 requiredFeatures.putAll(features);
167 }
168
169 if (properties == null)
170 {
171 properties = Collections.<%if (genModel.useGenerics()) {%>emptyMap()<%} else {%>EMPTY_MAP<%}%>;
172 }
173
174 SAXParser saxParser = null;
175 try
176 {
177 saxParser = parserPool.get(requiredFeatures, properties, useLexicalHandler);
178 final FrameFactory.DocumentRootStackFrame documentRoot = FrameFactory.INSTANCE.pushDocumentRoot(null, null);
179 XMLTypeResourceImpl.Handler handler = new XMLTypeResourceImpl.Handler(documentRoot);
180 saxParser.parse(inputSource, handler);
181 <%if (genModel.isSuppressEMFTypes()) {%>
182 return (EObject)((EObject)FrameFactory.INSTANCE.popDocumentRoot(documentRoot)).eContents().get(0);
183 <%} else {%>
184 return FrameFactory.INSTANCE.popDocumentRoot(documentRoot).eContents().get(0);
185 <%}%>
186 }
187 catch (Exception exception)
188 {
189 throw new IOWrappedException(exception);
190 }
191 finally
192 {
193 parserPool.release(saxParser, requiredFeatures, properties, useLexicalHandler);
194 }
195 }
196
197 <%}%>
198 /**
199 * <!-- begin-user-doc -->
200 * <!-- end-user-doc -->
201 * @generated
202 */
203 public final static class FrameFactory
204 {
205 /**
206 * <!-- begin-user-doc -->
207 * <!-- end-user-doc -->
208 * @generated
209 */
210 public static final FrameFactory INSTANCE = new FrameFactory();
211
212 <%for (GenClass genClass : genPackage.getGenClasses()) {%>
213 /**
214 * <!-- begin-user-doc -->
215 * <!-- end-user-doc -->
216 * @generated
217 */
218 protected <%=genClass.getName()%>StackFrame <%=genClass.getSafeUncapName()%>;
219
220 <%}%>
221 <%for (GenDataType genDataType : genPackage.getAllGenDataTypes()) {%>
222 /**
223 * <!-- begin-user-doc -->
224 * <!-- end-user-doc -->
225 * @generated
226 */
227 protected <%=_DataFrame%> <%=genDataType.getSafeUncapName()%>;
228
229 <%}%>
230 <%for (GenClass genClass : genPackage.getGenClasses()) {%>
231 <%List<EStructuralFeature> attributes = extendedMetaData.getAllAttributes(genClass.getEcoreClass());%>
232 <%List<EStructuralFeature> elements = extendedMetaData.getAllElements(genClass.getEcoreClass());%>
233 /**
234 * <!-- begin-user-doc -->
235 * <!-- end-user-doc -->
236 * @generated
237 */
238 public <%=genClass.getName()%>StackFrame push<%=genClass.getName()%>(<%=_StackFrame%> previous, Attributes attributes)
239 {
240 <%=genClass.getName()%>StackFrame result<%=genClass.getName()%> = <%=genClass.getSafeUncapName()%> == null ? new <%=genClass.getName()%>StackFrame() : <%=genClass.getSafeUncapName()%>;
241 <%=genClass.getSafeUncapName()%> = null;
242 result<%=genClass.getName()%>.pushOnto(previous);
243 result<%=genClass.getName()%>.handleAttributes(attributes);
244 return result<%=genClass.getName()%>;
245 }
246
247 /**
248 * <!-- begin-user-doc -->
249 * <!-- end-user-doc -->
250 * @generated
251 */
252 public <%=genClass.getImportedInterfaceName()%> pop<%=genClass.getName()%>(<%=genClass.getName()%>StackFrame <%=genClass.getSafeUncapName()%>)
253 {
254 <%=genClass.getImportedInterfaceName()%> result<%=genClass.getName()%>Value = <%=genClass.getSafeUncapName()%>.pop<%=genClass.getName()%>();
255 this.<%=genClass.getSafeUncapName()%> = <%=genClass.getSafeUncapName()%>;
256 return result<%=genClass.getName()%>Value;
257 }
258
259 /**
260 * <!-- begin-user-doc -->
261 * <!-- end-user-doc -->
262 * @generated
263 */
264 public static class <%=genClass.getName()%>StackFrame extends <%=_StackFrame%>
265 {
266 /**
267 * <!-- begin-user-doc -->
268 * <!-- end-user-doc -->
269 * @generated
270 */
271 protected <%=genClass.getImportedInterfaceName()%> the<%=genClass.getName()%>;
272
273 <%for (GenFeature genFeature : genClass.getAllGenFeatures()) {%>
274 <%String name = extendedMetaData.getName(genFeature.getEcoreFeature());%>
275 <%if ((elements.contains(genFeature.getEcoreFeature()) || attributes.contains(genFeature.getEcoreFeature())) && name.indexOf(":") == -1) {%>
276 <%if (genFeature.isReferenceType()) {%>
277 /**
278 * <!-- begin-user-doc -->
279 * <!-- end-user-doc -->
280 * @generated
281 */
282 protected <%=genFeature.getTypeGenClass().getGenPackage().getImportedResourceClassName()%>.FrameFactory.<%=genFeature.getTypeGenClass().getName()%>StackFrame <%=genFeature.getSafeName()%>;
283
284 <%} else {%>
285 /**
286 * <!-- begin-user-doc -->
287 * <!-- end-user-doc -->
288 * @generated
289 */
290 protected <%=_DataFrame%> <%=genFeature.getSafeName()%>;
291
292 <%}%>
293 <%}%>
294 <%}%>
295 /**
296 * <!-- begin-user-doc -->
297 * <!-- end-user-doc -->
298 * @generated
299 */
300 <%if (genModel.useClassOverrideAnnotation()) {%>
301 @Override
302 <%}%>
303 public void handleAttributes(Attributes attributes)
304 {
305 <%int count = 0; for (GenFeature genFeature : genClass.getAllGenFeatures()) {%>
306 <%String name = extendedMetaData.getName(genFeature.getEcoreFeature());%>
307 <%if (attributes.contains(genFeature.getEcoreFeature()) && !genFeature.isDerived() && name.indexOf(":") == -1) {%>
308 <%String namespace = Literals.toStringLiteral(extendedMetaData.getNamespace(genFeature.getEcoreFeature()), genModel); if ("null".equals(namespace)) namespace = "\"\"";%>
309 <%if (!genFeature.isReferenceType()) { GenClassifier genClassifier = genFeature.getTypeGenClassifier();%>
310 <%if (count++ == 0) {%>
311 String theValue = attributes.getValue(<%=namespace%>, "<%=name%>");
312 <%} else {%>
313 theValue = attributes.getValue(<%=namespace%>, "<%=name%>");
314 <%}%>
315 if (theValue != null)
316 {
317 <%if (genClassifier.getGenPackage().isDataTypeConverters()) {%>
318 the<%=genClass.getName()%>.set<%=genFeature.getAccessorName()%>(<%=genClassifier.getGenPackage().getQualifiedFactoryInstanceAccessor()%>.create<%=genClassifier.getName()%>(theValue));
319 <%} else {%>
320 the<%=genClass.getName()%>.set<%=genFeature.getAccessorName()%>((<%=genFeature.getImportedType(null)%>)<%=genClassifier.getGenPackage().getQualifiedEFactoryInstanceAccessor()%>.createFromString(<%=genClassifier.getQualifiedClassifierAccessor()%>, theValue));
321 <%}%>
322 }
323 <%}%>
324 <%}%>
325 <%}%>
326 <%if (count == 0) {%>
327 // There are attributes to handle.
328 <%}%>
329 }
330
331 /**
332 * <!-- begin-user-doc -->
333 * <!-- end-user-doc -->
334 * @generated
335 */
336 <%if (genModel.useClassOverrideAnnotation()) {%>
337 @Override
338 <%}%>
339 public <%=_StackFrame%> startElement(String namespace, String localName, String qName, Attributes attributes) throws SAXException
340 {
341 <%count = 0; for (GenFeature genFeature : genClass.getAllGenFeatures()) {%>
342 <%String name = extendedMetaData.getName(genFeature.getEcoreFeature());%>
343 <%if (elements.contains(genFeature.getEcoreFeature()) && name.indexOf(":") == -1) {%>
344 <%String namespace = Literals.toStringLiteral(extendedMetaData.getNamespace(genFeature.getEcoreFeature()), genModel); if ("null".equals(namespace)) namespace = "\"\"";%>
345 <%if (count++ != 0) {%>else <%}%>if ("<%=name%>".equals(localName) && <%=namespace%>.equals(namespace))
346 {
347 return <%=genFeature.getSafeName()%> = <%=genFeature.getTypeGenClassifier().getGenPackage().getImportedResourceClassName()%>.FrameFactory.INSTANCE.push<%=genFeature.getTypeGenClassifier().getName()%>(this, attributes);
348 }
349 <%}%>
350 <%}%>
351 <%if (count == 0) {%>
352 return super.startElement(namespace, localName, qName, attributes);
353 <%} else {%>
354 else
355 {
356 return super.startElement(namespace, localName, qName, attributes);
357 }
358 <%}%>
359 }
360
361 /**
362 * <!-- begin-user-doc -->
363 * <!-- end-user-doc -->
364 * @generated
365 */
366 <%if (genModel.useClassOverrideAnnotation()) {%>
367 @Override
368 <%}%>
369 public void endElement(<%=_StackFrame%> child) throws SAXException
370 {
371 <%count = 0; for (GenFeature genFeature : genClass.getAllGenFeatures()) {%>
372 <%String name = extendedMetaData.getName(genFeature.getEcoreFeature());%>
373 <%if (elements.contains(genFeature.getEcoreFeature()) && name.indexOf(":") == -1) {%>
374 <%if (count++ != 0) {%>else <%}%>if (child == <%=genFeature.getSafeName()%>)
375 {
376 <%if (genFeature.isListType()) {%>
377 the<%=genClass.getName()%>.<%=genFeature.getGetAccessor()%>().add(<%=genFeature.getTypeGenClassifier().getGenPackage().getImportedResourceClassName()%>.FrameFactory.INSTANCE.pop<%=genFeature.getTypeGenClassifier().getName()%>(<%=genFeature.getSafeName()%>));
378 <%} else {%>
379 the<%=genClass.getName()%>.set<%=genFeature.getAccessorName()%>(<%=genFeature.getTypeGenClassifier().getGenPackage().getImportedResourceClassName()%>.FrameFactory.INSTANCE.pop<%=genFeature.getTypeGenClassifier().getName()%>(<%=genFeature.getSafeName()%>));
380 <%}%>
381 <%=genFeature.getSafeName()%> = null;
382 }
383 <%}%>
384 <%}%>
385 <%if (count == 0) {%>
386 super.endElement(child);
387 <%} else {%>
388 else
389 {
390 super.endElement(child);
391 }
392 <%}%>
393 }
394
395 /**
396 * <!-- begin-user-doc -->
397 * <!-- end-user-doc -->
398 * @generated
399 */
400 <%if (genModel.useClassOverrideAnnotation()) {%>
401 @Override
402 <%}%>
403 public void create()
404 {
405 the<%=genClass.getName()%> = <%=genPackage.getQualifiedFactoryInstanceAccessor()%>.create<%=genClass.getName()%>();
406 }
407
408 /**
409 * <!-- begin-user-doc -->
410 * <!-- end-user-doc -->
411 * @generated
412 */
413 protected <%=genClass.getImportedInterfaceName()%> pop<%=genClass.getName()%>()
414 {
415 pop();
416 <%=genClass.getImportedInterfaceName()%> result<%=genClass.getName()%>Value = the<%=genClass.getName()%>;
417 the<%=genClass.getName()%> = null;
418 return result<%=genClass.getName()%>Value;
419 }
420
421 }
422
423 <%}%>
424 <%for (GenDataType genDataType : genPackage.getAllGenDataTypes()) {%>
425 /**
426 * <!-- begin-user-doc -->
427 * <!-- end-user-doc -->
428 * @generated
429 */
430 public <%=_DataFrame%> push<%=genDataType.getName()%>(<%=_StackFrame%> previous, Attributes attributes)
431 {
432 <%=_DataFrame%> result<%=genDataType.getName()%> = <%=genDataType.getSafeUncapName()%> == null ? new <%=_DataFrame%>() : <%=genDataType.getSafeUncapName()%>;
433 <%=genDataType.getSafeUncapName()%> = null;
434 result<%=genDataType.getName()%>.pushOnto(previous);
435 result<%=genDataType.getName()%>.handleAttributes(attributes);
436 return result<%=genDataType.getName()%>;
437 }
438
439 /**
440 * <!-- begin-user-doc -->
441 * <!-- end-user-doc -->
442 * @generated
443 */
444 public <%=genDataType.getImportedParameterizedInstanceClassName()%> pop<%=genDataType.getName()%>(<%=_DataFrame%> <%=genDataType.getSafeUncapName()%>)
445 {
446 <%if (genDataType.getGenPackage().isDataTypeConverters()) {%>
447 <%=genDataType.getImportedParameterizedInstanceClassName()%> result<%=genDataType.getName()%>Value = <%=genDataType.getGenPackage().getQualifiedFactoryInstanceAccessor()%>.create<%=genDataType.getName()%>(<%=genDataType.getSafeUncapName()%>.popValue());
448 <%} else if (genDataType.isPrimitiveType() && genModel.getComplianceLevel().getValue() < GenJDKLevel.JDK50) {%>
449 <%=genDataType.getImportedInstanceClassName()%> result<%=genDataType.getName()%>Value = ((<%=genDataType.getObjectInstanceClassName()%>)<%=genDataType.getGenPackage().getQualifiedEFactoryInstanceAccessor()%>.createFromString(<%=genDataType.getQualifiedClassifierAccessor()%>, <%=genDataType.getSafeUncapName()%>.popValue())).<%=genDataType.getPrimitiveValueFunction()%>();
450 <%} else {%>
451 <%=genDataType.getImportedInstanceClassName()%> result<%=genDataType.getName()%>Value = (<%=genDataType.getObjectInstanceClassName()%>)<%=genDataType.getGenPackage().getQualifiedEFactoryInstanceAccessor()%>.createFromString(<%=genDataType.getQualifiedClassifierAccessor()%>, <%=genDataType.getSafeUncapName()%>.popValue());
452 <%}%>
453 this.<%=genDataType.getSafeUncapName()%> = <%=genDataType.getSafeUncapName()%>;
454 return result<%=genDataType.getName()%>Value;
455 }
456
457 <%}%>
458 }
459
460 <%}%>
461 } //<%=genPackage.getResourceClassName()%>
462 <%genModel.emitSortedImports();%>