Changeset 6 for trunk/src/ws
- Timestamp:
- 09/21/2005 10:00:46 PM (21 years ago)
- Location:
- trunk/src/ws/fugue88/jpath
- Files:
-
- 7 added
- 3 deleted
- 9 edited
-
Accessor.java (deleted)
-
BrokenGraphException.java (modified) (2 diffs)
-
Context.java (modified) (6 diffs)
-
ContextFactory.java (modified) (2 diffs)
-
DefaultCreator.java (added)
-
GraphCreator.java (added)
-
Identifier.java (modified) (2 diffs)
-
ListAccessor.java (deleted)
-
MapAccessor.java (deleted)
-
NullCreator.java (added)
-
NumberSelector.java (modified) (2 diffs)
-
Path.java (modified) (5 diffs)
-
PathParser.java (added)
-
PathPart.java (modified) (2 diffs)
-
PropertyAccessor.java (modified) (3 diffs)
-
SimplePathParser.java (added)
-
StringSelector.java (modified) (2 diffs)
-
URLPathParser.java (added)
-
package.html (added)
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.
