Checking of Closure Violation, Composition Cycle and Composition Violation. BLD200206170100
authormmatula@netbeans.org
Thu, 13 Jun 2002 17:01:36 +0000
changeset 881aacda6782038
parent 880 9c0166588d28
child 882 bfb3fc01174f
Checking of Closure Violation, Composition Cycle and Composition Violation.
mdr/src/org/netbeans/mdr/handlers/InstanceHandler.java
mdr/src/org/netbeans/mdr/storagemodel/AssocEndIndexSet.java
mdr/src/org/netbeans/mdr/storagemodel/AssocEndIndexUList.java
mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java
mdr/src/org/netbeans/mdr/storagemodel/AttrImmutList.java
mdr/src/org/netbeans/mdr/storagemodel/AttrImmutUList.java
mdr/src/org/netbeans/mdr/storagemodel/AttrList.java
mdr/src/org/netbeans/mdr/storagemodel/StorableAssociation.java
mdr/src/org/netbeans/mdr/storagemodel/StorableFeatured.java
mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java
     1.1 --- a/mdr/src/org/netbeans/mdr/handlers/InstanceHandler.java	Thu Jun 13 09:09:36 2002 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/handlers/InstanceHandler.java	Thu Jun 13 17:01:36 2002 +0000
     1.3 @@ -56,17 +56,9 @@
     1.4      public final RefFeatured refOutermostComposite() {
     1.5          try {
     1.6              _lock(false);
     1.7 -            RefFeatured result = refImmediateComposite();
     1.8 -            RefFeatured composite = this;
     1.9 -
    1.10 -            while (composite != result) {
    1.11 -                composite = result;
    1.12 -                if (result instanceof RefObject) {
    1.13 -                    result = ((RefObject) result).refImmediateComposite();
    1.14 -                }
    1.15 -            }
    1.16 -
    1.17 -            return result;
    1.18 +            return (RefFeatured) getHandler(getInstanceDelegate().getOutermostComposite());
    1.19 +        } catch ( StorageException e ) {
    1.20 +            throw new DebugException("Storage exception: " + e);
    1.21          } finally {
    1.22              _unlock();
    1.23          }
     2.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AssocEndIndexSet.java	Thu Jun 13 09:09:36 2002 +0000
     2.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AssocEndIndexSet.java	Thu Jun 13 17:01:36 2002 +0000
     2.3 @@ -31,8 +31,11 @@
     2.4      protected final StorableAssociation storable;
     2.5      protected final Index secondIndex;
     2.6      protected final boolean mutable;
     2.7 +    protected final boolean isAggregate;
     2.8 +    protected final boolean isAggregateOther;
     2.9 +    protected final StorableObject keyObject;
    2.10  
    2.11 -    protected AssocEndIndexSet(StorableAssociation storable, String metaMofId, MultivaluedIndex index, Object indexKey, Index secondIndex, Class type, int max, boolean mutable) {
    2.12 +    protected AssocEndIndexSet(StorableAssociation storable, String metaMofId, MultivaluedIndex index, Object indexKey, Index secondIndex, Class type, int max, boolean mutable, boolean isAggregate, boolean isAggregateOther) {
    2.13          super(storable.getMdrStorage(), index, indexKey);
    2.14          this.metaMofId = metaMofId;
    2.15          this.type = type;
    2.16 @@ -40,6 +43,19 @@
    2.17          this.storable = storable;
    2.18          this.secondIndex = secondIndex;
    2.19          this.mutable = mutable;
    2.20 +        this.isAggregate = isAggregate;
    2.21 +        this.isAggregateOther = isAggregateOther;
    2.22 +        
    2.23 +        if (isAggregate || isAggregateOther) {
    2.24 +            try {
    2.25 +                keyObject = (StorableObject) storage.getObject((String) indexKey);
    2.26 +            } catch (StorageException e) {
    2.27 +                e.printStackTrace();
    2.28 +                throw new DebugException();
    2.29 +            }
    2.30 +        } else {
    2.31 +            keyObject = null;
    2.32 +        }
    2.33      }
    2.34  
    2.35      public void checkType(Object obj) {
    2.36 @@ -72,6 +88,12 @@
    2.37      
    2.38      public boolean remove(Object o) {
    2.39          try { 
    2.40 +            if (isAggregate) {
    2.41 +                keyObject.clearComposite();
    2.42 +            } else if (isAggregateOther) {
    2.43 +                ((StorableObject) storage.getObject((String) o)).clearComposite();
    2.44 +            }
    2.45 +                
    2.46              boolean result = this.index.remove(indexKey, o);
    2.47              if (result) {
    2.48                  if (secondIndex instanceof SinglevaluedIndex) {
    2.49 @@ -90,9 +112,17 @@
    2.50      public boolean add(Object obj) {
    2.51          checkMaxSize(size() + 1);
    2.52          try { 
    2.53 +            if (isAggregate) {
    2.54 +                keyObject.setComposite((String) obj, (String) obj, metaMofId);
    2.55 +            } else if (isAggregateOther) {
    2.56 +                ((StorableObject) storage.getObject((String) obj)).setComposite(keyObject, (String) obj, metaMofId);
    2.57 +            }
    2.58              index.add(indexKey, obj);
    2.59              secondIndex.add(obj, indexKey);
    2.60              return true;
    2.61 +        } catch (StorageBadRequestException e) {
    2.62 +            // duplicate element -> return false
    2.63 +            return false;
    2.64          } catch (StorageException e) {
    2.65              e.printStackTrace();
    2.66              throw new DebugException();
    2.67 @@ -133,6 +163,12 @@
    2.68          public void remove() {
    2.69              innerIterator.remove();
    2.70              try {
    2.71 +                if (isAggregate) {
    2.72 +                    keyObject.clearComposite();
    2.73 +                } else if (isAggregateOther) {
    2.74 +                    ((StorableObject) lastRead).clearComposite();
    2.75 +                }
    2.76 +
    2.77                  String key = ((StorableBaseObject) lastRead).getMofId ();
    2.78                  if (secondIndex instanceof MultivaluedIndex) {
    2.79                      ((MultivaluedIndex) secondIndex).remove(key, indexKey);
     3.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AssocEndIndexUList.java	Thu Jun 13 09:09:36 2002 +0000
     3.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AssocEndIndexUList.java	Thu Jun 13 17:01:36 2002 +0000
     3.3 @@ -27,8 +27,8 @@
     3.4  public class AssocEndIndexUList extends AssocEndIndexSet implements List {
     3.5      private final MultivaluedOrderedIndex orderedIndex;
     3.6      
     3.7 -    protected AssocEndIndexUList(StorableAssociation storable, String metaMofId, MultivaluedOrderedIndex index, Object indexKey, Index secondIndex, Class type, int max, boolean mutable) {
     3.8 -        super(storable, metaMofId, index, indexKey, secondIndex, type, max, mutable);
     3.9 +    protected AssocEndIndexUList(StorableAssociation storable, String metaMofId, MultivaluedOrderedIndex index, Object indexKey, Index secondIndex, Class type, int max, boolean mutable, boolean isAggregate, boolean isAggregateOther) {
    3.10 +        super(storable, metaMofId, index, indexKey, secondIndex, type, max, mutable, isAggregate, isAggregateOther);
    3.11          this.orderedIndex = index;
    3.12      }
    3.13      
    3.14 @@ -79,6 +79,15 @@
    3.15      public Object set(int index, Object object) {
    3.16          try { 
    3.17              Object oldValue = ((List) getItems()).get(index);
    3.18 +
    3.19 +            if (isAggregate) {
    3.20 +                keyObject.clearComposite();
    3.21 +                keyObject.setComposite((String) object, (String) object, metaMofId);
    3.22 +            } else if (isAggregateOther) {
    3.23 +                ((StorableObject) storage.getObject((String) oldValue)).clearComposite();
    3.24 +                ((StorableObject) storage.getObject((String) object)).setComposite(keyObject, (String) object, metaMofId);
    3.25 +            }
    3.26 +
    3.27              orderedIndex.replace(indexKey, index, object);
    3.28              if (secondIndex instanceof SinglevaluedIndex) {
    3.29                  secondIndex.remove(oldValue);
    3.30 @@ -95,6 +104,11 @@
    3.31      public void add(int index, Object element) {
    3.32          try { 
    3.33              checkMaxSize(size() + 1);
    3.34 +            if (isAggregate) {
    3.35 +                keyObject.setComposite((String) element, (String) element, metaMofId);
    3.36 +            } else if (isAggregateOther) {
    3.37 +                ((StorableObject) storage.getObject((String) element)).setComposite(keyObject, (String) element, metaMofId);
    3.38 +            }
    3.39              orderedIndex.add(indexKey, index, element);
    3.40              secondIndex.add(element, indexKey);
    3.41          } catch (StorageException e) {
    3.42 @@ -105,6 +119,11 @@
    3.43      public Object remove(int index) {
    3.44          try { 
    3.45              Object oldValue = getItemsList().get(index);
    3.46 +            if (isAggregate) {
    3.47 +                keyObject.clearComposite();
    3.48 +            } else if (isAggregateOther) {
    3.49 +                ((StorableObject) storage.getObject((String) oldValue)).clearComposite();
    3.50 +            }
    3.51              orderedIndex.remove(indexKey, index);
    3.52              if (secondIndex instanceof SinglevaluedIndex) {
    3.53                  secondIndex.remove(oldValue);
    3.54 @@ -133,6 +152,11 @@
    3.55          public void add(Object obj) {
    3.56              listIterator.add(obj);
    3.57              try {
    3.58 +                if (isAggregate) {
    3.59 +                    keyObject.setComposite((String) obj, (String) obj, metaMofId);
    3.60 +                } else if (isAggregateOther) {
    3.61 +                    ((StorableObject) storage.getObject((String) obj)).setComposite(keyObject, (String) obj, metaMofId);
    3.62 +                }
    3.63                  secondIndex.add(obj, indexKey);
    3.64              } catch (StorageException e) {
    3.65                  throw new DebugException();
    3.66 @@ -159,6 +183,13 @@
    3.67              String key = ((StorableBaseObject) lastRead).getMofId ();
    3.68              listIterator.set(obj);
    3.69              try {
    3.70 +                if (isAggregate) {
    3.71 +                    keyObject.clearComposite();
    3.72 +                    keyObject.setComposite((String) obj, (String) obj, metaMofId);
    3.73 +                } else if (isAggregateOther) {
    3.74 +                    ((StorableObject) lastRead).clearComposite();
    3.75 +                    ((StorableObject) lastRead).setComposite(keyObject, (String) key, metaMofId);
    3.76 +                }
    3.77                  if (secondIndex instanceof MultivaluedIndex) {
    3.78                      ((MultivaluedIndex) secondIndex).remove(key, indexKey);
    3.79                  } else {
     4.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java	Thu Jun 13 09:09:36 2002 +0000
     4.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java	Thu Jun 13 17:01:36 2002 +0000
     4.3 @@ -128,7 +128,12 @@
     4.4          boolean result = inner.add(obj);
     4.5          if (result) {
     4.6              if (isRefObject) {
     4.7 -                setAttribComposite((RefObject) obj);
     4.8 +                try {
     4.9 +                    setAttribComposite((RefObject) obj);
    4.10 +                } catch (StorageException e) {
    4.11 +                    e.printStackTrace();
    4.12 +                    throw new DebugException();
    4.13 +                }
    4.14              }
    4.15              mdrObject.objectChanged();
    4.16          }
    4.17 @@ -179,7 +184,12 @@
    4.18          boolean result = inner.remove(obj);
    4.19          if (result) {
    4.20              if (isRefObject) {
    4.21 -                clearAttribComposite((RefObject) obj);
    4.22 +                try {
    4.23 +                    clearAttribComposite((RefObject) obj);
    4.24 +                } catch (StorageException e) {
    4.25 +                    e.printStackTrace();
    4.26 +                    throw new DebugException();
    4.27 +                }
    4.28              }
    4.29              mdrObject.objectChanged();
    4.30          }
    4.31 @@ -214,14 +224,14 @@
    4.32          }
    4.33      }
    4.34  
    4.35 -    protected void setAttribComposite(RefObject object) {        
    4.36 +    protected void setAttribComposite(RefObject object) throws StorageException {        
    4.37          StorableObject storable = (StorableObject) ((BaseObjectHandler) object)._getDelegate();
    4.38 -        storable.setAttribComposite(mdrObject.getMofId());
    4.39 +        storable.setComposite(mdrObject.getMofId(), storable.getMofId(), metaMofId);
    4.40      }
    4.41      
    4.42 -    protected void clearAttribComposite(RefObject object) {
    4.43 +    protected void clearAttribComposite(RefObject object) throws StorageException {
    4.44          StorableObject storable = (StorableObject) ((BaseObjectHandler) object)._getDelegate();
    4.45 -        storable.setAttribComposite(null);
    4.46 +        storable.clearComposite();
    4.47      }
    4.48      
    4.49      protected class AttrIterator implements Iterator {
    4.50 @@ -243,7 +253,12 @@
    4.51          public void remove() {
    4.52              inner.remove();
    4.53              if (isRefObject) {
    4.54 -                clearAttribComposite((RefObject) lastRead);
    4.55 +                try {
    4.56 +                    clearAttribComposite((RefObject) lastRead);
    4.57 +                } catch (StorageException e) {
    4.58 +                    e.printStackTrace();
    4.59 +                    throw new DebugException();
    4.60 +                }
    4.61              }
    4.62              mdrObject.objectChanged();
    4.63          }
     5.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrImmutList.java	Thu Jun 13 09:09:36 2002 +0000
     5.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrImmutList.java	Thu Jun 13 17:01:36 2002 +0000
     5.3 @@ -55,10 +55,21 @@
     5.4          }
     5.5  
     5.6          if (type.isInstance(RefObject.class)) {
     5.7 -            setAttribComposite(mdrObject.getMofId(), values);
     5.8 +            setAttribComposite(mdrObject.getMofId(), values, desc.getMofId());
     5.9          }
    5.10      }
    5.11      
    5.12 +    protected void setAttribComposite(String compositeId, RefObject object, String metaMofId) throws StorageException {        
    5.13 +        StorableObject storable = (StorableObject) ((BaseObjectHandler) object)._getDelegate();
    5.14 +        storable.setComposite(compositeId, storable.getMofId(), metaMofId);
    5.15 +    }
    5.16 +    
    5.17 +    protected void setAttribComposite(String compositeId, Collection list, String metaMofId) throws StorageException {
    5.18 +        for (Iterator it = list.iterator(); it.hasNext();) {
    5.19 +            setAttribComposite(compositeId, (RefObject) it.next(), metaMofId);
    5.20 +        }
    5.21 +    }        
    5.22 +
    5.23      protected RefObject getMetaElement(MdrStorage mdrStorage, String mofId) {
    5.24          try {
    5.25              return (RefObject) BaseObjectHandler.getHandler(mdrStorage.getObject(mofId));
    5.26 @@ -75,17 +86,6 @@
    5.27          return data.length;
    5.28      }
    5.29      
    5.30 -    protected void setAttribComposite(String compositeId, RefObject object) {        
    5.31 -        StorableObject storable = (StorableObject) ((BaseObjectHandler) object)._getDelegate();
    5.32 -        storable.setAttribComposite(compositeId);
    5.33 -    }
    5.34 -    
    5.35 -    protected void setAttribComposite(String compositeId, Collection list) {
    5.36 -        for (Iterator it = list.iterator(); it.hasNext();) {
    5.37 -            setAttribComposite(compositeId, (RefObject) it.next());
    5.38 -        }
    5.39 -    }        
    5.40 -    
    5.41      public void read(InputStream stream, StorableBaseObject storable) throws IOException {
    5.42          int size = IOUtils.readInt(stream);
    5.43          data = new Object[size];
     6.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrImmutUList.java	Thu Jun 13 09:09:36 2002 +0000
     6.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrImmutUList.java	Thu Jun 13 17:01:36 2002 +0000
     6.3 @@ -53,7 +53,7 @@
     6.4          }
     6.5  
     6.6          if (type.isInstance(RefObject.class)) {
     6.7 -            setAttribComposite(mdrObject.getMofId(), values);
     6.8 +            setAttribComposite(mdrObject.getMofId(), values, desc.getMofId());
     6.9          }
    6.10      }
    6.11  }
     7.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrList.java	Thu Jun 13 09:09:36 2002 +0000
     7.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrList.java	Thu Jun 13 17:01:36 2002 +0000
     7.3 @@ -48,7 +48,12 @@
     7.4          checkMaxSize(size() + 1);
     7.5          innerList.add(param, obj);
     7.6          if (isRefObject) {
     7.7 -            setAttribComposite((RefObject) obj);
     7.8 +            try {
     7.9 +                setAttribComposite((RefObject) obj);
    7.10 +            } catch (StorageException e) {
    7.11 +                e.printStackTrace();
    7.12 +                throw new DebugException();
    7.13 +            }
    7.14          }
    7.15          mdrObject.objectChanged();
    7.16      }    
    7.17 @@ -81,7 +86,12 @@
    7.18      public Object remove(int param) {
    7.19          Object result = innerList.remove(param);
    7.20          if (isRefObject) {
    7.21 -            clearAttribComposite((RefObject) result);
    7.22 +            try {
    7.23 +                clearAttribComposite((RefObject) result);
    7.24 +            } catch (StorageException e) {
    7.25 +                e.printStackTrace();
    7.26 +                throw new DebugException();
    7.27 +            }
    7.28          }
    7.29          mdrObject.objectChanged();
    7.30          return result;
    7.31 @@ -91,8 +101,13 @@
    7.32          checkType(obj);
    7.33          Object result = innerList.set(param, obj);
    7.34          if (isRefObject) {
    7.35 -            clearAttribComposite((RefObject) result);
    7.36 -            setAttribComposite((RefObject) obj);
    7.37 +            try {
    7.38 +                clearAttribComposite((RefObject) result);
    7.39 +                setAttribComposite((RefObject) obj);
    7.40 +            } catch (StorageException e) {
    7.41 +                e.printStackTrace();
    7.42 +                throw new DebugException();
    7.43 +            }
    7.44          }
    7.45          mdrObject.objectChanged();
    7.46          return result;
    7.47 @@ -115,7 +130,12 @@
    7.48              checkMaxSize(innerList.size() + 1);
    7.49              innerIterator.add(obj);
    7.50              if (isRefObject) {
    7.51 -                setAttribComposite((RefObject) obj);
    7.52 +                try {
    7.53 +                    setAttribComposite((RefObject) obj);
    7.54 +                } catch (StorageException e) {
    7.55 +                    e.printStackTrace();
    7.56 +                    throw new DebugException();
    7.57 +                }
    7.58              }
    7.59              mdrObject.objectChanged();
    7.60          }
    7.61 @@ -140,8 +160,13 @@
    7.62              checkType(obj);
    7.63              innerIterator.set(obj);
    7.64              if (isRefObject) {
    7.65 -                clearAttribComposite((RefObject) lastRead);
    7.66 -                setAttribComposite((RefObject) obj);
    7.67 +                try {
    7.68 +                    clearAttribComposite((RefObject) lastRead);
    7.69 +                    setAttribComposite((RefObject) obj);
    7.70 +                } catch (StorageException e) {
    7.71 +                    e.printStackTrace();
    7.72 +                    throw new DebugException();
    7.73 +                }
    7.74              }
    7.75              mdrObject.objectChanged();
    7.76          }
     8.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableAssociation.java	Thu Jun 13 09:09:36 2002 +0000
     8.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableAssociation.java	Thu Jun 13 17:01:36 2002 +0000
     8.3 @@ -277,14 +277,16 @@
     8.4          int min = isEndA ? minA : minB;
     8.5          int max = isEndA ? maxA : maxB;
     8.6          String endId = isEndA ? endAId : endBId;
     8.7 +        boolean aggr = isEndA ? aggrA : aggrB;
     8.8 +        boolean otherAggr = isEndA ? aggrB : aggrA;
     8.9          Object result;
    8.10          if (obj == null) throw new NullPointerException();
    8.11  
    8.12          if (multi) {
    8.13              if (order) {
    8.14 -                result = new AssocEndIndexUList(this, endId, (MultivaluedOrderedIndex) index, obj, secondIndex, type, max, true);
    8.15 +                result = new AssocEndIndexUList(this, endId, (MultivaluedOrderedIndex) index, obj, secondIndex, type, max, true, aggr, otherAggr);
    8.16              } else {
    8.17 -                result = new AssocEndIndexSet(this, endId, (MultivaluedIndex) index, obj, secondIndex, type, max, true);
    8.18 +                result = new AssocEndIndexSet(this, endId, (MultivaluedIndex) index, obj, secondIndex, type, max, true, aggr, otherAggr);
    8.19              }
    8.20          } else {
    8.21              result = getMdrStorage().getObjectFromIndexIfExists((SinglevaluedIndex) index, obj);
    8.22 @@ -445,30 +447,43 @@
    8.23       * @throws StorageException
    8.24       */
    8.25      public boolean addLink (String a, String b) throws StorageException {
    8.26 -        try {
    8.27 -            StorableObject oA = null, oB = null;
    8.28 -            if (indexedA) {
    8.29 +        if (multiValuedA) {
    8.30 +            return ((Collection) queryObjects(endA, b)).add(a);
    8.31 +        } else if (multiValuedB) {
    8.32 +            return ((Collection) queryObjects(endB, a)).add(b);
    8.33 +        } else {
    8.34 +            try {
    8.35 +                StorableObject oA = null, oB = null;
    8.36 +                oA = (StorableObject) getMdrStorage().getObject(a);
    8.37                  oB = (StorableObject) getMdrStorage().getObject(b);
    8.38 -                oB.removeFromIndex (getMofId(), endAId);
    8.39 +                if (indexedA) {
    8.40 +                    oB.removeFromIndex (getMofId(), endAId);
    8.41 +                }
    8.42 +                if (indexedB) {
    8.43 +                    oA.removeFromIndex (getMofId(), endBId);
    8.44 +                }
    8.45 +                // set composites
    8.46 +                if (aggrA) {
    8.47 +                    oB.setComposite(oA, a, endAId);
    8.48 +                } else if (aggrB) {
    8.49 +                    oA.setComposite(oB, b, endBId);
    8.50 +                }
    8.51 +                aIndex.add(b, a);
    8.52 +                bIndex.add(a, b);
    8.53 +                if (indexedA) {
    8.54 +                    // oB = (StorableObject) getMdrStorage().getObject(b);
    8.55 +                    oB.addToIndex (getMofId(), endAId);
    8.56 +                }
    8.57 +                if (indexedB) {
    8.58 +                    // oA = (StorableObject) getMdrStorage().getObject(a);
    8.59 +                    oA.addToIndex (getMofId(), endBId);
    8.60 +                }
    8.61 +
    8.62 +                return true;
    8.63 +            } catch (StorageBadRequestException e) {
    8.64 +                // ignore
    8.65 +                return false;
    8.66              }
    8.67 -            if (indexedB) {
    8.68 -                oA = (StorableObject) getMdrStorage().getObject(a);
    8.69 -                oA.removeFromIndex (getMofId(), endBId);
    8.70 -            }
    8.71 -            aIndex.add(b, a);
    8.72 -            bIndex.add(a, b);
    8.73 -            if (indexedA) {
    8.74 -                // oB = (StorableObject) getMdrStorage().getObject(b);
    8.75 -                oB.addToIndex (getMofId(), endAId);
    8.76 -            }
    8.77 -            if (indexedB) {
    8.78 -                // oA = (StorableObject) getMdrStorage().getObject(a);
    8.79 -                oA.addToIndex (getMofId(), endBId);
    8.80 -            }
    8.81 -            return true;
    8.82 -        } catch (StorageBadRequestException e) {
    8.83 -            // ignore
    8.84 -            return false;
    8.85          }
    8.86      }
    8.87  
    8.88 @@ -480,14 +495,20 @@
    8.89      public boolean removeLink (String a, String b) throws StorageException {
    8.90          try {
    8.91              StorableObject oA = null, oB = null;
    8.92 +            oA = (StorableObject) getMdrStorage().getObject(a);
    8.93 +            oB = (StorableObject) getMdrStorage().getObject(b);
    8.94              if (indexedA) {
    8.95 -                oB = (StorableObject) getMdrStorage().getObject(b);
    8.96                  oB.removeFromIndex (getMofId(), endAId);
    8.97              }
    8.98              if (indexedB) {
    8.99 -                oA = (StorableObject) getMdrStorage().getObject(a);
   8.100                  oA.removeFromIndex (getMofId(), endBId);
   8.101              }
   8.102 +            // remove composites
   8.103 +            if (aggrA) {
   8.104 +                oB.clearComposite();
   8.105 +            } else if (aggrB) {
   8.106 +                oA.clearComposite();
   8.107 +            }
   8.108              removeLinkEnd(b, a, aIndex, multiValuedA);
   8.109              removeLinkEnd(a, b, bIndex, multiValuedB);
   8.110              if (indexedA) {
     9.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableFeatured.java	Thu Jun 13 09:09:36 2002 +0000
     9.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableFeatured.java	Thu Jun 13 17:01:36 2002 +0000
     9.3 @@ -112,10 +112,10 @@
     9.4          
     9.5          if (!attribute.isMultivalued() && (value instanceof RefObject)) {
     9.6              StorableObject storableObj = (StorableObject) ((BaseObjectHandler) value)._getDelegate();
     9.7 -            storableObj.setAttribComposite (getMofId());
     9.8 +            storableObj.setComposite(getMofId(), storableObj.getMofId(), attribute.getMofId());
     9.9              if (oldValue != null) {
    9.10                  storableObj = (StorableObject) ((BaseObjectHandler) oldValue)._getDelegate();
    9.11 -                storableObj.setAttribComposite (null);
    9.12 +                storableObj.clearComposite();
    9.13              }
    9.14          }
    9.15          
    10.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java	Thu Jun 13 09:09:36 2002 +0000
    10.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java	Thu Jun 13 17:01:36 2002 +0000
    10.3 @@ -84,7 +84,7 @@
    10.4                      values[i] = params[i];
    10.5                      if (values[i] instanceof RefObject) {
    10.6                          StorableObject storableObj = (StorableObject) ((BaseObjectHandler) values[i])._getDelegate();
    10.7 -                        storableObj.setAttribComposite (getMofId());
    10.8 +                        storableObj.setComposite(this, storableObj.getMofId(), desc.getMofId());
    10.9                      }
   10.10                  } // else
   10.11                  modifyIndex(i, null, this.values[i]);
   10.12 @@ -104,21 +104,20 @@
   10.13       * @return result of this method is valid only if the immediate coposite was previously set
   10.14       * @throws StorageException
   10.15       */
   10.16 -    public StorableObject getImmediateComposite() throws StorageException {
   10.17 +    public StorableFeatured getImmediateComposite() throws StorageException {
   10.18          StorablePackage pkg;
   10.19          StorableAssociation assoc;
   10.20          String assocEnd;
   10.21          Object temp;
   10.22 -        StorableObject composite = null;
   10.23 +        StorableFeatured composite = null;
   10.24  
   10.25          if (attribComposite != null) {
   10.26              StorableFeatured sf = (StorableFeatured) getMdrStorage().getObject(attribComposite);
   10.27 -            if (!(sf instanceof StorableObject))
   10.28 -                return null;
   10.29 -            else
   10.30 -                return (StorableObject) sf;
   10.31 +            return sf;
   10.32 +        } else {
   10.33 +            return null;
   10.34          }
   10.35 -
   10.36 +/*
   10.37          pkg = getImmediatePackage();
   10.38          for (Iterator it = pkg.getAllAssociations().iterator(); it.hasNext();) {
   10.39              assoc = (StorableAssociation) it.next();
   10.40 @@ -148,20 +147,60 @@
   10.41          }
   10.42  
   10.43          return (composite == null ? this : composite);
   10.44 + */
   10.45 +    }
   10.46 +
   10.47 +    public StorableFeatured getOutermostComposite() throws StorageException {
   10.48 +        StorableFeatured result = getImmediateComposite();
   10.49 +        StorableFeatured composite = this;
   10.50 +
   10.51 +        while (result != null) {
   10.52 +            composite = result;
   10.53 +            if (result instanceof StorableObject) {
   10.54 +                result = ((StorableObject) result).getImmediateComposite();
   10.55 +            } else {
   10.56 +                result = null;
   10.57 +            }
   10.58 +        }
   10.59 +
   10.60 +        return composite;
   10.61 +    }
   10.62 +    
   10.63 +    void clearComposite() throws StorageException {
   10.64 +        setComposite((String) null, null, null);
   10.65 +    }
   10.66 +    
   10.67 +    void setComposite(String composite, String objectId, String elementId) throws StorageException {
   10.68 +        setComposite(getMdrStorage().getObject(composite), objectId, elementId);
   10.69      }
   10.70  
   10.71      /**
   10.72       * Sets (resp. unsets) immediate composite in case the object is (resp. was)
   10.73       * value of an attribute.
   10.74       *
   10.75 -     * @param id mofid of immediate composite object
   10.76 +     * @param id immediate composite object
   10.77       */
   10.78 -    void setAttribComposite(String id) {
   10.79 -        if (id == attribComposite)
   10.80 -            return;
   10.81 -        if ((id != null) && (attribComposite != null))
   10.82 -            throw new DebugException("Instance already has a composite: " + getMofId()); // object is already contained in another object
   10.83 -        attribComposite = id;
   10.84 +    void setComposite(StorableBaseObject composite, String objectId, String elementId) throws StorageException {
   10.85 +        if (composite == null) {
   10.86 +            attribComposite = null;
   10.87 +        } else {
   10.88 +            String id = composite.getMofId();
   10.89 +            if (id != attribComposite) {
   10.90 +                // check for Composition Violation
   10.91 +                if (attribComposite != null) {
   10.92 +                    throw new DebugException("Instance already has a composite: " + getMofId()); // object is already contained in another object
   10.93 +                }
   10.94 +                // check for Composition Cycle
   10.95 +                if ((composite instanceof StorableObject) && (((StorableObject) composite).getOutermostComposite().equals(this))) {
   10.96 +                    throw new javax.jmi.reflect.CompositionCycleException(BaseObjectHandler.getHandler(getMdrStorage().getObject(objectId)), (RefObject) BaseObjectHandler.getHandler(getMdrStorage().getObject(elementId)));
   10.97 +                }
   10.98 +                // check for Composition Closure
   10.99 +                if (!composite.getOutermostPackageId().equals(getOutermostPackageId())) {
  10.100 +                    throw new javax.jmi.reflect.ClosureViolationException(BaseObjectHandler.getHandler(getMdrStorage().getObject(objectId)), (RefObject) BaseObjectHandler.getHandler(getMdrStorage().getObject(elementId)));
  10.101 +                }
  10.102 +                attribComposite = id;
  10.103 +            }
  10.104 +        }
  10.105      }
  10.106  
  10.107      /**