Author: frankb
Date: Mon May 8 07:35:35 2006
New Revision: 405063
URL: http://svn.apache.org/viewcvs?rev=405063&view=rev
Log:
Fix for TUSCANY-308
Added:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectBase.java
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/FactoryBase.java
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenClassGeneratorAdapter.java
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenModelGeneratorAdapterFactory.java
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenPackageGeneratorAdapter.java
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOClass.java
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/MixedQuote.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/MixedRepeatingChoice.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/RepeatingChoice.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/SequencesFactory.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/TwoRCs.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/TwoRCsMixed.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/MixedQuoteImpl.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/MixedRepeatingChoiceImpl.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/RepeatingChoiceImpl.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/SequencesFactoryImpl.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsImpl.java
incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsMixedImpl.java
incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/StaticSequenceNoEmfTest.java
incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java
incubator/tuscany/java/sdo/tools/src/test/resources/mixedRepeatingChoiceTestResult.xml
incubator/tuscany/java/sdo/tools/src/test/resources/mixedStaticTestResult.xml
incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoice.xsd
incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoiceTestResult.xml
incubator/tuscany/java/sdo/tools/src/test/resources/sequences.xsd
incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesMixedTestResult.xml
incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesTestResult.xml
incubator/tuscany/java/sdo/tools/templates/
incubator/tuscany/java/sdo/tools/templates/Header.javajetinc
incubator/tuscany/java/sdo/tools/templates/models/
incubator/tuscany/java/sdo/tools/templates/models/SDOClass.javajet
incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet
Modified:
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
Added:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectBase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectBase.java?rev=405063&view=auto
==============================================================================
---
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectBase.java
(added)
+++
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectBase.java
Mon May 8 07:35:35 2006
@@ -0,0 +1,238 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as
applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.tuscany.sdo.impl;
+
+
+import java.util.List;
+
+import org.apache.tuscany.sdo.util.BasicSequence;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.NotificationChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.emf.ecore.util.BasicFeatureMap;
+import org.eclipse.emf.ecore.util.EObjectContainmentEList;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.ecore.util.InternalEList;
+
+
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+
+
+/**
+ * Base implementation of the SDO DataObject interface. Used as base class for
prototype of EMF-less generated subclasses
+ */
+public abstract class DataObjectBase extends DataObjectImpl
+{
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Following methods should be proposed SPI for generated subclasses to use
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ protected boolean isNotifying()
+ {
+ return changeRecorder != null;
+ }
+
+ protected interface ChangeKind
+ {
+ int SET = Notification.SET;
+ int UNSET = Notification.UNSET;
+ int RESOLVE = Notification.RESOLVE;
+ }
+
+ protected void notify(int changeKind, int property, Object oldValue, Object
newValue)
+ {
+ eNotify(new ENotificationImpl(this, Notification.SET, property, oldValue,
newValue));
+ }
+
+ protected void notify(int changeKind, int property, double oldDoubleValue,
double newDoubleValue, boolean isSetChange)
+ {
+ eNotify(new ENotificationImpl(this, Notification.SET, property,
oldDoubleValue, newDoubleValue, isSetChange));
+ }
+
+ protected interface ListKind
+ {
+ int CONTAINMENT = 0;
+ }
+
+ protected List createPropertyList(int listKind, Class dataClass, int
property)
+ {
+ switch (listKind)
+ {
+ case ListKind.CONTAINMENT:
+ return new EObjectContainmentEList(dataClass, this, property);
+ }
+ return null;
+ }
+
+ protected BasicSequence createSequence(int property) {
+ return new BasicSequence(new BasicFeatureMap(this, property));
+ }
+
+ protected Sequence createSequence(Sequence sequence, Type type, int
propertyIndex) {
+ return new
BasicSequence((FeatureMap.Internal)((FeatureMap.Internal.Wrapper)sequence).featureMap().list(((EClass)type).getEStructuralFeature(propertyIndex)));
+ }
+
+ /*
+ * get the value of the type's property at propertyIndex via the sequence
+ * @param seq
+ * @param type
+ * @param propertyIndex
+ * @return
+ */
+ protected Object get(Sequence seq, Type type, int propertyIndex) {
+ return
((FeatureMap.Internal.Wrapper)seq).featureMap().get(((EClass)type).getEStructuralFeature(propertyIndex),
true);
+ }
+
+ protected List getList(Sequence seq, Type type, int propertyIndex) {
+ return
((FeatureMap.Internal.Wrapper)seq).featureMap().list(((EClass)type).getEStructuralFeature(propertyIndex));
+ }
+
+ protected void set(Sequence seq, Type type, int propertyIndex, Object
newValue) {
+
((FeatureMap.Internal)((FeatureMap.Internal.Wrapper)seq).featureMap()).set(((EClass)type).getEStructuralFeature(propertyIndex),
newValue);
+ }
+
+ protected void unset(Sequence seq, Type type, int propertyIndex) {
+
((FeatureMap.Internal)((FeatureMap.Internal.Wrapper)seq).featureMap()).clear(((EClass)type).getEStructuralFeature(propertyIndex));
+
+ }
+ protected boolean isSet(Sequence seq, Type type, int propertyIndex) {
+ return
!((FeatureMap.Internal)((FeatureMap.Internal.Wrapper)seq).featureMap()).isEmpty(((EClass)type).getEStructuralFeature(propertyIndex));
+ }
+
+ protected boolean isSequenceEmpty(Sequence sequence) {
+ return ((FeatureMap.Internal.Wrapper)sequence).featureMap().isEmpty();
+ }
+
+ protected void setSequence(Sequence seq, Object newValue) {
+
((FeatureMap.Internal)((FeatureMap.Internal.Wrapper)seq).featureMap()).set(newValue);
+ }
+
+ protected void unsetSequence(Sequence seq) {
+ ((FeatureMap.Internal.Wrapper)seq).featureMap().clear();
+ }
+
+ protected Object get(int featureID, boolean resolve)
+ {
+ return null;
+ }
+
+ protected interface ChangeContext {}
+
+ protected ChangeContext inverseRemove(Object otherEnd, int propertyIndex,
ChangeContext changeContext)
+ {
+ ChangeContextImpl changeContextImpl = (ChangeContextImpl)changeContext;
+ changeContextImpl.notificationChain =
super.eInverseRemove((InternalEObject)otherEnd, propertyIndex,
changeContextImpl.notificationChain);
+ return changeContextImpl;
+ }
+
+ protected ChangeContext removeFromList(List propertyList, Object
objectToRemove, ChangeContext changeContext)
+ {
+ ChangeContextImpl changeContextImpl = (ChangeContextImpl)changeContext;
+ changeContextImpl.notificationChain =
((InternalEList)propertyList).basicRemove(objectToRemove,
changeContextImpl.notificationChain);
+ return changeContextImpl;
+ }
+
+ protected ChangeContext removeFromSequence(Sequence sequence, Object
otherEnd, ChangeContext changeContext) {
+ ChangeContextImpl changeContextImpl = (ChangeContextImpl)changeContext;
+ changeContextImpl.notificationChain =
((InternalEList)((FeatureMap.Internal.Wrapper)sequence).featureMap()).basicRemove(otherEnd,
changeContextImpl.notificationChain);
+ return changeContextImpl;
+ }
+
+ protected boolean isProxy()
+ {
+ return eIsProxy();
+ }
+
+ protected Object resolveProxy(Object proxy)
+ {
+ return EcoreUtil.resolve((EObject)proxy, this);
+ }
+
+
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Following methods override EMF methods to work with pure SDO generated
subclasses
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ public EClass eStaticClass()
+ {
+ return (EClass)getType();
+ }
+
+ public Type getType() // must be overridem in subclasses
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object eGet(int featureID, boolean resolve, boolean coreType)
+ {
+ Object result = get(featureID, resolve);
+ if (coreType)
+ {
+ if (result instanceof FeatureMap.Internal.Wrapper) result =
((FeatureMap.Internal.Wrapper)result).featureMap();
+ }
+ return result;
+ }
+
+ public void eSet(int featureID, Object newValue)
+ {
+ set(featureID, newValue);
+ }
+
+ public void eUnset(int featureID)
+ {
+ unset(featureID);
+ }
+
+ public boolean eIsSet(int featureID)
+ {
+ return isSet(featureID);
+ }
+
+ private class ChangeContextImpl implements ChangeContext
+ {
+ protected NotificationChain notificationChain;
+ public ChangeContextImpl(NotificationChain notificationChain) {
+ this.notificationChain = notificationChain;
+ }
+ }
+
+ public NotificationChain eInverseRemove(InternalEObject otherEnd, int
propertyIndex, NotificationChain msgs)
+ {
+ return ((ChangeContextImpl)inverseRemove(otherEnd, propertyIndex, new
ChangeContextImpl(msgs))).notificationChain;
+ }
+
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer(getClass().getName());
+ result.append('@');
+ result.append(Integer.toHexString(hashCode()));
+ if (eIsProxy())
+ {
+ result.append(" (proxyURI: ");
+ result.append(eProxyURI());
+ result.append(')');
+ }
+ return result.toString();
+ }
+
+} //DataObjectBase
+
Added:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/FactoryBase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/FactoryBase.java?rev=405063&view=auto
==============================================================================
---
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/FactoryBase.java
(added)
+++
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/FactoryBase.java
Mon May 8 07:35:35 2006
@@ -0,0 +1,214 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as
applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.tuscany.sdo.impl;
+
+import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.impl.EClassImpl;
+import org.eclipse.emf.ecore.impl.EFactoryImpl;
+import org.eclipse.emf.ecore.impl.EPackageImpl;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+
+/**
+ */
+public class FactoryBase extends EPackageImpl
+{
+ protected FactoryBase(String namespaceURI, String namespacePrefix)
+ {
+ super(new SDOEFactoryImpl());
+
+ int index = namespacePrefix.lastIndexOf(".");
+ setName(index != -1 ? namespacePrefix.substring(index + 1) :
namespacePrefix);
+ setNsPrefix(namespacePrefix);
+
+ createResource(namespaceURI);
+ setNsURI(namespaceURI);
+ //FIXME ... figure out proper (scoped) way to register static packages
+ EPackage.Registry.INSTANCE.put(namespaceURI, this);
+
+ ((SDOEFactoryImpl)getEFactoryInstance()).sdoFactory = this;
+ }
+
+ public DataObject create(int typeNumber)
+ {
+ return null;
+ }
+
+ protected Type createType(boolean isDataType, int typeNumber)
+ {
+ if (isDataType)
+ return (Type)createEDataType(typeNumber);
+ else
+ return (Type)createEClass(typeNumber);
+ }
+
+ protected void createProperty(boolean isDataType, Type containingType, int
propertyNumber)
+ {
+ if (isDataType)
+ createEAttribute((EClass)containingType, propertyNumber);
+ else
+ createEReference((EClass)containingType, propertyNumber);
+ }
+
+ protected void initializeType(Type type, Class instanceClass, String name)
+ {
+ initEClass((EClass)type, instanceClass, name, !IS_ABSTRACT, !IS_INTERFACE,
IS_GENERATED_INSTANCE_CLASS);
+ }
+
+ protected void initializeProperty(Property property, Type type, String name,
String defaultValue, int lower, int upper, Class containerClass, boolean
isReadonly, boolean isUnsettable, boolean isDerived)
+ {
+ initEAttribute((EAttribute)property, (EClassifier)type, name,
defaultValue, lower, upper, containerClass, isDerived, isDerived, !isReadonly,
isUnsettable, !IS_ID, !IS_UNIQUE, isDerived, IS_ORDERED);
+ }
+
+ protected void initializeProperty(Property property, Type type, String name,
String defaultValue, int lower, int upper, Class containerClass, boolean
isReadonly, boolean isUnsettable, boolean isDerived, boolean isComposite,
Property oppositeProperty)
+ {
+ initEReference((EReference)property, (EClassifier)type,
(EReference)oppositeProperty, name, defaultValue, lower, upper, containerClass,
isDerived, isDerived, !isReadonly, isComposite, !isComposite /*resolve*/,
isUnsettable, IS_UNIQUE, isDerived, IS_ORDERED);
+ }
+
+
+
+ protected void createXSDMetaData()
+ {
+ createDocumentRoot();
+ }
+
+ protected void addXSDMapping(Type type, String[] xsdMappings)
+ {
+ addAnnotation((ENamedElement)type, ANNOTATION_SOURCE, xsdMappings);
+ }
+
+ protected void addXSDMapping(Property property, String[] xsdMappings)
+ {
+ addAnnotation((ENamedElement)property, ANNOTATION_SOURCE, xsdMappings);
+ }
+
+ protected void createGlobalProperty(String name, Type type, String[]
xsdMappings)
+ {
+ int propertyNumber = documentRootEClass.getEStructuralFeatures().size();
+ createEReference(documentRootEClass, propertyNumber);
+ EReference globalProperty =
(EReference)documentRootEClass.getEStructuralFeatures().get(propertyNumber);
+ initEReference(globalProperty, (EClass)type, null, name, null, 0, -2,
null, IS_TRANSIENT, IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE,
!IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
+ addAnnotation((ENamedElement)globalProperty, ANNOTATION_SOURCE,
xsdMappings);
+ }
+
+ protected Type getSequence() {
+ return (Type)ecorePackage.getEFeatureMapEntry();
+ }
+
+ //public static FactoryBase getStaticFactory(String namespaceURI)
+ // temporarily return Object - until everything is gen'd with new codegen
pattern
+ public static Object getStaticFactory(String namespaceURI)
+ {
+ EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(namespaceURI);
+ //return (FactoryBase)ePackage;
+ return ePackage instanceof FactoryBase ? (Object)ePackage :
(Object)ePackage.getEFactoryInstance();
+ }
+
+ // private EMF-specific methods
+
+ private static class SDOEFactoryImpl extends EFactoryImpl
+ {
+ protected FactoryBase sdoFactory;
+
+ public SDOEFactoryImpl()
+ {
+ super();
+ }
+
+ public EObject create(EClass eClass)
+ {
+ DataObject result = sdoFactory.create(eClass.getClassifierID());
+ if (result == null) {
+ return super.create(eClass);
+ }
+ return (EObject)result;
+ }
+ }
+
+ private static final int DOCUMENT_ROOT = 0;
+ private static final int DOCUMENT_ROOT__MIXED = 0;
+ private static final int DOCUMENT_ROOT__XMLNS_PREFIX_MAP = 1;
+ private static final int DOCUMENT_ROOT__XSI_SCHEMA_LOCATION = 2;
+ private static final String ANNOTATION_SOURCE =
"http:///org/eclipse/emf/ecore/util/ExtendedMetaData";
+ private EClass documentRootEClass = null;
+
+ private void createDocumentRoot()
+ {
+ documentRootEClass = ecoreFactory.createEClass();
+ ((EClassImpl)documentRootEClass).setClassifierID(DOCUMENT_ROOT);
+ getEClassifiers().add(DOCUMENT_ROOT, documentRootEClass);
+
+ createEAttribute(documentRootEClass, DOCUMENT_ROOT__MIXED);
+ createEReference(documentRootEClass, DOCUMENT_ROOT__XMLNS_PREFIX_MAP);
+ createEReference(documentRootEClass, DOCUMENT_ROOT__XSI_SCHEMA_LOCATION);
+
+ initEClass(documentRootEClass, null, "DocumentRoot", !IS_ABSTRACT,
!IS_INTERFACE, !IS_GENERATED_INSTANCE_CLASS);
+
initEAttribute((EAttribute)documentRootEClass.getEStructuralFeatures().get(DOCUMENT_ROOT__MIXED),
ecorePackage.getEFeatureMapEntry(), "mixed", null, 0, -1, null, !IS_TRANSIENT,
!IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED,
IS_ORDERED);
+
initEReference((EReference)documentRootEClass.getEStructuralFeatures().get(DOCUMENT_ROOT__XMLNS_PREFIX_MAP),
ecorePackage.getEStringToStringMapEntry(), null, "xMLNSPrefixMap", null, 0,
-1, null, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE,
!IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+
initEReference((EReference)documentRootEClass.getEStructuralFeatures().get(DOCUMENT_ROOT__XSI_SCHEMA_LOCATION),
ecorePackage.getEStringToStringMapEntry(), null, "xSISchemaLocation", null, 0,
-1, null, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE,
!IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+
+ addAnnotation
+ (documentRootEClass,
+ ANNOTATION_SOURCE,
+ new String[]
+ {
+ "name", "",
+ "kind", "mixed"
+ });
+ addAnnotation
+
((EAttribute)documentRootEClass.getEStructuralFeatures().get(DOCUMENT_ROOT__MIXED),
+ ANNOTATION_SOURCE,
+ new String[]
+ {
+ "kind", "elementWildcard",
+ "name", ":mixed"
+ });
+ addAnnotation
+
((EReference)documentRootEClass.getEStructuralFeatures().get(DOCUMENT_ROOT__XMLNS_PREFIX_MAP),
+ ANNOTATION_SOURCE,
+ new String[]
+ {
+ "kind", "attribute",
+ "name", "xmlns:prefix"
+ });
+ addAnnotation
+
((EReference)documentRootEClass.getEStructuralFeatures().get(DOCUMENT_ROOT__XSI_SCHEMA_LOCATION),
+ ANNOTATION_SOURCE,
+ new String[]
+ {
+ "kind", "attribute",
+ "name", "xsi:schemaLocation"
+ });
+ }
+
+ /**
+ * Initialize SDO runtime.
+ */
+ static
+ {
+ DataObjectUtil.initRuntime();
+ }
+}
Modified:
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java?rev=405063&r1=405062&r2=405063&view=diff
==============================================================================
---
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
(original)
+++
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
Mon May 8 07:35:35 2006
@@ -28,16 +28,22 @@
import java.util.List;
import java.util.StringTokenizer;
+import
org.apache.tuscany.sdo.generate.adapter.SDOGenModelGeneratorAdapterFactory;
import org.apache.tuscany.sdo.helper.XSDHelperImpl;
import org.apache.tuscany.sdo.impl.SDOPackageImpl;
import org.apache.tuscany.sdo.model.impl.ModelPackageImpl;
import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.eclipse.emf.codegen.ecore.generator.Generator;
+import org.eclipse.emf.codegen.ecore.generator.GeneratorAdapterFactory;
import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenDelegationKind;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.ecore.genmodel.GenResourceKind;
+import
org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
+import
org.eclipse.emf.codegen.ecore.genmodel.generator.GenModelGeneratorAdapterFactory;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Diagnostic;
@@ -67,6 +73,8 @@
public static int OPTION_NO_UNSETTABLE=0x80;
//FIXME Temporary, I need this option for now to get Switch classes
generated for the SCDL models
public static int OPTION_GENERATE_SWITCH=0x100;
+ public static int OPTION_NO_EMF=0x200;
+
/**
* Generate static SDOs from XML Schema
@@ -83,6 +91,7 @@
* [ -arrayAccessors ]
* [ -generateLoader ]
* [ -noUnsettable ]
+ * [ -noEMF ]
* <xsd-file> | <wsdl-file>
*
* For example:
@@ -110,6 +119,9 @@
* reflective methods (as opposed to the other way around) and
changes the DataObject base class
* to org.apache.tuscany.sdo.impl.StoreDataObjectImpl. Note that
this option generates classes that
* require a Store implementation to be provided before they can be
run.
+ * -noEMF
+ * This option is used to generate static classes that have no
references to EMF classes. This
+ * feature is currently being implemented and is in a preliminary
state.
*
* The following options can be used to increase performance, but with
some loss of SDO functionality:
*
@@ -250,6 +262,10 @@
{
genOptions |= OPTION_NO_UNSETTABLE;
}
+ else if (args[index].equalsIgnoreCase("-noEMF"))
+ {
+ genOptions |= OPTION_NO_EMF;
+ }
//else if (...)
else
{
@@ -339,7 +355,7 @@
// Invoke the SDO JavaGenerator to generate the SDO classes
try
{
- generateFromGenModel(genModel, new
File(targetDirectory).getCanonicalPath());
+ generateFromGenModel(genModel, new
File(targetDirectory).getCanonicalPath(), genOptions);
}
catch (IOException e)
{
@@ -386,10 +402,10 @@
Resource genModelResource = resourceSet.createResource(genModelURI);
genModelResource.getContents().add(genModel);
- generateFromGenModel(genModel, targetDirectory);
+ generateFromGenModel(genModel, targetDirectory, genOptions);
}
- public static void generateFromGenModel(GenModel genModel, String
targetDirectory)
+ public static void generateFromGenModel(GenModel genModel, String
targetDirectory, int genOptions)
{
Resource resource = genModel.eResource();
@@ -401,7 +417,21 @@
genModel.setModelDirectory("/TargetProject");
}
- genModel.gen(new BasicMonitor.Printing(System.out));
+ //genModel.gen(new BasicMonitor.Printing(System.out));
+ GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor
+ (GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
+
+ Generator generator = new Generator();
+
+ if ((genOptions & OPTION_NO_EMF) != 0)
+ {
+ generator.getAdapterFactoryDescriptorRegistry().addDescriptor
+ (GenModelPackage.eNS_URI,
SDOGenModelGeneratorAdapterFactory.DESCRIPTOR);
+ }
+
+ generator.setInput(genModel);
+ generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE,
new BasicMonitor.Printing(System.out));
+
for (Iterator j = resource.getContents().iterator(); j.hasNext();)
{
@@ -468,6 +498,11 @@
genModel.setSuppressUnsettable(true);
}
+ if ((genOptions & OPTION_NO_EMF) != 0)
+ {
+
genModel.setRootExtendsClass("org.apache.tuscany.sdo.impl.DataObjectBase");
+ }
+
GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
if (basePackage != null)
@@ -564,6 +599,7 @@
System.out.println(" [ -arrayAccessors ]");
System.out.println(" [ -generateLoader ]");
System.out.println(" [ -noUnsettable ]");
+ System.out.println(" [ -noEMF ]");
System.out.println(" <xsd-file> | <wsdl-file>");
System.out.println("");
System.out.println("For example:");
Added:
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenClassGeneratorAdapter.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenClassGeneratorAdapter.java?rev=405063&view=auto
==============================================================================
---
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenClassGeneratorAdapter.java
(added)
+++
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenClassGeneratorAdapter.java
Mon May 8 07:35:35 2006
@@ -0,0 +1,27 @@
+package org.apache.tuscany.sdo.generate.adapter;
+
+import org.eclipse.emf.codegen.ecore.generator.GeneratorAdapterFactory;
+import
org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter;
+
+public class SDOGenClassGeneratorAdapter extends GenClassGeneratorAdapter {
+
+ public SDOGenClassGeneratorAdapter(GeneratorAdapterFactory
generatorAdapterFactory)
+ {
+ super(generatorAdapterFactory);
+ }
+
+ private static JETEmitterDescriptor[] jetEmitterDescriptors;
+
+ protected JETEmitterDescriptor[] getJETEmitterDescriptors()
+ {
+ if (jetEmitterDescriptors == null)
+ {
+ JETEmitterDescriptor[] base = super.getJETEmitterDescriptors();
+ jetEmitterDescriptors = new JETEmitterDescriptor[base.length];
+ System.arraycopy(base, 0, jetEmitterDescriptors, 0, base.length);
+ jetEmitterDescriptors[CLASS_ID] = new
JETEmitterDescriptor("model/SDOClass.javajet",
"org.apache.tuscany.sdo.generate.templates.model.SDOClass");
+ }
+ return jetEmitterDescriptors;
+ }
+
+}
Added:
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenModelGeneratorAdapterFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenModelGeneratorAdapterFactory.java?rev=405063&view=auto
==============================================================================
---
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenModelGeneratorAdapterFactory.java
(added)
+++
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenModelGeneratorAdapterFactory.java
Mon May 8 07:35:35 2006
@@ -0,0 +1,35 @@
+package org.apache.tuscany.sdo.generate.adapter;
+
+import org.eclipse.emf.codegen.ecore.generator.GeneratorAdapterFactory;
+import
org.eclipse.emf.codegen.ecore.genmodel.generator.GenModelGeneratorAdapterFactory;
+import org.eclipse.emf.common.notify.Adapter;
+
+public class SDOGenModelGeneratorAdapterFactory extends
+ GenModelGeneratorAdapterFactory {
+
+ public static final GeneratorAdapterFactory.Descriptor DESCRIPTOR = new
GeneratorAdapterFactory.Descriptor()
+ {
+ public GeneratorAdapterFactory createAdapterFactory()
+ {
+ return new SDOGenModelGeneratorAdapterFactory();
+ }
+ };
+
+ public Adapter createGenClassAdapter()
+ {
+ if (genClassGeneratorAdapter == null)
+ {
+ genClassGeneratorAdapter = new SDOGenClassGeneratorAdapter(this);
+ }
+ return genClassGeneratorAdapter;
+ }
+
+ public Adapter createGenPackageAdapter()
+ {
+ if (genPackageGeneratorAdapter == null)
+ {
+ genPackageGeneratorAdapter = new
SDOGenPackageGeneratorAdapter(this);
+ }
+ return genPackageGeneratorAdapter;
+ }
+}
Added:
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenPackageGeneratorAdapter.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenPackageGeneratorAdapter.java?rev=405063&view=auto
==============================================================================
---
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenPackageGeneratorAdapter.java
(added)
+++
incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/adapter/SDOGenPackageGeneratorAdapter.java
Mon May 8 07:35:35 2006
@@ -0,0 +1,33 @@
+package org.apache.tuscany.sdo.generate.adapter;
+
+import org.eclipse.emf.codegen.ecore.generator.GeneratorAdapterFactory;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import
org.eclipse.emf.codegen.ecore.genmodel.generator.GenPackageGeneratorAdapter;
+import org.eclipse.emf.common.util.Monitor;
+
+public class SDOGenPackageGeneratorAdapter extends GenPackageGeneratorAdapter
+{
+ public SDOGenPackageGeneratorAdapter(GeneratorAdapterFactory
generatorAdapterFactory)
+ {
+ super(generatorAdapterFactory);
+ }
+
+ private static JETEmitterDescriptor[] jetEmitterDescriptors;
+
+ protected JETEmitterDescriptor[] getJETEmitterDescriptors()
+ {
+ if (jetEmitterDescriptors == null)
+ {
+ JETEmitterDescriptor[] base = super.getJETEmitterDescriptors();
+ jetEmitterDescriptors = new JETEmitterDescriptor[base.length];
+ System.arraycopy(base, 0, jetEmitterDescriptors, 0, base.length);
+ jetEmitterDescriptors[FACTORY_CLASS_ID] = new
JETEmitterDescriptor("model/SDOFactoryClass.javajet",
"org.apache.tuscany.sdo.generate.templates.model.SDOFactoryClass");
+ }
+ return jetEmitterDescriptors;
+ }
+
+ protected void generatePackageClass(GenPackage genPackage, Monitor
monitor)
+ {
+ // do nothing
+ }
+}