| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| ArrayFault |
|
| 1.1578947368421053;1.158 |
| 1 | /* |
|
| 2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
| 3 | Copyright (C) 2001 Intersect Software Corporation |
|
| 4 | ||
| 5 | This library is free software; you can redistribute it and/or |
|
| 6 | modify it under the terms of the GNU Lesser General Public |
|
| 7 | License as published by the Free Software Foundation; either |
|
| 8 | version 2.1 of the License, or (at your option) any later version. |
|
| 9 | ||
| 10 | This library is distributed in the hope that it will be useful, |
|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 | Lesser General Public License for more details. |
|
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public |
|
| 16 | License along with this library; if not, see http://www.gnu.org |
|
| 17 | */ |
|
| 18 | ||
| 19 | package net.wotonomy.control; |
|
| 20 | ||
| 21 | import java.util.Iterator; |
|
| 22 | import java.util.List; |
|
| 23 | import java.util.ListIterator; |
|
| 24 | ||
| 25 | import net.wotonomy.foundation.NSArray; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * A class that extends NSArray to intercept any accessor calls |
|
| 29 | * in order to defer loading until the last possible moment.<br><br> |
|
| 30 | * |
|
| 31 | * Because ArrayFault inherits from NSArray which implements |
|
| 32 | * List which implements Collection, data objects may declare |
|
| 33 | * their relationships to be of type NSArray, List, or Collection.<br><br> |
|
| 34 | * |
|
| 35 | * This class should be returned by implementations of |
|
| 36 | * EOObjectStore.arrayFaultForSourceGlobalID(). |
|
| 37 | */ |
|
| 38 | public class ArrayFault extends NSArray |
|
| 39 | { |
|
| 40 | private EOEditingContext editingContext; |
|
| 41 | private EOGlobalID sourceID; |
|
| 42 | private String relationshipKey; |
|
| 43 | private boolean fetched; |
|
| 44 | ||
| 45 | public ArrayFault( |
|
| 46 | EOGlobalID aSourceID, |
|
| 47 | String aRelationshipKey, |
|
| 48 | EOEditingContext aContext ) |
|
| 49 | { |
|
| 50 | 0 | super(); |
| 51 | 0 | editingContext = aContext; |
| 52 | 0 | sourceID = aSourceID; |
| 53 | 0 | relationshipKey = aRelationshipKey; |
| 54 | 0 | fetched = false; |
| 55 | 0 | } |
| 56 | ||
| 57 | public boolean isFetched() |
|
| 58 | { |
|
| 59 | 0 | return fetched; |
| 60 | } |
|
| 61 | ||
| 62 | protected void fireFault() |
|
| 63 | { |
|
| 64 | 0 | if ( !fetched ) |
| 65 | { |
|
| 66 | //new net.wotonomy.ui.swing.util.StackTraceInspector(); |
|
| 67 | //System.out.println( "ArrayFault.fireFault: before:" + this ); |
|
| 68 | 0 | fetched = true; |
| 69 | 0 | super.protectedAddAll( |
| 70 | 0 | editingContext.parentObjectStore().objectsForSourceGlobalID( |
| 71 | 0 | sourceID, |
| 72 | 0 | relationshipKey, |
| 73 | 0 | editingContext ) ); |
| 74 | //System.out.println( "ArrayFault.fireFault: after:" + this ); |
|
| 75 | } |
|
| 76 | 0 | } |
| 77 | ||
| 78 | public Object clone() |
|
| 79 | { |
|
| 80 | 0 | fireFault(); |
| 81 | 0 | return super.clone(); |
| 82 | } |
|
| 83 | ||
| 84 | public boolean contains(Object elem) |
|
| 85 | { |
|
| 86 | 0 | fireFault(); |
| 87 | 0 | return super.contains( elem ); |
| 88 | } |
|
| 89 | ||
| 90 | public boolean equals(Object o) |
|
| 91 | { |
|
| 92 | 0 | fireFault(); |
| 93 | 0 | return super.equals( o ); |
| 94 | } |
|
| 95 | ||
| 96 | public Object get(int index) |
|
| 97 | { |
|
| 98 | 0 | fireFault(); |
| 99 | 0 | return super.get( index ); |
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * Overridden to return the identity hash. |
|
| 104 | * This somewhat violates the List contract, |
|
| 105 | * but otherwise calling hash code would |
|
| 106 | * fire the fault. Bottom line: don't use |
|
| 107 | * array faults as keys in hash maps. |
|
| 108 | */ |
|
| 109 | public int hashCode() |
|
| 110 | { |
|
| 111 | 0 | return System.identityHashCode( this ); |
| 112 | } |
|
| 113 | ||
| 114 | public int indexOf(Object o) |
|
| 115 | { |
|
| 116 | 0 | fireFault(); |
| 117 | 0 | return super.indexOf( o ); |
| 118 | } |
|
| 119 | ||
| 120 | public boolean isEmpty() |
|
| 121 | { |
|
| 122 | 0 | fireFault(); |
| 123 | 0 | return super.isEmpty(); |
| 124 | } |
|
| 125 | ||
| 126 | public Iterator iterator() |
|
| 127 | { |
|
| 128 | 0 | fireFault(); |
| 129 | 0 | return super.iterator(); |
| 130 | } |
|
| 131 | ||
| 132 | public int lastIndexOf(Object o) |
|
| 133 | { |
|
| 134 | 0 | fireFault(); |
| 135 | 0 | return super.lastIndexOf( o ); |
| 136 | } |
|
| 137 | ||
| 138 | public ListIterator listIterator() |
|
| 139 | { |
|
| 140 | 0 | fireFault(); |
| 141 | 0 | return super.listIterator(); |
| 142 | } |
|
| 143 | ||
| 144 | public ListIterator listIterator(int index) |
|
| 145 | { |
|
| 146 | 0 | fireFault(); |
| 147 | 0 | return super.listIterator( index ); |
| 148 | } |
|
| 149 | ||
| 150 | public int size() |
|
| 151 | { |
|
| 152 | 0 | fireFault(); |
| 153 | 0 | return super.size(); |
| 154 | } |
|
| 155 | ||
| 156 | public List subList(int fromIndex, int toIndex) |
|
| 157 | { |
|
| 158 | 0 | fireFault(); |
| 159 | 0 | return super.subList( fromIndex, toIndex ); |
| 160 | } |
|
| 161 | ||
| 162 | public Object[] toArray() |
|
| 163 | { |
|
| 164 | 0 | fireFault(); |
| 165 | 0 | return super.toArray(); |
| 166 | } |
|
| 167 | ||
| 168 | public Object[] toArray(Object[] a) |
|
| 169 | { |
|
| 170 | 0 | fireFault(); |
| 171 | 0 | return super.toArray( a ); |
| 172 | } |
|
| 173 | ||
| 174 | /** |
|
| 175 | * Overridden to display information about |
|
| 176 | * the fault only if not fetched. |
|
| 177 | * Calls to super if fetched. |
|
| 178 | */ |
|
| 179 | public String toString() |
|
| 180 | { |
|
| 181 | 0 | if ( isFetched() ) |
| 182 | { |
|
| 183 | 0 | return super.toString(); |
| 184 | } |
|
| 185 | 0 | return "[ArrayFault@"+Integer.toHexString( System.identityHashCode( this ) )+":"+sourceID+":"+relationshipKey+"]"; |
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| 189 | /* |
|
| 190 | * $Log$ |
|
| 191 | * Revision 1.2 2006/02/16 16:47:14 cgruber |
|
| 192 | * Move some classes in to "internal" packages and re-work imports, etc. |
|
| 193 | * |
|
| 194 | * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions. |
|
| 195 | * |
|
| 196 | * Revision 1.1 2006/02/16 13:19:57 cgruber |
|
| 197 | * Check in all sources in eclipse-friendly maven-enabled packages. |
|
| 198 | * |
|
| 199 | * Revision 1.5 2003/12/18 15:37:38 mpowers |
|
| 200 | * Changes to retain ability to work with objects that don't necessarily |
|
| 201 | * implement EOEnterpriseObject. I would still like to preserve this case |
|
| 202 | * for general usage, however the access package is free to assume that |
|
| 203 | * those objects will be EOs and cast appropriately. |
|
| 204 | * |
|
| 205 | * Revision 1.4 2003/08/19 01:53:12 chochos |
|
| 206 | * EOObjectStore had some incompatible return types (Object instead of EOEnterpriseObject, in fault methods mostly). It's internally consistent but I hope it doesn't break anything based on this, even though fault methods mostly throw exceptions for now. |
|
| 207 | * |
|
| 208 | * Revision 1.3 2002/10/24 18:17:37 mpowers |
|
| 209 | * ArrayFaults are now read-only. |
|
| 210 | * |
|
| 211 | * Revision 1.2 2001/05/06 22:22:55 mpowers |
|
| 212 | * Debugging. |
|
| 213 | * |
|
| 214 | * Revision 1.1 2001/05/05 23:05:42 mpowers |
|
| 215 | * Implemented Array Faults. |
|
| 216 | * |
|
| 217 | * |
|
| 218 | */ |
|
| 219 |