diff options
Diffstat (limited to 'extraplugins/facade/org.eclipse.papyrus.facade.codegen/src-templates/org/eclipse/papyrus/facade/codegen/genfacade/ResourceClass.mtl')
-rw-r--r-- | extraplugins/facade/org.eclipse.papyrus.facade.codegen/src-templates/org/eclipse/papyrus/facade/codegen/genfacade/ResourceClass.mtl | 536 |
1 files changed, 536 insertions, 0 deletions
diff --git a/extraplugins/facade/org.eclipse.papyrus.facade.codegen/src-templates/org/eclipse/papyrus/facade/codegen/genfacade/ResourceClass.mtl b/extraplugins/facade/org.eclipse.papyrus.facade.codegen/src-templates/org/eclipse/papyrus/facade/codegen/genfacade/ResourceClass.mtl new file mode 100644 index 00000000000..5db46f61e88 --- /dev/null +++ b/extraplugins/facade/org.eclipse.papyrus.facade.codegen/src-templates/org/eclipse/papyrus/facade/codegen/genfacade/ResourceClass.mtl @@ -0,0 +1,536 @@ +[comment]Copyright (c) 2013 CEA LIST. + +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: + Obeo - Initial API and implementation + CEA LIST - Modification to support Facade code generation[/comment] +[comment encoding = UTF-8 /] +[module ResourceClass('http://www.eclipse.org/emf/2002/GenModel', 'http://www.eclipse.org/emf/2002/Ecore')/] + +[import org::eclipse::emf::eef::codegen::ecore::services::common /] +[import org::eclipse::emf::eef::codegen::ecore::services::header /] +[import org::eclipse::emf::eef::codegen::ecore::services::wrappers::GenModel /] +[import org::eclipse::emf::eef::codegen::ecore::services::wrappers::GenPackage /] +[import org::eclipse::emf::eef::codegen::ecore::services::wrappers::GenClass /] +[import org::eclipse::emf::eef::codegen::ecore::services::wrappers::GenClassifier /] +[import org::eclipse::emf::eef::codegen::ecore::services::wrappers::GenFeature /] +[import org::eclipse::emf::eef::codegen::ecore::services::wrappers::GenDataType /] +[import org::eclipse::emf::eef::codegen::ecore::services::StringUtil /] + +[comment] +/** + * <copyright> + * + * Copyright (c) 2002-2006 IBM Corporation and others. + * 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: + * IBM - Initial API and implementation + * + * </copyright> + */ +[/comment] + +[template public resourceClass(genPackage : GenPackage) { genModel : GenModel = genPackage.genModel; packageName : String = genPackage.getUtilitiesPackageName(); className : String = genPackage.getResourceClassName();} ] +[genModel.initializeImportManager(packageName, className)/] + +[genModel.getImportedName('org.eclipse.emf.common.util.URI')/] + +[file (genPackage.resourceClassPath(), false, 'UTF-8')] +[genModel.includeHeader()/] +package [packageName/]; +[let content : String = genPackage.resourceFileContent(genModel, className)] +[genModel.genSortedImports()/] +[content/] +[/let] +[/file] +[/template] + +[template protected resourceFileContent(genPackage : GenPackage, genModel : GenModel, className : String)] +/** + * <!-- begin-user-doc --> + * The <b>Resource </b> associated with the package. + * <!-- end-user-doc --> + * @see [genPackage.getQualifiedResourceFactoryClassName()/] + * @generated + */ +public class [className/] extends [genPackage.getImportedResourceBaseClassName()/] +{ + private [genModel.getImportedName('org.eclipse.emf.ecore.resource.Resource')/] resUML; + + @Override + public void doLoad([genModel.getImportedName('java.io.InputStream')/] inputStream, [genModel.getImportedName('java.util.Map')/]<?, ?> options) throws [genModel.getImportedName('java.io.IOException')/] { + resUML = [genModel.getImportedName(genPackage.getUtilitiesPackageName()+'.Loader')/].doLoad(inputStream, options, [genModel.getImportedName(genPackage.getImportedFactoryInterfaceName())/].eINSTANCE, this); + } + + @Override + public void doSave([genModel.getImportedName('java.io.OutputStream')/] outputStream, [genModel.getImportedName('java.util.Map')/]<?, ?> options) throws [genModel.getImportedName('java.io.IOException')/] { + if(resUML != null) { + resUML.save(options); + } + [genModel.getImportedName('java.io.PrintStream')/] stream = new [genModel.getImportedName('java.io.PrintStream')/](outputStream); + stream.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); + String uri = resUML.getURI().toString(); + stream.println("<source uri=\"" + uri + "\"/>"); + } + +[if (genModel.hasCopyrightField())] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final [genModel.getImportedName('java.lang.String')/] copyright = [genModel.getCopyrightFieldLiteral()/];[genModel.getNonNLS()/] + +[/if] + /** + * Creates an instance of the resource. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param uri the URI of the new resource. + * @generated + */ + public [className/](URI uri) + { + super(uri); +[if (genPackage.getResource() = GenResourceKind::XML)][comment Do nothing/] +[/if] + } + +[if (genPackage.dataTypeConverters and (genPackage.hasDocumentRoot() or genPackage.isXMLTypePackage()))] +[let _Map : String = if (genModel.useGenerics()) then 'Map<?, ?>' else 'Map' endif] +[let _MapStringBoolean : String = if (genModel.useGenerics()) then 'Map<String, Boolean>' else 'Map' endif] +[let _MapStringWildcard : String = if (genModel.useGenerics()) then 'Map<String, ?>' else 'Map' endif] +[comment || 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());%>/] + [if (not genPackage.isXMLTypePackage())] +[genModel.getImportedName('org.eclipse.emf.ecore.xmi.XMLResource')/] +[genModel.getImportedName('org.eclipse.emf.ecore.xmi.XMLParserPool')/] +[genModel.getImportedName('org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl')/] +[genModel.getImportedName('java.io.InputStream')/] +[genModel.getImportedName('java.io.IOException')/] +[genModel.getImportedName('org.eclipse.emf.ecore.EObject')/] +[genModel.getImportedName('java.util.Collections')/] +[genModel.getImportedName('java.util.HashMap')/] +[genModel.getImportedName('java.util.Map')/] +[genModel.getImportedName('org.xml.sax.InputSource')/] +[genModel.getImportedName('javax.xml.parsers.SAXParser')/] + [/if] +[genModel.getImportedName('org.xml.sax.Attributes')/] +[genModel.getImportedName('org.xml.sax.SAXException')/] +[let _StackFrame : String = genModel.getImportedName('org.eclipse.emf.ecore.xml.type.util.XMLTypeResourceImpl') + '.StackFrame'] +[let _DataFrame : String = genModel.getImportedName('org.eclipse.emf.ecore.xml.type.util.XMLTypeResourceImpl') + '.DataFrame'] + [if (not genPackage.isXMLTypePackage())] + /** + * A load option that turns of the use of the generate data converters. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String OPTION_USE_DATA_CONVERTER = "USE_DATA_CONVERTER"; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + [if (genModel.useClassOverrideAnnotation())] + @Override + [/if] + public void doLoad(InputStream inputStream, [_Map/] options) throws IOException + { + if (options != null && Boolean.TRUE.equals(options.get(OPTION_USE_DATA_CONVERTER))) + { + getContents().add + (load + (new InputSource(inputStream), + ([_MapStringBoolean/])options.get(XMLResource.OPTION_PARSER_FEATURES), + ([_MapStringWildcard/])options.get(XMLResource.OPTION_PARSER_PROPERTIES), + Boolean.TRUE.equals(options.get(XMLResource.OPTION_USE_LEXICAL_HANDLER))).eContainer()); + } + else + { + super.doLoad(inputStream, options); + } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + [if (genModel.useClassOverrideAnnotation())] + @Override + [/if] + public void doLoad(InputSource inputSource, [_Map/] options) throws IOException + { + if (options != null && Boolean.TRUE.equals(options.get(OPTION_USE_DATA_CONVERTER))) + { + getContents().add + (load + (inputSource, + ([_MapStringBoolean/])options.get(XMLResource.OPTION_PARSER_FEATURES), + ([_MapStringWildcard/])options.get(XMLResource.OPTION_PARSER_PROPERTIES), + Boolean.TRUE.equals(options.get(XMLResource.OPTION_USE_LEXICAL_HANDLER))).eContainer()); + } + else + { + super.doLoad(inputSource, options); + } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected static final XMLParserPool parserPool = new XMLParserPoolImpl(); + + /** + * Loads an instance from the input. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param inputSource the input from which to load. + * @param features a map of the parser features and their values. + * @param properties a map of a parser properties and their values. + * @param useLexicalHandler whether a lexical handler should be used during loading. + * @return the root object; for the case of a document root, the child of that document root is return. + * @throws ParserConfigurationException + * @throws SAXException + * @generated + */ + public static EObject load(InputSource inputSource, [_MapStringBoolean/] features, [_MapStringWildcard/] properties, boolean useLexicalHandler) throws IOException + { + [_MapStringBoolean/] requiredFeatures = new [_MapStringBoolean.replaceAll('Map','HashMap')/](); + requiredFeatures.put("http://xml.org/sax/features/namespaces", Boolean.TRUE); + if (features != null) + { + requiredFeatures.putAll(features); + } + + if (properties == null) + { + properties = Collections.[if (genModel.useGenerics())]emptyMap()[else]EMPTY_MAP[/if]; + } + + SAXParser saxParser = null; + try + { + saxParser = parserPool.get(requiredFeatures, properties, useLexicalHandler); + final FrameFactory.DocumentRootStackFrame documentRoot = FrameFactory.INSTANCE.pushDocumentRoot(null, null); + XMLTypeResourceImpl.Handler handler = new XMLTypeResourceImpl.Handler(documentRoot); + saxParser.parse(inputSource, handler); + [if (genModel.suppressEMFTypes)] + return (EObject)((EObject)FrameFactory.INSTANCE.popDocumentRoot(documentRoot)).eContents().get(0); + [else] + return FrameFactory.INSTANCE.popDocumentRoot(documentRoot).eContents().get(0); + [/if] + } + catch (Exception exception) + { + throw new IOWrappedException(exception); + } + finally + { + parserPool.release(saxParser, requiredFeatures, properties, useLexicalHandler); + } + } + + [/if] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public final static class FrameFactory + { + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final FrameFactory INSTANCE = new FrameFactory(); + + [for (genClass : GenClass | genPackage.genClasses)] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected [genClass.getName()/]StackFrame [genClass.getSafeUncapName()/]; + + [/for] + [for (genDataType : GenDataType | genPackage.getAllGenDataTypes())] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected [_DataFrame/] [genDataType.getSafeUncapName()/]; + + [/for] + [for (genClass : GenClass | genPackage.genClasses)] + [let attributes : Sequence(EStructuralFeature) = genModel.getAllExtendedMetaDataAttributes(genClass.ecoreClass)] + [let elements : Sequence(EStructuralFeature) = genModel.getAllExtendedMetaDataElements(genClass.ecoreClass)] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public [genClass.getName()/]StackFrame push[genClass.getName()/]([_StackFrame/] previous, Attributes attributes) + { + [genClass.getName()/]StackFrame result[genClass.getName()/] = [genClass.getSafeUncapName()/] == null ? new [genClass.getName()/]StackFrame() : [genClass.getSafeUncapName()/]; + [genClass.getSafeUncapName()/] = null; + result[genClass.getName()/].pushOnto(previous); + result[genClass.getName()/].handleAttributes(attributes); + return result[genClass.getName()/]; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public [genClass.getImportedInterfaceName()/] pop[genClass.getName()/]([genClass.getName()/]StackFrame [genClass.getSafeUncapName()/]) + { + [genClass.getImportedInterfaceName()/] result[genClass.getName()/]Value = [genClass.getSafeUncapName()/].pop[genClass.getName()/](); + this.[genClass.getSafeUncapName()/] = [genClass.getSafeUncapName()/]; + return result[genClass.getName()/]Value; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static class [genClass.getName()/]StackFrame extends [_StackFrame/] + { + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected [genClass.getImportedInterfaceName()/] the[genClass.getName()/]; + + [for (genFeature : GenFeature | genClass.getAllGenFeatures())] + [let name : String = genModel.getExtendedMetaDataName(genFeature.ecoreFeature)] + [if ((elements->includes(genFeature.ecoreFeature) or attributes->includes(genFeature.ecoreFeature)) and name.index(':') < 0)] + [if (genFeature.isReferenceType())] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected [genFeature.getTypeGenClass().genPackage.getImportedResourceClassName()/].FrameFactory.[genFeature.getTypeGenClass().getName()/]StackFrame [genFeature.getSafeName()/]; + + [else] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected [_DataFrame/] [genFeature.getSafeName()/]; + + [/if] + [/if] + [/let] + [/for] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + [if (genModel.useClassOverrideAnnotation())] + @Override + [/if] + public void handleAttributes(Attributes attributes) + { + [comment int count = 0; for (GenFeature genFeature : genClass.getAllGenFeatures()) /] + [let featuresToHandle : Sequence(GenFeature) = genClass.getAllGenFeatures()->filter(GenFeature) + ->select(f : GenFeature| attributes->includes(f.ecoreFeature) + and not f.isDerived() + and genModel.getExtendedMetaDataName(f.ecoreFeature).index(':') < 0 + and not f.isReferenceType())] + [for (genFeature : GenFeature | featuresToHandle)] + [let name : String = genModel.getExtendedMetaDataName(genFeature.ecoreFeature)] + [let namespace : String = genModel.getExtendedMetaDataNamespaceAsLiteral(genFeature.ecoreFeature)] + [let genClassifier : GenClassifier = genFeature.getTypeGenClassifier()] + [if (i = 0)] + String theValue = attributes.getValue([namespace/], "[name/]"); + [else] + theValue = attributes.getValue([namespace/], "[name/]"); + [/if] + if (theValue != null) + { + [if (genClassifier.genPackage.dataTypeConverters)] + the[genClass.getName()/].set[genFeature.getAccessorName()/]([genClassifier.genPackage.getQualifiedFactoryInstanceAccessor()/].create[genClassifier.getName()/](theValue)); + [else] + the[genClass.getName()/].set[genFeature.getAccessorName()/](([genFeature.getImportedType(null)/])[genClassifier.genPackage.getQualifiedEFactoryInstanceAccessor()/].createFromString([genClassifier.getQualifiedClassifierAccessor()/], theValue)); + [/if] + } + [/let] + [/let] + [/let] + [/for] + [if (featuresToHandle->isEmpty())] + // There are attributes to handle. + [/if] + [/let] + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + [if (genModel.useClassOverrideAnnotation())] + @Override + [/if] + public [_StackFrame/] startElement(String namespace, String localName, String qName, Attributes attributes) throws SAXException + { + [let featuresToHandle : Sequence(GenFeature) = genClass.getAllGenFeatures()->filter(GenFeature) + ->select(f : GenFeature | elements->includes(f.ecoreFeature) + and genModel.getExtendedMetaDataName(f.ecoreFeature).index(':') < 0)] + [for (genFeature : GenFeature | featuresToHandle)] + [let name : String = genModel.getExtendedMetaDataName(genFeature.ecoreFeature)] + [let namespace : String = genModel.getExtendedMetaDataNamespaceAsLiteral(genFeature.ecoreFeature)] + [if (i > 0)]else [/if]if ("[name/]".equals(localName) && [namespace/].equals(namespace)) + { + return [genFeature.getSafeName()/] = [genFeature.getTypeGenClassifier().genPackage.getImportedResourceClassName()/].FrameFactory.INSTANCE.push[genFeature.getTypeGenClassifier().getName()/](this, attributes); + } + [/let] + [/let] + [/for] + [if (featuresToHandle->isEmpty())] + return super.startElement(namespace, localName, qName, attributes); + [else] + else + { + return super.startElement(namespace, localName, qName, attributes); + } + [/if] + [/let] + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + [if (genModel.useClassOverrideAnnotation())] + @Override + [/if] + public void endElement([_StackFrame/] child) throws SAXException + { + [let featuresToHandle : Sequence(GenFeature) = genClass.getAllGenFeatures()->filter(GenFeature) + ->select(f : GenFeature | elements->includes(f.ecoreFeature) + and genModel.getExtendedMetaDataName(f.ecoreFeature).index(':') < 0)] + [for (genFeature : GenFeature | featuresToHandle)] + [let name : String = genModel.getExtendedMetaDataName(genFeature.ecoreFeature)] + [if (i > 0)]else [/if]if (child == [genFeature.getSafeName()/]) + { + [if (genFeature.isListType())] + the[genClass.getName()/].[genFeature.getGetAccessor()/]().add([genFeature.getTypeGenClassifier().genPackage.getImportedResourceClassName()/].FrameFactory.INSTANCE.pop[genFeature.getTypeGenClassifier().getName()/]([genFeature.getSafeName()/])); + [else] + the[genClass.getName()/].set[genFeature.getAccessorName()/]([genFeature.getTypeGenClassifier().genPackage.getImportedResourceClassName()/].FrameFactory.INSTANCE.pop[genFeature.getTypeGenClassifier().getName()/]([genFeature.getSafeName()/])); + [/if] + [genFeature.getSafeName()/] = null; + } + [/let] + [/for] + [if (featuresToHandle->isEmpty())] + super.endElement(child); + [else] + else + { + super.endElement(child); + } + [/if] + [/let] + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + [if (genModel.useClassOverrideAnnotation())] + @Override + [/if] + public void create() + { + the[genClass.getName()/] = [genPackage.getQualifiedFactoryInstanceAccessor()/].create[genClass.getName()/](); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected [genClass.getImportedInterfaceName()/] pop[genClass.getName()/]() + { + pop(); + [genClass.getImportedInterfaceName()/] result[genClass.getName()/]Value = the[genClass.getName()/]; + the[genClass.getName()/] = null; + return result[genClass.getName()/]Value; + } + + } + + [/let] + [/let] + [/for] + [for (genDataType : GenDataType | genPackage.getAllGenDataTypes())] + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public [_DataFrame/] push[genDataType.getName()/]([_StackFrame/] previous, Attributes attributes) + { + [_DataFrame/] result[genDataType.getName()/] = [genDataType.getSafeUncapName()/] == null ? new [_DataFrame/]() : [genDataType.getSafeUncapName()/]; + [genDataType.getSafeUncapName()/] = null; + result[genDataType.getName()/].pushOnto(previous); + result[genDataType.getName()/].handleAttributes(attributes); + return result[genDataType.getName()/]; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public [genDataType.getImportedParameterizedInstanceClassName()/] pop[genDataType.getName()/]([_DataFrame/] [genDataType.getSafeUncapName()/]) + { + [if (genDataType.genPackage.dataTypeConverters)] + [genDataType.getImportedParameterizedInstanceClassName()/] result[genDataType.getName()/]Value = [genDataType.genPackage.getQualifiedFactoryInstanceAccessor()/].create[genDataType.getName()/]([genDataType.getSafeUncapName()/].popValue()); + [else][if (genDataType.isPrimitiveType() and not genModel.isJDK50())] + [genDataType.getImportedInstanceClassName()/] result[genDataType.getName()/]Value = (([genDataType.getObjectInstanceClassName()/])[genDataType.genPackage.getQualifiedEFactoryInstanceAccessor()/].createFromString([genDataType.getQualifiedClassifierAccessor()/], [genDataType.getSafeUncapName()/].popValue())).[genDataType.getPrimitiveValueFunction()/](); + [else] + [genDataType.getImportedInstanceClassName()/] result[genDataType.getName()/]Value = ([genDataType.getObjectInstanceClassName()/])[genDataType.genPackage.getQualifiedEFactoryInstanceAccessor()/].createFromString([genDataType.getQualifiedClassifierAccessor()/], [genDataType.getSafeUncapName()/].popValue()); + [/if][/if] + this.[genDataType.getSafeUncapName()/] = [genDataType.getSafeUncapName()/]; + return result[genDataType.getName()/]Value; + } + + [/for] + } + +[/let] +[/let] +[/let] +[/let] +[/let] +[/if] +} //[className/] +[/template] + +[query public resourceClassPath(genPackage : GenPackage) : String + = genPackage.genModel.extractSourceDirectory(genPackage.genModel.modelDirectory) + '/' + + genPackage.getQualifiedResourceClassName().toPath() + '.java'/] |