%@ jet package="org.apache.tuscany.sdo.generate.templates.model" imports="org.apache.tuscany.sdo.generate.util.* java.util.* org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.ecore.* org.eclipse.emf.codegen.ecore.genmodel.impl.Literals org.eclipse.emf.ecore.util.*" class="SDOFactoryClass" version="$Id: SDOFactoryClass.javajet,v 1.23 2005/12/10 13:31:02 emerks Exp $" %>
<%
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
%>
<%GenPackage genPackage = (GenPackage)((Object[])argument)[0]; GenModel genModel=genPackage.getGenModel();%>
<%boolean isInterface = Boolean.TRUE.equals(((Object[])argument)[1]); boolean isImplementation = Boolean.TRUE.equals(((Object[])argument)[2]);%>
<%String publicStaticFinalFlag = isImplementation ? "public static final " : "";%>
<%@ include file="../Header.javajetinc"%>
<%if (isInterface || genModel.isSuppressInterfaces()) {%>
package <%=genPackage.getReflectionPackageName()%>;
<%} else {%>
package <%=genPackage.getClassPackageName()%>;
<%}%>
<%if (isImplementation) {%>
<%if (!genPackage.hasJavaLangConflict() && !genPackage.hasInterfaceImplConflict() && !genPackage.getClassPackageName().equals(genPackage.getInterfacePackageName())) genModel.addImport(genPackage.getInterfacePackageName() + ".*");%>
<%}%>
<%genModel.markImportLocation(stringBuffer);%>
<%if (isInterface) {%>
/**
*
* The Factory for the model.
* It provides a create method for each non-abstract class of the model.
*
<%if (!genModel.isSuppressEMFMetaData()) {%>
* @see <%=genPackage.getQualifiedPackageInterfaceName()%>
<%}%>
* @generated
*/
<%} else {%>
/**
*
* An implementation of the model Factory.
*
* @generated
*/
<%}%>
<%if (isImplementation) {%>
public class <%=genPackage.getFactoryClassName()%> extends <%=genModel.getImportedName("org.apache.tuscany.sdo.impl.FactoryBase")%><%if (!genModel.isSuppressInterfaces()) {%> implements <%=genPackage.getImportedFactoryInterfaceName()%><%}%>
<%} else {%>
public interface <%=genPackage.getFactoryInterfaceName()%><%if (!genModel.isSuppressEMFMetaData()) {%> extends <%=genModel.getImportedName("org.eclipse.emf.ecore.EFactory")%><%}%>
<%}%>
{
<%if (genModel.getCopyrightText() != null) {%>
/**
*
*
* @generated
*/
<%=publicStaticFinalFlag%><%=genModel.getImportedName("java.lang.String")%> copyright = "<%=genModel.getCopyrightText()%>";<%=genModel.getNonNLS()%>
<%}%>
<%if (isInterface && genModel.isSuppressEMFMetaData()) {%>
/**
* The singleton instance of the factory.
*
*
* @generated
*/
<%=publicStaticFinalFlag%><%=genPackage.getFactoryInterfaceName()%> INSTANCE = <%=genPackage.getQualifiedFactoryClassName()%>.init();
<%} else if (isInterface && !genModel.isSuppressInterfaces()) {%>
/**
* The singleton instance of the factory.
*
*
* @generated
*/
<%=publicStaticFinalFlag%><%=genPackage.getFactoryInterfaceName()%> eINSTANCE = <%=genPackage.getQualifiedFactoryClassName()%>.init();
<%}%>
<%if (isImplementation) {%>
/**
* The package namespace URI.
*
*
* @generated
*/
<%=publicStaticFinalFlag%><%=genModel.getImportedName("java.lang.String")%> NAMESPACE_URI = "<%=genPackage.getNSURI()%>";<%=genModel.getNonNLS()%>
/**
* The package namespace name.
*
*
* @generated
*/
<%=publicStaticFinalFlag%><%=genModel.getImportedName("java.lang.String")%> NAMESPACE_PREFIX = "<%=genPackage.getNSName()%>";<%=genModel.getNonNLS()%>
<%int genIndex = 1;
for (Iterator i=genPackage.getOrderedGenClassifiers().iterator(); i.hasNext();) { GenClassifier genClassifier = (GenClassifier)i.next();%>
<%if (!genPackage.getClassifierID(genClassifier).equals("DOCUMENT_ROOT")) { %>
<%=publicStaticFinalFlag%>int <%=genPackage.getClassifierID(genClassifier)%> = <%=genIndex%>;
<%genIndex++;%>
<% } }%>
<%String factoryType = genModel.isSuppressEMFMetaData() ? genPackage.getFactoryClassName() : genPackage.getImportedFactoryInterfaceName();%>
/**
* Creates an instance of the factory.
*
*
* @generated
*/
public <%=genPackage.getFactoryClassName()%>()
{
super(NAMESPACE_URI, NAMESPACE_PREFIX);
}
/**
*
*
* @generated
*/
public <%=genModel.getImportedName("commonj.sdo.DataObject")%> create(int typeNumber)
{
switch (typeNumber)
{
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.isDynamic()) {%>
case <%=genClass.getClassifierID()%>: return (<%=genModel.getImportedName("commonj.sdo.DataObject")%>)create<%=genClass.getName()%>();
<%}%>
<%}%>
default:
return super.create(typeNumber);
}
}
<%if (!genPackage.getAllGenDataTypes().isEmpty()) {%>
/**
*
*
* @generated
*/
public Object createFromString(<%=genModel.getImportedName("commonj.sdo.Type")%> type, String initialValue, int propertyValue)
{
switch (propertyValue)
{
<%for (Iterator i=genPackage.getAllGenDataTypes().iterator(); i.hasNext();) { GenDataType genDataType = (GenDataType)i.next();%>
<%if (genDataType.isSerializable()) {%>
case <%=genDataType.getClassifierID()%>:
return create<%=genDataType.getName()%>FromString(type, initialValue);
<%}%>
<%}%>
default:
throw new IllegalArgumentException("The datatype '" + type.getName() + "' is not a valid property value");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
}
}
/**
*
*
* @generated
*/
public String convertToString(<%=genModel.getImportedName("commonj.sdo.Type")%> type, Object instanceValue, int propertyValue)
{
switch (propertyValue)
{
<%for (Iterator i=genPackage.getAllGenDataTypes().iterator(); i.hasNext();) { GenDataType genDataType = (GenDataType)i.next();%>
<%if (genDataType.isSerializable()) {%>
case <%=genDataType.getClassifierID()%>:
return convert<%=genDataType.getName()%>ToString(type, instanceValue);
<%}%>
<%}%>
default:
throw new IllegalArgumentException("The datatype '" + type.getName() + "' is not a valid property value");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
}
}
<%}%>
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.isDynamic()) {%>
/**
*
*
* @generated
*/
public <%=genClass.getImportedInterfaceName()%> create<%=genClass.getName()%>()
{
<%if (genClass.isDynamic()) {%>
<%=genClass.getImportedInterfaceName()%> <%=genClass.getSafeUncapName()%> = <%=genClass.getCastFromEObject()%>super.create(<%=genClass.getQualifiedClassifierAccessor()%>);
<%} else {%>
<%=genClass.getImportedClassName()%> <%=genClass.getSafeUncapName()%> = new <%=genClass.getImportedClassName()%>()<%if (genModel.isSuppressInterfaces() && !genPackage.getReflectionPackageName().equals(genPackage.getInterfacePackageName())) {%>{}<%}%>;
<%}%>
return <%=genClass.getSafeUncapName()%>;
}
<%}%>
<%}%>
// Following creates and initializes SDO metadata for the supported types.
<%for (Iterator i=genPackage.getOrderedGenClassifiers().iterator(); i.hasNext();) { GenClassifier genClassifier = (GenClassifier)i.next();%>
<%if (!genPackage.getClassifierID(genClassifier).equals("DOCUMENT_ROOT")) { %>
protected <%=genModel.getImportedName("commonj.sdo.Type")%> <%=genClassifier.getSafeUncapName()%>Type = null;
public <%=genModel.getImportedName("commonj.sdo.Type")%> get<%=genClassifier.getClassifierAccessorName()%>()
{
return <%=genClassifier.getSafeUncapName()%>Type;
}
<%} }%>
private static boolean isInited = false;
public static <%=factoryType%> init()
{
if (isInited) return (<%=factoryType%>)FactoryBase.getStaticFactory(<%=factoryType%>.NAMESPACE_URI);
<%=factoryType%> the<%=factoryType%> = new <%=factoryType%>();
isInited = true;
// Initialize simple dependencies
<%=genModel.getImportedName("org.apache.tuscany.sdo.util.SDOUtil")%>.registerStaticTypes(<%=genModel.getImportedName("org.apache.tuscany.sdo.impl.SDOFactoryImpl")%>.class);
<%=genModel.getImportedName("org.apache.tuscany.sdo.util.SDOUtil")%>.registerStaticTypes(<%=genModel.getImportedName("org.apache.tuscany.sdo.model.impl.ModelPackageImpl")%>.class);
// Create package meta-data objects
the<%=factoryType%>.createMetaData();
// Initialize created meta-data
the<%=factoryType%>.initializeMetaData();
// Mark meta-data to indicate it can't be changed
//the<%=factoryType%>.freeze(); //FB do we need to freeze / should we freeze ????
return the<%=factoryType%>;
}
private boolean isCreated = false;
public void createMetaData()
{
if (isCreated) return;
isCreated = true;
<%if (!genPackage.getGenClasses().isEmpty()) {%>
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.isDynamic()) {%>
<%=genClass.getSafeUncapName()%>Type = createType(false, <%=genPackage.getClassifierID(genClass)%>);
<%for (Iterator j=genClass.getGenFeatures().iterator(); j.hasNext();) { GenFeature genFeature = (GenFeature)j.next();%>
createProperty(<%=!genFeature.isReferenceType()%>, <%=genClass.getSafeUncapName()%>Type, <%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>);
<%}%>
<%}%>
<%}%>
<%}%>
<%if (!genPackage.getGenEnums().isEmpty()) {%>
// Create enums
// todo
<%for (Iterator e=genPackage.getGenEnums().iterator(); e.hasNext();) { GenEnum genEnum = (GenEnum)e.next();%>
<%=genEnum.getClassifierInstanceName()%> = createEEnum(<%=genEnum.getClassifierID()%>);
<%}%>
<%}%>
<%if (!genPackage.getGenDataTypes().isEmpty()) {%>
<%for (Iterator d=genPackage.getGenDataTypes().iterator(); d.hasNext();) { GenDataType genDataType = (GenDataType)d.next();%>
<%=genDataType.getSafeUncapName()%>Type = createType(true, <%=genPackage.getClassifierID(genDataType)%> );
<%}%>
<%}%>
}
private boolean isInitialized = false;
public void initializeMetaData()
{
if (isInitialized) return;
isInitialized = true;
<%if (!genPackage.getPackageInitializationDependencies().isEmpty()) {%>
// Obtain other dependent packages
<%for (Iterator p=genPackage.getPackageInitializationDependencies().iterator(); p.hasNext();) { GenPackage dep = (GenPackage)p.next();%>
<%=dep.getImportedFactoryClassName()%> <%=genPackage.getPackageInstanceVariable(dep)%> = (<%=dep.getImportedFactoryClassName()%>)FactoryBase.getStaticFactory(<%=dep.getImportedFactoryClassName()%>.NAMESPACE_URI);
<%}%>
<%}%>
<%List annotationSources = genPackage.getAnnotationSources();%>
<%annotationSources.remove(ExtendedMetaData.ANNOTATION_URI);%>
<%=genModel.getImportedName("commonj.sdo.Property")%> property = null;
// Add supertypes to classes
<%for (Iterator c=genPackage.getGenClasses().iterator(); c.hasNext();) { GenClass genClass = (GenClass)c.next();%>
<%for (Iterator b=genClass.getBaseGenClasses().iterator(); b.hasNext();) { GenClass baseGenClass = (GenClass)b.next();%>
addSuperType(<%=genClass.getSafeUncapName()%>Type, <%=baseGenClass.getSafeUncapName()%>Type);
<%}%>
<%}%>
// Initialize classes and features; add operations and parameters
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.isDynamic()) {%>
initializeType(<%=genClass.getSafeUncapName()%>Type, <%=genClass.getImportedInterfaceName()%>.class, "<%=genClass.getName()%>");
<%for (Iterator sources = annotationSources.iterator(); sources.hasNext();) { String annotationSource = (String)sources.next();%>
<%EAnnotation classAnnotation = genClass.getEcoreClassifier().getEAnnotation(annotationSource);%>
<%if (classAnnotation != null) { %>
<%for (Iterator k = classAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
setInstanceProperty (<%=genClass.getSafeUncapName()%>Type, "<%=annotationSource%>", <%=key%>, <%=value%><%=genModel.getNonNLS(key + value)%>);
<%}%>
<%}%>
<%}%>
<%for (Iterator j=genClass.getGenFeatures().iterator(); j.hasNext();) {GenFeature genFeature = (GenFeature)j.next();%>
<%String type = genFeature.getType().equals("commonj.sdo.Sequence") ? "getSequence()" : genPackage.getPackageInstanceVariable(genFeature.getTypeGenPackage()) + ".get" + genFeature.getTypeClassifierAccessorName() + "()";%>
property = (<%=genModel.getImportedName("commonj.sdo.Property")%>)<%=genClass.getSafeUncapName()%>Type.getProperties().get(<%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>);
<%if (genFeature.isReferenceType()) { GenFeature reverseGenFeature = genFeature.getReverse();%>
<%String reverse = reverseGenFeature == null ? "null" : genPackage.getPackageInstanceVariable(reverseGenFeature.getGenPackage()) + ".get" + reverseGenFeature.getFeatureAccessorName() + "()";%>
initializeProperty(property, <%=type%>, "<%=genFeature.getSafeName()%>", <%=genFeature.getDefaultValue()%>, <%=genFeature.getLowerBound()%>, <%=genFeature.getUpperBound()%>, <%=genFeature.getContainerClass()%>, <%=genFeature.getChangeableFlag().equals("IS_CHANGEABLE") ? "false" : "true"%>, <%=genFeature.getUnsettableFlag().equals("IS_UNSETTABLE") ? "true": "false"%>, <%=genFeature.getDerivedFlag().equals("IS_DERIVED") ? "true" : "false"%>, <%=genFeature.getContainmentFlag().equals("IS_COMPOSITE")? "true": "false"%> , <%=reverse%>);
<%}else{%>
initializeProperty(property, <%=type%>, "<%=genFeature.getSafeName()%>", <%=genFeature.getDefaultValue()%>, <%=genFeature.getLowerBound()%>, <%=genFeature.getUpperBound()%>, <%=genFeature.getContainerClass()%>, <%=genFeature.getChangeableFlag().equals("IS_CHANGEABLE") ? "false" : "true"%>, <%=genFeature.getUnsettableFlag().equals("IS_UNSETTABLE") ? "true": "false"%>, <%=genFeature.getDerivedFlag().equals("IS_DERIVED") ? "true" : "false"%>);
<%}%>
<%for (Iterator sources = annotationSources.iterator(); sources.hasNext();) { String annotationSource = (String)sources.next();%>
<%EAnnotation featureAnnotation = genFeature.getEcoreFeature().getEAnnotation(annotationSource);%>
<%if (featureAnnotation != null) { %>
<%for (Iterator k = featureAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
setInstanceProperty (property, "<%=annotationSource%>", <%=key%>, <%=value%><%=genModel.getNonNLS(key + value)%>);
<%}%>
<%}%>
<%}%>
<%}%>
<%}%>
<%}%>
<%if (!genPackage.getGenDataTypes().isEmpty()) {%>
// Initialize data types
<%for (Iterator d=genPackage.getGenDataTypes().iterator(); d.hasNext();) { GenDataType genDataType = (GenDataType)d.next();%>
initializeType(<%=genDataType.getSafeUncapName()%>Type, <%=genDataType.getImportedInstanceClassName()%>.class, "<%=genDataType.getName()%>", <%=genDataType.getSerializableFlag().equals("IS_SERIALIZABLE") ? "true" : "false"%>, <%=genDataType.getGeneratedInstanceClassFlag().equals("IS_GENERATED_INSTANCE_CLASS") ? "true" : "false" %>);<%=genModel.getNonNLS()%>
<%for (Iterator sources = annotationSources.iterator(); sources.hasNext();) { String annotationSource = (String)sources.next();%>
<%EAnnotation dataTypeAnnotation = genDataType.getEcoreDataType().getEAnnotation(annotationSource);%>
<%if (dataTypeAnnotation != null) { %>
<%for (Iterator k = dataTypeAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
setInstanceProperty (<%=genDataType.getSafeUncapName()%>Type, "<%=annotationSource%>", <%=key%>, <%=value%><%=genModel.getNonNLS(key + value)%>);
<%}%>
<%}%>
<%}%>
<%}%>
<%}%>
createXSDMetaData(theModelPackageImpl);
}
protected void createXSDMetaData(ModelFactoryImpl theModelPackageImpl)
{
super.createXSDMetaData();
<%=genModel.getImportedName("commonj.sdo.Property")%> property = null;
<%String extendedMetaDataSource = ExtendedMetaData.ANNOTATION_URI;%>
<%EAnnotation packageAnnotation = genPackage.getEcorePackage().getEAnnotation(extendedMetaDataSource);%>
<%if (packageAnnotation != null){ %>
addXSDMapping
(new String[]
{
<%for (Iterator k = packageAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
<%=key%>, <%=value%><%=k.hasNext() ? "," : ""%><%=genModel.getNonNLS(key + value)%>
<%}%>
});
<%}%>
<%for (Iterator i=genPackage.getGenClassifiers().iterator(); i.hasNext();) { GenClassifier genClassifier = (GenClassifier)i.next(); EAnnotation classAnnotation = genClassifier.getEcoreClassifier().getEAnnotation(extendedMetaDataSource);%>
<%if (classAnnotation != null && !genClassifier.getName().equals("DocumentRoot")) {%>
addXSDMapping
(<%=genClassifier.getSafeUncapName()%>Type,
new String[]
{
<%for (Iterator k = classAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
<%=key%>, <%=value%><%=k.hasNext() ? "," : ""%><%=genModel.getNonNLS(key + value)%>
<%}%>
});
<%}%>
<%if (genClassifier instanceof GenClass) { GenClass genClass = (GenClass) genClassifier;%>
<%for (Iterator j=genClass.getGenFeatures().iterator(); j.hasNext();) { GenFeature genFeature = (GenFeature)j.next(); %>
<%EAnnotation featureAnnotation = genFeature.getEcoreFeature().getEAnnotation(extendedMetaDataSource);%>
<%if (genClass.getName().equals("DocumentRoot")) { %>
<%if (!(genFeature.getName().equals("mixed") || genFeature.getName().equals("xMLNSPrefixMap") || genFeature.getName().equals("xSISchemaLocation"))) { %>
property = createGlobalProperty
("<%=genFeature.getName()%>",
<%=genPackage.getPackageInstanceVariable(genFeature.getTypeGenPackage())%>.get<%=genFeature.getTypeClassifierAccessorName()%>(),
new String[]
{
<%for (Iterator k = featureAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
<%=key%>, <%=value%><%=k.hasNext() ? "," : ""%><%=genModel.getNonNLS(key + value)%>
<%}%>
<%if (!genFeature.isReferenceType()) {%>
},
IS_ATTRIBUTE);
<%} else {%>
});
<%}%>
<%for (Iterator sources = genPackage.getAnnotationSources().iterator(); sources.hasNext();) { String annotationSource = (String)sources.next(); %>
<%if (!annotationSource.equals(extendedMetaDataSource)) {%>
<%EAnnotation globalAnnotation = genFeature.getEcoreFeature().getEAnnotation(annotationSource);%>
<%if (globalAnnotation != null) {%>
<%for (Iterator k = globalAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
setInstanceProperty
(property,
"<%=annotationSource%>",
<%=key%>, <%=value%><%=genModel.getNonNLS(key + value)%>);
<%}%>
<%}%>
<%}%>
<%}%>
<%}%>
<%} else {%>
addXSDMapping
((<%=genModel.getImportedName("commonj.sdo.Property")%>)<%=genClassifier.getSafeUncapName()%>Type.getProperties().get(<%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>),
new String[]
{
<%for (Iterator k = featureAnnotation.getDetails().iterator(); k.hasNext();) { Map.Entry detail = (Map.Entry)k.next(); String key = Literals.toStringLiteral((String)detail.getKey(), genModel); String value = Literals.toStringLiteral((String)detail.getValue(), genModel);%>
<%=key%>, <%=value%><%=k.hasNext() ? "," : ""%><%=genModel.getNonNLS(key + value)%>
<%}%>
});
<%}%>
<%}%>
<%}%>
<%}%>
}
<%for (Iterator i=genPackage.getAllGenDataTypes().iterator(); i.hasNext();) { GenDataType genDataType = (GenDataType)i.next();%>
<%if (genDataType.isSerializable()) {%>
<%if (genPackage.isDataTypeConverters()) { String eDataType = genDataType.getQualifiedClassifierAccessor();%>
/**
*
*
* @generated
*/
public <%=genDataType.getImportedInstanceClassName()%> create<%=genDataType.getName()%>(String literal)
{
<%if (genDataType instanceof GenEnum) {%>
<%=genDataType.getImportedInstanceClassName()%> result = <%=genDataType.getImportedInstanceClassName()%>.get(literal);
if (result == null) throw new IllegalArgumentException("The value '" + literal + "' is not a valid enumerator of '" + <%=eDataType%>.getName() + "'");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%><%=genModel.getNonNLS(3)%>
return result;
<%} else if (genDataType.getBaseType() != null) { GenDataType genBaseType = genDataType.getBaseType(); boolean isPrimitiveConversion = !genDataType.isPrimitiveType() && genBaseType.isPrimitiveType();%>
<%if (genBaseType.getGenPackage() == genPackage) {%>
<%if (isPrimitiveConversion) {%>
return new <%=genDataType.getObjectInstanceClassName()%>(create<%=genBaseType.getName()%>(literal));
<%} else {%>
return create<%=genBaseType.getName()%>(literal);
<%}%>
<%} else if (genBaseType.getGenPackage().isDataTypeConverters()) {%>
<%if (isPrimitiveConversion) {%>
return new <%=genDataType.getObjectInstanceClassName()%>(<%=genBaseType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.create<%=genBaseType.getName()%>(literal));
<%} else {%>
return <%=genBaseType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.create<%=genBaseType.getName()%>(literal);
<%}%>
<%} else {%>
return (<%=genDataType.getObjectInstanceClassName()%>)<%=genBaseType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.createFromString(<%=genBaseType.getQualifiedClassifierAccessor()%>, literal);
<%}%>
<%} else if (genDataType.getItemType() != null) { GenDataType genItemType = genDataType.getItemType(); %>
if (literal == null) return null;
<%=genModel.getImportedName("java.util.List")%> result = new <%=genModel.getImportedName("java.util.ArrayList")%>();
for (<%=genModel.getImportedName("java.util.StringTokenizer")%> stringTokenizer = new <%=genModel.getImportedName("java.util.StringTokenizer")%>(literal); stringTokenizer.hasMoreTokens(); )
{
String item = stringTokenizer.nextToken();
<%if (genItemType.getGenPackage() == genPackage) {%>
<%if (genPackage.isDataTypeConverters()) { genItemType = genItemType.getObjectType();%>
result.add(create<%=genItemType.getName()%>(item));
<%} else {%>
result.add(create<%=genItemType.getName()%>FromString(<%=genItemType.getQualifiedClassifierAccessor()%>, item));
<%}%>
<%} else {%>
<%if (genItemType.getGenPackage().isDataTypeConverters()) { genItemType = genItemType.getObjectType();%>
result.add(<%=genItemType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.create<%=genItemType.getName()%>(item));
<%} else {%>
result.add(<%=genItemType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.createFromString(<%=genItemType.getQualifiedClassifierAccessor()%>, item));
<%}%>
<%}%>
}
return result;
<%} else if (!genDataType.getMemberTypes().isEmpty()) {%>
if (literal == null) return <%=genDataType.getStaticValue(null)%>;
<%=genDataType.getImportedInstanceClassName()%> result = <%=genDataType.getStaticValue(null)%>;
RuntimeException exception = null;
<%for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) { GenDataType genMemberType = (GenDataType)j.next();%>
try
{
<%if (genMemberType.getGenPackage() == genPackage) {%>
<%if (genPackage.isDataTypeConverters()) { if (!genDataType.isPrimitiveType()) genMemberType = genMemberType.getObjectType();%>
result = create<%=genMemberType.getName()%>(literal);
<%} else {%>
result = (<%=genDataType.getObjectInstanceClassName()%>)create<%=genMemberType.getName()%>FromString(<%=genMemberType.getQualifiedClassifierAccessor()%>, literal);
<%}%>
<%} else {%>
<%if (genPackage.isDataTypeConverters()) { if (!genDataType.isPrimitiveType()) genMemberType = genMemberType.getObjectType();%>
result = <%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.create<%=genMemberType.getName()%>(literal);
<%} else {%>
result = (<%=genDataType.getObjectInstanceClassName()%>)<%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.createFromString(<%=genMemberType.getQualifiedClassifierAccessor()%>, literal);
<%}%>
<%}%>
if (<%if (!genDataType.isPrimitiveType()) {%>result != null && <%}%><%=genModel.getImportedName("org.eclipse.emf.ecore.util.Diagnostician")%>.INSTANCE.validate(<%=eDataType%>, <%if (genDataType.isPrimitiveType()) {%>new <%=genDataType.getObjectInstanceClassName()%>(result)<%} else {%>result<%}%>, null, null))
{
return result;
}
}
catch (RuntimeException e)
{
exception = e;
}
<%}%>
if (<%if (!genDataType.isPrimitiveType()) {%>result != null || <%}%>exception == null) return result;
throw exception;
<%} else if (genDataType.isArrayType()) {%>
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new <%=genModel.getImportedName("java.lang.UnsupportedOperationException")%>();
<%} else if (genDataType.isPrimitiveType()) {%>
return ((<%=genDataType.getObjectInstanceClassName()%>)super.createFromString(<%=eDataType%>, literal)).<%=genDataType.getPrimitiveValueFunction()%>();
<%} else {%>
return (<%=genDataType.getObjectInstanceClassName()%>)super.createFromString(<%=eDataType%>, literal);
<%}%>
}
<%}%>
/**
*
*
* @generated
*/
public <%=genDataType.getObjectInstanceClassName()%> create<%=genDataType.getName()%>FromString(<%=genModel.getImportedName("commonj.sdo.Type")%> type, String initialValue)
{
<%if (genDataType instanceof GenEnum) {%>
<%if (genPackage.isDataTypeConverters()) {%>
return create<%=genDataType.getName()%>(initialValue);
<%} else {%>
<%=((GenEnum)genDataType).getImportedInstanceClassName()%> result = <%=((GenEnum)genDataType).getImportedInstanceClassName()%>.get(initialValue);
if (result == null) throw new IllegalArgumentException("The value '" + initialValue + "' is not a valid enumerator of '" + type.getName() + "'");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%><%=genModel.getNonNLS(3)%>
return result;
<%}%>
<%} else if (genDataType.getBaseType() != null) { GenDataType genBaseType = genDataType.getBaseType(); %>
<%if (genBaseType.getGenPackage() == genPackage) {%>
return (<%=genDataType.getObjectInstanceClassName()%>)create<%=genBaseType.getName()%>FromString(<%=SDOGenUtil.getQualifiedTypeAccessor(genDataType)%>, initialValue);
<%} else {%>
return (<%=genDataType.getObjectInstanceClassName()%>)<%=genBaseType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.createFromString(<%=genBaseType.getQualifiedClassifierAccessor()%>, initialValue);
<%}%>
<%} else if (genDataType.getItemType() != null) { GenDataType genItemType = genDataType.getItemType(); %>
<%if (genPackage.isDataTypeConverters()) {%>
return create<%=genDataType.getName()%>(initialValue);
<%} else {%>
if (initialValue == null) return null;
<%=genModel.getImportedName("java.util.List")%> result = new <%=genModel.getImportedName("java.util.ArrayList")%>();
for (<%=genModel.getImportedName("java.util.StringTokenizer")%> stringTokenizer = new <%=genModel.getImportedName("java.util.StringTokenizer")%>(initialValue); stringTokenizer.hasMoreTokens(); )
{
String item = stringTokenizer.nextToken();
<%if (genItemType.getGenPackage() == genPackage) {%>
result.add(create<%=genItemType.getName()%>FromString(<%=genItemType.getQualifiedClassifierAccessor()%>, item));
<%} else {%>
result.add(<%=genItemType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.createFromString(<%=genItemType.getQualifiedClassifierAccessor()%>, item));
<%}%>
}
return result;
<%}%>
<%} else if (!genDataType.getMemberTypes().isEmpty()) {%>
<%if (genPackage.isDataTypeConverters()) {%>
<%if (genDataType.isPrimitiveType()) {%>
return new <%=genDataType.getObjectInstanceClassName()%>(create<%=genDataType.getName()%>(initialValue));
<%} else {%>
return create<%=genDataType.getName()%>(initialValue);
<%}%>
<%} else {%>
if (initialValue == null) return null;
<%=genDataType.getObjectInstanceClassName()%> result = null;
RuntimeException exception = null;
<%for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) { GenDataType genMemberType = (GenDataType)j.next();%>
try
{
<%if (genMemberType.getGenPackage() == genPackage) {%>
result = (<%=genDataType.getObjectInstanceClassName()%>)create<%=genMemberType.getName()%>FromString(<%=genMemberType.getQualifiedClassifierAccessor()%>, initialValue);
<%} else {%>
result = (<%=genDataType.getObjectInstanceClassName()%>)<%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.createFromString(<%=genMemberType.getQualifiedClassifierAccessor()%>, initialValue);
<%}%>
if (result != null && <%=genModel.getImportedName("org.eclipse.emf.ecore.util.Diagnostician")%>.INSTANCE.validate(type, result, null, null))
{
return result;
}
}
catch (RuntimeException e)
{
exception = e;
}
<%}%>
if (result != null || exception == null) return result;
throw exception;
<%}%>
<%} else if (genDataType.isArrayType()) {%>
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new <%=genModel.getImportedName("java.lang.UnsupportedOperationException")%>();
<%} else {%>
return (<%=genDataType.getObjectInstanceClassName()%>)super.createFromString(type, initialValue);
<%}%>
}
<%if (genPackage.isDataTypeConverters()) { String eDataType = genDataType.getQualifiedClassifierAccessor();%>
/**
*
*
* @generated
*/
public String convert<%=genDataType.getName()%>(<%=genDataType.getImportedInstanceClassName()%> instanceValue)
{
<%if (genDataType instanceof GenEnum) {%>
return instanceValue == null ? null : instanceValue.toString();
<%} else if (genDataType.getBaseType() != null) { GenDataType genBaseType = genDataType.getBaseType(); boolean isPrimitiveConversion = !genDataType.isPrimitiveType() && genBaseType.isPrimitiveType();%>
<%if (genBaseType.getGenPackage() == genPackage) {%>
<%if (isPrimitiveConversion) {%>
return instanceValue == null ? null : convert<%=genBaseType.getName()%>(instanceValue.<%=genBaseType.getPrimitiveValueFunction()%>());
<%} else {%>
return convert<%=genBaseType.getName()%>(instanceValue);
<%}%>
<%} else if (genBaseType.getGenPackage().isDataTypeConverters()) {%>
return <%=genBaseType.getGenPackage().getQualifiedFactoryInstanceAccessor()%>.convert<%=genBaseType.getName()%>(instanceValue);
<%} else {%>
return <%=genBaseType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genBaseType.getQualifiedClassifierAccessor()%>, instanceValue);
<%}%>
<%} else if (genDataType.getItemType() != null) { GenDataType genItemType = genDataType.getItemType(); %>
if (instanceValue == null) return null;
if (instanceValue.isEmpty()) return "";
<%=genModel.getImportedName("java.lang.StringBuffer")%> result = new <%=genModel.getImportedName("java.lang.StringBuffer")%>();
for (<%=genModel.getImportedName("java.util.Iterator")%> i = instanceValue.iterator(); i.hasNext(); )
{
<%if (genItemType.getGenPackage() == genPackage) {%>
<%if (genPackage.isDataTypeConverters()) { genItemType = genItemType.getObjectType();%>
result.append(convert<%=genItemType.getName()%>((<%=genItemType.getObjectInstanceClassName()%>)i.next()));
<%} else {%>
result.append(convert<%=genItemType.getName()%>ToString(<%=genItemType.getQualifiedClassifierAccessor()%>, i.next()));
<%}%>
<%} else {%>
<%if (genItemType.getGenPackage().isDataTypeConverters()) { genItemType = genItemType.getObjectType();%>
result.append(<%=genItemType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convert<%=genItemType.getName()%>((<%=genItemType.getObjectInstanceClassName()%>)i.next()));
<%} else {%>
result.append(<%=genItemType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genItemType.getQualifiedClassifierAccessor()%>, i.next()));
<%}%>
<%}%>
result.append(' ');
}
return result.substring(0, result.length() - 1);
<%} else if (!genDataType.getMemberTypes().isEmpty()) {%>
<%if (!genDataType.isPrimitiveType()) {%>
if (instanceValue == null) return null;
<%for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) { GenDataType genMemberType = (GenDataType)j.next();%>
if (<%=genMemberType.getQualifiedClassifierAccessor()%>.isInstance(instanceValue))
{
try
{
<%if (genMemberType.getGenPackage() == genPackage) {%>
<%if (genPackage.isDataTypeConverters()) {%>
String value = convert<%=genMemberType.getName()%>(instanceValue);
<%} else {%>
String value = convert<%=genMemberType.getName()%>ToString(<%=genMemberType.getQualifiedClassifierAccessor()%>, instanceValue);
<%}%>
<%} else {%>
<%if (genMemberType.getGenPackage().isDataTypeConverters()) { genMemberType = genMemberType.getObjectType();%>
String value = <%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convert<%=genMemberType.getName()%>((<%=genMemberType.getObjectInstanceClassName()%>)instanceValue);
<%} else {%>
String value = <%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genMemberType.getQualifiedClassifierAccessor()%>, instanceValue);
<%}%>
<%}%>
if (value != null) return value;
}
catch (Exception e)
{
}
}
<%}%>
<%} else {%>
<%for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) { GenDataType genMemberType = (GenDataType)j.next();%>
try
{
<%if (genMemberType.getGenPackage() == genPackage) {%>
<%if (genPackage.isDataTypeConverters()) {%>
String value = convert<%=genMemberType.getName()%>(instanceValue);
<%} else {%>
String value = convert<%=genMemberType.getName()%>ToString(<%=genMemberType.getQualifiedClassifierAccessor()%>, new <%=genMemberType.getObjectInstanceClassName()%>(instanceValue));
<%}%>
<%} else {%>
<%if (genMemberType.getGenPackage().isDataTypeConverters()) {%>
String value = <%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convert<%=genMemberType.getName()%>(instanceValue);
<%} else {%>
String value = <%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genMemberType.getQualifiedClassifierAccessor()%>, new <%=genMemberType.getObjectInstanceClassName()%>(instanceValue));
<%}%>
<%}%>
if (value != null) return value;
}
catch (Exception e)
{
}
<%}%>
<%}%>
throw new IllegalArgumentException("Invalid value: '"+instanceValue+"' for datatype :"+<%=eDataType%>.getName());
<%} else if (genDataType.isArrayType()) {%>
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new <%=genModel.getImportedName("java.lang.UnsupportedOperationException")%>();
<%} else if (genDataType.isPrimitiveType()) {%>
return super.convertToString(<%=eDataType%>, new <%=genDataType.getObjectInstanceClassName()%>(instanceValue));
<%} else {%>
return super.convertToString(<%=eDataType%>, instanceValue);
<%}%>
}
<%}%>
/**
*
*
* @generated
*/
public String convert<%=genDataType.getName()%>ToString(<%=genModel.getImportedName("commonj.sdo.Type")%> type, Object instanceValue)
{
<%if (genDataType instanceof GenEnum) {%>
return instanceValue == null ? null : instanceValue.toString();
<%} else if (genDataType.getBaseType() != null) { GenDataType genBaseType = genDataType.getBaseType(); %>
<%if (genBaseType.getGenPackage() == genPackage) {%>
return convert<%=genBaseType.getName()%>ToString(<%=SDOGenUtil.getQualifiedTypeAccessor(genBaseType)%>, instanceValue);
<%} else {%>
return <%=genBaseType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genBaseType.getQualifiedClassifierAccessor()%>, instanceValue);
<%}%>
<%} else if (genDataType.getItemType() != null) { GenDataType genItemType = genDataType.getItemType(); %>
<%if (genPackage.isDataTypeConverters()) {%>
return convert<%=genDataType.getName()%>((<%=genModel.getImportedName("java.util.List")%>)instanceValue);
<%} else {%>
if (instanceValue == null) return null;
<%=genModel.getImportedName("java.util.List")%> list = (<%=genModel.getImportedName("java.util.List")%>)instanceValue;
if (list.isEmpty()) return "";
<%=genModel.getImportedName("java.lang.StringBuffer")%> result = new <%=genModel.getImportedName("java.lang.StringBuffer")%>();
for (<%=genModel.getImportedName("java.util.Iterator")%> i = list.iterator(); i.hasNext(); )
{
<%if (genItemType.getGenPackage() == genPackage) {%>
result.append(convert<%=genItemType.getName()%>ToString(<%=genItemType.getQualifiedClassifierAccessor()%>, i.next()));
<%} else {%>
result.append(<%=genItemType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genItemType.getQualifiedClassifierAccessor()%>, i.next()));
<%}%>
result.append(' ');
}
return result.substring(0, result.length() - 1);
<%}%>
<%} else if (!genDataType.getMemberTypes().isEmpty()) {%>
<%if (genPackage.isDataTypeConverters()) {%>
<%if (genDataType.isPrimitiveType()) {%>
return instanceValue == null ? null : convert<%=genDataType.getName()%>(((<%=genDataType.getObjectInstanceClassName()%>)instanceValue).<%=genDataType.getPrimitiveValueFunction()%>());
<%} else {%>
return convert<%=genDataType.getName()%>(instanceValue);
<%}%>
<%} else {%>
if (instanceValue == null) return null;
<%for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) { GenDataType genMemberType = (GenDataType)j.next();%>
if (<%=genMemberType.getQualifiedClassifierAccessor()%>.isInstance(instanceValue))
{
try
{
<%if (genMemberType.getGenPackage() == genPackage) {%>
String value = convert<%=genMemberType.getName()%>ToString(<%=genMemberType.getQualifiedClassifierAccessor()%>, instanceValue);
<%} else {%>
String value = <%=genMemberType.getGenPackage().getQualifiedEFactoryInternalInstanceAccessor()%>.convertToString(<%=genMemberType.getQualifiedClassifierAccessor()%>, instanceValue);
<%}%>
if (value != null) return value;
}
catch (Exception e)
{
}
}
<%}%>
throw new IllegalArgumentException("Invalid value: '"+instanceValue+"' for datatype :"+type.getName());
<%}%>
<%} else if (genDataType.isArrayType()) {%>
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new <%=genModel.getImportedName("java.lang.UnsupportedOperationException")%>();
<%} else {%>
return super.convertToString(type, instanceValue);
<%}%>
}
<%}%>
<%}%>
<%} else {%>
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (genClass.hasFactoryInterfaceCreateMethod()) {%>
/**
* Returns a new object of class '<%=genClass.getFormattedName()%>'.
*
*
* @return a new object of class '<%=genClass.getFormattedName()%>'.
* @generated
*/
<%=genClass.getImportedInterfaceName()%> create<%=genClass.getName()%>();
<%}%>
<%}%>
<%if (genPackage.isDataTypeConverters()) {%>
<%for (Iterator i=genPackage.getAllGenDataTypes().iterator(); i.hasNext();) { GenDataType genDataType = (GenDataType)i.next();%>
<%if (genDataType.isSerializable()) {%>
/**
* Returns an instance of data type '<%=genDataType.getFormattedName()%>' corresponding the given literal.
*
*
* @param literal a literal of the data type.
* @return a new instance value of the data type.
* @generated
*/
<%=genDataType.getImportedInstanceClassName()%> create<%=genDataType.getName()%>(String literal);
/**
* Returns a literal representation of an instance of data type '<%=genDataType.getFormattedName()%>'.
*
*
* @param instanceValue an instance value of the data type.
* @return a literal representation of the instance value.
* @generated
*/
String convert<%=genDataType.getName()%>(<%=genDataType.getImportedInstanceClassName()%> instanceValue);
<%}%>
<%}%>
<%}%>
<%}%>
} //<%=isInterface ? genPackage.getFactoryInterfaceName() : genPackage.getFactoryClassName()%>
<%genModel.emitSortedImports();%>