1 21 package oracle.toplink.essentials.internal.queryframework; 23 24 import java.util.*; 25 import oracle.toplink.essentials.exceptions.*; 26 import oracle.toplink.essentials.indirection.*; 27 import oracle.toplink.essentials.internal.helper.ClassConstants; 28 29 37 public class IndirectListContainerPolicy extends InterfaceContainerPolicy { 38 39 43 public IndirectListContainerPolicy() { 44 super(); 45 } 46 47 52 public IndirectListContainerPolicy(Class containerClass) { 53 super(containerClass); 54 DescriptorException.invalidContainerPolicy(this, containerClass); 55 } 56 57 65 protected boolean addInto(Object key, Object element, Object container) { 66 try { 67 ((IndirectList)container).addElement(element); 68 return true; 69 } catch (ClassCastException ex) { 70 throw QueryException.cannotAddElement(element, container, ex); 71 } 72 } 73 74 82 public void addIntoWithOrder(Vector indexes, Hashtable elements, Object container) { 83 Object object = null; 84 try { 85 Enumeration indexEnum = indexes.elements(); 86 while (indexEnum.hasMoreElements()) { 87 Integer index = (Integer )indexEnum.nextElement(); 88 object = elements.get(index); 89 if (index.intValue() >= (sizeFor(container) - 1)) { 90 ((IndirectList)container).addElement(object); 91 } else { 92 ((IndirectList)container).setElementAt(object, index.intValue()); 93 } 94 } 95 } catch (ClassCastException ex1) { 96 throw QueryException.cannotAddElement(object, container, ex1); 97 } 98 } 99 100 106 public void clear(Object container) { 107 ((IndirectList)container).clear(); 108 } 109 110 118 protected boolean contains(Object element, Object container) { 119 return ((IndirectList)container).contains(element); 120 } 121 122 public Class getInterfaceType() { 123 return ClassConstants.IndirectList_Class; 124 } 125 126 133 public boolean hasNext(Object iterator) { 134 return ((Enumeration)iterator).hasMoreElements(); 135 } 136 137 143 public boolean hasOrder() { 144 return true; 145 } 146 147 154 public Object iteratorFor(Object container) { 155 return ((IndirectList)container).elements(); 156 } 157 158 166 protected Object next(Object iterator) { 167 return ((Enumeration)iterator).nextElement(); 168 } 169 170 177 protected boolean removeFrom(Object key, Object element, Object container) { 178 return ((IndirectList)container).removeElement(element); 179 } 180 181 189 public void removeFromWithOrder(int beginIndex, Object container) { 190 int size = sizeFor(container) - 1; 191 try { 192 for (; size >= beginIndex; --size) { 193 ((IndirectList)container).removeElementAt(size); 194 } 195 } catch (ClassCastException ex1) { 196 throw QueryException.cannotRemoveFromContainer(new Integer (size), container, this); 197 } 198 } 199 200 207 public int sizeFor(Object container) { 208 return ((IndirectList)container).size(); 209 } 210 } 211 | Popular Tags |