1 25 26 package org.objectweb.jonas_ejb.container.jorm; 27 28 import java.util.Iterator ; 29 import java.lang.reflect.Array ; 30 import javax.ejb.EJBException ; 31 import org.objectweb.jorm.api.PIndexedElem; 32 import org.objectweb.jorm.api.PClassMapping; 33 import org.objectweb.jorm.api.PException; 34 35 43 public class Collection extends GenClassImpl implements java.util.Collection { 44 45 int nextIndex = -1; 46 47 50 public Collection(PClassMapping gcm) { 51 super(gcm); 52 } 53 54 public Collection() { 55 super(); 56 } 57 58 61 public PIndexedElem createPIndexedElem() { 62 if (pIndexedElems.size() == 0) { 63 nextIndex = 0; 64 } 65 return new CollectionElement(this, nextIndex++); 66 } 67 68 71 public int size() { 72 return size; 73 } 74 75 public boolean isEmpty() { 76 return size == 0; 77 } 78 79 public boolean contains(Object o) { 80 try { 81 return gcContains((PObject) o, null); 82 } catch (PException e) { 83 e.printStackTrace(); 84 throw new ArrayStoreException (e.getMessage()); 85 } 86 } 87 88 public Iterator iterator() { 89 try { 90 return gcIterator(); 91 } catch (PException e) { 92 e.printStackTrace(); 93 throw new ArrayStoreException (e.getMessage()); 94 } 95 } 96 97 101 public Object [] toArray() { 102 return toArray(new Object [size]); 103 } 104 105 111 public Object [] toArray(Object [] objects) { 112 try { 113 int i = 0; 114 for (Iterator it = gcIterator(); it.hasNext();) { 115 objects[i++] = it.next(); 116 } 117 } catch (PException e) { 118 e.printStackTrace(); 119 throw new ArrayStoreException (e.getMessage()); 120 } 121 return objects; 122 } 123 124 127 public boolean add(Object o) { 128 gcAdd((PObject) o, true); 129 return true; 130 } 131 132 135 public boolean remove(Object o) { 136 try { 137 return gcRemove(o, true) != null; 138 } catch (PException e) { 139 throw new EJBException (e); 140 } 141 } 142 143 146 public boolean remove(Object o, boolean callListener) { 147 try { 148 return gcRemove(o, callListener) != null; 149 } catch (PException e) { 150 throw new EJBException (e); 151 } 152 } 153 154 157 public boolean containsAll(java.util.Collection collection) { 158 if (collection == null) { 159 return true; 160 } 161 try { 162 boolean res = true; 163 Object conn = gcm.getPMapper().getConnection(); 164 for (Iterator it = collection.iterator(); it.hasNext() && res;) { 165 res = gcContains((PObject) it.next(), conn); 166 } 167 gcm.getPMapper().closeConnection(conn); 168 return res; 169 } catch (PException e) { 170 e.printStackTrace(); 171 throw new ArrayStoreException (e.getMessage()); 172 } 173 } 174 175 179 public boolean addAll(java.util.Collection collection) { 180 if (collection == null) { 181 return true; 182 } 183 boolean res = true; 184 for (Iterator it = collection.iterator(); it.hasNext();) { 185 res &= add((PObject) it.next()); 186 } 187 return res; 188 } 189 190 194 public boolean removeAll(java.util.Collection collection) { 195 if (collection == null) { 196 return true; 197 } 198 try { 199 for (Iterator it = collection.iterator(); it.hasNext();) { 200 gcRemove((PObject) it.next(), true); 201 } 202 } catch (PException e) { 203 throw new EJBException (e); 204 } 205 return true; 206 } 207 208 213 public boolean retainAll(java.util.Collection collection) { 214 if (collection == null) { 215 clear(); 216 return true; 217 } 218 try { 219 for (Iterator it = iterator(); it.hasNext();) { 220 PObject o = (PObject) it.next(); 221 if (!collection.contains(o)) 222 gcRemove(o, true); 223 } 224 } catch (PException e) { 225 throw new EJBException (e); 226 } 227 return true; 228 } 229 230 233 public void clear() { 234 gcClear(false); 235 } 236 } 237 | Popular Tags |