tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianocrest...@apache.org
Subject svn commit: r562586 - in /incubator/tuscany/java/sdo/impl/src: main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java
Date Fri, 03 Aug 2007 21:20:55 GMT
Author: adrianocrestani
Date: Fri Aug  3 14:20:54 2007
New Revision: 562586

URL: http://svn.apache.org/viewvc?view=rev&rev=562586
Log:
applying patch from JIRA-1397

Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java?view=diff&rev=562586&r1=562585&r2=562586
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
Fri Aug  3 14:20:54 2007
@@ -449,8 +449,27 @@
   public static DataObject createDataObject(DataObject dataObject, String propertyName, String
namespaceURI, String typeName)
   {
     Property property = getInstanceProperty(dataObject, propertyName);
-    Type type = DataObjectUtil.getType(dataObject, namespaceURI, typeName);
-    return createDataObject(dataObject, property, type);
+    if (property != null) {
+      Type type = DataObjectUtil.getType(dataObject, namespaceURI, typeName);
+      return createDataObject(dataObject, property, type);
+    }
+    else {
+      if (dataObject.getType().isOpen()) {
+        HelperContext ctx = HelperProvider.getDefaultContext();
+        Type propertyType = ctx.getTypeHelper().getType( namespaceURI, typeName );
+        if (propertyType == null) {
+          throw new IllegalStateException( "type does not exist: uri=" + namespaceURI + ",
name=" + typeName );
+        }
+        DataObject value = ctx.getDataFactory().create( propertyType );
+        List list = new ArrayList(1);
+        list.add(value);
+        dataObject.setList( propertyName, list );
+        return value;
+      }
+      else {
+        throw new IllegalArgumentException( "property '" + propertyName + "' does not exist"
);
+      }
+    }
   }
   
   public static DataObject createDataObject(DataObject dataObject, Property property)
@@ -469,8 +488,13 @@
   public static DataObject createDataObject(DataObject dataObject, String propertyName)
   {
     Property property = (Property)getInstanceProperty(dataObject, propertyName);
-    Type type = property.getType();
-    return createDataObject(dataObject,property, type);
+    if (property != null) {
+      Type type = property.getType();
+      return createDataObject(dataObject,property, type);
+    }
+    else {
+      return createDataObject(dataObject, propertyName, "http://www.apache.org/tuscany/2005/SDO",
"AnyTypeDataObject" );
+    }
   }
   
   public static void setString(DataObject dataObject, String path, String value)

Modified: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java?view=diff&rev=562586&r1=562585&r2=562586
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java
Fri Aug  3 14:20:54 2007
@@ -91,7 +91,36 @@
       // allows is to use the !isMany getters and setters for open content
       quote.set(priceProperty, new BigDecimal("1000.0"));
       
-   }
+    }
+
+    /**
+     * Although this behavior is not mandated by the SDO 2.1 specification it should be possible
+     * to demand-create DataObject properties by calling createDataObject(String name).
+     * The behavior should be the same as that specified in section 9.10 for parsing XML
that has
+     * no types defined e.g. the property should be created as an open, sequenced type with
many=true.
+     *
+     * See https://issues.apache.org/jira/browse/TUSCANY-1397 for more information.
+     *
+     * @throws Exception
+     */
+    public void testOnDemandCreateDataObject() throws Exception {
+        // define an open type with no properties
+        DataObject typeDef = df.create( "commonj.sdo", "Type" );
+        typeDef.set( "uri", TEST_NAMESPACE );
+        typeDef.set( "name", "testOnDemandCreateDataObjectType" );
+        typeDef.setBoolean( "open", true );
+        Type t = th.define( typeDef );
+    
+        // create a DataObject that uses this type
+        DataObject testDO = df.create(t);
+
+        // create an on-demand property
+        DataObject foo = testDO.createDataObject( "foo" );
+        assertNotNull( "createDataObject() demand created a DataObject", foo );
+        assertTrue( "DataObject is open", foo.getType().isOpen() );
+        assertTrue( "DataObject is sequenced", foo.getType().isSequenced() );
+    }
+
 
     protected void setUp() throws Exception {
         super.setUp();



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


Mime
View raw message