commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom DOMNodePointer.java DOMAttributePointer.java
Date Wed, 08 May 2002 23:05:05 GMT
dmitri      02/05/08 16:05:05

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri/model
                        VariablePointer.java NodePointer.java
               jxpath/src/test/org/apache/commons/jxpath TestFactory.java
                        JXPathTestCase.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
                        PropertyOwnerPointer.java NullPropertyPointer.java
                        NullPointer.java NullElementPointer.java
                        DynamicPropertyPointer.java CollectionPointer.java
                        BeanPropertyPointer.java BeanPointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri
                        JXPathContextReferenceImpl.java
                        JXPathCompiledExpression.java
               jxpath/src/java/org/apache/commons/jxpath JXPathContext.java
                        CompiledExpression.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
                        DOMNodePointer.java DOMAttributePointer.java
  Log:
  Added createPath without value,
  renamed createPath to createPathAndSetValue,
  added removePath
  
  Revision  Changes    Path
  1.5       +32 -8     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java
  
  Index: VariablePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- VariablePointer.java	26 Apr 2002 03:28:36 -0000	1.4
  +++ VariablePointer.java	8 May 2002 23:05:04 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v 1.4 2002/04/26 03:28:36 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:36 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v 1.5 2002/05/08 23:05:04 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:04 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -73,7 +73,7 @@
    * Pointer to a context variable.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:36 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:04 $
    */
   public class VariablePointer extends NodePointer {
       private Variables variables;
  @@ -153,12 +153,14 @@
           return 0;
       }
   
  -    public void createPath(JXPathContext context, Object value){
  +    public NodePointer createPath(JXPathContext context, Object value){
           if (actual){
               setValue(value);
  -            return;
  +            return this;
           }
  -        createPath(context).setValue(value);
  +        NodePointer ptr = createPath(context);
  +        ptr.setValue(value);
  +        return ptr;
       }
   
       public NodePointer createPath(JXPathContext context){
  @@ -188,9 +190,12 @@
   
       /**
        */
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
           Object collection = createCollection(context, index);
           ValueUtils.setValue(collection, index, value);
  +        NodePointer cl = (NodePointer)clone();
  +        cl.setIndex(index);
  +        return cl;
       }
   
       private Object createCollection(JXPathContext context, int index){
  @@ -214,6 +219,25 @@
           }
   
           return collection;
  +    }
  +
  +    public void remove(){
  +        if (actual){
  +            if (index == WHOLE_COLLECTION){
  +                variables.undeclareVariable(name.toString());
  +            }
  +            else {
  +                if (index < 0){
  +                    throw new JXPathException("Index is less than 1: " + asPath());
  +                }
  +
  +                Object collection = getBaseValue();
  +                if (collection != null && index < getLength()){
  +                    collection = ValueUtils.remove(collection, index);
  +                    variables.declareVariable(name.toString(), collection);
  +                }
  +            }
  +        }
       }
   
       protected void findVariables(JXPathContext context){
  
  
  
  1.5       +28 -6     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
  
  Index: NodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NodePointer.java	26 Apr 2002 03:28:36 -0000	1.4
  +++ NodePointer.java	8 May 2002 23:05:04 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v 1.4 2002/04/26 03:28:36 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:36 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v 1.5 2002/05/08 23:05:04 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:04 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -84,7 +84,7 @@
    * context-independent predicates.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:36 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:04 $
    */
   public abstract class NodePointer implements Pointer, Cloneable, Comparable {
   
  @@ -327,8 +327,19 @@
        *  Called directly by JXPathContext. Must create path and
        *  set value.
        */
  -    public void createPath(JXPathContext context, Object value) {
  +    public NodePointer createPath(JXPathContext context, Object value) {
           setValue(value);
  +        return this;
  +    }
  +
  +    /**
  +     * Remove the node of the object graph this pointer points to.
  +     */
  +    public void remove(){
  +        // It is a no-op
  +
  +//        System.err.println("REMOVING: " + asPath() + " " + getClass());
  +//        printPointerChain();
       }
   
       /**
  @@ -346,7 +357,7 @@
        * node. This method must may have to expand the collection in order to
        * assign the element.
        */
  -    public void createChild(JXPathContext context, QName name,
  +    public NodePointer createChild(JXPathContext context, QName name,
                               int index, Object value) {
           throw new JXPathException(
               "Cannot create an object for path "
  @@ -576,5 +587,16 @@
           }
   
           return p1.parent.compareChildNodePointers(p1, p2);
  +    }
  +
  +    public void printPointerChain(){
  +        Pointer p = this;
  +        while (p != null){
  +            System.err.println((p == this ? "POINTER: " : " PARENT: ")
  +                + p.getClass() + " " + p.asPath());
  +            if (p instanceof NodePointer){
  +                p = ((NodePointer)p).getParent();
  +            }
  +        }
       }
   }
  
  
  
  1.3       +28 -26    jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/TestFactory.java
  
  Index: TestFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/TestFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestFactory.java	21 Apr 2002 21:52:34 -0000	1.2
  +++ TestFactory.java	8 May 2002 23:05:05 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/TestFactory.java,v 1.2 2002/04/21 21:52:34 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/21 21:52:34 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/TestFactory.java,v 1.3 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -69,7 +69,7 @@
    * Test AbstractFactory.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2002/04/21 21:52:34 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/08 23:05:05 $
    */
   public class TestFactory extends AbstractFactory {
   
  @@ -83,6 +83,14 @@
               ((TestBean[])parent)[index] = new TestBean();
               return true;
           }
  +        else if (name.equals("stringArray")){
  +            ((String[])parent)[index] = "";
  +            return true;
  +        }
  +        else if (name.equals("array")){
  +            ((String[])parent)[index] = "";
  +            return true;
  +        }
           else if (name.equals("strings")){
               NestedTestBean bean = (NestedTestBean)parent;
               bean.setStrings(new String[index + 1]);
  @@ -105,6 +113,10 @@
               ((TestBean)parent).setMap(new HashMap());
               return true;
           }
  +        else if (name.equals("TestKey1")){
  +            ((Map)parent).put(name, "");
  +            return true;
  +        }
           else if (name.equals("TestKey2")){
               ((Map)parent).put(name, new NestedTestBean("newName"));
               return true;
  @@ -132,30 +144,20 @@
       }
   
       private void addElement(Node parent, int index, String tag){
  -        boolean repeat = true;
  -        while(repeat){
  -            Node child = parent.getFirstChild();
  -            int count = 0;
  -            while (child != null){
  -                if (child.getNodeName().equals(tag)){
  -                    if (count == index){
  -                        repeat = false;
  -                        break;
  -                    }
  -                    count++;
  -                }
  -                child = child.getNextSibling();
  -            }
  -            if (child != null){
  -                child = child.getNextSibling();
  +        Node child = parent.getFirstChild();
  +        int count = 0;
  +        while (child != null){
  +            if (child.getNodeName().equals(tag)){
  +                count++;
               }
  +            child = child.getNextSibling();
  +        }
  +
  +        // Keep inserting new elements until we have index + 1 of them
  +        while (count <= index){
               Node newElement = parent.getOwnerDocument().createElement(tag);
  -            if (child != null){
  -                parent.insertBefore(newElement, child);
  -            }
  -            else {
  -                parent.appendChild(newElement);
  -            }
  +            parent.appendChild(newElement);
  +            count++;
           }
       }
   
  
  
  
  1.18      +204 -26   jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java
  
  Index: JXPathTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JXPathTestCase.java	8 May 2002 00:40:52 -0000	1.17
  +++ JXPathTestCase.java	8 May 2002 23:05:05 -0000	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v 1.17 2002/05/08 00:40:52 dmitri Exp $
  - * $Revision: 1.17 $
  - * $Date: 2002/05/08 00:40:52 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v 1.18 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.18 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -100,7 +100,7 @@
    * </p>
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.17 $ $Date: 2002/05/08 00:40:52 $
  + * @version $Revision: 1.18 $ $Date: 2002/05/08 23:05:05 $
    */
   
   public class JXPathTestCase extends TestCase
  @@ -477,12 +477,118 @@
       }
   
       /**
  -     * Test JXPath.createPath() with various arguments
  +     * Test JXPathContext.createPath() with various arguments
        */
       public void testCreatePath(){
           if (!enabled){
               return;
           }
  +        TestBeanWithDOM tBean = createTestBeanWithDOM();
  +        tBean.setNestedBean(null);
  +        tBean.setBeans(null);
  +        tBean.setMap(null);
  +        JXPathContext context = JXPathContext.newContext(tBean);
  +        context.setFactory(new TestFactory());
  +
  +        // Calls factory.declareVariable("string")
  +        testCreatePath(context, "$string", null);    // Declare and set to null
  +
  +        assertTrue("Variable created",
  +                context.getVariables().isDeclaredVariable("string"));
  +
  +        // Calls factory.declareVariable("stringArray"). The factory needs to create a collection
  +        testCreatePath(context, "$stringArray[2]", "");
  +        assertEquals("Created <" + "$stringArray[1]" + ">", "Value1", context.getValue("$stringArray[1]"));
  +
  +        context.getVariables().declareVariable("array", new String[]{"Value1"});
  +
  +        // Does not involve factory at all - just expands the collection
  +        testCreatePath(context, "$array[2]", "");
  +
  +        // Make sure it is still the same array
  +        assertEquals("Created <" + "$array[1]" + ">", "Value1", context.getValue("$array[1]"));
  +
  +        // Calls factory.declareVariable("test"). The factory should create a TestBean
  +        testCreatePath(context, "$test/boolean", Boolean.FALSE);
  +
  +        // Calls factory.declareVariable("testArray").
  +        // The factory should create a collection of TestBeans.
  +        // Then calls factory.createObject(..., collection, "testArray", 1).
  +        // That one should produce an instance of TestBean and put it in the collection
  +        // at index 1.
  +        testCreatePath(context, "$testArray[2]/boolean", Boolean.FALSE);
  +
  +        // Calls factory.createObject(..., TestBean, "nestedBean")
  +        testCreatePath(context, "/nestedBean/int", new Integer(1));
  +
  +        // Calls factory.expandCollection(..., testBean, "beans", 2), then
  +        // factory.createObject(..., testBean, "beans", 2)
  +        testCreatePath(context, "/beans[2]/int", new Integer(1));
  +
  +        // Another, but the collection already exists
  +        testCreatePath(context, "/beans[3]/int", new Integer(1));
  +
  +        // Calls factory.expandCollection(..., testBean, "beans", 2), then
  +        // sets the value
  +        testCreatePath(context, "/nestedBean/strings[2]", "String 2");
  +
  +        // Calls factory.createObject(..., testBean, "map"), then
  +        // sets the value
  +        testCreatePath(context, "/map[@name='TestKey1']", "");
  +
  +        // Calls factory.createObject(..., testBean, "map"), then
  +        // then factory.createObject(..., map, "TestKey2"), then
  +        // sets the value
  +        testCreatePath(context, "/map[@name='TestKey2']/int", new Integer(1));
  +
  +        testCreatePath(context, "/map/TestKey3[2]", null,
  +                "/map[@name='TestKey3'][2]");
  +
  +        // Should be the same as the one before
  +        testCreatePath(context, "/map[@name='TestKey3'][3]", null);
  +
  +        // Create an element of a dynamic map element, which is a collection
  +        testCreatePath(context, "/map/TestKey4[1]/int", new Integer(1),
  +                "/map[@name='TestKey4'][1]/int");
  +
  +        tBean.getMap().remove("TestKey4");
  +
  +        // Should be the same as the one before
  +        testCreatePath(context, "/map[@name='TestKey4'][1]/int", new Integer(1));
  +
  +        // Create a DOM element
  +        testCreatePath(context, "/vendor/location[3]", "");
  +
  +        // Create a DOM element with contents
  +        testCreatePath(context, "/vendor/location[3]/address/street", "",
  +                "/vendor/location[3]/address[1]/street[1]");
  +
  +        // Comprehensive tests: map & bean
  +        tBean.setMap(null);
  +        testCreatePath(context, "/map[@name='TestKey5']/nestedBean/int", new Integer(1));
  +        tBean.setMap(null);
  +        testCreatePath(context, "/map[@name='TestKey5']/beans[2]/int", new Integer(1));
  +    }
  +
  +    private void testCreatePath(JXPathContext context, String path, Object value){
  +        testCreatePath(context, path, value, path);
  +    }
  +
  +    private void testCreatePath(JXPathContext context, String path,
  +                Object value, String expectedPath){
  +        Pointer ptr = context.createPath(path);
  +        assertEquals("Pointer <" + path + ">", expectedPath, ptr.asPath());
  +        assertEquals("Created <" + path + ">", value, ptr.getValue());
  +    }
  +
  +
  +    /**
  +     * Test JXPath.createPathAndSetValue() with various arguments
  +     */
  +    public void testCreatePathAndSetValue(){
  +        if (!enabled){
  +            return;
  +        }
           TestBean tBean = createTestBeanWithDOM();
           tBean.setNestedBean(null);
           tBean.setBeans(null);
  @@ -491,83 +597,155 @@
           context.setFactory(new TestFactory());
   
           // Calls factory.declareVariable("string")
  -        testCreatePath(context, "$string", "Value");
  +        testCreatePathAndSetValue(context, "$string", "Value");
   
           // Calls factory.declareVariable("stringArray"). The factory needs to create a collection
  -        testCreatePath(context, "$stringArray[2]", "Value2");
  +        testCreatePathAndSetValue(context, "$stringArray[2]", "Value2");
           assertEquals("Created <" + "$stringArray[1]" + ">", "Value1", context.getValue("$stringArray[1]"));
   
           context.getVariables().declareVariable("array", new String[]{"Value1"});
   
           // Does not involve factory at all - just expands the collection
  -        testCreatePath(context, "$array[2]", "Value2");
  +        testCreatePathAndSetValue(context, "$array[2]", "Value2");
   
           // Make sure it is still the same array
           assertEquals("Created <" + "$array[1]" + ">", "Value1", context.getValue("$array[1]"));
   
           // Calls factory.declareVariable("test"). The factory should create a TestBean
  -        testCreatePath(context, "$test/boolean", Boolean.TRUE);
  +        testCreatePathAndSetValue(context, "$test/boolean", Boolean.TRUE);
   
           // Calls factory.declareVariable("testArray").
           // The factory should create a collection of TestBeans.
           // Then calls factory.createObject(..., collection, "testArray", 1).
           // That one should produce an instance of TestBean and put it in the collection
           // at index 1.
  -        testCreatePath(context, "$testArray[2]/boolean", Boolean.TRUE);
  +        testCreatePathAndSetValue(context, "$testArray[2]/boolean", Boolean.TRUE);
   
           // Calls factory.createObject(..., TestBean, "nestedBean")
  -        testCreatePath(context, "nestedBean/int", new Integer(1));
  +        testCreatePathAndSetValue(context, "nestedBean/int", new Integer(1));
   
           // Calls factory.expandCollection(..., testBean, "beans", 2), then
           // factory.createObject(..., testBean, "beans", 2)
  -        testCreatePath(context, "beans[2]/int", new Integer(2));
  +        testCreatePathAndSetValue(context, "beans[2]/int", new Integer(2));
   
           // Another, but the collection already exists
  -        testCreatePath(context, "beans[3]/int", new Integer(3));
  +        testCreatePathAndSetValue(context, "beans[3]/int", new Integer(3));
   
           // Calls factory.expandCollection(..., testBean, "beans", 2), then
           // sets the value
  -        testCreatePath(context, "nestedBean/strings[2]", "Test");
  +        testCreatePathAndSetValue(context, "nestedBean/strings[2]", "Test");
   
           // Calls factory.createObject(..., testBean, "map"), then
           // sets the value
  -        testCreatePath(context, "map[@name = 'TestKey1']", "Test");
  +        testCreatePathAndSetValue(context, "map[@name = 'TestKey1']", "Test");
   
           // Calls factory.createObject(..., testBean, "map"), then
           // then factory.createObject(..., map, "TestKey2"), then
           // sets the value
  -        testCreatePath(context, "map[@name = 'TestKey2']/int", new Integer(4));
  +        testCreatePathAndSetValue(context, "map[@name = 'TestKey2']/int", new Integer(4));
   
           // Calls factory.expandCollection(..., map, "TestKey3", 2)
  -        testCreatePath(context, "map/TestKey3[2]", "Test");
  +        testCreatePathAndSetValue(context, "map/TestKey3[2]", "Test");
   
           // Should be the same as the one before
  -        testCreatePath(context, "map[@name='TestKey3'][3]", "Test");
  +        testCreatePathAndSetValue(context, "map[@name='TestKey3'][3]", "Test");
   
           // Create an element of a dynamic map element, which is a collection
  -        testCreatePath(context, "map/TestKey4[1]/int", new Integer(5));
  +        testCreatePathAndSetValue(context, "map/TestKey4[1]/int", new Integer(5));
   
           tBean.getMap().remove("TestKey4");
   
           // Should be the same as the one before
  -        testCreatePath(context, "map[@name = 'TestKey4'][1]/int", new Integer(5));
  +        testCreatePathAndSetValue(context, "map[@name = 'TestKey4'][1]/int", new Integer(5));
   
           // Create a DOM element
  -        testCreatePath(context, "vendor/location[3]", "");
  +        testCreatePathAndSetValue(context, "vendor/location[3]", "");
   
           // Create a DOM element with contents
  -        testCreatePath(context, "vendor/location[3]/address/street", "Lemon Circle");
  +        testCreatePathAndSetValue(context, "vendor/location[3]/address/street", "Lemon Circle");
   
           // Comprehensive tests: map & bean
           tBean.setMap(null);
  -        testCreatePath(context, "map[@name = 'TestKey5']/nestedBean/int", new Integer(6));
  +        testCreatePathAndSetValue(context, "map[@name = 'TestKey5']/nestedBean/int", new Integer(6));
           tBean.setMap(null);
  -        testCreatePath(context, "map[@name = 'TestKey5']/beans[2]/int", new Integer(7));
  +        testCreatePathAndSetValue(context, "map[@name = 'TestKey5']/beans[2]/int", new Integer(7));
       }
   
  -    private void testCreatePath(JXPathContext context, String path, Object value){
  -        context.createPath(path, value);
  +    private void testCreatePathAndSetValue(JXPathContext context, String path, Object value){
  +        Pointer ptr = context.createPathAndSetValue(path, value);
  +        assertTrue("Pointer <" + path + ">", ptr != null);
           assertEquals("Created <" + path + ">", value, context.getValue(path));
  +        assertEquals("Pointer value <" + path + ">", value, ptr.getValue());
  +    }
  +
  +    /**
  +     * Test JXPathContext.removePath() with various arguments
  +     */
  +    public void testRemovePath(){
  +        if (!enabled){
  +            return;
  +        }
  +        TestBeanWithDOM tBean = createTestBeanWithDOM();
  +        JXPathContext context = JXPathContext.newContext(tBean);
  +
  +        // Undeclare variable
  +        context.getVariables().declareVariable("temp", "temp");
  +        context.removePath("$temp");
  +        assertTrue("Undeclare variable",
  +                !context.getVariables().isDeclaredVariable("temp"));
  +
  +        // Remove array element
  +        context.getVariables().
  +                declareVariable("temp", new String[]{"temp1", "temp2"});
  +        context.removePath("$temp[1]");
  +        assertEquals("Remove array element", "temp2",
  +                    context.getValue("$temp[1]"));
  +
  +        // Remove list element
  +        context.getVariables().
  +                declareVariable("temp", list("temp1", "temp2"));
  +        context.removePath("$temp[1]");
  +        assertEquals("Remove collection element", "temp2",
  +                    context.getValue("$temp[1]"));
  +
  +        // Remove property value
  +        context.removePath("nestedBean/int");
  +        assertEquals("Remove property value", new Integer(0),
  +                    context.getValue("nestedBean/int"));
  +
  +        // Remove property value
  +        context.removePath("nestedBean/strings[1]");
  +        assertEquals("Remove property value", "String 2",
  +                    context.getValue("nestedBean/strings[1]"));
  +
  +        context.removePath("nestedBean");
  +        assertEquals("Remove property value", null,
  +                    context.getValue("nestedBean"));
  +
  +        tBean.getMap().put("TestKey1", "test");
  +
  +        // Remove dynamic property
  +        context.removePath("map[@name = 'TestKey1']");
  +        assertEquals("Remove dynamic property value", null,
  +                    context.getValue("map[@name = 'TestKey1']"));
  +
  +        tBean.getMap().put("TestKey2", new String[]{"temp1", "temp2"});
  +        context.removePath("map[@name = 'TestKey2'][1]");
  +        assertEquals("Remove dynamic property collection element", "temp2",
  +                    context.getValue("map[@name = 'TestKey2'][1]"));
  +
  +        // Remove DOM nodes
  +        context.removePath("vendor/location[@id = '101']//street/text()");
  +        assertEquals("Remove DOM text", "",
  +                    context.getValue("vendor/location[@id = '101']//street"));
  +
  +        context.removePath("vendor/location[@id = '101']//street");
  +        assertEquals("Remove DOM element", new Double(0),
  +                    context.getValue("count(vendor/location[@id = '101']//street)"));
  +
  +        context.removePath("vendor/location[@id = '100']/@name");
  +        assertEquals("Remove DOM attribute", new Double(0),
  +                    context.getValue("count(vendor/location[@id = '100']/@name)"));
       }
   
       public void testNull(){
  
  
  
  1.4       +9 -7      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java
  
  Index: PropertyOwnerPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertyOwnerPointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ PropertyOwnerPointer.java	8 May 2002 23:05:05 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v 1.4 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -79,7 +79,7 @@
    * a collection.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/05/08 23:05:05 $
    */
   public abstract class PropertyOwnerPointer extends NodePointer {
   
  @@ -149,7 +149,9 @@
       }
   
       public abstract QName getName();
  -    public abstract void setValue(Object value);
  +    public void setValue(Object value){
  +        this.value = value;
  +    }
   
       public abstract PropertyPointer getPropertyPointer();
   
  @@ -161,11 +163,11 @@
           return NodePointer.newChildNodePointer(this, getName(), getNodeValue());
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
           PropertyPointer prop = getPropertyPointer();
           prop.setPropertyName(name.getName());
           prop.setIndex(index);
  -        prop.createPath(context, value);
  +        return prop.createPath(context, value);
       }
   
       public NodePointer createChild(JXPathContext context, QName name, int index){
  
  
  
  1.5       +8 -8      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
  
  Index: NullPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NullPropertyPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  +++ NullPropertyPointer.java	8 May 2002 23:05:05 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -68,7 +68,7 @@
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $
    */
   public class NullPropertyPointer extends PropertyPointer {
   
  @@ -125,12 +125,12 @@
           return parent.createChild(context, getName(), getIndex());
       }
   
  -    public void createPath(JXPathContext context, Object value){
  -        parent.createChild(context, getName(), getIndex(), value);
  +    public NodePointer createPath(JXPathContext context, Object value){
  +        return parent.createChild(context, getName(), getIndex(), value);
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  -        createPath(context).createChild(context, name, index, value);
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
  +        return createPath(context).createChild(context, name, index, value);
       }
   
       public NodePointer createChild(JXPathContext context, QName name, int index){
  
  
  
  1.3       +11 -10    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java
  
  Index: NullPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- NullPointer.java	24 Apr 2002 04:05:40 -0000	1.2
  +++ NullPointer.java	8 May 2002 23:05:05 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/24 04:05:40 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java,v 1.3 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -69,7 +69,7 @@
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/08 23:05:05 $
    */
   public class NullPointer extends PropertyOwnerPointer {
       private QName name;
  @@ -96,6 +96,7 @@
       }
   
       public void setValue(Object value){
  +        super.setValue(value);
           if (parent instanceof PropertyPointer){
               parent.setValue(value);
           }
  @@ -112,13 +113,13 @@
           return new NullPropertyPointer(this);
       }
   
  -    public void createPath(JXPathContext context, Object value){
  +    public NodePointer createPath(JXPathContext context, Object value){
           if (parent != null){
               if (parent instanceof PropertyPointer){
  -                parent.createPath(context, value);
  +                return parent.createPath(context, value);
               }
               else {
  -                parent.createChild(context, getName(), 0, value);
  +                return parent.createChild(context, getName(), 0, value);
               }
           }
           else {
  @@ -138,12 +139,12 @@
           throw new UnsupportedOperationException("Cannot create the root object: " + asPath());
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
           if (parent != null){
               NodePointer pointer = createPath(context);
               if (pointer != null){
  -                pointer.getValuePointer().createChild(context, name, index, value);
  -                return;
  +                pointer = pointer.getValuePointer().createChild(context, name, index, value);
  +                return pointer;
               }
           }
           throw new UnsupportedOperationException("Cannot create the root object: " + asPath());
  
  
  
  1.5       +11 -10    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java
  
  Index: NullElementPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NullElementPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  +++ NullElementPointer.java	8 May 2002 23:05:05 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -77,7 +77,7 @@
    * as the parent.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $
    */
   public class NullElementPointer extends PropertyOwnerPointer {
   
  @@ -107,6 +107,7 @@
       }
   
       public void setValue(Object value){
  +        super.setValue(value);
           if (parent instanceof PropertyPointer){
               parent.setValue(value);
           }
  @@ -123,12 +124,12 @@
           return false;
       }
   
  -    public void createPath(JXPathContext context, Object value){
  +    public NodePointer createPath(JXPathContext context, Object value){
           if (parent instanceof PropertyPointer){
  -            parent.getParent().createChild(context, parent.getName(), index, value);
  +            return parent.getParent().createChild(context, parent.getName(), index, value);
           }
           else {
  -            parent.createChild(context, null, index, value);
  +            return parent.createChild(context, null, index, value);
           }
       }
   
  @@ -141,16 +142,16 @@
           }
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
           if (index != 0 && index != WHOLE_COLLECTION){
               throw new JXPathException("Internal error. " +
                   "Indexed passed to NullElementPointer.createChild() is not 0: " + index);
           }
           if (parent instanceof PropertyPointer){
  -            parent.getParent().createChild(context, parent.getName(), getIndex(), value);
  +            return parent.getParent().createChild(context, parent.getName(), getIndex(), value);
           }
           else {
  -            parent.createChild(context, name, getIndex(), value);
  +            return parent.createChild(context, name, getIndex(), value);
           }
       }
   
  
  
  
  1.5       +23 -7     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java
  
  Index: DynamicPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DynamicPropertyPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  +++ DynamicPropertyPointer.java	8 May 2002 23:05:05 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -75,7 +75,7 @@
    * Pointer pointing to a property of an object with dynamic properties.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $
    */
   public class DynamicPropertyPointer extends PropertyPointer {
       private DynamicPropertyHandler handler;
  @@ -243,11 +243,11 @@
           }
       }
   
  -    public void createPath(JXPathContext context, Object value){
  -        createChild(context, getName(), index, value);
  +    public NodePointer createPath(JXPathContext context, Object value){
  +        return createChild(context, getName(), index, value);
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
           // Ignore the name passed to us, use our own data
           if (index == WHOLE_COLLECTION){
               handler.setProperty(getBean(), getPropertyName(), value);
  @@ -273,6 +273,9 @@
   
               ValueUtils.setValue(collection, index, value);
           }
  +        NodePointer ptr = (NodePointer)clone();
  +        ptr.setIndex(index);
  +        return ptr;
       }
   
       public NodePointer createChild(JXPathContext context, QName name, int index){
  @@ -309,6 +312,19 @@
               }
           }
           return this;
  +    }
  +
  +    public void remove(){
  +        if (index == WHOLE_COLLECTION){
  +            handler.setProperty(getBean(), getPropertyName(), null);
  +        }
  +        else if (isCollection()){
  +            Object collection = ValueUtils.remove(getBaseValue(), index);
  +            handler.setProperty(getBean(), getPropertyName(), collection);
  +        }
  +        else if (index == 0){
  +            handler.setProperty(getBean(), getPropertyName(), null);
  +        }
       }
   
       public String asPath(){
  
  
  
  1.4       +11 -8     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
  
  Index: CollectionPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CollectionPointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ CollectionPointer.java	8 May 2002 23:05:05 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v 1.4 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -74,7 +74,7 @@
    * Transparent pointer to a collection (array or Collection).
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/05/08 23:05:05 $
    */
   public class CollectionPointer extends NodePointer {
       private Object collection;
  @@ -122,9 +122,9 @@
           return valuePointer;
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
           if (parent instanceof PropertyPointer){
  -            parent.createChild(context, name, index, value);
  +            return parent.createChild(context, name, index, value);
           }
           else {
               Object collection = getBaseValue();
  @@ -132,6 +132,9 @@
                   ValueUtils.expandCollection(getNodeValue(), index + 1);
               }
               ValueUtils.setValue(collection, index, value);
  +            NodePointer ptr = (NodePointer)clone();
  +            ptr.setIndex(index);
  +            return ptr;
           }
       }
   
  @@ -201,8 +204,8 @@
       public boolean testNode(NodeTest nodeTest){
           return getValuePointer().testNode(nodeTest);
       }
  -    
  -    public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){        
  +
  +    public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
           return pointer1.getIndex() - pointer2.getIndex();
       }
   }
  
  
  
  1.5       +46 -22    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java
  
  Index: BeanPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BeanPropertyPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  +++ BeanPropertyPointer.java	8 May 2002 23:05:05 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -75,7 +75,7 @@
    * Pointer pointing to a property of a JavaBean.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $
    */
   public class BeanPropertyPointer extends PropertyPointer {
       private String propertyName;
  @@ -206,7 +206,8 @@
       public void setValue(Object value){
           PropertyDescriptor pd = getPropertyDescriptor();
           if (pd == null){
  -            throw new JXPathException("Cannot set property: " + asPath() + " - no such property");
  +            throw new JXPathException("Cannot set property: " + asPath() +
  +                    " - no such property");
           }
   
           if (index == WHOLE_COLLECTION){
  @@ -222,8 +223,10 @@
           if (getNodeValue() == null){
               AbstractFactory factory = getAbstractFactory(context);
               int inx = (index == WHOLE_COLLECTION ? 0 : index);
  -            if (!factory.createObject(context, this, getBean(), getPropertyName(), inx)){
  -                throw new JXPathException("Factory could not create an object for path: " + asPath());
  +            if (!factory.createObject(context, this, getBean(),
  +                    getPropertyName(), inx)){
  +                throw new JXPathException(
  +                    "Factory could not create an object for path: " + asPath());
               }
               baseValue = UNINITIALIZED;
               value = UNINITIALIZED;
  @@ -231,19 +234,20 @@
           return this;
       }
   
  -    public NodePointer createChild(JXPathContext context, QName name, int index){
  -        return createPath(context).getValuePointer().createChild(context, name, index);
  -//        NodePointer pointer = setIndexExpandingCollection(context, name, index);
  -//        return pointer.createPath(context);
  +    public NodePointer createChild(JXPathContext context,
  +            QName name, int index){
  +        return createPath(context).getValuePointer().
  +                createChild(context, name, index);
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  -        createPath(context).getValuePointer().createChild(context, name, index, value);
  -//        NodePointer pointer = setIndexExpandingCollection(context, name, index);
  -//        pointer.createPath(context, value);
  +    public NodePointer createChild(JXPathContext context,
  +            QName name, int index, Object value){
  +        return createPath(context).getValuePointer().
  +                createChild(context, name, index, value);
       }
   
  -    private BeanPropertyPointer setIndexExpandingCollection(JXPathContext context, QName name, int index){
  +    private BeanPropertyPointer setIndexExpandingCollection(
  +            JXPathContext context, QName name, int index){
           // Ignore the name passed to us, use our own information
           PropertyDescriptor pd = getPropertyDescriptor();
           if (pd == null){
  @@ -257,8 +261,10 @@
   
           if (index >= getLength()){
               AbstractFactory factory = getAbstractFactory(context);
  -            if (!factory.createObject(context, this, getBean(), getPropertyName(), index)){
  -                throw new JXPathException("Factory could not create path " + asPath());
  +            if (!factory.createObject(context, this, getBean(),
  +                    getPropertyName(), index)){
  +                throw new JXPathException("Factory could not create path " +
  +                        asPath());
               }
           }
           BeanPropertyPointer clone = (BeanPropertyPointer)this.clone();
  @@ -268,6 +274,20 @@
           return clone;
       }
   
  +    public void remove(){
  +        if (index == WHOLE_COLLECTION){
  +            setValue(null);
  +        }
  +        else if (isCollection()){
  +            Object collection = ValueUtils.remove(getBaseValue(), index);
  +            ValueUtils.setValue(getBean(), getPropertyDescriptor(), collection);
  +        }
  +        else if (index == 0){
  +            index = WHOLE_COLLECTION;
  +            setValue(null);
  +        }
  +    }
  +
       /**
        * Name of the currently selected property.
        */
  @@ -282,16 +302,19 @@
       }
   
       /**
  -     * Finds the property descriptor corresponding to the current property index.
  +     * Finds the property descriptor corresponding to the current property
  +     * index.
        */
       private PropertyDescriptor getPropertyDescriptor(){
           if (propertyDescriptor == null){
               int inx = getPropertyIndex();
               if (inx == UNSPECIFIED_PROPERTY){
  -                propertyDescriptor = beanInfo.getPropertyDescriptor(propertyName);
  +                propertyDescriptor = beanInfo.
  +                        getPropertyDescriptor(propertyName);
               }
               else {
  -                PropertyDescriptor propertyDescriptors[] = getPropertyDescriptors();
  +                PropertyDescriptor propertyDescriptors[] =
  +                        getPropertyDescriptors();
                   if (inx >=0 && inx < propertyDescriptors.length){
                       propertyDescriptor = propertyDescriptors[inx];
                   }
  @@ -313,7 +336,8 @@
       private AbstractFactory getAbstractFactory(JXPathContext context){
           AbstractFactory factory = context.getFactory();
           if (factory == null){
  -            throw new JXPathException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
  +            throw new JXPathException("Factory is not set on the " +
  +                "JXPathContext - cannot create path: " + asPath());
           }
           return factory;
       }
  
  
  
  1.3       +17 -4     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java
  
  Index: BeanPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BeanPointer.java	24 Apr 2002 04:06:46 -0000	1.2
  +++ BeanPointer.java	8 May 2002 23:05:05 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java,v 1.2 2002/04/24 04:06:46 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/24 04:06:46 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java,v 1.3 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -74,7 +74,7 @@
    * a path, following elements will by of type PropertyPointer.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2002/04/24 04:06:46 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/08 23:05:05 $
    */
   public class BeanPointer extends PropertyOwnerPointer {
       private QName name;
  @@ -119,11 +119,24 @@
        * Throws an exception if you try to change the root element.
        */
       public void setValue(Object value){
  +        super.setValue(value);
           if (parent instanceof PropertyPointer){
               parent.setValue(value);
           }
           else {
               throw new UnsupportedOperationException("Cannot setValue of an object that is not some other object's property");
  +        }
  +    }
  +
  +    public void remove(){
  +        super.setValue(null);
  +        if (parent != null){
  +            parent.remove();
  +        }
  +        else {
  +            throw new UnsupportedOperationException(
  +                "Cannot remove an object that is not " +
  +                "some other object's property or a collection element");
           }
       }
   
  
  
  
  1.16      +71 -13    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
  
  Index: JXPathContextReferenceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JXPathContextReferenceImpl.java	8 May 2002 00:40:00 -0000	1.15
  +++ JXPathContextReferenceImpl.java	8 May 2002 23:05:05 -0000	1.16
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v 1.15 2002/05/08 00:40:00 dmitri Exp $
  - * $Revision: 1.15 $
  - * $Date: 2002/05/08 00:40:00 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v 1.16 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.16 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -84,7 +84,7 @@
    * The reference implementation of JXPathContext.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.15 $ $Date: 2002/05/08 00:40:00 $
  + * @version $Revision: 1.16 $ $Date: 2002/05/08 23:05:05 $
    */
   public class JXPathContextReferenceImpl extends JXPathContext
   {
  @@ -279,13 +279,41 @@
           }
       }
   
  -    public void createPath(String xpath, Object value){
  -        createPath(xpath, compileExpression(xpath), value);
  +    public Pointer createPath(String xpath){
  +        return createPath(xpath, compileExpression(xpath));
       }
   
  -    public void createPath(String xpath, Expression expr, Object value){
  +    public Pointer createPath(String xpath, Expression expr){
           try {
  -            setValue(xpath, expr, value, true);
  +            Object result = expr.computeValue(getRootContext());
  +            Pointer pointer = null;
  +
  +            if (result instanceof Pointer){
  +                pointer = (Pointer)result;
  +            }
  +            else if (result instanceof EvalContext){
  +                EvalContext ctx = (EvalContext)result;
  +                pointer = ctx.getSingleNodePointer();
  +            }
  +            else {
  +                // This should never happen
  +                throw new JXPathException("Expression is not a path:" + xpath);
  +            }
  +            return ((NodePointer)pointer).createPath(this);
  +        }
  +        catch (Throwable ex){
  +            throw new JXPathException(
  +                "Exception trying to create xpath " + xpath, ex);
  +        }
  +    }
  +
  +    public Pointer createPathAndSetValue(String xpath, Object value){
  +        return createPathAndSetValue(xpath, compileExpression(xpath), value);
  +    }
  +
  +    public Pointer createPathAndSetValue(String xpath, Expression expr, Object value){
  +        try {
  +            return setValue(xpath, expr, value, true);
           }
           catch (Throwable ex){
               throw new JXPathException(
  @@ -293,7 +321,7 @@
           }
       }
   
  -    private void setValue(String xpath, Expression expr, Object value, boolean create){
  +    private Pointer setValue(String xpath, Expression expr, Object value, boolean create){
           Object result = expr.computeValue(getRootContext());
   //        System.err.println("RESULT: " + result);
           Pointer pointer = null;
  @@ -310,11 +338,12 @@
               throw new JXPathException("Cannot set value for xpath: " + xpath);
           }
           if (create){
  -            ((NodePointer)pointer).createPath(this, value);
  +            pointer = ((NodePointer)pointer).createPath(this, value);
           }
           else {
               pointer.setValue(value);
           }
  +        return pointer;
       }
   
       /**
  @@ -331,14 +360,43 @@
           return expr.iteratePointers(getRootContext());
       }
   
  -    private void printPointer(NodePointer pointer){
  -        Pointer p = pointer;
  -        while (p != null){
  -            System.err.println((p == pointer ? "POINTER: " : " PARENT: ")
  -                + p.getClass() + " " + p.asPath());
  -            if (p instanceof NodePointer){
  -                p = ((NodePointer)p).getParent();
  +    public void removePath(String xpath){
  +        removePath(xpath, compileExpression(xpath));
  +    }
  +
  +    public void removePath(String xpath, Expression expr){
  +        try {
  +            NodePointer pointer = (NodePointer)getPointer(xpath, expr);
  +            if (pointer != null){
  +                ((NodePointer)pointer).remove();
               }
  +        }
  +        catch (Throwable ex){
  +            throw new JXPathException(
  +                "Exception trying to remove xpath " + xpath, ex);
  +        }
  +    }
  +
  +    public void removeAll(String xpath){
  +        removeAll(xpath, compileExpression(xpath));
  +    }
  +
  +    public void removeAll(String xpath, Expression expr){
  +        try {
  +            ArrayList list = new ArrayList();
  +            Iterator it = expr.iterate(getRootContext());
  +            while (it.hasNext()){
  +                list.add(it.next());
  +            }
  +            Collections.sort(list);
  +            for (int i = list.size() - 1; i >= 0; i--){
  +                NodePointer pointer = (NodePointer)list.get(i);
  +                pointer.remove();
  +            }
  +        }
  +        catch (Throwable ex){
  +            throw new JXPathException(
  +                "Exception trying to remove all for xpath " + xpath, ex);
           }
       }
   
  
  
  
  1.2       +30 -9     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java
  
  Index: JXPathCompiledExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JXPathCompiledExpression.java	28 Apr 2002 04:37:01 -0000	1.1
  +++ JXPathCompiledExpression.java	8 May 2002 23:05:05 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java,v 1.1 2002/04/28 04:37:01 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/04/28 04:37:01 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java,v 1.2 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -67,21 +67,21 @@
   import org.apache.commons.jxpath.Pointer;
   
   /**
  - * 
  + *
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2002/04/28 04:37:01 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/08 23:05:05 $
    */
   public class JXPathCompiledExpression implements CompiledExpression {
   
       private String xpath;
       private Expression expression;
  -    
  +
       public JXPathCompiledExpression(String xpath, Expression expression){
           this.xpath = xpath;
           this.expression = expression;
       }
  -    
  +
       /**
        * @see CompiledExpression#getValue(JXPathContext)
        */
  @@ -109,9 +109,16 @@
       /**
        * @see CompiledExpression#createPath(JXPathContext, Object)
        */
  +    public Pointer createPathAndSetValue(JXPathContext context, Object value) {
  +        return ((JXPathContextReferenceImpl)context).
  +                    createPathAndSetValue(xpath, expression, value);
  +    }
  +
  +    /**
  +     * @deprecated use createPathAndSetValue
  +     */
       public void createPath(JXPathContext context, Object value) {
  -        ((JXPathContextReferenceImpl)context).
  -                    createPath(xpath, expression, value);
  +        createPathAndSetValue(context, value);
       }
   
       /**
  @@ -136,5 +143,19 @@
       public Iterator iteratePointers(JXPathContext context) {
           return ((JXPathContextReferenceImpl)context).
                       iteratePointers(xpath, expression);
  +    }
  +
  +    /**
  +     * @see CompiledExpression#remove(JXPathContext)
  +     */
  +    public void removePath(JXPathContext context){
  +        ((JXPathContextReferenceImpl)context).removePath(xpath, expression);
  +    }
  +
  +    /**
  +     * @see CompiledExpression#removeAll(JXPathContext)
  +     */
  +    public void removeAll(JXPathContext context){
  +        ((JXPathContextReferenceImpl)context).removeAll(xpath, expression);
       }
   }
  
  
  
  1.8       +35 -8     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java
  
  Index: JXPathContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JXPathContext.java	28 Apr 2002 04:37:01 -0000	1.7
  +++ JXPathContext.java	8 May 2002 23:05:05 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v 1.7 2002/04/28 04:37:01 dmitri Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/04/28 04:37:01 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v 1.8 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -404,7 +404,7 @@
    * Also see <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0 </a>
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.7 $ $Date: 2002/04/28 04:37:01 $
  + * @version $Revision: 1.8 $ $Date: 2002/05/08 23:05:05 $
    */
   public abstract class JXPathContext {
       protected JXPathContext parentContext;
  @@ -544,7 +544,7 @@
        * between invocations.
        */
       public abstract CompiledExpression compile(String xpath);
  -    
  +
       /**
        * Evaluates the xpath and returns the resulting object. Primitive
        * types are wrapped into objects.
  @@ -567,6 +567,16 @@
        */
       public abstract void setValue(String xpath, Object value);
   
  +
  +    /**
  +     * Creates missing elements of the path by invoking an AbstractFactory,
  +     * which should first be installed on the context by calling "setFactory".
  +     * <p>
  +     * Will throw an exception if the AbstractFactory fails to create
  +     * an instance for a path element.
  +     */
  +    public abstract Pointer createPath(String xpath);
  +
       /**
        * The same as setValue, except it creates intermediate elements of
        * the path by invoking an AbstractFactory, which should first be
  @@ -574,14 +584,31 @@
        * <p>
        * Will throw an exception if one of the following conditions occurs:
        * <ul>
  -     * <li>Elements of the xpath aleady exist, by the path does not in
  +     * <li>Elements of the xpath aleady exist, but the path does not in
        *  fact describe an existing property
        * <li>The AbstractFactory fails to create an instance for an intermediate
        * element.
        * <li>The property is not writable (no public, non-static set method)
        * </ul>
        */
  -    public abstract void createPath(String xpath, Object value);
  +    public abstract Pointer createPathAndSetValue(String xpath, Object value);
  +
  +    /**
  +     * Removes the element of the object graph described by the xpath.
  +     */
  +    public abstract void removePath(String xpath);
  +
  +    /**
  +     * Removes all elements of the object graph described by the xpath.
  +     */
  +    public abstract void removeAll(String xpath);
  +
  +    /**
  +     * @deprecated please use createPathAndSetValue(xpath, value)
  +     */
  +    public void createPath(String xpath, Object value){
  +        createPathAndSetValue(xpath, value);
  +    }
   
       /**
        * @deprecated Please use iterate
  @@ -617,7 +644,7 @@
        * in the graph, the pointer will be null.
        */
       public abstract Pointer getPointer(String xpath);
  -    
  +
       /**
        * @deprecated Please use iteratePointers
        */
  
  
  
  1.2       +22 -7     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/CompiledExpression.java
  
  Index: CompiledExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/CompiledExpression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CompiledExpression.java	28 Apr 2002 04:37:01 -0000	1.1
  +++ CompiledExpression.java	8 May 2002 23:05:05 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/CompiledExpression.java,v 1.1 2002/04/28 04:37:01 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/04/28 04:37:01 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/CompiledExpression.java,v 1.2 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -70,16 +70,16 @@
    * <p>
    * Use CompiledExpression only when there is a need to evaluate the
    * same expression multiple times and the CompiledExpression can be
  - * conveniently cached.  
  + * conveniently cached.
    * <p>
    * To acqure a CompiledExpression, call {@link JXPathContext#compile
    * JXPathContext.compile}
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2002/04/28 04:37:01 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/08 23:05:05 $
    */
   public interface CompiledExpression {
  -    
  +
       /**
        * Evaluates the xpath and returns the resulting object. Primitive
        * types are wrapped into objects.
  @@ -116,6 +116,11 @@
        * <li>The property is not writable (no public, non-static set method)
        * </ul>
        */
  +    Pointer createPathAndSetValue(JXPathContext context, Object value);
  +
  +    /**
  +     * @deprecated switch to createPathAndSetValue
  +     */
       void createPath(JXPathContext context, Object value);
   
       /**
  @@ -132,7 +137,7 @@
        * in the graph, the pointer will be null.
        */
       Pointer getPointer(JXPathContext context, String xpath);
  -    
  +
       /**
        * Traverses the xpath and returns an Iterator of Pointers.
        * A Pointer provides easy access to a property.
  @@ -140,4 +145,14 @@
        * in the graph, the Iterator be empty, but not null.
        */
       Iterator iteratePointers(JXPathContext context);
  +
  +    /**
  +     * Remove the graph element described by this expression
  +     */
  +    void removePath(JXPathContext context);
  +
  +    /**
  +     * Remove all graph elements described by this expression
  +     */
  +    void removeAll(JXPathContext context);
   }
  
  
  
  1.5       +16 -6     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
  
  Index: DOMNodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DOMNodePointer.java	26 Apr 2002 03:28:37 -0000	1.4
  +++ DOMNodePointer.java	8 May 2002 23:05:05 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/26 03:28:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -88,7 +88,7 @@
    * A Pointer that points to a DOM node.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $
    */
   public class DOMNodePointer extends NodePointer {
       private Node node;
  @@ -383,8 +383,18 @@
           return it.getNodePointer();
       }
   
  -    public void createChild(JXPathContext context, QName name, int index, Object value){
  -        createChild(context, name, index).setValue(value);
  +    public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
  +        NodePointer ptr = createChild(context, name, index);
  +        ptr.setValue(value);
  +        return ptr;
  +    }
  +
  +    public void remove(){
  +        Node parent = node.getParentNode();
  +        if (parent == null){
  +            throw new JXPathException("Cannot remove root DOM node");
  +        }
  +        parent.removeChild(node);
       }
   
       public String asPath(){
  
  
  
  1.5       +8 -4      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java
  
  Index: DOMAttributePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DOMAttributePointer.java	8 May 2002 00:40:00 -0000	1.4
  +++ DOMAttributePointer.java	8 May 2002 23:05:05 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java,v 1.4 2002/05/08 00:40:00 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/08 00:40:00 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/08 23:05:05 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -73,7 +73,7 @@
    * A Pointer that points to a DOM node.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/05/08 00:40:00 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $
    */
   public class DOMAttributePointer extends NodePointer {
       private Attr attr;
  @@ -133,6 +133,10 @@
        */
       public void setValue(Object value){
           attr.setValue((String)TypeUtils.convert(value, String.class));
  +    }
  +
  +    public void remove(){
  +        attr.getOwnerElement().removeAttributeNode(attr);
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message