- Timestamp:
- 08/12/2005 07:01:46 PM (21 years ago)
- Location:
- trunk/src/ws/fugue88/jpath
- Files:
-
- 1 added
- 2 edited
-
BrokenGraphException.java (added)
-
Context.java (modified) (5 diffs)
-
ContextFactory.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ws/fugue88/jpath/Context.java
r2 r4 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/08/12 19:01:46 dsowen 6 * Feature: can automatically fill missing parts of a graph. 7 * 5 8 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 9 * Initial commit. … … 26 29 27 30 public Accessor getTargetAccessor(final Path path) 28 throws InvocationTargetException, NoSuchPropertyException 31 throws BrokenGraphException, IllegalAccessException, 32 InstantiationException, InvocationTargetException, 33 NoSuchPropertyException 29 34 { 30 35 Context current = this; … … 32 37 for(Iterator i = path.iterator(); i.hasNext();) { 33 38 accessor = current.getTargetAccessor((PathPart)i.next()); 34 current = new Context(accessor.getValue(), _binder); 39 Object obj = accessor.getValue(); 40 if(obj == null) { 41 if(_modifying && i.hasNext()) { 42 obj = createBlank(accessor.getType()); 43 accessor.setValue(obj); 44 } else { 45 throw new BrokenGraphException(); 46 } 47 } 48 current = new Context(obj, _binder, _modifying); 35 49 } 36 50 return accessor; 37 51 } 38 52 39 public Object getTarget(final Path path) throws InvocationTargetException, 53 public Object getTarget(final Path path) throws IllegalAccessException, 54 InstantiationException, InvocationTargetException, 40 55 NoSuchPropertyException 41 56 { 42 return getTargetAccessor(path).getValue(); 57 try { 58 return getTargetAccessor(path).getValue(); 59 } catch(BrokenGraphException e) { 60 return null; 61 } 43 62 } 44 63 45 public Context navigate(final Path path) throws InvocationTargetException, 64 public Context navigate(final Path path) throws IllegalAccessException, 65 InstantiationException, InvocationTargetException, 46 66 NoSuchPropertyException 47 67 { 48 68 Object child = getTarget(path); 49 return new Context(child, _binder );69 return new Context(child, _binder, _modifying); 50 70 } 51 71 … … 55 75 } 56 76 57 Context(final Object root, final Binder binder )77 Context(final Object root, final Binder binder, final boolean modifying) 58 78 { 79 // NPEs 80 root.getClass(); 81 binder.getClass(); 82 59 83 _root = root; 60 84 _binder = binder; 85 _modifying = modifying; 61 86 } 62 87 … … 83 108 } 84 109 110 private Object createBlank(final Class type) throws IllegalAccessException, 111 InstantiationException 112 { 113 return type.newInstance(); 114 } 115 85 116 private final Object _root; 86 117 private final Binder _binder; 118 private final boolean _modifying; 87 119 } -
trunk/src/ws/fugue88/jpath/ContextFactory.java
r2 r4 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/08/12 19:01:46 dsowen 6 * Feature: can automatically fill missing parts of a graph. 7 * 5 8 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 9 * Initial commit. … … 16 19 public Context createContext(final Object root) 17 20 { 18 return new Context(root, _binder); 21 return new Context(root, _binder, false); 22 } 23 24 public Context createModifyingContext(final Object root) 25 { 26 return new Context(root, _binder, true); 19 27 } 20 28
Note: See TracChangeset
for help on using the changeset viewer.
