You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/10/25 17:45:37 UTC
svn commit: r588261 - in /incubator/tuscany/java/sdo:
tools-test/src/main/resources/
tools-test/src/test/java/org/apache/tuscany/sdo/test/
tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/
tools/src/main/java/org/apache/tuscany/sdo/g...
Author: kelvingoodson
Date: Thu Oct 25 08:45:35 2007
New Revision: 588261
URL: http://svn.apache.org/viewvc?rev=588261&view=rev
Log:
Fix for TUSCANY-1780. Put in a catch for special condition described in the problem. Handling this case outside of the EMF provided methods -- dropping through for other cases.
Added:
incubator/tuscany/java/sdo/tools-test/src/main/resources/xsdlistitem.xsd
incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java
Modified:
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/main/java/org/apache/tuscany/sdo/generate/util/SDOGenUtil.java
incubator/tuscany/java/sdo/tools/templates/models/SDOClass.javajet
Added: incubator/tuscany/java/sdo/tools-test/src/main/resources/xsdlistitem.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/main/resources/xsdlistitem.xsd?rev=588261&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/tools-test/src/main/resources/xsdlistitem.xsd (added)
+++ incubator/tuscany/java/sdo/tools-test/src/main/resources/xsdlistitem.xsd Thu Oct 25 08:45:35 2007
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+ -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/AddressWithList" xmlns:address="http://www.example.org/AddressWithList" elementFormDefault="qualified">
+
+ <xsd:element name="Address" type="address:AddressType" />
+
+ <xsd:complexType name="SubCategoryType">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <xsd:attribute name="categoryType" type="address:CategoryType" default="myCat"/>
+ <xsd:attribute name="displayable" type="xsd:boolean" use="optional"/>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:simpleType name="CategoryType">
+ <xsd:list itemType="xsd:string" />
+ </xsd:simpleType>
+ <xsd:simpleType name="CategoryType2">
+ <xsd:restriction base="xsd:string" />
+ </xsd:simpleType>
+
+
+
+ <xsd:complexType name="AddressType">
+ <xsd:sequence>
+ <xsd:element name="Street" type="xsd:string"></xsd:element>
+ <xsd:element name="City" type="xsd:string"></xsd:element>
+ <xsd:element name="Zip" type="xsd:string"></xsd:element>
+ <xsd:element name="SubCategory" type="address:SubCategoryType"></xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+</xsd:schema>
\ No newline at end of file
Added: incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java?rev=588261&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java (added)
+++ incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java Thu Oct 25 08:45:35 2007
@@ -0,0 +1,53 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.tuscany.sdo.test;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.test.xsdlistwitdefault.SubCategoryType;
+import org.apache.tuscany.sdo.test.xsdlistwitdefault.XsdlistwitdefaultFactory;
+
+import commonj.sdo.helper.HelperContext;
+
+public class ListWithDefaultTestCase extends TestCase {
+ HelperContext scope = null;
+
+ public void testListWithDefault() {
+ SubCategoryType sct = (SubCategoryType)scope.getDataFactory().create(SubCategoryType.class);
+ List l = sct.getCategoryType();
+ assertTrue(l.size() == 1);
+ assertEquals((String)l.get(0), "myCat");
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ scope = SDOUtil.createHelperContext();
+
+ XsdlistwitdefaultFactory.INSTANCE.register(scope);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}
Modified: incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOClass.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOClass.java?rev=588261&r1=588260&r2=588261&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOClass.java (original)
+++ incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOClass.java Thu Oct 25 08:45:35 2007
@@ -1642,7 +1642,7 @@
stringBuffer.append(TEXT_104);
stringBuffer.append(genFeature.getUpperName());
stringBuffer.append(TEXT_105);
- stringBuffer.append(genFeature.getStaticDefaultValue());
+ stringBuffer.append(SDOGenUtil.getStaticDefaultValue(genFeature));
stringBuffer.append(TEXT_106);
stringBuffer.append(genModel.getNonNLS(genFeature.getStaticDefaultValue()));
stringBuffer.append(TEXT_107);
Modified: incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java?rev=588261&r1=588260&r2=588261&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java (original)
+++ incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java Thu Oct 25 08:45:35 2007
@@ -1129,4 +1129,4 @@
stringBuffer.append(TEXT_313);
return stringBuffer.toString();
}
-}
+}
\ No newline at end of file
Modified: incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/util/SDOGenUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/util/SDOGenUtil.java?rev=588261&r1=588260&r2=588261&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/util/SDOGenUtil.java (original)
+++ incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/util/SDOGenUtil.java Thu Oct 25 08:45:35 2007
@@ -25,12 +25,17 @@
import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl;
import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier;
+import org.eclipse.emf.codegen.ecore.genmodel.GenDataType;
import org.eclipse.emf.codegen.ecore.genmodel.GenDelegationKind;
import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.codegen.ecore.genmodel.impl.GenFeatureImpl;
+import org.eclipse.emf.codegen.ecore.genmodel.impl.Literals;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EcorePackage;
import commonj.sdo.Type;
@@ -246,5 +251,76 @@
return result.toString();
}
-
+
+ /*
+ * EMF doesn't do what we want in all cases, so filter the cases we need to handle
+ * and drop through to EMF for all others.
+ */
+ public static String getStaticDefaultValue(GenFeature genFeature) {
+ String result = "null";
+ boolean defaultFound = false;
+
+ String defaultString = genFeature.getEcoreFeature()
+ .getDefaultValueLiteral();
+ EClassifier eType = genFeature.getEcoreFeature().getEType();
+ if (eType instanceof EDataType) {
+ GenPackage genPackage = ((GenFeatureImpl) genFeature)
+ .findGenPackage(genFeature.getEcoreFeature().getEType().getEPackage());
+ GenDataType gdt = null;
+ if (genPackage != null) {
+ for (Iterator iter = genPackage.getGenDataTypes().iterator(); iter
+ .hasNext()
+ && gdt == null;) {
+ GenDataType genDataType = (GenDataType) iter.next();
+ if (eType.getName().equals(genDataType.getEcoreDataType().getName())) {
+ gdt = genDataType;
+ }
+ }
+ }
+ EClassifier eDataType = gdt.getEcoreDataType();
+ if (eDataType.getEPackage() != EcorePackage.eINSTANCE
+ && defaultString != null) {
+ boolean replaced = false;
+ for (Iterator i = EcorePackage.eINSTANCE.getEClassifiers().iterator(); i
+ .hasNext();) {
+ EClassifier eClassifier = (EClassifier) i.next();
+ if (eClassifier instanceof EDataType
+ && eClassifier.getInstanceClassName().equals(
+ eDataType.getInstanceClassName())
+ && ((EDataType) eClassifier).isSerializable()
+ && eClassifier != EcorePackage.eINSTANCE.getEDate()) {
+ replaced = true;
+ eDataType = eClassifier;
+ break;
+ }
+ }
+ if (!replaced) {
+ result = "((" + genPackage.getFactoryClassName() + ")"
+ + genPackage.getFactoryInterfaceName() + "."
+ + genPackage.getFactoryInstanceName() + ")." + "create"
+ + gdt.getName() + "FromString("
+ + Literals.toLiteral(defaultString) + ")";
+
+
+ if (gdt.isPrimitiveType())
+ {
+ result = "((" + gdt.getObjectInstanceClassName() + ")" + result
+ + ")." + gdt.getPrimitiveValueFunction() + "()";
+ } else if (!gdt.isObjectType()) {
+ result = "(" + gdt.getImportedInstanceClassName() + ")" + result;
+ }
+
+ defaultFound = true;
+ }
+ }
+ }
+
+ if (!defaultFound) {
+ // the input didn't match any special case that we want to handle differently
+ // from EMF's default approach, so go ahead and get EMF to do it
+ result = genFeature.getStaticDefaultValue();
+ }
+
+ return result;
+ }
}
Modified: incubator/tuscany/java/sdo/tools/templates/models/SDOClass.javajet
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/templates/models/SDOClass.javajet?rev=588261&r1=588260&r2=588261&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/tools/templates/models/SDOClass.javajet (original)
+++ incubator/tuscany/java/sdo/tools/templates/models/SDOClass.javajet Thu Oct 25 08:45:35 2007
@@ -343,7 +343,7 @@
* @generated
* @ordered
*/
- protected static final <%=genFeature.getImportedType()%> <%=genFeature.getUpperName()%>_DEFAULT_ = <%=genFeature.getStaticDefaultValue()%>;<%=genModel.getNonNLS(genFeature.getStaticDefaultValue())%>
+ protected static final <%=genFeature.getImportedType()%> <%=genFeature.getUpperName()%>_DEFAULT_ = <%=SDOGenUtil.getStaticDefaultValue(genFeature)%>;<%=genModel.getNonNLS(genFeature.getStaticDefaultValue())%>
<%}%>
<%if (genClass.isField(genFeature)) {%>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org