You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by fr...@apache.org on 2007/05/08 18:26:34 UTC

svn commit: r536241 - 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/

Author: frankb
Date: Tue May  8 09:26:30 2007
New Revision: 536241

URL: http://svn.apache.org/viewvc?view=rev&rev=536241
Log:
Part of TUSCANY-1197 Fix

Added:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java
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/util/SDOUtil.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=536241&r1=536240&r2=536241
==============================================================================
--- 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 Tue May  8 09:26:30 2007
@@ -137,55 +137,73 @@
     return false;
   }
 
-  private EAttribute sequenceFeature = (EAttribute)UNINITIALIZED_PROPERTY;
+  private static final EStructuralFeature UNINITIALIZED_SEQUENCE_FEATURE = (EAttribute)SDOFactory.eINSTANCE.createAttribute();
+  protected static final EStructuralFeature VIRTUAL_SEQUENCE_FEATURE = (EAttribute)SDOFactory.eINSTANCE.createAttribute();
   
-  public EAttribute getSequenceFeature()
+  private EStructuralFeature sequenceFeature = UNINITIALIZED_SEQUENCE_FEATURE;
+
+  public EStructuralFeature getSequenceFeature()
   {
-    //FB This isn't quite right. 
-    //FB What if there are multiple sequences? We'll need to provide a mixed-like combined Sequence.
-    if (sequenceFeature == UNINITIALIZED_PROPERTY)
+    if (sequenceFeature == UNINITIALIZED_SEQUENCE_FEATURE)
     {
-      for (final Iterator iterator = getBaseTypes().iterator() ; iterator.hasNext(); )
-      {
-        ClassImpl baseType = (ClassImpl)iterator.next();
-        sequenceFeature = baseType.getSequenceFeature();
-        if (sequenceFeature != null) return sequenceFeature;
-      }
-
-      List properties = getExtendedProperties();
-      if (properties != Collections.EMPTY_LIST)
+      EStructuralFeature sequenceFeatureCandidate = null;
+      boolean hasNonDerivedFeatures = false;
+      
+      for (Iterator iterator = getEAllStructuralFeatures().iterator(); iterator.hasNext(); ) 
       {
-        for (int i = 0, count = properties.size(); i < count; ++i)
-        {
-          EStructuralFeature eStructuralFeature = (EStructuralFeature)properties.get(i);
-          if (isSequenceFeatureMap(eStructuralFeature))
-          {
-            sequenceFeature = (EAttribute)eStructuralFeature;
-            return sequenceFeature;
-          }
+        EStructuralFeature eStructuralFeature = (EStructuralFeature)iterator.next();
+        if (!eStructuralFeature.isDerived()) {
+          if (sequenceFeatureCandidate == null && isSequenceFeatureMap(eStructuralFeature))
+            sequenceFeatureCandidate = eStructuralFeature;
+          else if (isElementFeature(eStructuralFeature))
+            hasNonDerivedFeatures = true;
         }
       }
       
-      sequenceFeature = null;
+      sequenceFeature = 
+        sequenceFeatureCandidate != null && hasNonDerivedFeatures ? 
+          VIRTUAL_SEQUENCE_FEATURE : 
+          sequenceFeatureCandidate;
     }
+    
     return sequenceFeature;
   }
   
   protected boolean isSequenceFeatureMap(EStructuralFeature eStructuralFeature)
   {
-    //return eStructuralFeature == ExtendedMetaData.INSTANCE.getMixedFeature(this);
     switch (ExtendedMetaData.INSTANCE.getFeatureKind(eStructuralFeature))
     {
       case ExtendedMetaData.ELEMENT_WILDCARD_FEATURE:
-        //return eStructuralFeature.getUpperBound() != 1; //FB TODO - I think this may be needed
-        int contentKind = ExtendedMetaData.INSTANCE.getContentKind(this);
-        return contentKind == ExtendedMetaData.MIXED_CONTENT || contentKind == ExtendedMetaData.SIMPLE_CONTENT;
+        return eStructuralFeature.getUpperBound() != 1;
       case ExtendedMetaData.GROUP_FEATURE:
         return true;
     }
     return false;
   }
 
+  protected boolean isElementFeature(EStructuralFeature eStructuralFeature)
+  {
+    switch (ExtendedMetaData.INSTANCE.getFeatureKind(eStructuralFeature))
+    {
+      case ExtendedMetaData.ATTRIBUTE_FEATURE:
+      case ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE:
+        return false;
+    }
+    return true;
+  }
+  
+  public List getVirtualSequenceFeatures()
+  {
+    List result = new ArrayList();
+    for (Iterator iterator = getEAllStructuralFeatures().iterator(); iterator.hasNext(); ) 
+    {
+      EStructuralFeature eStructuralFeature = (EStructuralFeature)iterator.next();
+      if (!eStructuralFeature.isDerived() && isElementFeature(eStructuralFeature))
+        result.add(eStructuralFeature);
+    }
+    return result;
+  }
+  
   public void setSequenceFeature(EAttribute sequenceFeature)
   {
     getEStructuralFeatures().add(sequenceFeature);
@@ -318,7 +336,7 @@
       allFeaturesCache = allFeatures;
       allProperties = allExtendedProperties = null;
     }
-    if (allProperties == null)
+    if (allExtendedProperties == null)
     {
       List allExtendedProperties = new UniqueEList();
       for (final Iterator iterator = getBaseTypes().iterator(); iterator.hasNext(); )

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=536241&r1=536240&r2=536241
==============================================================================
--- 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 Tue May  8 09:26:30 2007
@@ -29,10 +29,10 @@
 import org.apache.tuscany.sdo.SDOPackage;
 import org.apache.tuscany.sdo.impl.ChangeSummaryImpl.SDOChangeRecorder;
 import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.apache.tuscany.sdo.util.VirtualSequence;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EAttribute;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.InternalEObject;
@@ -1254,6 +1254,8 @@
   {
     DataObjectUtil.delete(this);
   }
+  
+  protected Sequence sequence = null;
 
   /**
    * <!-- begin-user-doc -->
@@ -1262,8 +1264,16 @@
    */
   public Sequence getSequence()
   {
-    EAttribute sequenceFeature = ((ClassImpl)eClass()).getSequenceFeature();
-    return sequenceFeature != null ? (Sequence)eGet(sequenceFeature, true, false) : null;
+    if (sequence == null)
+    {
+      EStructuralFeature sequenceFeature = ((ClassImpl)eClass()).getSequenceFeature();
+      if (sequenceFeature == null) return null;
+      if (sequenceFeature == ClassImpl.VIRTUAL_SEQUENCE_FEATURE)
+        sequence = new VirtualSequence(this);
+      else
+        sequence = (Sequence)eGet(sequenceFeature, true, false);
+    }
+    return sequence;
   }
 
   /**

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java?view=diff&rev=536241&r1=536240&r2=536241
==============================================================================
--- 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 Tue May  8 09:26:30 2007
@@ -82,7 +82,6 @@
 import org.eclipse.emf.ecore.util.FeatureMap;
 import org.eclipse.emf.ecore.util.FeatureMapUtil;
 import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
 
 import commonj.sdo.DataGraph;
 import commonj.sdo.DataObject;

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java?view=auto&rev=536241
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java Tue May  8 09:26:30 2007
@@ -0,0 +1,780 @@
+/**
+ *
+ *  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
+ *  to you under the Apache License, Version 2.0 (the
+ *  "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.
+ */
+package org.apache.tuscany.sdo.util;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tuscany.sdo.impl.ClassImpl;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.FeatureMapUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+
+/**
+ *  SDO Sequance implementation which delegates to a Collection of hidden FeatureMap properties.
+ */
+public class VirtualSequence implements Sequence
+{
+  private final DataObject dataObject;
+  protected final List properties; // size > 1
+
+  public VirtualSequence(DataObject object)
+  {
+    dataObject = object;
+    properties = ((ClassImpl)dataObject.getType()).getVirtualSequenceFeatures();
+  }
+  
+  static protected boolean sequence(Object property)
+  {
+    return FeatureMapUtil.isFeatureMap((EStructuralFeature)property);
+  }
+  
+  public int size()
+  {
+    int size = 0;
+    for (Iterator iterator = properties.iterator() ; iterator.hasNext() ;)
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+          size += dataObject.getSequence(property).size();
+        else if (property.isMany())
+          size += dataObject.getList(property).size();
+        else
+          ++size;
+    }
+    return size;
+  }
+
+  public Property getProperty(int index)
+  {
+    for (Iterator iterator = properties.iterator() ; iterator.hasNext() ;)
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+        {
+          Sequence sequence = dataObject.getSequence(property);
+          int size = sequence.size();
+          if (index < size)
+            return sequence.getProperty(index);
+          index -= size;
+        }
+        else if (property.isMany())
+        {
+          int size = dataObject.getList(property).size();
+          if (index < size)
+            return property;
+          index -= size;
+        }
+        else if (index == 0)
+          return property;
+        else
+          --index;
+    }
+    throw new IndexOutOfBoundsException();
+  }
+
+  public Object getValue(int index)
+  {
+    for (Iterator iterator = properties.iterator() ; iterator.hasNext() ;)
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+        {
+          Sequence sequence = dataObject.getSequence(property);
+          int size = sequence.size();
+          if (index < size)
+            return sequence.getValue(index);
+          index -= size;
+        }
+        else if (property.isMany())
+        {
+          List values = dataObject.getList(property);
+          int size = values.size();
+          if (index < size)
+            return values.get(index);
+          index -= size;
+        }
+        else if (index == 0)
+          return dataObject.get(property);
+        else
+          --index;
+    }
+    throw new IndexOutOfBoundsException();
+  }
+
+  public Object setValue(int index, Object value)
+  {
+    for (Iterator iterator = properties.iterator() ; iterator.hasNext() ;)
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+        {
+          Sequence sequence = dataObject.getSequence(property);
+          int size = sequence.size();
+          if (index < size)
+            return sequence.setValue(index, value);
+          index -= size;
+        }
+        else if (property.isMany())
+        {
+          List values = dataObject.getList(property);
+          int size = values.size();
+          if (index < size)
+            return values.set(index, value);
+          index -= size;
+        }
+        else if (index == 0)
+        {
+          Object old = dataObject.get(property);  
+          dataObject.set(property, value);
+          return old;
+        }
+        else
+          --index;
+    }
+    throw new IndexOutOfBoundsException();
+  }
+  
+  boolean validate(EStructuralFeature feature, Object property)
+  {
+    return FeatureMapUtil.getValidator((EClass)dataObject.getType(), feature).isValid((EStructuralFeature)property);
+  }
+
+  boolean append(Property property, Property p, Object value)
+  {
+    return dataObject.getSequence(property).add(p, value);
+  }
+  
+  boolean append(Property property, Object value)
+  {
+    return dataObject.getList(property).add(value);
+  }
+  
+  boolean set(Property property, Object value)
+  {
+    if (property.isMany())
+      return append(property, value);
+    dataObject.set(property, value);
+    return true;
+  }
+  
+  public final boolean add(Property p, Object value)
+  {
+    Property property;
+    int size = properties.size(), index = size;
+    do
+    {
+      property = (Property)properties.get(--index);
+      if (!dataObject.isSet(property))
+        continue;
+      EStructuralFeature feature = (EStructuralFeature)property;
+      if (FeatureMapUtil.isFeatureMap(feature))
+      {
+        if (validate(feature, p))
+          return append(property, p, value);
+      }
+      else if (property == p && property.isMany())
+        return append(property, value);
+      if (size == ++index)
+        return false;
+      property = (Property)properties.get(index);
+      break;
+    }
+    while (index != 0);
+    for (;;)
+    {
+      EStructuralFeature feature = (EStructuralFeature)property;
+      if (FeatureMapUtil.isFeatureMap(feature))
+      {
+        if (validate(feature, p))
+          return append(property, p, value);
+      }
+      else if (property == p)
+        return set(p, value);
+      if (size == ++index)
+        return false;
+      property = (Property)properties.get(index);
+    }
+  }
+
+  protected final Property property(String name)
+  {
+    return dataObject.getType().getProperty(name);
+  }
+
+  public boolean add(String propertyName, Object value)
+  {
+    return add(property(propertyName), value);
+  }
+
+  protected final Property property(int index)
+  {
+    return (Property)dataObject.getType().getProperties().get(index);
+  }
+
+  public boolean add(int propertyIndex, Object value)
+  {
+    return add(property(propertyIndex), value);
+  }
+  
+  void insert(Property property, Property p, Object value)
+  {
+    dataObject.getSequence(property).add(0, p, value);
+  }
+  
+  void insert(Property property, Object value)
+  {
+    dataObject.getList(property).add(0, value);
+  }
+  
+  protected final int insert(Iterator iterator, Property p, Object value)
+  {
+    while (iterator.hasNext())
+    {
+      Property property = (Property)iterator.next();
+      EStructuralFeature feature = (EStructuralFeature)property;
+      if (dataObject.isSet(property))
+      {
+        if (FeatureMapUtil.isFeatureMap(feature))
+        {
+          if (!validate(feature, p))
+            return 2;
+          insert(property, p, value);
+          return 0;
+        }
+        if (property != p || !property.isMany())
+          return 2;
+        insert(property, value);
+        return 0;
+      }
+      if (FeatureMapUtil.isFeatureMap(feature))
+      {
+        if (validate(feature, p))
+        {
+          append(property, p, value);
+          return 0;
+        }
+      }
+      else if (property == p)
+      {
+        set(property, value);
+        return 0;
+      }
+    } // iterator.hasNext()
+    return 1;
+  }
+  
+  public final void add(int index, Property p, Object value)
+  {
+    Iterator iterator = properties.iterator();
+    if (index == 0)
+      switch (insert(iterator, p, value))
+      {
+        case 0:
+          return;
+        case 1:  
+          throw new IndexOutOfBoundsException();
+        default: // 2  
+          throw new IllegalArgumentException();
+      }
+    while (iterator.hasNext())
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+        {
+          Sequence sequence = dataObject.getSequence(property);
+          int size = sequence.size();
+          if (index < size)
+          {
+            sequence.add(index, p, value);
+            return;
+          }
+          index -= size;
+          if (index != 0)
+            continue;
+          if (insert(iterator, p, value) != 0)
+            /*assert */sequence.add(p, value);
+          return;
+        } // sequence(property)
+        else if (property.isMany())
+        {
+          List values = dataObject.getList(property);
+          int size = values.size();
+          if (index < size)
+          {
+            values.add(index, value);
+            return;
+          }
+          index -= size;
+          if (index == 0 && property == p)
+          {
+            values.add(value);
+            return;
+          }
+        }
+        else if (index == 0)
+          throw new IllegalArgumentException();
+        else
+          --index;
+    }
+    throw new IndexOutOfBoundsException();
+  }
+
+  public void add(int index, String propertyName, Object value)
+  {
+    add(index, property(propertyName), value);
+  }
+
+  public void add(int index, int propertyIndex, Object value)
+  {
+    add(index, property(propertyIndex), value);
+  }
+
+  public final void addText(String text)
+  {
+    throw new IllegalArgumentException();
+  }
+
+  /**
+   * @deprecated
+   */
+  public void add(String text)
+  {
+    addText(text);
+  }
+
+  public final void addText(int index, String text)
+  {
+    throw new IllegalArgumentException();
+  }
+
+  /**
+   * @deprecated
+   */
+  public void add(int index, String text)
+  {
+    addText(index, text);
+  }
+
+  public void remove(int index)
+  {
+    for (Iterator iterator = properties.iterator() ; iterator.hasNext() ;)
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+        {
+          Sequence sequence = dataObject.getSequence(property);
+          int size = sequence.size();
+          if (index < size)
+          {
+            sequence.remove(index);
+            return;
+          }
+          index -= size;
+        }
+        else if (property.isMany())
+        {
+          List values = dataObject.getList(property);
+          int size = values.size();
+          if (index < size)
+          {
+            values.remove(index);
+            return;
+          }
+          index -= size;
+        }
+        else if (index == 0)
+        {
+          dataObject.unset(property);
+          return;
+        }
+        else
+          --index;
+    }
+    throw new IndexOutOfBoundsException();
+  }
+
+  static private Object remove(Sequence sequence, int index)
+  {
+    Object value = sequence.getValue(index);
+    sequence.remove(index);
+    return value;
+  }
+  
+  static void move(Sequence fromSequence, int fromIndex, Sequence toSequence, int toIndex, Property property)
+  {
+    toSequence.add(toIndex, property, remove(fromSequence, fromIndex)); // removes containment
+  }
+  
+  static protected void move(Sequence fromSequence, int fromIndex, Sequence toSequence, int toIndex)
+  {
+    move(fromSequence, fromIndex, toSequence, toIndex, fromSequence.getProperty(fromIndex));
+  }
+  
+  static protected void add(Object value,List list,int index, int size)
+  {
+    if (++index == size)
+      /*assert */list.add(value);
+    else
+      list.add(index, value); // removes containment
+  }
+  
+  static protected void add(Property property, Object value, Sequence toSequence, int toIndex, int size)
+  {
+    if (++toIndex == size)
+      toSequence.add(property, value); // removes containment
+    else
+      toSequence.add(toIndex, property, value); // removes containment
+  }
+  
+  public void move(int toIndex, int fromIndex)
+  {
+    for (Iterator iterator = properties.iterator() ; iterator.hasNext() ;)
+    {
+      Property property = (Property)iterator.next();
+      if (dataObject.isSet(property))
+        if (sequence(property))
+        {
+          Sequence sequence = dataObject.getSequence(property);
+          int size = sequence.size();
+          if (toIndex < size)
+          {
+            if (fromIndex < size)
+            {
+              sequence.move(toIndex, fromIndex);
+              return;
+            }
+            while (iterator.hasNext())
+            {
+              property = (Property)iterator.next();
+              if (!dataObject.isSet(property))
+                continue;
+              fromIndex -= size;
+              if (sequence(property))
+              {
+                Sequence fromSequence = dataObject.getSequence(property);
+                size = fromSequence.size();
+                if (fromIndex >= size)
+                  continue;
+                move(fromSequence, fromIndex, sequence, toIndex);
+                return;
+              }
+              if (property.isMany())
+              {
+                List list = dataObject.getList(property);
+                size = list.size();
+                if (fromIndex >= size)
+                  continue;
+                sequence.add(toIndex, property, list.remove(fromIndex)); // removes containment
+                return;
+              }
+              if (fromIndex == 0)
+              {
+                sequence.add(toIndex, property, dataObject.get(property)); // removes containment
+                dataObject.unset(property);
+                return;
+              }
+              size = 1;
+            } // iterator.hasNext()
+            break;
+          } // toIndex < size
+          if (fromIndex < size)
+          {
+            while (iterator.hasNext())
+            {
+              property = (Property)iterator.next();
+              if (!dataObject.isSet(property))
+                continue;
+              toIndex -= size;
+              if (sequence(property))
+              {
+                Sequence toSequence = dataObject.getSequence(property);
+                size = toSequence.size();
+                if (toIndex >= size)
+                  continue;
+                if (++toIndex == size)
+                  toSequence.add(sequence.getProperty(fromIndex), remove(sequence, fromIndex)); // Java pushes stack from left to right
+                    // removes containment
+                else
+                  move(sequence, fromIndex, toSequence, toIndex);
+                return;
+              }
+              if (property.isMany())
+              {
+                List list = dataObject.getList(property);
+                size = list.size();
+                if (toIndex >= size)
+                  continue;
+                if (sequence.getProperty(fromIndex) != property)
+                  throw new IllegalArgumentException();
+                add(remove(sequence, fromIndex), list, toIndex, size);
+                return;
+              }
+              if (toIndex == 0)
+              {
+                while (iterator.hasNext())
+                {
+                  Property p = sequence.getProperty(fromIndex);
+                  property = (Property)iterator.next();
+                  EStructuralFeature feature = (EStructuralFeature)property;
+                  if (dataObject.isSet(property))
+                  {
+                    if (FeatureMapUtil.isFeatureMap(feature))
+                    {
+                      /*if (!validate(feature, p))
+                        throw new IllegalArgumentException(); */
+                      move(sequence, fromIndex, dataObject.getSequence(property), 0, p);
+                      return;
+                    }
+                    if (property != p || !property.isMany())
+                      throw new IllegalArgumentException();
+                    insert(property, remove(sequence, fromIndex)); // removes containment
+                    return;
+                  }
+                  if (FeatureMapUtil.isFeatureMap(feature))
+                  {
+                    if (validate(feature, p))
+                    {
+                      append(property, p, remove(sequence, fromIndex)); // removes containment
+                      return;
+                    }
+                  }
+                  else if (property == p)
+                  {
+                    set(property, remove(sequence, fromIndex));
+                    return;
+                  }
+                } // iterator.hasNext()
+                break;
+              }
+              size = 1;
+            } // iterator.hasNext()
+            break;
+          } // fromIndex < size
+          toIndex -= size;
+          fromIndex -= size;
+        } // sequence(property)
+        else if (property.isMany())
+        {
+          List list = dataObject.getList(property);
+          int size = list.size();
+          if (toIndex < size)
+          {
+            if (fromIndex < size)
+            {
+              ((EList)list).move(toIndex, fromIndex);
+              return;
+            }
+            while (iterator.hasNext())
+            {
+              Property p = (Property)iterator.next();
+              if (!dataObject.isSet(p))
+                continue;
+              fromIndex -= size;
+              if (sequence(p))
+              {
+                Sequence fromSequence = dataObject.getSequence(p);
+                size = fromSequence.size();
+                if (fromIndex >= size)
+                  continue;
+                if (fromSequence.getProperty(fromIndex) != property)
+                  throw new IllegalArgumentException();
+                list.add(toIndex, remove(fromSequence, fromIndex)); // removes containment
+                return;
+              }
+              if (p.isMany())
+              {
+                List l = dataObject.getList(p);
+                size = l.size();
+                if (fromIndex >= size)
+                  continue;
+                /*if (p != property)
+                  throw new IllegalArgumentException(); */
+                list.add(toIndex, l.remove(fromIndex)); // removes containment
+                return;
+              }
+              if (fromIndex == 0)
+              {
+                /*if (p != property)
+                throw new IllegalArgumentException(); */
+                list.add(toIndex, dataObject.get(p)); // removes containment
+                dataObject.unset(p);
+                return;
+              }
+              size = 1;
+            } // iterator.hasNext()
+            break;
+          } // toIndex < size
+          if (fromIndex < size)
+          {
+            while (iterator.hasNext())
+            {
+              Property p = (Property)iterator.next();
+              if (!dataObject.isSet(p))
+                continue;
+              toIndex -= size;
+              if (sequence(p))
+              {
+                Sequence toSequence = dataObject.getSequence(p);
+                size = toSequence.size();
+                if (toIndex >= size)
+                  continue;
+                add(property, list.remove(fromIndex), toSequence, toIndex, size);
+                return;
+              }
+              if (p.isMany())
+              {
+                List l = dataObject.getList(p);
+                size = l.size();
+                if (toIndex >= size)
+                  continue;
+                /*if (property != p)
+                  throw new IllegalArgumentException(); */
+                add(list.remove(fromIndex), l, toIndex, size);
+                return;
+              }
+              if (toIndex == 0)
+              {
+                while (iterator.hasNext())
+                {
+                  p = (Property)iterator.next();
+                  EStructuralFeature feature = (EStructuralFeature)p;
+                  if (dataObject.isSet(p))
+                  {
+                    if (FeatureMapUtil.isFeatureMap(feature))
+                    {
+                      /*if (!validate(feature, property))
+                        throw new IllegalArgumentException(); */
+                      insert(p, property, list.remove(fromIndex));
+                      return;
+                    }
+                    if (/*p != property || */!p.isMany())
+                      throw new IllegalArgumentException();
+                    insert(p, list.remove(fromIndex)); // removes containment
+                    return;
+                  }
+                  if (FeatureMapUtil.isFeatureMap(feature))
+                  {
+                    if (!validate(feature, property))
+                      continue;
+                    append(p, property, list.remove(fromIndex)); // removes containment
+                    return;
+                  }
+                  else if (p == property)
+                  {
+                    set(p, list.remove(fromIndex));
+                    return;
+                  }
+                } // iterator.hasNext()
+                break;
+              } // toIndex == 0
+              size = 1;
+            } // iterator.hasNext()
+            break;
+          } // fromIndex < size
+          toIndex -= size;
+          fromIndex -= size;
+        } // property.isMany()
+        else if (toIndex == 0)
+          throw new IllegalArgumentException();
+        else if (fromIndex == 0)
+        {
+          for (int size = 1; iterator.hasNext() ;)
+          {
+            Property p = (Property)iterator.next();
+            if (!dataObject.isSet(p))
+              continue;
+            toIndex -= size;
+            if (sequence(p))
+            {
+              Sequence toSequence = dataObject.getSequence(p);
+              size = toSequence.size();
+              if (toIndex >= size)
+                continue;
+              add(property, dataObject.get(property), toSequence, toIndex, size);
+              dataObject.unset(property);
+              return;
+            }
+            if (p.isMany())
+            {
+              List l = dataObject.getList(p);
+              size = l.size();
+              if (toIndex >= size)
+                continue;
+              /*if (property != p)
+                throw new IllegalArgumentException(); */
+              add(dataObject.get(property), l, toIndex, size);
+              dataObject.unset(property);
+              return;
+            }
+            if (toIndex == 0)
+            {
+              while (iterator.hasNext())
+              {
+                p = (Property)iterator.next();
+                EStructuralFeature feature = (EStructuralFeature)p;
+                if (dataObject.isSet(p))
+                  if (FeatureMapUtil.isFeatureMap(feature))
+                    /*if (!validate(feature, property))
+                      throw new IllegalArgumentException(); */
+                    insert(p, property, dataObject.get(property));
+                  else if (/*p == property && */p.isMany())
+                    insert(p, dataObject.get(property)); // removes containment
+                  else
+                    throw new IllegalArgumentException();
+                else if (FeatureMapUtil.isFeatureMap(feature))
+                {
+                  if (!validate(feature, property))
+                    continue;
+                  append(p, property, dataObject.get(property)); // removes containment
+                }
+                else if (p == property)
+                  set(p, dataObject.get(property));
+                else
+                  continue;
+                dataObject.unset(property);
+                return;
+              } // iterator.hasNext()
+              break;
+            } // toIndex == 0
+            size = 1;
+          } // iterator.hasNext()
+          break;
+        } // fromIndex == 0
+        else
+        {
+          --toIndex;
+          --fromIndex;
+        }
+    }
+    throw new IndexOutOfBoundsException();
+  }
+}

Added: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java?view=auto&rev=536241
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java (added)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java Tue May  8 09:26:30 2007
@@ -0,0 +1,99 @@
+/**
+ *
+ *  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
+ *  to you under the Apache License, Version 2.0 (the
+ *  "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.
+ */
+package org.apache.tuscany.sdo.test;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XSDHelper;
+
+public class SequenceTestCase extends TestCase {
+    Type type;
+    Property localA, choiceX, choiceY, localB, open;
+
+    String xml = "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"testNS\" xmlns:tns=\"testNS\">"+
+                   "<element name=\"open\" type=\"string\"/>"+
+                   "<complexType name=\"Sequenced\">"+
+                     "<sequence>"+
+                       "<element name=\"localA\" type=\"string\" maxOccurs=\"unbounded\"/>"+
+                       "<choice maxOccurs=\"unbounded\">"+
+                         "<element name=\"choiceX\" type=\"string\"/>"+
+                         "<element name=\"choiceY\" type=\"string\"/>"+
+                       "</choice>"+
+                       "<element name=\"localB\" type=\"string\"/>"+
+                       "<any namespace=\"##any\" maxOccurs=\"unbounded\"/>"+
+                     "</sequence>"+
+                     "<anyAttribute/>"+
+                   "</complexType>"+
+		         "</schema>";
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        HelperContext hc = SDOUtil.createHelperContext();
+        hc.getXSDHelper().define(xml);
+        type = hc.getTypeHelper().getType("testNS", "Sequenced");
+        localA = type.getProperty("localA");
+        choiceX = type.getProperty("choiceX");
+        choiceY = type.getProperty("choiceY");
+        localB = type.getProperty("localB");
+        XSDHelper xsdHelper = hc.getXSDHelper();
+        open = xsdHelper.getGlobalProperty("testNS", "open", true);
+    }
+
+    public void testSequenced() {
+        DataObject dataObject = DataFactory.INSTANCE.create(type);
+        Sequence sequence = dataObject.getSequence();
+        
+        sequence.add(choiceX, "x1");
+        sequence.add(0, localA, "a");
+        sequence.add(choiceY, "y1");
+        sequence.add(choiceX, "x2");
+        sequence.add(localB, "b");
+        sequence.add(open, "open");
+        
+        List list = dataObject.getList(localA);
+        assertEquals(list.size(), 1);
+        assertEquals(list.get(0), "a");
+
+        assertEquals(dataObject.getString(localB), "b");
+        
+        list = dataObject.getList(choiceX);
+        assertEquals(list.size(), 2);
+        assertEquals(list.get(0), "x1");
+        assertEquals(list.get(1), "x2");
+
+        list = dataObject.getList(choiceY);
+        assertEquals(list.size(), 1);
+        assertEquals(list.get(0), "y1");
+        
+        list = dataObject.getList(open);
+        assertEquals(list.size(), 1);
+        assertEquals(list.get(0), "open");
+    }
+}



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