1 21 package oracle.toplink.essentials.internal.queryframework; 23 24 import java.util.*; 25 import oracle.toplink.essentials.exceptions.*; 26 import oracle.toplink.essentials.internal.helper.*; 27 import oracle.toplink.essentials.internal.sessions.AbstractSession; 28 29 39 public class CollectionContainerPolicy extends InterfaceContainerPolicy { 40 41 45 public CollectionContainerPolicy() { 46 super(); 47 } 48 49 53 public CollectionContainerPolicy(Class containerClass) { 54 super(containerClass); 55 } 56 57 61 public CollectionContainerPolicy(String containerClassName) { 62 super(containerClassName); 63 } 64 65 73 public boolean addInto(Object key, Object element, Object container) { 74 try { 75 return ((Collection)container).add(element); 76 } catch (ClassCastException ex1) { 77 throw QueryException.cannotAddElement(element, container, ex1); 78 } catch (IllegalArgumentException ex2) { 79 throw QueryException.cannotAddElement(element, container, ex2); 80 } catch (UnsupportedOperationException ex3) { 81 throw QueryException.cannotAddElement(element, container, ex3); 82 } 83 } 84 85 89 public Object buildContainerFromVector(Vector vector, AbstractSession session) { 90 if ((getContainerClass() == vector.getClass()) && (!hasElementDescriptor())) { 91 return vector; 92 } else { 93 return super.buildContainerFromVector(vector, session); 94 } 95 } 96 97 103 public void clear(Object container) { 104 try { 105 ((Collection)container).clear(); 106 } catch (UnsupportedOperationException ex) { 107 throw QueryException.methodNotValid(container, "clear()"); 108 } 109 } 110 111 119 protected boolean contains(Object element, Object container) { 120 return ((Collection)container).contains(element); 121 } 122 123 public Class getInterfaceType() { 124 return ClassConstants.Collection_Class; 125 } 126 127 132 public boolean hasOrder() { 133 return Helper.classImplementsInterface(this.getContainerClass(), ClassConstants.SortedSet_Class); 134 } 135 136 140 public boolean isValidContainer(Object container) { 141 return container instanceof Collection; 143 } 144 145 public boolean isCollectionPolicy() { 146 return true; 147 } 148 149 156 public Object iteratorFor(Object container) { 157 return ((Collection)container).iterator(); 158 } 159 160 168 protected boolean removeFrom(Object key, Object element, Object container) { 169 try { 170 return ((Collection)container).remove(element); 171 } catch (UnsupportedOperationException ex) { 172 throw QueryException.methodNotValid(element, "remove(Object element)"); 173 } 174 } 175 176 183 public int sizeFor(Object container) { 184 return ((Collection)container).size(); 185 } 186 } 187 | Popular Tags |