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/02/12 18:00:15 UTC

svn commit: r506537 - in /incubator/tuscany/java/sdo/impl/src: main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java test/resources/simple2.xsd

Author: kelvingoodson
Date: Mon Feb 12 09:00:14 2007
New Revision: 506537

URL: http://svn.apache.org/viewvc?view=rev&rev=506537
Log:
TUSCANY-1085 applying Fuhwei's patch

Added:
    incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd   (with props)
Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java?view=diff&rev=506537&r1=506536&r2=506537
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java Mon Feb 12 09:00:14 2007
@@ -85,7 +85,13 @@
           xsdTypeDefinition.getURI(), 
           xsdTypeDefinition.getName());
     } else {
-      eClassifier = super.getEClassifier(xsdTypeDefinition);
+        EPackage pkg = extendedMetaData.getPackage(xsdTypeDefinition.getTargetNamespace());
+        if(pkg != null) {
+          eClassifier = pkg.getEClassifier(xsdTypeDefinition.getName());
+        }
+        if (eClassifier == null) {
+            eClassifier = super.getEClassifier(xsdTypeDefinition);
+        }
     }
     return eClassifier;
   }
@@ -165,6 +171,21 @@
   protected EStructuralFeature createFeature(EClass eClass, String name, EClassifier type, XSDComponent xsdComponent, int minOccurs, int maxOccurs) {
     EStructuralFeature feature = 
       super.createFeature(eClass, name, type, xsdComponent, minOccurs, maxOccurs);
+    
+    if (feature instanceof EReference) {
+        EReference eReference = (EReference)feature;
+            if (xsdComponent != null && xsdComponent instanceof XSDParticle) {
+                XSDTerm xsdTerm = ((XSDParticle)xsdComponent).getTerm();
+                if (xsdTerm instanceof XSDElementDeclaration) {
+                        XSDTypeDefinition elementTypeDefinition = getEffectiveTypeDefinition(xsdComponent, (XSDElementDeclaration)xsdTerm);
+                        EClassifier eClassifier = getEClassifier(elementTypeDefinition);
+                        if(elementTypeDefinition instanceof XSDSimpleTypeDefinition && eClassifier instanceof EClass) { 
+                                eReference.setContainment(true);
+                        }
+                }
+            }
+   }
+
     feature.setName(name); // this is needed because super.createFeature() does EMF name mangling (toLower)
     if (xsdComponent != null) {
       String aliasNames = getEcoreAttribute(xsdComponent.getElement(), "aliasName");

Modified: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java?view=diff&rev=506537&r1=506536&r2=506537
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java (original)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java Mon Feb 12 09:00:14 2007
@@ -30,6 +30,7 @@
 import junit.framework.TestCase;
 
 import commonj.sdo.DataObject;
+import commonj.sdo.Property;
 import commonj.sdo.Type;
 import commonj.sdo.helper.DataFactory;
 import commonj.sdo.helper.TypeHelper;
@@ -42,10 +43,14 @@
     private final String TEST_NAMESPACE = "http://www.example.com/simple";
     private final String QUOTE_XML = "/quote.xml";
 
+	private final String TEST_MODEL2 = "/simple2.xsd";
+    private final String TEST_NAMESPACE2 = "http://www.example.com/simple2";
+    private final String QUOTE_XML2 = "/quote2.xml";
+
     /**
      * Simple Dynamic SDO 2 test.
      */
-    public void testDynamic() throws IOException {
+    public void donttestDynamic() throws IOException {
         Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "Quote");
         DataObject quote = DataFactory.INSTANCE.create(quoteType);
 
@@ -69,7 +74,26 @@
         
         assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(QUOTE_XML)));
     }
+	
+	public void testResolveXSDWithoutSchemaLocation() throws IOException {
+        Type quote2Type = TypeHelper.INSTANCE.getType(TEST_NAMESPACE2, "Quote2");
+        DataObject quote2 = DataFactory.INSTANCE.create(quote2Type);
+        
+        quote2.setString("symbol", "fbnt");
+        quote2.setString("companyName", "FlyByNightTechnology");
+        quote2.setBigDecimal("price", new BigDecimal("1000.0"));
+        quote2.setBigDecimal("open1", new BigDecimal("1000.0"));
+        quote2.setBigDecimal("high", new BigDecimal("1000.0"));
+        quote2.setBigDecimal("low", new BigDecimal("1000.0"));
+        quote2.setDouble("volume", 1000);
+        quote2.setDouble("change1", 1000);
 
+        DataObject child = quote2.createDataObject("quotes");
+        child.setBigDecimal("price", new BigDecimal("2000.0"));
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		XMLHelper.INSTANCE.save(quote2, TEST_NAMESPACE2, "stockQuote", System.out);
+    }
 
     protected void setUp() throws Exception {
         super.setUp();
@@ -78,6 +102,11 @@
         URL url = getClass().getResource(TEST_MODEL);
         InputStream inputStream = url.openStream();
         XSDHelper.INSTANCE.define(inputStream, url.toString());
+        inputStream.close();
+
+		url = getClass().getResource(TEST_MODEL2);
+		inputStream = url.openStream();
+        XSDHelper.INSTANCE.define(inputStream, null);
         inputStream.close();
     }
 

Added: incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd?view=auto&rev=506537
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd (added)
+++ incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd Mon Feb 12 09:00:14 2007
@@ -0,0 +1,39 @@
+<?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
+    "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:simple="http://www.example.com/simple" xmlns:simple2="http://www.example.com/simple2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/simple2"> 
+  
+	<xsd:import namespace="http://www.example.com/simple"/>
+	
+   <xsd:element name="stockQuote" type="simple2:Quote2"/>
+
+   <xsd:complexType name="Quote2">
+       <xsd:sequence>
+          <xsd:element name="symbol" type="xsd:string"/>
+          <xsd:element name="companyName" type="xsd:string"/>
+          <xsd:element name="price" type="xsd:decimal"/>
+          <xsd:element name="open1" type="xsd:decimal"/>
+          <xsd:element name="high" type="xsd:decimal"/>
+          <xsd:element name="low" type="xsd:decimal"/>
+          <xsd:element name="volume" type="xsd:double"/>
+          <xsd:element name="change1" type="xsd:double"/>
+          <xsd:element maxOccurs="unbounded" minOccurs="0" name="quotes" type="simple:Quote"/>
+       </xsd:sequence>
+   </xsd:complexType>
+
+</xsd:schema>

Propchange: incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/tuscany/java/sdo/impl/src/test/resources/simple2.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org