Changeset 4 for trunk/src


Ignore:
Timestamp:
08/12/2005 07:01:46 PM (21 years ago)
Author:
dsowen
Message:

Feature: can automatically fill missing parts of a graph.

Location:
trunk/src/ws/fugue88/jpath
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ws/fugue88/jpath/Context.java

    r2 r4  
    33 *
    44 * $Log$
     5 * Revision 1.2  2005/08/12 19:01:46  dsowen
     6 * Feature: can automatically fill missing parts of a graph.
     7 *
    58 * Revision 1.1  2005/08/03 00:35:29  dsowen
    69 * Initial commit.
     
    2629
    2730        public Accessor getTargetAccessor(final Path path)
    28                         throws InvocationTargetException, NoSuchPropertyException
     31                        throws BrokenGraphException, IllegalAccessException,
     32                        InstantiationException, InvocationTargetException,
     33                        NoSuchPropertyException
    2934        {
    3035                Context current = this;
     
    3237                for(Iterator i = path.iterator(); i.hasNext();) {
    3338                        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);
    3549                }
    3650                return accessor;
    3751        }
    3852
    39         public Object getTarget(final Path path) throws InvocationTargetException,
     53        public Object getTarget(final Path path) throws IllegalAccessException,
     54                        InstantiationException, InvocationTargetException,
    4055                        NoSuchPropertyException
    4156        {
    42                 return getTargetAccessor(path).getValue();
     57                try {
     58                        return getTargetAccessor(path).getValue();
     59                } catch(BrokenGraphException e) {
     60                        return null;
     61                }
    4362        }
    4463
    45         public Context navigate(final Path path) throws InvocationTargetException,
     64        public Context navigate(final Path path) throws IllegalAccessException,
     65                        InstantiationException, InvocationTargetException,
    4666                        NoSuchPropertyException
    4767        {
    4868                Object child = getTarget(path);
    49                 return new Context(child, _binder);
     69                return new Context(child, _binder, _modifying);
    5070        }
    5171
     
    5575        }
    5676
    57         Context(final Object root, final Binder binder)
     77        Context(final Object root, final Binder binder, final boolean modifying)
    5878        {
     79                // NPEs
     80                root.getClass();
     81                binder.getClass();
     82
    5983                _root = root;
    6084                _binder = binder;
     85                _modifying = modifying;
    6186        }
    6287
     
    83108        }
    84109
     110        private Object createBlank(final Class type) throws IllegalAccessException,
     111                        InstantiationException
     112        {
     113                return type.newInstance();
     114        }
     115
    85116        private final Object _root;
    86117        private final Binder _binder;
     118        private final boolean _modifying;
    87119}
  • trunk/src/ws/fugue88/jpath/ContextFactory.java

    r2 r4  
    33 *
    44 * $Log$
     5 * Revision 1.2  2005/08/12 19:01:46  dsowen
     6 * Feature: can automatically fill missing parts of a graph.
     7 *
    58 * Revision 1.1  2005/08/03 00:35:29  dsowen
    69 * Initial commit.
     
    1619        public Context createContext(final Object root)
    1720        {
    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);
    1927        }
    2028
Note: See TracChangeset for help on using the changeset viewer.