1 18 package org.objectweb.speedo.genclass.collection; 19 20 import org.objectweb.speedo.mim.api.SpeedoAccessor; 21 import org.objectweb.speedo.genclass.GenClass; 22 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 32 public class CollectionImpl extends GenClass implements Collection { 33 34 protected final static int DEFAULT_SIZE = -1; 35 36 CollectionAccessor accessor; 37 38 41 public CollectionImpl() { 42 super(); 43 accessor = (CollectionAccessor) createAccessor(); 44 } 45 46 48 52 public boolean add(Object o) { 53 boolean result; 54 if (!jdoIsActive) { 55 result = accessor.collection.add(o); 56 } else { 57 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().writeIntention(this, null, getDataIdentifier(o)); 58 result = ca.add(o); 59 } 60 return result; 61 } 62 63 public boolean addAll(Collection c) { 64 boolean result; 65 if (!jdoIsActive) { 66 result = accessor.collection.addAll(c); 67 } else { 68 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().writeIntention(this, null, getDataIdentifiers(c)); 69 result = ca.addAll(c); 70 } 71 return result; 72 } 73 74 public void clear() { 75 if (!jdoIsActive) { 76 accessor.collection.clear(); 77 } else { 78 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().writeIntention(this, null); 79 ca.clear(); 80 } 81 } 82 83 public boolean contains(Object o) { 84 if (!jdoIsActive) { 85 return accessor.collection.contains(o); 86 } else { 87 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 88 return ca.contains(o); 89 } 90 } 91 92 public boolean containsAll(Collection c) { 93 if (!jdoIsActive) { 94 return accessor.collection.containsAll(c); 95 } else { 96 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 97 return ca.containsAll(c); 98 } 99 } 100 101 public boolean equals(Object o) { 102 if (!jdoIsActive) { 103 return accessor.collection.equals(o); 104 } else { 105 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 106 return ca.equals(o); 107 } 108 } 109 110 public boolean isEmpty() { 111 if (!jdoIsActive) { 112 return accessor.collection.isEmpty(); 113 } else { 114 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 115 return ca.isEmpty(); 116 } 117 } 118 119 public Iterator iterator() { 120 if (!jdoIsActive) { 121 return accessor.collection.iterator(); 122 } else { 123 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 124 return ca.iterator(); 125 } 126 } 127 128 public boolean remove(Object o) { 129 boolean result; 130 if (!jdoIsActive) { 131 result = accessor.collection.remove(o); 132 } else { 133 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().writeIntention(this, null, getDataIdentifier(o)); 134 result = ca.remove(o); 135 } 136 return result; 137 } 138 139 public boolean removeAll(Collection c) { 140 boolean result; 141 if (!jdoIsActive) { 142 result = accessor.collection.removeAll(c); 143 } else { 144 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().writeIntention(this, null, getDataIdentifiers(c)); 145 result = ca.removeAll(c); 146 } 147 return result; 148 } 149 150 public boolean retainAll(Collection c) { 151 throw new UnsupportedOperationException (); 152 } 153 154 public int size() { 155 if (!jdoIsActive) { 156 return accessor.collection.size(); 157 } else { 158 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 159 return ca.size(); 160 } 161 } 162 163 public Object [] toArray() { 164 if (!jdoIsActive) { 165 return accessor.collection.toArray(); 166 } else { 167 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 168 return ca.toArray(); 169 } 170 } 171 172 public Object [] toArray(Object [] a) { 173 if (!jdoIsActive) { 174 return accessor.collection.toArray(a); 175 } else { 176 CollectionAccessor ca = (CollectionAccessor) getSpeedoHome().readIntention(this, null); 177 return ca.toArray(a); 178 } 179 } 180 181 184 public SpeedoAccessor createAccessor() { 185 return new CollectionAccessor(this); 186 } 187 188 public Object createGenClass() { 189 return new ArrayList (); 190 } 191 192 public SpeedoAccessor getReferenceAccessor() { 193 return accessor; 194 } 195 public void setReferenceAccessor(SpeedoAccessor refAcc) { 196 accessor = (CollectionAccessor) refAcc; 197 } 198 199 200 201 } 202 | Popular Tags |