Changeset 6
- Timestamp:
- 09/21/2005 10:00:46 PM (21 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 3 deleted
- 12 edited
-
project.xml (modified) (1 diff)
-
src/ws/fugue88/jpath/Accessor.java (deleted)
-
src/ws/fugue88/jpath/BrokenGraphException.java (modified) (2 diffs)
-
src/ws/fugue88/jpath/Context.java (modified) (6 diffs)
-
src/ws/fugue88/jpath/ContextFactory.java (modified) (2 diffs)
-
src/ws/fugue88/jpath/DefaultCreator.java (added)
-
src/ws/fugue88/jpath/GraphCreator.java (added)
-
src/ws/fugue88/jpath/Identifier.java (modified) (2 diffs)
-
src/ws/fugue88/jpath/ListAccessor.java (deleted)
-
src/ws/fugue88/jpath/MapAccessor.java (deleted)
-
src/ws/fugue88/jpath/NullCreator.java (added)
-
src/ws/fugue88/jpath/NumberSelector.java (modified) (2 diffs)
-
src/ws/fugue88/jpath/Path.java (modified) (5 diffs)
-
src/ws/fugue88/jpath/PathParser.java (added)
-
src/ws/fugue88/jpath/PathPart.java (modified) (2 diffs)
-
src/ws/fugue88/jpath/PropertyAccessor.java (modified) (3 diffs)
-
src/ws/fugue88/jpath/SimplePathParser.java (added)
-
src/ws/fugue88/jpath/StringSelector.java (modified) (2 diffs)
-
src/ws/fugue88/jpath/URLPathParser.java (added)
-
src/ws/fugue88/jpath/package.html (added)
-
testsrc/ws/fugue88/ContextTest.java (modified) (10 diffs)
-
testsrc/ws/fugue88/jpath/PathTest.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/project.xml
r5 r6 70 70 </unitTest> 71 71 </build> 72 <dependencies> 73 <dependency> 74 <groupId>accesslib</groupId> 75 <artifactId>accesslib</artifactId> 76 <version>SNAPSHOT</version> 77 </dependency> 78 </dependencies> 72 79 </project> -
trunk/src/ws/fugue88/jpath/BrokenGraphException.java
r4 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/12 19:01:46 dsowen 6 10 * Feature: can automatically fill missing parts of a graph. … … 14 18 public class BrokenGraphException extends Exception { 15 19 20 public BrokenGraphException(final Context context, final Path path, 21 final Object parent, final PathPart child) 22 { 23 super("Graph broken for path '" + child + "' on object {" + parent 24 + "}, accessed from context " + context + " at '" + path + "'."); 25 26 _context = context; 27 _path = path; 28 _parent = parent; 29 _child = child; 30 } 31 32 private final Context _context; 33 private final Path _path; 34 private final Object _parent; 35 private final PathPart _child; 16 36 } -
trunk/src/ws/fugue88/jpath/Context.java
r5 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.4 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.3 2005/08/19 17:51:17 dsowen 6 10 * Fixed: NPEs when using accessors from paths, &c. Included tests. … … 28 32 import java.util.Map; 29 33 34 import ws.fugue88.access.Accessor; 35 import ws.fugue88.access.ListAccessor; 36 import ws.fugue88.access.MapAccessor; 37 30 38 /** 31 39 * @author dsowen … … 40 48 Context current = this; 41 49 for(Iterator i = path.parents().iterator(); i.hasNext();) { 42 Accessor accessor = current.getTargetAccessor((PathPart)i.next()); 50 final PathPart part = (PathPart)i.next(); 51 Accessor accessor = current.getTargetAccessor(part); 43 52 Object obj = accessor.getValue(); 44 if(obj == null) {45 if(_modifying) {46 obj = createBlank(accessor.getType());47 accessor.setValue(obj);48 } else {49 throw new BrokenGraphException();50 } 51 }52 current = new Context(obj, _binder, _ modifying);53 if(obj == null) 54 obj = _creator.create(accessor.getType(), current._root, 55 part); 56 if(obj == null) 57 throw new BrokenGraphException(this, path, current._root, 58 part); 59 60 accessor.setValue(obj); 61 current = new Context(obj, _binder, _creator); 53 62 } 54 63 return current.getTargetAccessor(path.terminal()); … … 71 80 { 72 81 Object child = getTarget(path); 73 return new Context(child, _binder, _ modifying);82 return new Context(child, _binder, _creator); 74 83 } 75 84 … … 79 88 } 80 89 81 Context(final Object root, final Binder binder, final boolean modifying)90 Context(final Object root, final Binder binder, final GraphCreator creator) 82 91 { 83 92 // NPEs 84 93 root.getClass(); 85 94 binder.getClass(); 95 creator.getClass(); 86 96 87 97 _root = root; 88 98 _binder = binder; 89 _ modifying = modifying;99 _creator = creator; 90 100 } 91 101 … … 127 137 private final Object _root; 128 138 private final Binder _binder; 129 private final boolean _modifying;139 private final GraphCreator _creator; 130 140 } -
trunk/src/ws/fugue88/jpath/ContextFactory.java
r4 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.3 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.2 2005/08/12 19:01:46 dsowen 6 10 * Feature: can automatically fill missing parts of a graph. … … 17 21 public class ContextFactory { 18 22 19 public Context createContext(final Object root )23 public Context createContext(final Object root, final GraphCreator creator) 20 24 { 21 return new Context(root, _binder, false); 22 } 23 24 public Context createModifyingContext(final Object root) 25 { 26 return new Context(root, _binder, true); 25 return new Context(root, _binder, creator); 27 26 } 28 27 -
trunk/src/ws/fugue88/jpath/Identifier.java
r2 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:46 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 24 28 } 25 29 30 public String toString() 31 { 32 return "/" + _name; 33 } 34 26 35 private final String _name; 27 36 } -
trunk/src/ws/fugue88/jpath/NumberSelector.java
r2 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 29 33 } 30 34 35 public String toString() 36 { 37 return "[" + _number + "]"; 38 } 39 31 40 private final Integer _number; 32 41 } -
trunk/src/ws/fugue88/jpath/Path.java
r5 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.3 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.2 2005/08/19 17:51:17 dsowen 6 10 * Fixed: NPEs when using accessors from paths, &c. Included tests. … … 16 20 package ws.fugue88.jpath; 17 21 18 import java.nio.CharBuffer;19 import java.text.ParseException;20 22 import java.util.Collections; 21 23 import java.util.Iterator; 22 import java.util.LinkedList;23 24 import java.util.List; 24 import java.util.regex.Matcher;25 import java.util.regex.Pattern;26 25 27 26 /** … … 30 29 public class Path { 31 30 32 public static String quote(final Strings)31 Path(final List parts) 33 32 { 34 return s.replaceAll("'", "\\\\'"); 35 } 36 37 public static String unquote(final String s) 38 { 39 return s.replaceAll("\\\\'", "'"); 40 } 41 42 public Path(final String path) throws ParseException 43 { 44 _parts = new LinkedList(); 45 46 CharSequence buff = CharBuffer.wrap(path); 47 do { 48 Matcher m; 49 final PathPart pp; 50 if((m = IDENT.matcher(buff)).find()) { 51 pp = new Identifier(m.group(1)); 52 } else if((m = NUM_SEL.matcher(buff)).find()) { 53 pp = new NumberSelector(m.group(1)); 54 } else if((m = STR_SEL.matcher(buff)).find()) { 55 pp = new StringSelector(unquote(m.group(1))); 56 } else { 57 throw new ParseException( 58 "Expected identifier or selector, found '" 59 + (buff.length() > 40 ? buff.subSequence(0, 37) 60 + "..." : buff) + "'.", -1); 61 } 62 _parts.add(pp); 63 buff = buff.subSequence(m.end(), buff.length()); 64 } while(buff.length() > 0); 33 _parts = parts; 65 34 } 66 35 … … 68 37 { 69 38 return new Path(_parts.subList(0, _parts.size() - 1)); 39 } 40 41 public Path children() 42 { 43 return new Path(_parts.subList(1, _parts.size())); 44 } 45 46 public PathPart head() 47 { 48 return (PathPart)_parts.get(0); 70 49 } 71 50 … … 80 59 } 81 60 82 p rotected Path(final List list)61 public boolean isEmpty() 83 62 { 84 _parts = list; 63 return _parts.isEmpty(); 64 } 65 66 public String toString() 67 { 68 final StringBuffer buff = new StringBuffer(); 69 for(final Iterator i = _parts.iterator(); i.hasNext();) { 70 buff.append(i.next()); 71 } 72 return buff.toString(); 85 73 } 86 74 87 75 private final List _parts; 88 89 private static final String IDENT_START = "A-Za-z_";90 private static final String IDENT_END = IDENT_START + "0-9";91 private static final Pattern IDENT = Pattern.compile("^/([" + IDENT_START92 + "][" + IDENT_END + "]*)");93 94 private static final String NUM_LIT = "-?[0-9]+";95 private static final Pattern NUM_SEL = Pattern.compile("^\\[(" + NUM_LIT96 + ")\\]");97 98 private static final String STR_LIT = "'((?:[^']|\\\\')*)'";99 private static final Pattern STR_SEL = Pattern.compile("^\\[" + STR_LIT100 + "\\]");101 76 } -
trunk/src/ws/fugue88/jpath/PathPart.java
r2 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 12 16 * @author dsowen 13 17 */ 14 public class PathPart { 18 public abstract class PathPart { 19 20 public abstract String toString(); 15 21 } -
trunk/src/ws/fugue88/jpath/PropertyAccessor.java
r2 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 10 14 11 15 import java.lang.reflect.InvocationTargetException; 16 17 import ws.fugue88.access.Accessor; 12 18 13 19 /** … … 19 25 { 20 26 return _prop.getType(); 27 } 28 29 public void clearValue() throws InvocationTargetException 30 { 31 _prop.setValue(_that, null); 21 32 } 22 33 -
trunk/src/ws/fugue88/jpath/StringSelector.java
r2 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:45 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 24 28 } 25 29 30 public String toString() 31 { 32 return "['" + PathParser.quote(_str) + "']"; 33 } 34 26 35 private final String _str; 27 36 } -
trunk/testsrc/ws/fugue88/ContextTest.java
r5 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:46 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/19 17:51:17 dsowen 6 10 * Fixed: NPEs when using accessors from paths, &c. Included tests. … … 19 23 20 24 import junit.framework.TestCase; 21 import ws.fugue88. jpath.Accessor;25 import ws.fugue88.access.Accessor; 22 26 import ws.fugue88.jpath.Context; 23 27 import ws.fugue88.jpath.ContextFactory; 24 import ws.fugue88.jpath.Path; 28 import ws.fugue88.jpath.GraphCreator; 29 import ws.fugue88.jpath.SimplePathParser; 25 30 26 31 /** … … 38 43 39 44 ContextFactory factory = new ContextFactory(); 40 Context context = factory.createContext(a );41 assertSame(a.b, context.getTarget(new Path("/b")));42 43 Accessor accessor = context.getTargetAccessor(new Path("/b"));45 Context context = factory.createContext(a, GraphCreator.NULL); 46 assertSame(a.b, context.getTarget(new SimplePathParser().parse("/b"))); 47 48 Accessor accessor = context.getTargetAccessor(new SimplePathParser().parse("/b")); 44 49 assertSame(a.b, accessor.getValue()); 45 50 accessor.setValue("done"); … … 60 65 61 66 ContextFactory factory = new ContextFactory(); 62 Context context = factory.createContext(a); 63 assertEquals("test", context.getTarget(new Path("/b"))); 67 Context context = factory.createContext(a, GraphCreator.NULL); 68 assertEquals("test", 69 context.getTarget(new SimplePathParser().parse("/b"))); 64 70 try { 65 context.getTargetAccessor(new Path("/b")).setValue("done"); 71 context.getTargetAccessor(new SimplePathParser().parse("/b")).setValue( 72 "done"); 66 73 assertTrue(false); 67 74 } catch(UnsupportedOperationException e) {} … … 87 94 88 95 ContextFactory factory = new ContextFactory(); 89 Context context = factory.createContext(a); 90 assertEquals("test", context.getTarget(new Path("/b"))); 91 context.getTargetAccessor(new Path("/b")).setValue("done"); 96 Context context = factory.createContext(a, GraphCreator.NULL); 97 assertEquals("test", 98 context.getTarget(new SimplePathParser().parse("/b"))); 99 context.getTargetAccessor(new SimplePathParser().parse("/b")).setValue( 100 "done"); 92 101 assertEquals("done", a.getB()); 93 102 } … … 107 116 108 117 ContextFactory factory = new ContextFactory(); 109 Context context = factory.createContext(a); 110 assertEquals("test", context.getTarget(new Path("/b['c']"))); 111 context.getTargetAccessor(new Path("/b['c']")).setValue("done"); 118 Context context = factory.createContext(a, GraphCreator.NULL); 119 assertEquals("test", 120 context.getTarget(new SimplePathParser().parse("/b['c']"))); 121 context.getTargetAccessor(new SimplePathParser().parse("/b['c']")).setValue( 122 "done"); 112 123 assertEquals("done", a.b.get("c")); 113 124 } … … 126 137 127 138 ContextFactory factory = new ContextFactory(); 128 Context context = factory.createContext(b );129 assertNull(context.getTarget(new Path("/a/s")));139 Context context = factory.createContext(b, GraphCreator.NULL); 140 assertNull(context.getTarget(new SimplePathParser().parse("/a/s"))); 130 141 assertNull(b.a); 131 142 } … … 145 156 146 157 ContextFactory factory = new ContextFactory(); 147 Context context = factory.create ModifyingContext(b);148 assertNull(context.getTarget(new Path("/a/s")));158 Context context = factory.createContext(b, GraphCreator.DEFAULT); 159 assertNull(context.getTarget(new SimplePathParser().parse("/a/s"))); 149 160 assertNotNull(b.a); 150 161 assertNull(b.a.s); … … 160 171 161 172 ContextFactory factory = new ContextFactory(); 162 Context context = factory.create ModifyingContext(b);163 Accessor accessor = context.getTargetAccessor(new Path("/a/s"));173 Context context = factory.createContext(b, GraphCreator.DEFAULT); 174 Accessor accessor = context.getTargetAccessor(new SimplePathParser().parse("/a/s")); 164 175 assertNotNull(b.a); 165 176 assertNull(b.a.s); … … 184 195 185 196 ContextFactory factory = new ContextFactory(); 186 Context context = factory.create ModifyingContext(b);187 assertNull(context.getTarget(new Path("/x/s")));197 Context context = factory.createContext(b, GraphCreator.DEFAULT); 198 assertNull(context.getTarget(new SimplePathParser().parse("/x/s"))); 188 199 assertNotNull(b.x); 189 200 assertNull(b.x.s); -
trunk/testsrc/ws/fugue88/jpath/PathTest.java
r2 r6 3 3 * 4 4 * $Log$ 5 * Revision 1.2 2005/09/21 22:00:46 dsowen 6 * Split out the access stuff into accesslib. 7 * New Creator interface off-loads object creation to user. 8 * 5 9 * Revision 1.1 2005/08/03 00:35:29 dsowen 6 10 * Initial commit. … … 20 24 public void testQuote() 21 25 { 22 assertEquals("test", Path .quote("test"));23 assertEquals("te\\'st", Path .quote("te'st"));26 assertEquals("test", PathParser.quote("test")); 27 assertEquals("te\\'st", PathParser.quote("te'st")); 24 28 } 25 29 26 30 public void testIdentifier() throws Exception 27 31 { 28 Path path = new Path("/test");32 Path path = new SimplePathParser().parse("/test"); 29 33 Iterator i = path.iterator(); 30 34 PathPart part = (PathPart)i.next(); … … 36 40 public void testNumberSelector() throws Exception 37 41 { 38 Path path = new Path("[0]");42 Path path = new SimplePathParser().parse("[0]"); 39 43 Iterator i = path.iterator(); 40 44 PathPart part = (PathPart)i.next(); … … 46 50 public void testStringSelectorSimple() throws Exception 47 51 { 48 Path path = new Path("['test']");52 Path path = new SimplePathParser().parse("['test']"); 49 53 Iterator i = path.iterator(); 50 54 PathPart part = (PathPart)i.next(); … … 56 60 public void testStringSelectorQuoted() throws Exception 57 61 { 58 Path path = new Path("['te\\'st']");62 Path path = new SimplePathParser().parse("['te\\'st']"); 59 63 Iterator i = path.iterator(); 60 64 PathPart part = (PathPart)i.next(); … … 63 67 assertFalse(i.hasNext()); 64 68 } 69 65 70 public void testCompound1() throws Exception 66 71 { 67 Path path = new Path("/a/b");72 Path path = new SimplePathParser().parse("/a/b"); 68 73 Iterator i = path.iterator(); 69 74 PathPart part = (PathPart)i.next();
Note: See TracChangeset
for help on using the changeset viewer.
