Ignore:
Timestamp:
08/19/2005 05:51:17 PM (21 years ago)
Author:
dsowen
Message:

Fixed: NPEs when using accessors from paths, &c. Included tests.
Fixed: parsing exception wasn't very enlightening.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22.classpath
        33.project
         4velocity.log
  • trunk/src/ws/fugue88/jpath/Context.java

    r4 r5  
    33 *
    44 * $Log$
     5 * Revision 1.3  2005/08/19 17:51:17  dsowen
     6 * Fixed: NPEs when using accessors from paths, &c.  Included tests.
     7 * Fixed: parsing exception wasn't very enlightening.
     8 *
    59 * Revision 1.2  2005/08/12 19:01:46  dsowen
    610 * Feature: can automatically fill missing parts of a graph.
     
    1822package ws.fugue88.jpath;
    1923
     24import java.lang.reflect.Constructor;
    2025import java.lang.reflect.InvocationTargetException;
    2126import java.util.Iterator;
     
    3439        {
    3540                Context current = this;
    36                 Accessor accessor = null;
    37                 for(Iterator i = path.iterator(); i.hasNext();) {
    38                         accessor = current.getTargetAccessor((PathPart)i.next());
     41                for(Iterator i = path.parents().iterator(); i.hasNext();) {
     42                        Accessor accessor = current.getTargetAccessor((PathPart)i.next());
    3943                        Object obj = accessor.getValue();
    4044                        if(obj == null) {
    41                                 if(_modifying && i.hasNext()) {
     45                                if(_modifying) {
    4246                                        obj = createBlank(accessor.getType());
    4347                                        accessor.setValue(obj);
     
    4852                        current = new Context(obj, _binder, _modifying);
    4953                }
    50                 return accessor;
     54                return current.getTargetAccessor(path.terminal());
    5155        }
    5256
     
    109113
    110114        private Object createBlank(final Class type) throws IllegalAccessException,
    111                         InstantiationException
     115                        InstantiationException, InvocationTargetException
    112116        {
    113                 return type.newInstance();
     117                try {
     118                        final Constructor ctor = type.getDeclaredConstructor(null);
     119                        ctor.setAccessible(true);
     120                        return ctor.newInstance(null);
     121                } catch(NoSuchMethodException e) {
     122                        throw new InstantiationException("Class " + type.getName()
     123                                        + " must have a no-argument constructor.");
     124                }
    114125        }
    115126
  • trunk/src/ws/fugue88/jpath/Path.java

    r2 r5  
    33 *
    44 * $Log$
     5 * Revision 1.2  2005/08/19 17:51:17  dsowen
     6 * Fixed: NPEs when using accessors from paths, &c.  Included tests.
     7 * Fixed: parsing exception wasn't very enlightening.
     8 *
    59 * Revision 1.1  2005/08/03 00:35:29  dsowen
    610 * Initial commit.
     
    5155                                pp = new StringSelector(unquote(m.group(1)));
    5256                        } else {
    53                                 throw new ParseException(null, -1);
     57                                throw new ParseException(
     58                                                "Expected identifier or selector, found '"
     59                                                                + (buff.length() > 40 ? buff.subSequence(0, 37)
     60                                                                                + "..." : buff) + "'.", -1);
    5461                        }
    5562                        _parts.add(pp);
     
    6370        }
    6471
    65         public String terminal()
     72        public PathPart terminal()
    6673        {
    67                 return (String)_parts.get(_parts.size() - 1);
     74                return (PathPart)_parts.get(_parts.size() - 1);
    6875        }
    6976
Note: See TracChangeset for help on using the changeset viewer.