Index: trunk/src/ws/fugue88/jpath/Context.java
===================================================================
--- trunk/src/ws/fugue88/jpath/Context.java	(revision 2)
+++ trunk/src/ws/fugue88/jpath/Context.java	(revision 4)
@@ -3,4 +3,7 @@
  *
  * $Log$
+ * Revision 1.2  2005/08/12 19:01:46  dsowen
+ * Feature: can automatically fill missing parts of a graph.
+ *
  * Revision 1.1  2005/08/03 00:35:29  dsowen
  * Initial commit.
@@ -26,5 +29,7 @@
 
 	public Accessor getTargetAccessor(final Path path)
-			throws InvocationTargetException, NoSuchPropertyException
+			throws BrokenGraphException, IllegalAccessException,
+			InstantiationException, InvocationTargetException,
+			NoSuchPropertyException
 	{
 		Context current = this;
@@ -32,20 +37,35 @@
 		for(Iterator i = path.iterator(); i.hasNext();) {
 			accessor = current.getTargetAccessor((PathPart)i.next());
-			current = new Context(accessor.getValue(), _binder);
+			Object obj = accessor.getValue();
+			if(obj == null) {
+				if(_modifying && i.hasNext()) {
+					obj = createBlank(accessor.getType());
+					accessor.setValue(obj);
+				} else {
+					throw new BrokenGraphException();
+				}
+			}
+			current = new Context(obj, _binder, _modifying);
 		}
 		return accessor;
 	}
 
-	public Object getTarget(final Path path) throws InvocationTargetException,
+	public Object getTarget(final Path path) throws IllegalAccessException,
+			InstantiationException, InvocationTargetException,
 			NoSuchPropertyException
 	{
-		return getTargetAccessor(path).getValue();
+		try {
+			return getTargetAccessor(path).getValue();
+		} catch(BrokenGraphException e) {
+			return null;
+		}
 	}
 
-	public Context navigate(final Path path) throws InvocationTargetException,
+	public Context navigate(final Path path) throws IllegalAccessException,
+			InstantiationException, InvocationTargetException,
 			NoSuchPropertyException
 	{
 		Object child = getTarget(path);
-		return new Context(child, _binder);
+		return new Context(child, _binder, _modifying);
 	}
 
@@ -55,8 +75,13 @@
 	}
 
-	Context(final Object root, final Binder binder)
+	Context(final Object root, final Binder binder, final boolean modifying)
 	{
+		// NPEs
+		root.getClass();
+		binder.getClass();
+
 		_root = root;
 		_binder = binder;
+		_modifying = modifying;
 	}
 
@@ -83,5 +108,12 @@
 	}
 
+	private Object createBlank(final Class type) throws IllegalAccessException,
+			InstantiationException
+	{
+		return type.newInstance();
+	}
+
 	private final Object _root;
 	private final Binder _binder;
+	private final boolean _modifying;
 }
