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/07/11 17:32:12 UTC

svn commit: r555312 - in /incubator/tuscany/branches/sdo-1.0-incubating: impl/src/main/java/org/apache/tuscany/sdo/helper/ impl/src/test/java/org/apache/tuscany/sdo/test/ lib/src/main/java/org/apache/tuscany/sdo/api/

Author: kelvingoodson
Date: Wed Jul 11 08:32:10 2007
New Revision: 555312

URL: http://svn.apache.org/viewvc?view=rev&rev=555312
Log:
Fix for TUSCANY-1408 (1.0-incubating branch)

Modified:
    incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
    incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java
    incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
    incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
    incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java?view=diff&rev=555312&r1=555311&r2=555312
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java Wed Jul 11 08:32:10 2007
@@ -357,38 +357,46 @@
     }
 
     public Property createProperty(Type containingType, String name, Type propertyType) {
-        EStructuralFeature eStructuralFeature =
+      EStructuralFeature eStructuralFeature = 
             propertyType.isDataType() ? (EStructuralFeature)SDOFactory.eINSTANCE.createAttribute()
                 : (EStructuralFeature)SDOFactory.eINSTANCE.createReference();
 
-        eStructuralFeature.setName(name);
-        eStructuralFeature.setEType((EClassifier)propertyType);
-        ((EClass)containingType).getEStructuralFeatures().add(eStructuralFeature);
+      eStructuralFeature.setName(name);
+      eStructuralFeature.setEType((EClassifier)propertyType);
+      ((EClass)containingType).getEStructuralFeatures().add(eStructuralFeature);
 
         if ("".equals(ExtendedMetaData.INSTANCE.getName((EClass)containingType))) // DocumentRoot
                                                                                     // containingType?
-        {
-            ExtendedMetaData.INSTANCE.setNamespace(eStructuralFeature, containingType.getURI());
-            // FB???eStructuralFeature.setUnique(false);
-            // FB???eStructuralFeature.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY);
-        }
-
-        if (ExtendedMetaData.INSTANCE.getMixedFeature((EClass)containingType) != null) {
-            eStructuralFeature.setDerived(true);
-            eStructuralFeature.setTransient(true);
-            eStructuralFeature.setVolatile(true);
-            ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE);
-        } else {
-            // FB TBD ... figure out how to decide whether to use
-            // ELEMENT_FEATURE or ATTRIBUTE_FEATURE
-            // ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature,
-            // ExtendedMetaData.ELEMENT_FEATURE);
-        }
-
-        return (Property)eStructuralFeature;
+      {
+        ExtendedMetaData.INSTANCE.setNamespace(eStructuralFeature, containingType.getURI());
+        //FB???eStructuralFeature.setUnique(false);
+        //FB???eStructuralFeature.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY);
+      }
+      
+      if (ExtendedMetaData.INSTANCE.getMixedFeature((EClass)containingType) != null) {
+        eStructuralFeature.setDerived(true);
+        eStructuralFeature.setTransient(true);
+        eStructuralFeature.setVolatile(true);
+        ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE);
+      } else {
+          // By default, a SDO property is an XSD element
+          ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE);
+      }
+      
+      return (Property)eStructuralFeature;
     }
 
-    public Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type) {
+  public void setPropertyXMLKind(Property property, boolean isXmlElement) {
+      if (isXmlElement) {
+          ExtendedMetaData.INSTANCE.setFeatureKind((EStructuralFeature)property, ExtendedMetaData.ELEMENT_FEATURE);
+      }
+      else {
+          ExtendedMetaData.INSTANCE.setFeatureKind((EStructuralFeature)property, ExtendedMetaData.ATTRIBUTE_FEATURE);
+      }
+  }
+  
+  public Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type)
+  {
         ExtendedMetaData extendedMetaData = ((TypeHelperImpl)scope).getExtendedMetaData();
 
         // get/create document root

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java?view=diff&rev=555312&r1=555311&r2=555312
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java Wed Jul 11 08:32:10 2007
@@ -29,14 +29,17 @@
 import org.apache.tuscany.sdo.model.internal.InternalFactory;
 import org.apache.tuscany.sdo.model.java.JavaFactory;
 import org.apache.tuscany.sdo.model.xml.XMLFactory;
+import org.apache.tuscany.sdo.model.xml.impl.XMLFactoryImpl;
 import org.apache.tuscany.sdo.api.SDOUtil;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EClassifier;
 import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.util.ExtendedMetaData;
 
 import commonj.sdo.DataObject;
 import commonj.sdo.Property;
+import commonj.sdo.Sequence;
 import commonj.sdo.Type;
 import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.TypeHelper;
@@ -251,7 +254,26 @@
             String aliasName = (String)iter.next();
             SDOUtil.addAliasName(newProperty, aliasName);
         }
-        if (!newProperty.getType().isDataType()) {
+    
+    if (newProperty.getType().isDataType()) {
+        // Setting xmlElement to FALSE only makes sense here
+        Boolean isXmlElement = Boolean.TRUE;    // By default, a SDO property is an XSD element
+        Sequence anyAttr = modeledProperty.getAnyAttribute();
+        for (int i=0; i<anyAttr.size(); i++) {
+            Property anyProp = anyAttr.getProperty(i);
+            if (XMLFactoryImpl.NAMESPACE_URI.equals(anyProp.getContainingType().getURI())) {
+                String propName = anyProp.getName();
+                if ("xmlElement".equals(propName)) {
+                    isXmlElement = (Boolean)anyAttr.getValue(i);
+                }
+            }
+        }
+        if (!isXmlElement.booleanValue()) {
+            SDOUtil.setPropertyXMLKind(newProperty, false);
+        }
+    }
+    else
+    {
             SDOUtil.setContainment(newProperty, modeledProperty.isContainment());
             if (modeledProperty.getOpposite_() != null) {
                 SDOUtil.setOpposite(newProperty, getDefinedProperty(modeledProperty.getOpposite_()));

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java?view=diff&rev=555312&r1=555311&r2=555312
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java Wed Jul 11 08:32:10 2007
@@ -27,7 +27,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.tuscany.sdo.util.SDOUtil;
+import org.apache.tuscany.sdo.api.SDOUtil;
 
 import commonj.sdo.DataObject;
 import commonj.sdo.Property;
@@ -63,27 +63,32 @@
     Type intType = types.getType("commonj.sdo", "Int");
     Type stringType = types.getType("commonj.sdo", "String");
     
+    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false); 
+    
     // create a new Type for Customers
     DataObject customerType = factory.create("commonj.sdo",
     "Type");
     customerType.set("uri", "http://example.com/customer");
     customerType.set("name", "Customer");
     
-    // create a customer number property
+    // create a customer number property as an XSD attribute
     DataObject custNumProperty = customerType.createDataObject("property");
     custNumProperty.set("name", "custNum");
     custNumProperty.set("type", intType);
+    custNumProperty.setBoolean(xmlElementProp, false);
      
-    // create a first name property
+    // create a first name property as an XSD attribute
     DataObject firstNameProperty =
     customerType.createDataObject("property");
     firstNameProperty.set("name", "firstName");
     firstNameProperty.set("type", stringType);
+    firstNameProperty.setBoolean(xmlElementProp, false);
 
-    // create a last name property
+    // create a last name property as an XSD attribute
     DataObject lastNameProperty = customerType.createDataObject("property");
     lastNameProperty.set("name", "lastName");
     lastNameProperty.set("type", stringType);
+    lastNameProperty.setBoolean(xmlElementProp, false);
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     xmlHelper.save(customerType, "commonj.sdo", "type", baos);
@@ -156,6 +161,8 @@
     Type intType = types.getType("commonj.sdo", "Int");
     Type stringType = types.getType("commonj.sdo", "String");
     
+    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false); 
+    
     // create a new Type for Customers
     DataObject customerType = factory.create("commonj.sdo",
     "Type");
@@ -166,17 +173,20 @@
     DataObject custNumProperty = customerType.createDataObject("property");
     custNumProperty.set("name", "custNum");
     custNumProperty.set("type", intType);
+    custNumProperty.setBoolean(xmlElementProp, false);
 
     // create a first name property
     DataObject firstNameProperty =
     customerType.createDataObject("property");
     firstNameProperty.set("name", "firstName");
     firstNameProperty.set("type", stringType);
+    firstNameProperty.setBoolean(xmlElementProp, false);
 
     // create a last name property
     DataObject lastNameProperty = customerType.createDataObject("property");
     lastNameProperty.set("name", "lastName");
     lastNameProperty.set("type", stringType);
+    lastNameProperty.setBoolean(xmlElementProp, false);
 
     // now define the Customer type so that customers can be made
     types.define(customerType);
@@ -244,6 +254,7 @@
     XMLHelper xmlHelper = hc.getXMLHelper();
     XSDHelper xsdHelper = hc.getXSDHelper();
 
+    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);
     Property javaClassProperty = xsdHelper.getGlobalProperty("commonj.sdo/java", "javaClass", false);
     
     // create a data types
@@ -269,17 +280,20 @@
     DataObject custNumProperty = customerType.createDataObject("property");
     custNumProperty.set("name", "custNum");
     custNumProperty.set("type", intType);
+    custNumProperty.setBoolean(xmlElementProp, false);
 
     // create a first name property
     DataObject firstNameProperty =
     customerType.createDataObject("property");
     firstNameProperty.set("name", "firstName");
     firstNameProperty.set("type", stringType);
+    firstNameProperty.setBoolean(xmlElementProp, false);
 
     // create a last name property
     DataObject lastNameProperty = customerType.createDataObject("property");
     lastNameProperty.set("name", "lastName");
     lastNameProperty.set("type", stringType);
+    lastNameProperty.setBoolean(xmlElementProp, false);
 
     // now define the Customer type so that customers can be made
     types.define(customerType);
@@ -355,13 +369,16 @@
     Type customerType = SDOUtil.createType(types, "http://example.com/customer", "Customer", false);
 
     // create a customer number property
-    SDOUtil.createProperty(customerType, "custNum", intType);
+    Property custNumProperty = SDOUtil.createProperty(customerType, "custNum", intType);
+    SDOUtil.setPropertyXMLKind(custNumProperty, false);
 
     // create a first name property
-    SDOUtil.createProperty(customerType, "firstName", stringType);
+    Property firstNameProperty = SDOUtil.createProperty(customerType, "firstName", stringType);
+    SDOUtil.setPropertyXMLKind(firstNameProperty, false);
 
     // create a last name property
-    SDOUtil.createProperty(customerType, "lastName", stringType);
+    Property lastNameProperty = SDOUtil.createProperty(customerType, "lastName", stringType);
+    SDOUtil.setPropertyXMLKind(lastNameProperty, false);
 
     DataObject customer1 = factory.create("http://example.com/customer",
     "Customer");
@@ -572,6 +589,8 @@
     Type stringType = types.getType("commonj.sdo", "String");
     Type decimalType = types.getType("commonj.sdo", "Decimal");
     
+    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);
+    
     // Define a new open type - OpenQuote
     DataObject openQuoteType = factory.create("commonj.sdo", "Type");
     openQuoteType.set("uri", "http://www.example.com/open");
@@ -586,11 +605,12 @@
     companyType.set("uri", "http://www.example.com/open");
     companyType.set("name", "CompanyType");
     
-    // Create CompanyType property - "name"
+    // Create CompanyType property - "name" as an XSD attribute
     DataObject nameProperty = companyType.createDataObject("property");
     nameProperty.set("name", "name");
     nameProperty.set("type", stringType);
     nameProperty.set("containment", Boolean.TRUE);
+    nameProperty.setBoolean(xmlElementProp, false);
     
     types.define(companyType);
     

Modified: incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java?view=diff&rev=555312&r1=555311&r2=555312
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java Wed Jul 11 08:32:10 2007
@@ -309,6 +309,11 @@
     public Property createProperty(Type containingType, String name, Type propertyType);
 
     /**
+     * Set a SDO property to become an XSD element or attribute
+     */
+    public void setPropertyXMLKind(Property property, boolean isXmlElement);
+
+    /**
      * Create a new open content property in the specified TypeHelper scope.
      */
     public Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type);

Modified: incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java?view=diff&rev=555312&r1=555311&r2=555312
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java Wed Jul 11 08:32:10 2007
@@ -325,6 +325,13 @@
   }
   
   /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setPropertyXMLKind(Property, boolean)}.
+   */
+  public static void setPropertyXMLKind(Property property, boolean isXmlElement) {
+      defaultSDOHelper.getMetaDataBuilder().setPropertyXMLKind(property, isXmlElement);
+  }
+  
+  /**
    * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#createOpenContentProperty(TypeHelper, String, String, Type)}.
    */
   public static Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type)



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