tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fra...@apache.org
Subject svn commit: r513973 - in /incubator/tuscany/java/sdo/impl/src: main/java/org/apache/tuscany/sdo/impl/ main/java/org/apache/tuscany/sdo/util/ test/java/org/apache/tuscany/sdo/test/
Date Fri, 02 Mar 2007 21:52:08 GMT
Author: frankb
Date: Fri Mar  2 13:52:07 2007
New Revision: 513973

URL: http://svn.apache.org/viewvc?view=rev&rev=513973
Log:
Fixed AnyType problem caused by TUSCANY-1065 fix

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/impl/DataObjectImpl.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/SDOPackageImpl.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/BasicSequence.java
    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/XMLStreamHelperTestCase.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ClassImpl.java?view=diff&rev=513973&r1=513972&r2=513973
==============================================================================
--- 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 Mar  2 13:52:07 2007
@@ -19,18 +19,21 @@
  */
 package org.apache.tuscany.sdo.impl;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Set;
 
 import org.apache.tuscany.sdo.SDOFactory;
 import org.apache.tuscany.sdo.SDOPackage;
 import org.apache.tuscany.sdo.model.ModelFactory;
 import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl;
+import org.apache.tuscany.sdo.util.BasicSequence;
 import org.apache.tuscany.sdo.util.DataObjectUtil;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.UniqueEList;
@@ -42,7 +45,7 @@
 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
 import org.eclipse.emf.ecore.util.ExtendedMetaData;
 import org.eclipse.emf.ecore.util.FeatureMap;
-import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
+import org.eclipse.emf.ecore.util.FeatureMapUtil;
 
 import commonj.sdo.Property;
 import commonj.sdo.Sequence;
@@ -179,12 +182,17 @@
     return extendedProperties;
   }
   
+  protected List getTypeFeatures()
+  {
+    return getEStructuralFeatures();    
+  }
+  
   protected void initPropertyLists()
   {
     declaredProperties = new ArrayList();
     extendedProperties = Collections.EMPTY_LIST;
     
-    for (Iterator i = getEStructuralFeatures().iterator(); i.hasNext(); ) {
+    for (Iterator i = getTypeFeatures().iterator(); i.hasNext(); ) {
       EStructuralFeature eStructuralFeature = (EStructuralFeature)i.next();
       boolean isExtendedProperty = DataObjectUtil.isInternalProperty(eStructuralFeature);
       if (isExtendedProperty) {
@@ -277,12 +285,12 @@
     return false;
   }
 
-  public void addInstanceProperties(EObject dataObject, Collection propertyList)
+  public void addOpenProperties(EObject dataObject, Collection propertyList)
   {
     for (final Iterator iterator = getBaseTypes().iterator(); iterator.hasNext(); )
     {
       ClassImpl baseType = (ClassImpl)iterator.next();
-      baseType.addInstanceProperties(dataObject, propertyList);
+      baseType.addOpenProperties(dataObject, propertyList);
     }
 
     for (final Iterator iter = getExtendedProperties().iterator(); iter.hasNext(); )
@@ -295,15 +303,88 @@
         {
           FeatureMap.Entry entry = (FeatureMap.Entry)features.get(j);
           EStructuralFeature entryFeature = entry.getEStructuralFeature();
-          boolean isText = 
-              entryFeature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT ||
-              entryFeature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA ||  
 
-              entryFeature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__COMMENT;
-          if (!isText) propertyList.add(entryFeature);
+          Property property = BasicSequence.getFeatureProperty(entryFeature);
+          if (property != null) propertyList.add(entryFeature);
+        }
+      }
+    }
+  }
+  
+  public Property getOpenProperty(EObject dataObject, String featureName)
+  {
+    for (final Iterator iterator = getBaseTypes().iterator(); iterator.hasNext(); )
+    {
+      ClassImpl baseType = (ClassImpl)iterator.next();
+      Property result = baseType.getOpenProperty(dataObject, featureName);
+      if (result != null) return result;
+    }
+    
+    Set openFeatureSet = new HashSet();
+    for (final Iterator iter = getExtendedProperties().iterator(); iter.hasNext(); )
+    {
+      EStructuralFeature eStructuralFeature = (EStructuralFeature)iter.next();
+      //if (isOpenFeatureMap(eStructuralFeature)) 
+      //FB The above check excludes subsitition groups - i.e., doesn't support dObj.get("element.substitution")
+      if (FeatureMapUtil.isFeatureMap(eStructuralFeature))
+      {
+        List features = (List)dataObject.eGet(eStructuralFeature);
+        for (int j = 0, size = features.size(); j < size; ++j)
+        {
+          FeatureMap.Entry entry = (FeatureMap.Entry)features.get(j);
+          EStructuralFeature entryFeature = entry.getEStructuralFeature();
+          if (openFeatureSet.add(entryFeature))
+          {
+            Property property = BasicSequence.getFeatureProperty(entryFeature);
+            if (property != null)
+            {
+              if (property.getName().equals(featureName)) return (Property)entryFeature;
+               List aliasNames = property.getAliasNames();
+              for (int aliasCount = aliasNames.size(); aliasCount > 0; )
+              {
+                if (aliasNames.get(--aliasCount).equals(featureName)) return (Property)entryFeature;
+              }
+            }
+          }
+        }
+      }
+    }
+    
+    return null;
+  }
+  
+  /*
+  public Property getOpenProperty(DataObject dataObject, String featureName)
+  {
+    EObject eObject = (EObject)dataObject;
+    EClass eClass = eObject.eClass();
+    Set openFeatureSet = new HashSet();
+    for (int i = 0, count = eClass.getEAllStructuralFeatures().size(); i < count; ++i)
+    {
+      EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
+      if (FeatureMapUtil.isFeatureMap(eStructuralFeature))
+      {
+        List features = (List)eObject.eGet(eStructuralFeature);
+        for (int j = 0, size = features.size(); j < size; ++j)
+        {
+          FeatureMap.Entry entry = (FeatureMap.Entry)features.get(j);
+          EStructuralFeature entryFeature = entry.getEStructuralFeature();
+          if (openFeatureSet.add(entryFeature))
+          {
+            Property property = (Property)entryFeature;
+            if (property.getName().equals(featureName)) return (Property)entryFeature;
+  
+            List aliasNames = property.getAliasNames();
+            for (int aliasCount = aliasNames.size(); aliasCount > 0; )
+            {
+              if (aliasNames.get(--aliasCount).equals(featureName)) return (Property)entryFeature;
+            }
+          }
         }
       }
     }
+    return null;
   }
+  */
 
   /**
    * <!-- begin-user-doc -->

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java?view=diff&rev=513973&r1=513972&r2=513973
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
Fri Mar  2 13:52:07 2007
@@ -1284,7 +1284,7 @@
    */
   public Property getInstanceProperty(String propertyName)
   {
-    return DataObjectUtil.getProperty(this, propertyName);
+    return DataObjectUtil.getInstanceProperty(this, propertyName);
   }
 
   /**
@@ -1292,7 +1292,7 @@
    */
   public Property getProperty(String propertyName)
   {
-    return DataObjectUtil.getProperty(this, propertyName);
+    return DataObjectUtil.getInstanceProperty(this, propertyName);
   }
 
   /**

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/SDOPackageImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/SDOPackageImpl.java?view=diff&rev=513973&r1=513972&r2=513973
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/SDOPackageImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/SDOPackageImpl.java
Fri Mar  2 13:52:07 2007
@@ -20,12 +20,14 @@
 package org.apache.tuscany.sdo.impl;
 
 import java.io.ObjectStreamException;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.tuscany.sdo.AnyTypeDataObject;
 import org.apache.tuscany.sdo.SDOFactory;
 import org.apache.tuscany.sdo.SDOPackage;
 import org.apache.tuscany.sdo.SimpleAnyTypeDataObject;
+import org.apache.tuscany.sdo.impl.SDOFactoryImpl.SDOEcoreFactory;
 import org.eclipse.emf.ecore.EAttribute;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EDataType;
@@ -35,6 +37,7 @@
 import org.eclipse.emf.ecore.EcorePackage;
 import org.eclipse.emf.ecore.change.ChangePackage;
 import org.eclipse.emf.ecore.change.impl.ChangePackageImpl;
+import org.eclipse.emf.ecore.impl.EClassImpl;
 import org.eclipse.emf.ecore.impl.EPackageImpl;
 import org.eclipse.emf.ecore.impl.EcorePackageImpl;
 import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
@@ -201,11 +204,12 @@
    * @see org.eclipse.emf.ecore.EPackage.Registry
    * @see org.apache.tuscany.sdo.SDOPackage#eNS_URI
    * @see #init()
-   * @generated
+   * @generated NOT
    */
   private SDOPackageImpl()
   {
     super(eNS_URI, SDOFactory.eINSTANCE);
+    ecoreFactory = new SDOEcoreFactory();
   }
 
   /**
@@ -585,6 +589,41 @@
     // Create data types
     eJavaListEDataType = createEDataType(EJAVA_LIST);
     eObjectStreamExceptionEDataType = createEDataType(EOBJECT_STREAM_EXCEPTION);
+  }
+  
+  protected EClass createEClass(int id)
+  {
+    EClassImpl c;
+    switch(id) {
+      case ANY_TYPE_DATA_OBJECT:
+        c = new ClassImpl() {
+          List baseTypes = null;
+          public List getBaseTypes() {
+            if (baseTypes == null)
+              baseTypes = Collections.singletonList(getDataObject());
+            return baseTypes;
+          }
+          public List getTypeFeatures() {
+            return getEAllStructuralFeatures();
+          }
+        };
+        break;
+      case SIMPLE_ANY_TYPE_DATA_OBJECT:
+        c = new ClassImpl() {
+          List baseTypes = null;
+          public List getBaseTypes() {
+            if (baseTypes == null)
+              baseTypes = Collections.singletonList(getAnyTypeDataObject());
+            return baseTypes;
+          }
+        };
+        break;
+      default:
+        c = (EClassImpl)ecoreFactory.createEClass();
+    }
+    c.setClassifierID(id);
+    getEClassifiers().add(c);
+    return c;
   }
 
   /**

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/BasicSequence.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/BasicSequence.java?view=diff&rev=513973&r1=513972&r2=513973
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/BasicSequence.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/BasicSequence.java
Fri Mar  2 13:52:07 2007
@@ -53,6 +53,11 @@
   public Property getProperty(int index)
   {
     EStructuralFeature feature = featureMap.getEStructuralFeature(index);
+    return getFeatureProperty(feature);
+  }
+  
+  public static Property getFeatureProperty(EStructuralFeature feature)
+  {
     boolean isText = 
       feature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT ||
       feature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA ||    

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=513973&r1=513972&r2=513973
==============================================================================
--- 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 Mar  2 13:52:07 2007
@@ -375,27 +375,15 @@
   
   public static boolean isInternalProperty(EStructuralFeature eStructuralFeature)
   {
+    //return FeatureMapUtil.isFeatureMap(eStructuralFeature);
     return !(eStructuralFeature.getEType() instanceof Type);
-    /*
-    if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) return true;
-    EClassifier eType = eStructuralFeature.getEType();
-    if (!(eType instanceof Type))
-    {
-      System.out.println("Non Type property: " + eStructuralFeature.getName());
-      if (eType != null)
-      {
-        System.out.println("  type: " + eType.getName());
-      }
-    }
-    return false;
-    */
   }
 
   public static List getInstanceProperties(DataObject dataObject)
   {
     Type type = dataObject.getType();
     List result = new UniqueEList(type.getProperties());
-    ((ClassImpl)type).addInstanceProperties((EObject)dataObject, result);
+    ((ClassImpl)type).addOpenProperties((EObject)dataObject, result);
     return result;
   }
   
@@ -447,7 +435,7 @@
   
   public static DataObject createDataObject(DataObject dataObject, String propertyName, String
namespaceURI, String typeName)
   {
-    Property property = getProperty(dataObject, propertyName);
+    Property property = getInstanceProperty(dataObject, propertyName);
     Type type = DataObjectUtil.getType(dataObject, namespaceURI, typeName);
     return createDataObject(dataObject, property, type);
   }
@@ -467,7 +455,7 @@
 
   public static DataObject createDataObject(DataObject dataObject, String propertyName)
   {
-    Property property = (Property)getProperty(dataObject, propertyName);
+    Property property = (Property)getInstanceProperty(dataObject, propertyName);
     Type type = property.getType();
     return createDataObject(dataObject,property, type);
   }
@@ -1671,7 +1659,7 @@
     }
 
     if (value instanceof byte[]) {
-        return XMLTypeFactory.eINSTANCE.convertHexBinary((byte[])value);
+      return XMLTypeFactory.eINSTANCE.convertHexBinary((byte[])value);
     }
     
     if (value == null)
@@ -1781,37 +1769,6 @@
     throw new IndexOutOfBoundsException();
   }
   
-  public static EStructuralFeature getOpenFeature(EObject eObject, String featureName)
-  {
-    EClass eClass = eObject.eClass();
-    Set openFeatureSet = new HashSet();
-    for (int i = 0, count = eClass.getEAllStructuralFeatures().size(); i < count; ++i)
-    {
-      EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
-      if (/*!eStructuralFeature.isDerived() && */FeatureMapUtil.isFeatureMap(eStructuralFeature))
-      {
-        List features = (List)eObject.eGet(eStructuralFeature);
-        for (int j = 0, size = features.size(); j < size; ++j)
-        {
-          FeatureMap.Entry entry = (FeatureMap.Entry)features.get(j);
-          EStructuralFeature entryFeature = entry.getEStructuralFeature();
-          if (openFeatureSet.add(entryFeature))
-          {
-            Property property = (Property)entryFeature;
-            if (property.getName().equals(featureName)) return entryFeature;
-
-            List aliasNames = property.getAliasNames();
-            for (int aliasCount = aliasNames.size(); aliasCount > 0; )
-            {
-              if (aliasNames.get(--aliasCount).equals(featureName)) return entryFeature;
-            }
-          }
-        }
-      }
-    }
-    return null;
-  }
-  
   public static List getAliasNames(EStructuralFeature eStructuralFeature)
   {
     List list = SDOExtendedMetaData.INSTANCE.getAliasNames(eStructuralFeature);
@@ -2071,7 +2028,7 @@
     {
       if (name != null)
       {
-        feature = (EStructuralFeature)((DataObject)eObject).getProperty(name);
+        feature = (EStructuralFeature)((DataObject)eObject).getInstanceProperty(name);
         if (feature == null)
         {
           int index = name.lastIndexOf('.');
@@ -2085,7 +2042,7 @@
               index = Integer.parseInt(name.substring(++index));
                 //  NumberFormatException may be thrown
               String propertyName = name.substring(0, propertyNameEnd);
-              feature = (EStructuralFeature)((DataObject)eObject).getProperty(propertyName);
+              feature = (EStructuralFeature)((DataObject)eObject).getInstanceProperty(propertyName);
               if (feature != null)
               {
                 setIndex(index);
@@ -2224,23 +2181,18 @@
       }
     }
 
-    protected static int matchingIndex(List eObjects, String attributeName, String attributeValue)
+    protected static int matchingIndex(List dataObjects, String attributeName, String attributeValue)
     {
-      for (int i = 0, size = eObjects.size(); i < size; i++)
+      for (int i = 0, size = dataObjects.size(); i < size; i++)
       {
-        EObject eObject = (EObject)eObjects.get(i);
-        EStructuralFeature feature = (EStructuralFeature)((Type)eObject.eClass()).getProperty(attributeName);
-        // If feature is null, that means it could be an open feature.
-        if (feature == null)
-        {
-          feature = (EStructuralFeature)DataObjectUtil.getOpenFeature(eObject, attributeName);
-        }
-        if (feature != null)
+        DataObject dataObject = (DataObject)dataObjects.get(i);
+        Property property = getInstanceProperty(dataObject, attributeName);
+        if (property != null)
         {
-          Object test = eObject.eGet(feature, true);
+          Object test = dataObject.get(property);
           if (test != null)
           {
-            String testString = EcoreUtil.convertToString((EDataType)feature.getEType(),
test);
+            String testString = EcoreUtil.convertToString((EDataType)property.getType(),
test);
             if (attributeValue.equals(testString))
             {
               return i;
@@ -2428,12 +2380,13 @@
     }
   }
 
-  public static Property getProperty(DataObject dataObject, String propertyName)
+  public static Property getInstanceProperty(DataObject dataObject, String propertyName)
   {
-    Property property = dataObject.getType().getProperty(propertyName);
+    ClassImpl type = (ClassImpl)dataObject.getType();
+    Property property = type.getProperty(propertyName);
     if (property == null)
     {
-      property = (Property)DataObjectUtil.getOpenFeature((EObject)dataObject, propertyName);
+      property = type.getOpenProperty((EObject)dataObject, propertyName);
       //throw new IllegalArgumentException("Type '" + dataObject.getType().getName() + "'
does not have a property named '" + propertyName + "'");
     }
   

Modified: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java?view=diff&rev=513973&r1=513972&r2=513973
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java
Fri Mar  2 13:52:07 2007
@@ -121,9 +121,7 @@
         DataObject moduleObject = document.getRootObject();
         List components = moduleObject.getList("component");
         DataObject componentObject = (DataObject) components.get(0);
-        // componentObject.getDataObject("implementation.mock");
-        //DataObject implObject = (DataObject) componentObject.getSequence(0).getValue(0);
-        DataObject implObject = componentObject.getDataObject(componentObject.getProperty("implementation.mock"));
//FB
+        DataObject implObject = componentObject.getDataObject("implementation.mock");
         Assert.assertTrue(implObject.getString("myAttr").equals("helloworld.HelloWorldImpl"));
     }
 



---------------------------------------------------------------------
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