From aedc34d55462a75e329bbf342251ff6504cd117e Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sun, 19 May 2024 17:56:33 -0400 Subject: Initial import from SVN --- .../main/java/net/wotonomy/control/ArrayFault.java | 219 +++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/ArrayFault.java (limited to 'projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/ArrayFault.java') diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/ArrayFault.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/ArrayFault.java new file mode 100644 index 0000000..59e135b --- /dev/null +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/ArrayFault.java @@ -0,0 +1,219 @@ +/* +Wotonomy: OpenStep design patterns for pure Java applications. +Copyright (C) 2001 Intersect Software Corporation + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, see http://www.gnu.org +*/ + +package net.wotonomy.control; + +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import net.wotonomy.foundation.NSArray; + +/** +* A class that extends NSArray to intercept any accessor calls +* in order to defer loading until the last possible moment.

+* +* Because ArrayFault inherits from NSArray which implements +* List which implements Collection, data objects may declare +* their relationships to be of type NSArray, List, or Collection.

+* +* This class should be returned by implementations of +* EOObjectStore.arrayFaultForSourceGlobalID(). +*/ +public class ArrayFault extends NSArray +{ + private EOEditingContext editingContext; + private EOGlobalID sourceID; + private String relationshipKey; + private boolean fetched; + + public ArrayFault( + EOGlobalID aSourceID, + String aRelationshipKey, + EOEditingContext aContext ) + { + super(); + editingContext = aContext; + sourceID = aSourceID; + relationshipKey = aRelationshipKey; + fetched = false; + } + + public boolean isFetched() + { + return fetched; + } + + protected void fireFault() + { + if ( !fetched ) + { +//new net.wotonomy.ui.swing.util.StackTraceInspector(); +//System.out.println( "ArrayFault.fireFault: before:" + this ); + fetched = true; + super.protectedAddAll( + editingContext.parentObjectStore().objectsForSourceGlobalID( + sourceID, + relationshipKey, + editingContext ) ); +//System.out.println( "ArrayFault.fireFault: after:" + this ); + } + } + + public Object clone() + { + fireFault(); + return super.clone(); + } + + public boolean contains(Object elem) + { + fireFault(); + return super.contains( elem ); + } + + public boolean equals(Object o) + { + fireFault(); + return super.equals( o ); + } + + public Object get(int index) + { + fireFault(); + return super.get( index ); + } + + /** + * Overridden to return the identity hash. + * This somewhat violates the List contract, + * but otherwise calling hash code would + * fire the fault. Bottom line: don't use + * array faults as keys in hash maps. + */ + public int hashCode() + { + return System.identityHashCode( this ); + } + + public int indexOf(Object o) + { + fireFault(); + return super.indexOf( o ); + } + + public boolean isEmpty() + { + fireFault(); + return super.isEmpty(); + } + + public Iterator iterator() + { + fireFault(); + return super.iterator(); + } + + public int lastIndexOf(Object o) + { + fireFault(); + return super.lastIndexOf( o ); + } + + public ListIterator listIterator() + { + fireFault(); + return super.listIterator(); + } + + public ListIterator listIterator(int index) + { + fireFault(); + return super.listIterator( index ); + } + + public int size() + { + fireFault(); + return super.size(); + } + + public List subList(int fromIndex, int toIndex) + { + fireFault(); + return super.subList( fromIndex, toIndex ); + } + + public Object[] toArray() + { + fireFault(); + return super.toArray(); + } + + public Object[] toArray(Object[] a) + { + fireFault(); + return super.toArray( a ); + } + + /** + * Overridden to display information about + * the fault only if not fetched. + * Calls to super if fetched. + */ + public String toString() + { + if ( isFetched() ) + { + return super.toString(); + } + return "[ArrayFault@"+Integer.toHexString( System.identityHashCode( this ) )+":"+sourceID+":"+relationshipKey+"]"; + } +} + +/* + * $Log$ + * Revision 1.2 2006/02/16 16:47:14 cgruber + * Move some classes in to "internal" packages and re-work imports, etc. + * + * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions. + * + * Revision 1.1 2006/02/16 13:19:57 cgruber + * Check in all sources in eclipse-friendly maven-enabled packages. + * + * Revision 1.5 2003/12/18 15:37:38 mpowers + * Changes to retain ability to work with objects that don't necessarily + * implement EOEnterpriseObject. I would still like to preserve this case + * for general usage, however the access package is free to assume that + * those objects will be EOs and cast appropriately. + * + * Revision 1.4 2003/08/19 01:53:12 chochos + * 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. + * + * Revision 1.3 2002/10/24 18:17:37 mpowers + * ArrayFaults are now read-only. + * + * Revision 1.2 2001/05/06 22:22:55 mpowers + * Debugging. + * + * Revision 1.1 2001/05/05 23:05:42 mpowers + * Implemented Array Faults. + * + * + */ + -- cgit v1.2.3