Changeset 5
- Timestamp:
- 08/19/2005 05:51:17 PM (21 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 deleted
- 5 edited
-
. (modified) (1 prop)
-
.cvsignore (modified) (1 diff)
-
project.xml (modified) (2 diffs)
-
src/ws/fugue88/jpath/Context.java (modified) (5 diffs)
-
src/ws/fugue88/jpath/Path.java (modified) (3 diffs)
-
testsrc/ws/fugue88/ContextTest.java (added)
-
testsrc/ws/fugue88/jpath/ContextTest.java (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 .classpath 3 3 .project 4 velocity.log
-
- Property svn:ignore
-
trunk/.cvsignore
r2 r5 2 2 .classpath 3 3 .project 4 velocity.log -
trunk/project.xml
r3 r5 31 31 <inceptionYear>2005</inceptionYear> 32 32 <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> 35 class A { 36 String s; 37 } 38 class 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> 34 45 <!-- the project home page --> 35 46 <url>http://maven.apache.org/reference/plugins/examples/</url> … … 41 52 scm:<system>:<system specific connection string> --> 42 53 <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 --> 45 56 </repository> 46 57 <developers> -
trunk/src/ws/fugue88/jpath/Context.java
r4 r5 3 3 * 4 4 * $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 * 5 9 * Revision 1.2 2005/08/12 19:01:46 dsowen 6 10 * Feature: can automatically fill missing parts of a graph. … … 18 22 package ws.fugue88.jpath; 19 23 24 import java.lang.reflect.Constructor; 20 25 import java.lang.reflect.InvocationTargetException; 21 26 import java.util.Iterator; … … 34 39 { 35 40 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()); 39 43 Object obj = accessor.getValue(); 40 44 if(obj == null) { 41 if(_modifying && i.hasNext()) {45 if(_modifying) { 42 46 obj = createBlank(accessor.getType()); 43 47 accessor.setValue(obj); … … 48 52 current = new Context(obj, _binder, _modifying); 49 53 } 50 return accessor;54 return current.getTargetAccessor(path.terminal()); 51 55 } 52 56 … … 109 113 110 114 private Object createBlank(final Class type) throws IllegalAccessException, 111 InstantiationException 115 InstantiationException, InvocationTargetException 112 116 { 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 } 114 125 } 115 126 -
trunk/src/ws/fugue88/jpath/Path.java
r2 r5 3 3 * 4 4 * $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 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 51 55 pp = new StringSelector(unquote(m.group(1))); 52 56 } 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); 54 61 } 55 62 _parts.add(pp); … … 63 70 } 64 71 65 public Stringterminal()72 public PathPart terminal() 66 73 { 67 return ( String)_parts.get(_parts.size() - 1);74 return (PathPart)_parts.get(_parts.size() - 1); 68 75 } 69 76
Note: See TracChangeset
for help on using the changeset viewer.
