| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| TestDataSource |
|
| 1.3333333333333333;1.333 |
| 1 | package net.wotonomy.test; |
|
| 2 | ||
| 3 | import net.wotonomy.control.EOClassDescription; |
|
| 4 | import net.wotonomy.control.EODataSource; |
|
| 5 | import net.wotonomy.control.EOEditingContext; |
|
| 6 | import net.wotonomy.control.EOFetchSpecification; |
|
| 7 | import net.wotonomy.foundation.NSArray; |
|
| 8 | ||
| 9 | /** |
|
| 10 | * A custom DataSource that works with |
|
| 11 | * the datastore package for persistence. |
|
| 12 | */ |
|
| 13 | public class TestDataSource extends EODataSource |
|
| 14 | { |
|
| 15 | private EOEditingContext context; |
|
| 16 | private Object source; |
|
| 17 | private String key; |
|
| 18 | ||
| 19 | public TestDataSource() |
|
| 20 | { |
|
| 21 | 0 | this( Test.editingContext ); |
| 22 | 0 | } |
| 23 | ||
| 24 | 0 | public TestDataSource( EOEditingContext aContext ) |
| 25 | 0 | { |
| 26 | 0 | context = aContext; |
| 27 | 0 | } |
| 28 | ||
| 29 | public EOEditingContext editingContext() |
|
| 30 | { |
|
| 31 | 0 | return context; |
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * This implementation does nothing. |
|
| 36 | */ |
|
| 37 | public void insertObject ( Object anObject ) |
|
| 38 | { |
|
| 39 | // creates are handled by createObject(). |
|
| 40 | 0 | } |
| 41 | ||
| 42 | /** |
|
| 43 | * Deletes the specified object from this data source. |
|
| 44 | */ |
|
| 45 | public void deleteObject ( Object anObject ) |
|
| 46 | { |
|
| 47 | 0 | editingContext().deleteObject( anObject ); |
| 48 | 0 | } |
| 49 | ||
| 50 | /** |
|
| 51 | * Returns a List containing the objects in this |
|
| 52 | * data source. This implementation returns all |
|
| 53 | * TestObjects that have been persisted to the |
|
| 54 | * datastore in the data directory. |
|
| 55 | */ |
|
| 56 | public NSArray fetchObjects () |
|
| 57 | { |
|
| 58 | 0 | if ( source == null ) |
| 59 | { |
|
| 60 | 0 | NSArray result = editingContext().objectsWithFetchSpecification( |
| 61 | 0 | new EOFetchSpecification() ); |
| 62 | 0 | if ( result.size() > 0 ) |
| 63 | { |
|
| 64 | 0 | result = new NSArray( result.objectAtIndex( 0 ) ); |
| 65 | //result.add( result.objectAtIndex( 0 ) ); |
|
| 66 | } |
|
| 67 | 0 | return result; |
| 68 | } |
|
| 69 | else |
|
| 70 | { |
|
| 71 | 0 | return new NSArray( |
| 72 | 0 | ((TestObject)source).getChildList() ); |
| 73 | } |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Returns a data source that is capable of |
|
| 78 | * manipulating objects of the type returned by |
|
| 79 | * applying the specified key to objects |
|
| 80 | * vended by this data source. |
|
| 81 | * @see #qualifyWithRelationshipKey |
|
| 82 | */ |
|
| 83 | public EODataSource |
|
| 84 | dataSourceQualifiedByKey ( String aKey ) |
|
| 85 | { |
|
| 86 | 0 | return new TestDataSource( editingContext() ); |
| 87 | } |
|
| 88 | ||
| 89 | /** |
|
| 90 | * Restricts this data source to vend those |
|
| 91 | * objects that are associated with the specified |
|
| 92 | * key on the specified object. |
|
| 93 | */ |
|
| 94 | public void |
|
| 95 | qualifyWithRelationshipKey ( |
|
| 96 | String aKey, Object anObject ) |
|
| 97 | { |
|
| 98 | 0 | key = aKey; |
| 99 | 0 | source = anObject; |
| 100 | 0 | } |
| 101 | ||
| 102 | /** |
|
| 103 | * Returns the description of the class of the |
|
| 104 | * objects that is vended by this data source, |
|
| 105 | * or null if this cannot be determined. |
|
| 106 | * This implementation returns TestObject. |
|
| 107 | */ |
|
| 108 | public EOClassDescription |
|
| 109 | classDescriptionForObjects () |
|
| 110 | { |
|
| 111 | 0 | return EOClassDescription.classDescriptionForClass( |
| 112 | 0 | TestObject.class ); |
| 113 | } |
|
| 114 | ||
| 115 | } |