package net.wotonomy.test; import net.wotonomy.control.EOClassDescription; import net.wotonomy.control.EODataSource; import net.wotonomy.control.EOEditingContext; import net.wotonomy.control.EOFetchSpecification; import net.wotonomy.foundation.NSArray; /** * A custom DataSource that works with the datastore package for persistence. */ public class TestDataSource extends EODataSource { private EOEditingContext context; private Object source; private String key; public TestDataSource() { this(Test.editingContext); } public TestDataSource(EOEditingContext aContext) { context = aContext; } public EOEditingContext editingContext() { return context; } /** * This implementation does nothing. */ public void insertObject(Object anObject) { // creates are handled by createObject(). } /** * Deletes the specified object from this data source. */ public void deleteObject(Object anObject) { editingContext().deleteObject(anObject); } /** * Returns a List containing the objects in this data source. This * implementation returns all TestObjects that have been persisted to the * datastore in the data directory. */ public NSArray fetchObjects() { if (source == null) { NSArray result = editingContext().objectsWithFetchSpecification(new EOFetchSpecification()); if (result.size() > 0) { result = new NSArray(result.objectAtIndex(0)); //result.add( result.objectAtIndex( 0 ) ); } return result; } else { return new NSArray(((TestObject) source).getChildList()); } } /** * Returns a data source that is capable of manipulating objects of the type * returned by applying the specified key to objects vended by this data source. * * @see #qualifyWithRelationshipKey */ public EODataSource dataSourceQualifiedByKey(String aKey) { return new TestDataSource(editingContext()); } /** * Restricts this data source to vend those objects that are associated with the * specified key on the specified object. */ public void qualifyWithRelationshipKey(String aKey, Object anObject) { key = aKey; source = anObject; } /** * Returns the description of the class of the objects that is vended by this * data source, or null if this cannot be determined. This implementation * returns TestObject. */ public EOClassDescription classDescriptionForObjects() { return EOClassDescription.classDescriptionForClass(TestObject.class); } }