%@ jet package="org.apache.tuscany.sdo.generate.templates.model" imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.*" class="SDOFactoryClass" version="$Id: SDOFactoryClass.javajet,v 1.23 2005/12/10 13:31:02 emerks Exp $" %>
<%
/**
*
*
* Copyright (c) 2002-2005 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
*
*
*/
%>
<%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()%>
<%for (Iterator i=genPackage.getOrderedGenClassifiers().iterator(); i.hasNext();) { GenClassifier genClassifier = (GenClassifier)i.next();%>
<%if (!genClassifier.getClassifierID().equals("DOCUMENT_ROOT")) { %>
<%=publicStaticFinalFlag%>int <%=genPackage.getClassifierID(genClassifier)%> = <%=genPackage.getClassifierValue(genClassifier)%>;
<%} }%>
/**
* Creates the default factory implementation.
*
*
* @generated
*/
<%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.getClassifierID().equals("DOCUMENT_ROOT")) {%>
// TODO make sure we're supposed to ingore DOCUMENT_ROOT
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("org.eclipse.emf.ecore.EDataType")%> eDataType, String initialValue)
{
switch (eDataType.getClassifierID())
{
<%for (Iterator i=genPackage.getAllGenDataTypes().iterator(); i.hasNext();) { GenDataType genDataType = (GenDataType)i.next();%>
<%if (genDataType.isSerializable()) {%>
case <%=genPackage.getImportedPackageInterfaceName()%>.<%=genDataType.getClassifierID()%>:
return create<%=genDataType.getName()%>FromString(eDataType, initialValue);
<%}%>
<%}%>
default:
throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
}
}
/**
*
*
* @generated
*/
public String convertToString(<%=genModel.getImportedName("org.eclipse.emf.ecore.EDataType")%> eDataType, Object instanceValue)
{
switch (eDataType.getClassifierID())
{
<%for (Iterator i=genPackage.getAllGenDataTypes().iterator(); i.hasNext();) { GenDataType genDataType = (GenDataType)i.next();%>
<%if (genDataType.isSerializable()) {%>
case <%=genPackage.getImportedPackageInterfaceName()%>.<%=genDataType.getClassifierID()%>:
return convert<%=genDataType.getName()%>ToString(eDataType, instanceValue);
<%}%>
<%}%>
default:
throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
}
}
<%}%>
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.getClassifierID().equals("DOCUMENT_ROOT")) {%>
/**
*
*
* @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.
protected <%=genModel.getImportedName("commonj.sdo.Type")%> <%=genClass.getSafeUncapName()%>Type = null;
public <%=genModel.getImportedName("commonj.sdo.Type")%> get<%=genClass.getName()%>()
{
// TODO - kdk - verify how to generate quoteType...<%=genClass.getSafeUncapName()%>Type?
return <%=genClass.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;
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.getClassifierID().equals("DOCUMENT_ROOT")) {%>
<%=genClass.getSafeUncapName()%>Type = createType(false, <%=genPackage.getClassifierID(genClass)%>);
<%for (Iterator j=genClass.getAllGenFeatures().iterator(); j.hasNext();) { GenFeature genFeature = (GenFeature)j.next();%>
createProperty(<%=!genFeature.isReferenceType()%>, <%=genClass.getSafeUncapName()%>Type, <%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>);
<%}%>
<%}%>
<%}%>
}
private boolean isInitialized = false;
public void initializeMetaData()
{
if (isInitialized) return;
isInitialized = true;
// Obtain other dependent packages
<%=genModel.getImportedName("org.apache.tuscany.sdo.model.impl.ModelFactoryImpl")%> theModelPackageImpl = (<%=genModel.getImportedName("org.apache.tuscany.sdo.model.impl.ModelFactoryImpl")%>)FactoryBase.getStaticFactory(<%=genModel.getImportedName("org.apache.tuscany.sdo.model.impl.ModelFactoryImpl")%>.NAMESPACE_URI);
// Add supertypes to classes
// 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.getClassifierID().equals("DOCUMENT_ROOT")) {%>
initializeType(<%=genClass.getSafeUncapName()%>Type, <%=genClass.getImportedInterfaceName()%>.class, "<%=genClass.getName()%>");<%for (Iterator j=genClass.getAllGenFeatures().iterator(); j.hasNext();) {GenFeature genFeature = (GenFeature)j.next();%><%String type = genFeature.getImportedType().equals("Sequence") ? "getSequence()" : genPackage.getPackageInstanceVariable(genFeature.getTypeGenPackage()) + ".get" + genFeature.getTypeClassifierAccessorName() + "()";%><%if (genFeature.isReferenceType()) { GenFeature reverseGenFeature = genFeature.getReverse();%><%String reverse = reverseGenFeature == null ? "null" : genPackage.getPackageInstanceVariable(reverseGenFeature.getGenPackage()) + ".get" + reverseGenFeature.getFeatureAccessorName() + "()";%>
initializeProperty((<%=genModel.getImportedName("commonj.sdo.Property")%>)<%=genClass.getSafeUncapName()%>Type.getProperties().get(<%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>), <%=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((<%=genModel.getImportedName("commonj.sdo.Property")%>)<%=genClass.getSafeUncapName()%>Type.getProperties().get(<%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>), <%=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"%>);<%}%><%}%><%}%><%}%>createXSDMetaData();
}
protected void createXSDMetaData()
{
super.createXSDMetaData();
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && !genClass.getClassifierID().equals("DOCUMENT_ROOT")) {%>
// TODO - kdk - is the order right? should kind, elementOnly be first
addXSDMapping
(<%=genClass.getSafeUncapName()%>Type,
new String[]
{
"name", "<%=genClass.getName()%>",
"kind", "elementOnly"
});
<%for (Iterator j=genClass.getAllGenFeatures().iterator(); j.hasNext();) { GenFeature genFeature = (GenFeature)j.next();%>
addXSDMapping
((<%=genModel.getImportedName("commonj.sdo.Property")%>)<%=genClass.getSafeUncapName()%>Type.getProperties().get(<%=genClass.getClassName()%>.<%=genFeature.getUpperName()%>),
new String[]
{
"kind", "element",
"name", "<%=genFeature.getName()%>"
});
<%}%>
<%}%>
<%}%>
<%for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();%>
<%if (!genClass.isAbstract() && genClass.getClassifierID().equals("DOCUMENT_ROOT")) {%>
// TODO - kdk - how do I filter out mixed, xMLNSPrefixMap, and xSISchemaLocation without hardcoding it
// TODO - kdk - can I hardcode ##targetNamespace?
<%for (Iterator j=genClass.getAllGenFeatures().iterator(); j.hasNext();) { GenFeature genFeature = (GenFeature)j.next();%>
<%if (!genFeature.getName().equals("mixed") && !genFeature.getName().equals("xMLNSPrefixMap") && !genFeature.getName().equals("xSISchemaLocation")){ %>
createGlobalProperty
("<%=genFeature.getName()%>",
<%=genPackage.getPackageInstanceVariable(genFeature.getTypeGenPackage())%>.get<%=genFeature.getTypeClassifierAccessorName()%>(),
new String[]
{
"kind", "element",
"name", "<%=genFeature.getName()%>",
"namespace", "##targetNamespace"
});
<%}%>
<%}%>
<%}%>
<%}%>
}
<%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("org.eclipse.emf.ecore.EDataType")%> eDataType, 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 '" + eDataType.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(<%=genBaseType.getQualifiedClassifierAccessor()%>, 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(eDataType, 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(eDataType, 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("org.eclipse.emf.ecore.EDataType")%> eDataType, 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(<%=genBaseType.getQualifiedClassifierAccessor()%>, 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 :"+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 {%>
return super.convertToString(eDataType, 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();%>