1.1 --- a/mdr/src/org/netbeans/mdr/handlers/AttrCollWrapper.java Mon Mar 22 12:14:24 2004 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/handlers/AttrCollWrapper.java Mon Mar 22 15:32:56 2004 +0000
1.3 @@ -22,16 +22,22 @@
1.4 */
1.5 public class AttrCollWrapper extends AttrImmutCollWrapper {
1.6 protected final EventNotifier.Abstract notifier;
1.7 - protected final FeaturedHandler source;
1.8 protected String attrName = null;
1.9 protected final boolean isStatic;
1.10
1.11 - public AttrCollWrapper(FeaturedHandler source, Collection inner) {
1.12 - super(source._getMdrStorage(), inner);
1.13 + public AttrCollWrapper(FeaturedHandler source, int attrIndex, String attrName) {
1.14 + super(source._getMdrStorage(), source, attrIndex, attrName);
1.15 EventNotifier en = source._getMdrStorage().getEventNotifier();
1.16 this.isStatic = source instanceof ClassProxyHandler;
1.17 this.notifier = isStatic ? (EventNotifier.Abstract) en.CLASS : (EventNotifier.Abstract) en.INSTANCE;
1.18 + }
1.19 +
1.20 + public AttrCollWrapper(FeaturedHandler source, Collection inner) {
1.21 + super(source._getMdrStorage(), inner);
1.22 this.source = source;
1.23 + EventNotifier en = source._getMdrStorage().getEventNotifier();
1.24 + this.isStatic = source instanceof ClassProxyHandler;
1.25 + this.notifier = isStatic ? (EventNotifier.Abstract) en.CLASS : (EventNotifier.Abstract) en.INSTANCE;
1.26 }
1.27
1.28 public void setAttrName(String name) {
1.29 @@ -41,7 +47,7 @@
1.30 public final Iterator iterator() {
1.31 try {
1.32 lock(false);
1.33 - return new AttrIteratorWrapper(inner.iterator());
1.34 + return new AttrIteratorWrapper(getInnerCollection().iterator());
1.35 } finally {
1.36 unlock();
1.37 }
1.38 @@ -51,7 +57,7 @@
1.39 boolean fail = true;
1.40 try {
1.41 lock(true);
1.42 - Object elements[] = inner.toArray();
1.43 + Object elements[] = getInnerCollection().toArray();
1.44 for (int i = 0; i < elements.length; i++) {
1.45 remove(elements[i]);
1.46 }
1.47 @@ -89,7 +95,7 @@
1.48 AttributeEvent.POSITION_NONE);
1.49 notifier.firePlannedChange(source, event);
1.50 }
1.51 - boolean result = inner.remove(obj);
1.52 + boolean result = getInnerCollection().remove(obj);
1.53 fail = false;
1.54 return result;
1.55 } finally {
1.56 @@ -110,7 +116,7 @@
1.57 AttributeEvent.POSITION_NONE);
1.58 notifier.firePlannedChange(source, event);
1.59 }
1.60 - boolean result = inner.add(obj);
1.61 + boolean result = getInnerCollection().add(obj);
1.62 fail = false;
1.63 return result;
1.64 } finally {
1.65 @@ -123,7 +129,7 @@
1.66 try {
1.67 boolean result = false;
1.68 lock(true);
1.69 - Object elements[] = inner.toArray();
1.70 + Object elements[] = getInnerCollection().toArray();
1.71 for (int i = 0; i < elements.length; i++) {
1.72 if (!collection.contains(elements[i])) {
1.73 remove(elements[i]);
2.1 --- a/mdr/src/org/netbeans/mdr/handlers/AttrImmutCollWrapper.java Mon Mar 22 12:14:24 2004 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/handlers/AttrImmutCollWrapper.java Mon Mar 22 15:32:56 2004 +0000
2.3 @@ -14,7 +14,12 @@
2.4
2.5 import java.util.Collection;
2.6 import java.util.Iterator;
2.7 +import org.netbeans.mdr.persistence.StorageException;
2.8 import org.netbeans.mdr.storagemodel.MdrStorage;
2.9 +import org.netbeans.mdr.storagemodel.StorableFeatured;
2.10 +import org.netbeans.mdr.storagemodel.StorableObject;
2.11 +import org.netbeans.mdr.util.DebugException;
2.12 +import org.netbeans.mdr.util.Logger;
2.13 import org.netbeans.mdr.util.TransactionMutex;
2.14
2.15 /**
2.16 @@ -22,19 +27,45 @@
2.17 * @author Martin Matula
2.18 */
2.19 public class AttrImmutCollWrapper implements Collection {
2.20 + protected final MdrStorage storage;
2.21 + protected FeaturedHandler source;
2.22 + protected final String attrName;
2.23 + protected final int attrIndex;
2.24 + protected final TransactionMutex mutex;
2.25 protected final Collection inner;
2.26 - protected final MdrStorage storage;
2.27 - protected final TransactionMutex mutex;
2.28
2.29 /** Creates new CollectionWrapper */
2.30 + public AttrImmutCollWrapper(MdrStorage storage, FeaturedHandler source, int attrIndex, String attrName) {
2.31 + this.storage = storage;
2.32 + this.source = source;
2.33 + this.attrName = attrName;
2.34 + this.attrIndex = attrIndex;
2.35 + this.mutex = storage.getRepositoryMutex();
2.36 + this.inner = null;
2.37 + }
2.38 +
2.39 public AttrImmutCollWrapper(MdrStorage storage, Collection inner) {
2.40 - this.inner = inner;
2.41 this.storage = storage;
2.42 this.mutex = storage.getRepositoryMutex();
2.43 + this.inner = inner;
2.44 + this.source = null;
2.45 + this.attrName = null;
2.46 + this.attrIndex = 0;
2.47 }
2.48
2.49 public Collection getInnerCollection() {
2.50 - return inner;
2.51 + if (inner != null) {
2.52 + return inner;
2.53 + } else {
2.54 + try {
2.55 + if (attrName != null)
2.56 + return (Collection) ((StorableFeatured) source._getDelegate()).getAttribute(attrName);
2.57 + else
2.58 + return (Collection) ((StorableObject) source._getDelegate()).getAttribute(attrIndex);
2.59 + } catch (StorageException e) {
2.60 + throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
2.61 + }
2.62 + }
2.63 }
2.64
2.65 protected final void lock(boolean write) {
2.66 @@ -52,7 +83,7 @@
2.67 public final boolean contains(Object obj) {
2.68 try {
2.69 lock(false);
2.70 - return inner.contains(obj);
2.71 + return getInnerCollection().contains(obj);
2.72 } finally {
2.73 unlock();
2.74 }
2.75 @@ -61,7 +92,7 @@
2.76 public Iterator iterator() {
2.77 try {
2.78 lock(false);
2.79 - return new AttrImmutIteratorWrapper(inner.iterator());
2.80 + return new AttrImmutIteratorWrapper(getInnerCollection().iterator());
2.81 } finally {
2.82 unlock();
2.83 }
2.84 @@ -70,7 +101,7 @@
2.85 public final int size() {
2.86 try {
2.87 lock(false);
2.88 - return inner.size();
2.89 + return getInnerCollection().size();
2.90 } finally {
2.91 unlock();
2.92 }
2.93 @@ -79,7 +110,7 @@
2.94 public final boolean isEmpty() {
2.95 try {
2.96 lock(false);
2.97 - return inner.isEmpty();
2.98 + return getInnerCollection().isEmpty();
2.99 } finally {
2.100 unlock();
2.101 }
2.102 @@ -88,7 +119,7 @@
2.103 public final boolean containsAll(Collection collection) {
2.104 try {
2.105 lock(false);
2.106 - return inner.containsAll(collection);
2.107 + return getInnerCollection().containsAll(collection);
2.108 } finally {
2.109 unlock();
2.110 }
2.111 @@ -97,7 +128,7 @@
2.112 public final Object[] toArray(Object[] obj) {
2.113 try {
2.114 lock(false);
2.115 - return inner.toArray(obj);
2.116 + return getInnerCollection().toArray(obj);
2.117 } finally {
2.118 unlock();
2.119 }
2.120 @@ -106,7 +137,7 @@
2.121 public final Object[] toArray() {
2.122 try {
2.123 lock(false);
2.124 - return inner.toArray();
2.125 + return getInnerCollection().toArray();
2.126 } finally {
2.127 unlock();
2.128 }
3.1 --- a/mdr/src/org/netbeans/mdr/handlers/AttrImmutListWrapper.java Mon Mar 22 12:14:24 2004 +0000
3.2 +++ b/mdr/src/org/netbeans/mdr/handlers/AttrImmutListWrapper.java Mon Mar 22 15:32:56 2004 +0000
3.3 @@ -24,12 +24,18 @@
3.4 * @author Martin Matula
3.5 */
3.6 public final class AttrImmutListWrapper extends AttrImmutCollWrapper implements List {
3.7 - protected final List innerList;
3.8
3.9 /** Creates new ListWrapper */
3.10 - public AttrImmutListWrapper(MdrStorage mdrStorage, List innerList) {
3.11 - super(mdrStorage, innerList);
3.12 - this.innerList = innerList;
3.13 + public AttrImmutListWrapper(MdrStorage mdrStorage, FeaturedHandler source, int attrIndex, String attrName) {
3.14 + super(mdrStorage, source, attrIndex, attrName);
3.15 + }
3.16 +
3.17 + public AttrImmutListWrapper(MdrStorage mdrStorage, Collection inner) {
3.18 + super(mdrStorage, inner);
3.19 + }
3.20 +
3.21 + public List getInnerList() {
3.22 + return (List) getInnerCollection();
3.23 }
3.24
3.25 public Object remove(int param) {
3.26 @@ -39,7 +45,7 @@
3.27 public ListIterator listIterator(int param) {
3.28 try {
3.29 lock(false);
3.30 - return new AttrImmutListIteratorWrapper(innerList.listIterator(param));
3.31 + return new AttrImmutListIteratorWrapper(getInnerList().listIterator(param));
3.32 } finally {
3.33 unlock();
3.34 }
3.35 @@ -52,7 +58,7 @@
3.36 public int indexOf(Object obj) {
3.37 try {
3.38 lock(false);
3.39 - return innerList.indexOf(obj);
3.40 + return getInnerList().indexOf(obj);
3.41 } finally {
3.42 unlock();
3.43 }
3.44 @@ -61,7 +67,7 @@
3.45 public int lastIndexOf(Object obj) {
3.46 try {
3.47 lock(false);
3.48 - return innerList.lastIndexOf(obj);
3.49 + return getInnerList().lastIndexOf(obj);
3.50 } finally {
3.51 unlock();
3.52 }
3.53 @@ -70,7 +76,7 @@
3.54 public Object get(int param) {
3.55 try {
3.56 lock(false);
3.57 - return innerList.get(param);
3.58 + return getInnerList().get(param);
3.59 } finally {
3.60 unlock();
3.61 }
3.62 @@ -87,7 +93,7 @@
3.63 public ListIterator listIterator() {
3.64 try {
3.65 lock(false);
3.66 - return new AttrImmutListIteratorWrapper(innerList.listIterator());
3.67 + return new AttrImmutListIteratorWrapper(getInnerList().listIterator());
3.68 } finally {
3.69 unlock();
3.70 }
3.71 @@ -96,7 +102,7 @@
3.72 public List subList(int param, int param1) {
3.73 try {
3.74 lock(false);
3.75 - return new AttrImmutListWrapper(storage, innerList.subList(param, param1));
3.76 + return new AttrImmutListWrapper(storage, getInnerList().subList(param, param1));
3.77 } finally {
3.78 unlock();
3.79 }
4.1 --- a/mdr/src/org/netbeans/mdr/handlers/AttrListWrapper.java Mon Mar 22 12:14:24 2004 +0000
4.2 +++ b/mdr/src/org/netbeans/mdr/handlers/AttrListWrapper.java Mon Mar 22 15:32:56 2004 +0000
4.3 @@ -21,16 +21,18 @@
4.4 * @author Martin Matula
4.5 */
4.6 public final class AttrListWrapper extends AttrCollWrapper implements List {
4.7 - private final List innerList;
4.8
4.9 /** Creates new ListWrapper */
4.10 - public AttrListWrapper(FeaturedHandler source, List innerList) {
4.11 - super(source, innerList);
4.12 - this.innerList = innerList;
4.13 + public AttrListWrapper(FeaturedHandler source, int attrIndex, String attrName) {
4.14 + super(source, attrIndex, attrName);
4.15 + }
4.16 +
4.17 + public AttrListWrapper(FeaturedHandler source, Collection inner) {
4.18 + super(source, inner);
4.19 }
4.20
4.21 public List getInnerList() {
4.22 - return innerList;
4.23 + return (List) getInnerCollection();
4.24 }
4.25
4.26 public Object remove(int param) {
4.27 @@ -46,7 +48,7 @@
4.28 param);
4.29 notifier.firePlannedChange(source, event);
4.30 }
4.31 - Object result = innerList.remove(param);
4.32 + Object result = getInnerList().remove(param);
4.33 fail = false;
4.34 return result;
4.35 } finally {
4.36 @@ -57,7 +59,7 @@
4.37 public ListIterator listIterator(int param) {
4.38 try {
4.39 lock(false);
4.40 - return new AttrListIteratorWrapper(innerList.listIterator(param));
4.41 + return new AttrListIteratorWrapper(getInnerList().listIterator(param));
4.42 } finally {
4.43 unlock();
4.44 }
4.45 @@ -76,7 +78,7 @@
4.46 param);
4.47 notifier.firePlannedChange(source, event);
4.48 }
4.49 - innerList.add(param, obj);
4.50 + getInnerList().add(param, obj);
4.51 fail = false;
4.52 } finally {
4.53 unlock(fail);
4.54 @@ -86,7 +88,7 @@
4.55 public int indexOf(Object obj) {
4.56 try {
4.57 lock(false);
4.58 - return innerList.indexOf(obj);
4.59 + return getInnerList().indexOf(obj);
4.60 } finally {
4.61 unlock();
4.62 }
4.63 @@ -95,7 +97,7 @@
4.64 public int lastIndexOf(Object obj) {
4.65 try {
4.66 lock(false);
4.67 - return innerList.lastIndexOf(obj);
4.68 + return getInnerList().lastIndexOf(obj);
4.69 } finally {
4.70 unlock();
4.71 }
4.72 @@ -104,7 +106,7 @@
4.73 public Object get(int param) {
4.74 try {
4.75 lock(false);
4.76 - return innerList.get(param);
4.77 + return getInnerList().get(param);
4.78 } finally {
4.79 unlock();
4.80 }
4.81 @@ -123,7 +125,7 @@
4.82 param);
4.83 notifier.firePlannedChange(source, event);
4.84 }
4.85 - Object result = innerList.set(param, obj);
4.86 + Object result = getInnerList().set(param, obj);
4.87 fail = false;
4.88 return result;
4.89 } finally {
4.90 @@ -148,7 +150,7 @@
4.91 public ListIterator listIterator() {
4.92 try {
4.93 lock(false);
4.94 - return new AttrListIteratorWrapper(innerList.listIterator());
4.95 + return new AttrListIteratorWrapper(getInnerList().listIterator());
4.96 } finally {
4.97 unlock();
4.98 }
4.99 @@ -157,7 +159,7 @@
4.100 public List subList(int param, int param1) {
4.101 try {
4.102 lock(false);
4.103 - AttrListWrapper result = new AttrListWrapper(source, innerList.subList(param, param1));
4.104 + AttrListWrapper result = new AttrListWrapper(source, getInnerList().subList(param, param1));
4.105 result.setAttrName(attrName);
4.106 return result;
4.107 } finally {
5.1 --- a/mdr/src/org/netbeans/mdr/handlers/ClassProxyHandler.java Mon Mar 22 12:14:24 2004 +0000
5.2 +++ b/mdr/src/org/netbeans/mdr/handlers/ClassProxyHandler.java Mon Mar 22 15:32:56 2004 +0000
5.3 @@ -127,11 +127,11 @@
5.4 result = getClassDelegate().getAttribute(attrName);
5.5 if (result instanceof Collection) {
5.6 if (result instanceof AttrList) {
5.7 - result = new AttrListWrapper(this, (List) result);
5.8 + result = new AttrListWrapper(this, 0, attrName);
5.9 } else if (result instanceof AttrCollection) {
5.10 - result = new AttrCollWrapper(this, (Collection) result);
5.11 + result = new AttrCollWrapper(this, 0, attrName);
5.12 } else if (result instanceof AttrImmutList) {
5.13 - result = new AttrImmutListWrapper(_getMdrStorage(), (List) result);
5.14 + result = new AttrImmutListWrapper(_getMdrStorage(), this, 0, attrName);
5.15 }
5.16 }
5.17 return result;
6.1 --- a/mdr/src/org/netbeans/mdr/handlers/InstanceHandler.java Mon Mar 22 12:14:24 2004 +0000
6.2 +++ b/mdr/src/org/netbeans/mdr/handlers/InstanceHandler.java Mon Mar 22 15:32:56 2004 +0000
6.3 @@ -193,11 +193,11 @@
6.4 result = getInstanceDelegate().getAttribute(attrIndex);
6.5 if (result instanceof Collection) {
6.6 if (result instanceof AttrList) {
6.7 - result = new AttrListWrapper(this, (List) result);
6.8 + result = new AttrListWrapper(this, attrIndex, null);
6.9 } else if (result instanceof AttrCollection) {
6.10 - result = new AttrCollWrapper(this, (Collection) result);
6.11 + result = new AttrCollWrapper(this, attrIndex, null);
6.12 } else if (result instanceof AttrImmutList) {
6.13 - result = new AttrImmutListWrapper(_getMdrStorage(), (List) result);
6.14 + result = new AttrImmutListWrapper(_getMdrStorage(), this, attrIndex, null);
6.15 }
6.16 }
6.17 return result;