Author: frankb
Date: Fri May  5 08:58:35 2006
New Revision: 400094

URL: http://svn.apache.org/viewcvs?rev=400094&view=rev
Log:
Minor improvement to SDOUtil.setSequenced and setOpen methods

Modified:
    
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java
    
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
    
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java

Modified: 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java?rev=400094&r1=400093&r2=400094&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java
 Fri May  5 08:58:35 2006
@@ -96,6 +96,7 @@
       switch (ExtendedMetaData.INSTANCE.getFeatureKind(eStructuralFeature))
       {
         case ExtendedMetaData.ELEMENT_WILDCARD_FEATURE:
+          if (eStructuralFeature == 
ExtendedMetaData.INSTANCE.getMixedFeature(this)) break;
         case ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE:
         case ExtendedMetaData.GROUP_FEATURE:
           return true;

Modified: 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java?rev=400094&r1=400093&r2=400094&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
 Fri May  5 08:58:35 2006
@@ -262,16 +262,8 @@
   
   public static void setOpen(Type type, boolean isOpen)
   {
-    boolean hasProperties = 
-      (type.isSequenced()) ? 
-         type.getProperties().size() > 1 : 
-           !type.getProperties().isEmpty();
-    
-    if (type.isDataType() || hasProperties)
-    {
-      if (type.getName() != null) //FB TEMP ... figure out how to handle 
document root
-        throw new IllegalArgumentException(); // type must a non dataType with 
no properties yet
-    }
+    if (isOpen == type.isOpen()) return;
+
     if (isOpen)
     {
       EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
@@ -291,18 +283,25 @@
         eAttribute.setVolatile(true);
       }
     }
+    else
+    {
+      EClass eClass = (EClass)type;
+      EAttribute any = (EAttribute)eClass.getEStructuralFeature("any");
+      eClass.getEStructuralFeatures().remove(any);  
+    }
   }
   
   public static void setSequenced(Type type, boolean isSequenced)
   {
-    if ((isSequenced && type.isSequenced()) || 
-        !isSequenced && !type.isSequenced()) return;
+    if (isSequenced == type.isSequenced()) return;
     
+    // currently, we require setSequenced to be called first, before anything 
else is added to the type.
     if (type.isDataType() || !type.getProperties().isEmpty())
     {
-      if (type.getName() != null) //FB TEMP ... figure out how to handle 
document root
+      if (type.getName() != null) // document root is a special case
         throw new IllegalArgumentException();
     }
+    
     if (isSequenced) {
       EClass eClass = (EClass)type;
       ExtendedMetaData.INSTANCE.setContentKind(eClass, 
ExtendedMetaData.MIXED_CONTENT);
@@ -314,7 +313,11 @@
       mixedFeature.setUpperBound(-1);
       eClass.getEStructuralFeatures().add(mixedFeature);
       ExtendedMetaData.INSTANCE.setFeatureKind(mixedFeature, 
ExtendedMetaData.ELEMENT_WILDCARD_FEATURE);
-      ExtendedMetaData.INSTANCE.setName(mixedFeature, ":mixed");   
+      ExtendedMetaData.INSTANCE.setName(mixedFeature, ":mixed"); 
+    }
+    else
+    {
+      // nothing to do, because of current restriction that setSequence must 
be called first.
     }
   }
   

Modified: 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java?rev=400094&r1=400093&r2=400094&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
 Fri May  5 08:58:35 2006
@@ -457,7 +457,6 @@
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     xmlHelper.save(quote, "http://www.example.com/mixed";, "mixedStockQuote", 
baos);
     assertTrue(TestUtil.equalXmlFiles(new 
ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXED_XML)));
-    
   }
   
   public void testDefineSequencedOpenType() throws Exception 
@@ -500,7 +499,7 @@
     // Define a global type
     DataObject globalType = factory.create("commonj.sdo", "Type");
     globalType.set("uri", "http://www.example.com/open";);
-    // no need to specify the type's name
+    // Don't set the type's name - null is used for types containing global 
properties.
     
     DataObject symbolProperty = globalType.createDataObject("property");
     symbolProperty.set("name", "symbol");
@@ -520,7 +519,6 @@
     Type definedGlobalType = types.getType("http://www.example.com/open";, 
null);
     
     Property definedSymbolProperty = definedGlobalType.getProperty("symbol");
-    //sequence.add(definedSymbolProperty, "fbnt");
     quote.setString(definedSymbolProperty, "fbnt");
 
     sequence.add("\n  ");
@@ -541,9 +539,7 @@
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     xmlHelper.save(quote, "http://www.example.com/mixed";, 
"mixedOpenStockQuote", baos);
-    xmlHelper.save(quote, "http://www.example.com/mixed";, 
"mixedOpenStockQuote", System.out);
     assertTrue(TestUtil.equalXmlFiles(new 
ByteArrayInputStream(baos.toByteArray()), 
getClass().getResource(MIXEDOPEN_XML)));
-    
   }
 
   
@@ -581,7 +577,7 @@
     // Define a global type
     DataObject globalType = factory.create("commonj.sdo", "Type");
     globalType.set("uri", "http://www.example.com/open";);
-    // no need to specify the type's name
+    // Don't set the type's name - null is used for types containing global 
properties.
     
     DataObject symbolProperty = globalType.createDataObject("property");
     symbolProperty.set("name", "symbol");


Reply via email to