Set.java

00001 
00025 package org.objectweb.jonas_ejb.container.jorm;
00026 
00027 import org.objectweb.jorm.api.PClassMapping;
00028 import org.objectweb.jorm.api.PException;
00029 
00030 import javax.ejb.EJBException;
00031 import javax.ejb.NoSuchObjectLocalException;
00032 
00033 import java.lang.reflect.Array;
00034 import java.util.Iterator;
00035 
00044 public class Set extends GenClassImpl implements java.util.Set {
00045 
00049     public Set(PClassMapping gcm) {
00050         super(gcm);
00051     }
00052 
00053     public Set() {
00054         super();
00055     }
00056 
00064     public boolean add(Object o) {
00065         return add(o, true);
00066     }
00067 
00068     public boolean add(Object o, boolean callListener) {
00069         try {
00070             if (!gcContains((PObject) o, null)) {
00071                 gcAdd((PObject) o, callListener);
00072                 return true;
00073             } else {
00074                 return false;
00075             }
00076         } catch (NoSuchObjectLocalException e) {
00077             throw new IllegalArgumentException(e.getMessage());
00078         } catch (PException e) {
00079             e.printStackTrace();
00080             return false;
00081         }
00082     }
00083     //------------------------------------//
00084 
00085     public int size() {
00086         return size;
00087     }
00088 
00089     public boolean isEmpty() {
00090         return size == 0;
00091     }
00092 
00093     public boolean contains(Object o) {
00094         try {
00095             return gcContains((PObject) o, null);
00096         } catch (PException e) {
00097             e.printStackTrace();
00098             throw new ArrayStoreException(e.getMessage());
00099         }
00100     }
00101 
00102     public Iterator iterator() {
00103         try {
00104             return gcIterator();
00105         } catch (PException e) {
00106             e.printStackTrace();
00107             throw new ArrayStoreException(e.getMessage());
00108         }
00109     }
00110 
00115     public Object[] toArray() {
00116         return toArray(new Object[size]);
00117     }
00118 
00125     public Object[] toArray(Object[] objects) {
00126         try {
00127             int i = 0;
00128             for (Iterator it = gcIterator(); it.hasNext();) {
00129                 objects[i++] = it.next();
00130             }
00131         } catch (PException e) {
00132             e.printStackTrace();
00133             throw new ArrayStoreException(e.getMessage());
00134         }
00135         return objects;
00136     }
00137 
00138     public boolean remove(Object o) {
00139         try {
00140             return gcRemove(o, true) != null;
00141         } catch (PException e) {
00142             throw new EJBException(e);
00143         }
00144 
00145     }
00146 
00147     public boolean remove(Object o, boolean callListener) {
00148         try {
00149             return gcRemove(o, callListener) != null;
00150         } catch (PException e) {
00151             throw new EJBException(e);
00152         }
00153 
00154     }
00155 
00156     public boolean containsAll(java.util.Collection collection) {
00157         if (collection == null) {
00158             return true;
00159         }
00160         try {
00161             boolean res = true;
00162             Object conn = gcm.getPMapper().getConnection();
00163             for (Iterator it = collection.iterator(); it.hasNext() && res;) {
00164                 res = gcContains((PObject) it.next(), conn);
00165             }
00166             gcm.getPMapper().closeConnection(conn);
00167             return res;
00168         } catch (PException e) {
00169             e.printStackTrace();
00170             throw new ArrayStoreException(e.getMessage());
00171         }
00172     }
00173 
00179     public boolean addAll(java.util.Collection collection) {
00180         if (collection == null) {
00181             return true;
00182         }
00183         boolean res = true;
00184         for (Iterator it = collection.iterator(); it.hasNext();) {
00185             res &= add((PObject) it.next());
00186         }
00187         return res;
00188     }
00189 
00195     public boolean removeAll(java.util.Collection collection) {
00196         if (collection == null) {
00197             return true;
00198         }
00199         try {
00200             for (Iterator it = collection.iterator(); it.hasNext();) {
00201                 gcRemove((PObject) it.next(), true);
00202             }
00203         } catch (PException e) {
00204             throw new EJBException(e);
00205         }
00206         return true;
00207     }
00208 
00214     public boolean retainAll(java.util.Collection collection) {
00215         if (collection == null) {
00216             clear();
00217             return true;
00218         }
00219         try {
00220             for (Iterator it = iterator(); it.hasNext();) {
00221                 PObject o = (PObject) it.next();
00222                 if (!collection.contains(o)) {
00223                     gcRemove(o, true);
00224                 }
00225             }
00226         } catch (PException e) {
00227             throw new EJBException(e);
00228         }
00229         return true;
00230     }
00231 
00235     public void clear() {
00236         gcClear(false);
00237     }
00238 
00239 }

Generated on Tue Feb 15 15:05:41 2005 for JOnAS by  doxygen 1.3.9.1