Index: trunk/src/ws/fugue88/jpath/BrokenGraphException.java
===================================================================
--- trunk/src/ws/fugue88/jpath/BrokenGraphException.java	(revision 4)
+++ trunk/src/ws/fugue88/jpath/BrokenGraphException.java	(revision 4)
@@ -0,0 +1,16 @@
+/*
+ * Created on Aug 12, 2005
+ * 
+ * $Log$
+ * Revision 1.1  2005/08/12 19:01:46  dsowen
+ * Feature: can automatically fill missing parts of a graph.
+ *
+ */
+package ws.fugue88.jpath;
+
+/**
+ * @author dsowen
+ */
+public class BrokenGraphException extends Exception {
+
+}
Index: trunk/src/ws/fugue88/jpath/Context.java
===================================================================
--- trunk/src/ws/fugue88/jpath/Context.java	(revision 3)
+++ 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;
 }
Index: trunk/src/ws/fugue88/jpath/ContextFactory.java
===================================================================
--- trunk/src/ws/fugue88/jpath/ContextFactory.java	(revision 3)
+++ trunk/src/ws/fugue88/jpath/ContextFactory.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.
@@ -16,5 +19,10 @@
 	public Context createContext(final Object root)
 	{
-		return new Context(root, _binder);
+		return new Context(root, _binder, false);
+	}
+
+	public Context createModifyingContext(final Object root)
+	{
+		return new Context(root, _binder, true);
 	}
 
Index: trunk/testsrc/ws/fugue88/jpath/ContextTest.java
===================================================================
--- trunk/testsrc/ws/fugue88/jpath/ContextTest.java	(revision 3)
+++ trunk/testsrc/ws/fugue88/jpath/ContextTest.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.
@@ -101,3 +104,41 @@
 		assertEquals("done", a.b.get("c"));
 	}
+
+	public void testEarlyNull() throws Exception
+	{
+		class A {
+
+			String s;
+		}
+		class B {
+
+			A a;
+		}
+		B b = new B();
+
+		ContextFactory factory = new ContextFactory();
+		Context context = factory.createContext(b);
+		assertNull(context.getTarget(new Path("/a/s")));
+		assertNull(b.a);
+	}
+
+	static class A {
+
+		String s;
+	}
+
+	public void testAutoGraph() throws Exception
+	{
+		class B {
+
+			A a;
+		}
+		B b = new B();
+
+		ContextFactory factory = new ContextFactory();
+		Context context = factory.createModifyingContext(b);
+		assertNull(context.getTarget(new Path("/a/s")));
+		assertNotNull(b.a);
+		assertNull(b.a.s);
+	}
 }
