Changeset 5


Ignore:
Timestamp:
08/19/2005 05:51:17 PM (16 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:
1 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22.classpath
        33.project
         4velocity.log
  • trunk/.cvsignore

    r2 r5  
    22.classpath
    33.project
     4velocity.log
  • trunk/project.xml

    r3 r5  
    3131  <inceptionYear>2005</inceptionYear>
    3232  <package>ws.fugue88.jpath</package>
    33   <description>This is a small library that facilitates interaction with instance managers whose signatures aren't known at compile time. It assumes certain naming conventions that the instance managers are supposed to follow in order to locate and invoke the appropriate methods.</description>
     33  <description><![CDATA[This library allows access to graphs of Java objects by path-like strings.  As a short example, suppose you have the following:</p>
     34<source>
     35class A {
     36        String s;
     37}
     38class B {
     39        A x;
     40}
     41</source>
     42<p>Then, given an instance of class B, the path "/x/s" would provide access to the string <var>s</var>.</p>
     43
     44<p>Early-nulls (if <var>x</var> were <code>null</code>) are also supported (a la Expression Language), but so is automatic graph construction.  In such a case, a new instances of A would have been assigned to <var>x</var> to access the (still <code>null</code>) string <var>s</var>.]]></description>
    3445  <!-- the project home page -->
    3546  <url>http://maven.apache.org/reference/plugins/examples/</url>
     
    4152       scm:<system>:<system specific connection string> -->
    4253  <repository>
    43     <connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-plugins/examples</connection>
    44     <url>http://cvs.apache.org/viewcvs/maven-plugins/examples/</url>
     54    <connection>scm:cvs:ext:devel.home:/srv/cvs:jpathlib</connection>
     55    <!-- url>http://cvs.apache.org/viewcvs/maven-plugins/examples/</url -->
    4556  </repository>
    4657  <developers>
  • 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.