dmitri      2002/11/27 17:02:05

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri
                        JXPathContextReferenceImpl.java
               jxpath/src/java/org/apache/commons/jxpath/ri/axes
                        ChildContext.java ParentContext.java
                        PrecedingOrFollowingContext.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model
                        NodePointer.java VariablePointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
                        BeanPropertyPointer.java CollectionPointer.java
                        NullElementPointer.java NullPropertyPointer.java
                        PropertyIterator.java PropertyOwnerPointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/container
                        ContainerPointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/dynabeans
                        DynaBeanPropertyPointer.java
               jxpath/src/test/org/apache/commons/jxpath
                        JXPathTestSuite.java
               jxpath/src/test/org/apache/commons/jxpath/ri/axes
                        SimplePathInterpreterTest.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        MixedModelTest.java
  Added:       jxpath/src/test/org/apache/commons/jxpath/ri/model
                        ExceptionPropertyTestBean.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic
                        TestDynamicPropertyFactory.java
  Removed:     jxpath/src/test/org/apache/commons/jxpath/ri/model
                        TestDynamicPropertyFactory.java
  Log:
  Renamed isNode to !isContainer
  Cleaned up asPath
  Ignore exceptions during a property iteration
  
  Revision  Changes    Path
  1.24      +17 -14    
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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- JXPathContextReferenceImpl.java   20 Oct 2002 03:44:27 -0000      1.23
  +++ JXPathContextReferenceImpl.java   28 Nov 2002 01:02:04 -0000      1.24
  @@ -75,8 +75,8 @@
   import org.apache.commons.jxpath.ri.model.VariablePointer;
   import org.apache.commons.jxpath.ri.model.beans.BeanPointerFactory;
   import org.apache.commons.jxpath.ri.model.beans.CollectionPointerFactory;
  -import org.apache.commons.jxpath.ri.model.beans.DynamicPointerFactory;
   import org.apache.commons.jxpath.ri.model.container.ContainerPointerFactory;
  +import org.apache.commons.jxpath.ri.model.dynamic.DynamicPointerFactory;
   import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
  @@ -222,27 +222,30 @@
   
       public Object getValue(String xpath, Expression expr){
           Object result = expr.computeValue(getRootContext());
  -        if (result instanceof EvalContext){
  -            EvalContext ctx = (EvalContext)result;
  +        if (result instanceof EvalContext) {
  +            EvalContext ctx = (EvalContext) result;
               result = ctx.getSingleNodePointer();
  -            if (!lenient && result == null){
  +            if (!lenient && result == null) {
                   throw new JXPathException("No value for xpath: " + xpath);
               }
           }
  -        if (result instanceof NodePointer){
  -            if (!lenient && !((NodePointer)result).isActual()){
  +        if (result instanceof NodePointer) {
  +            result = ((NodePointer) result).getValuePointer();
  +            if (!lenient && !((NodePointer) result).isActual()) {
                   // We need to differentiate between pointers representing
  -                // a non-existing property and one representing a property
  +                // a non-existing property and ones representing a property
                   // whose value is null.  In the latter case, the pointer
                   // is going to have isActual == false, but its parent,
                   // which is a non-node pointer identifying the bean property,
                   // will return isActual() == true.
  -                NodePointer parent = ((NodePointer)result).getParent();
  -                if (parent == null || parent.isNode() || !parent.isActual()){
  +                NodePointer parent = ((NodePointer) result).getParent();
  +                if (parent == null
  +                    || !parent.isContainer()
  +                    || !parent.isActual()) {
                       throw new JXPathException("No value for xpath: " + xpath);
                   }
               }
  -            result = ((NodePointer)result).getValue();
  +            result = ((NodePointer) result).getValue();
           }
           return result;
       }
  
  
  
  1.11      +5 -5      
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
  
  Index: ChildContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/ChildContext.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ChildContext.java 10 Aug 2002 01:31:37 -0000      1.10
  +++ ChildContext.java 28 Nov 2002 01:02:04 -0000      1.11
  @@ -157,7 +157,7 @@
           }
           if (startFromParentLocation){
               NodePointer pointer = parent.getParent();
  -            while (pointer != null && !pointer.isNode()){
  +            while (pointer != null && pointer.isContainer()){
                   pointer = pointer.getParent();
               }
   
  
  
  
  1.10      +5 -5      
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/ParentContext.java
  
  Index: ParentContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/ParentContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ParentContext.java        26 Nov 2002 01:20:06 -0000      1.9
  +++ ParentContext.java        28 Nov 2002 01:02:04 -0000      1.10
  @@ -111,7 +111,7 @@
           setStarted = true;
           NodePointer thisLocation = parentContext.getCurrentNodePointer();
           currentNodePointer = thisLocation.getParent();
  -        while (currentNodePointer != null && !currentNodePointer.isNode()){
  +        while (currentNodePointer != null && currentNodePointer.isContainer()){
               currentNodePointer = currentNodePointer.getParent();
           }
           if (currentNodePointer != null &&
  
  
  
  1.10      +5 -5      
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java
  
  Index: PrecedingOrFollowingContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PrecedingOrFollowingContext.java  26 Nov 2002 01:20:06 -0000      1.9
  +++ PrecedingOrFollowingContext.java  28 Nov 2002 01:02:04 -0000      1.10
  @@ -194,7 +194,7 @@
        * If the pointer is auxiliary, return the parent; otherwise - the pointer 
itself
        */
       private NodePointer getMaterialPointer(NodePointer pointer){
  -        while (pointer != null && !pointer.isNode()){
  +        while (pointer != null && pointer.isContainer()){
               pointer = pointer.getParent();
           }
           return pointer;
  
  
  
  1.14      +46 -48    
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- NodePointer.java  26 Nov 2002 01:20:06 -0000      1.13
  +++ NodePointer.java  28 Nov 2002 01:02:04 -0000      1.14
  @@ -72,14 +72,13 @@
   import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
   import org.apache.commons.jxpath.ri.compiler.NodeTest;
   import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
  -import org.apache.commons.jxpath.ri.model.beans.NullElementPointer;
   import org.apache.commons.jxpath.ri.model.beans.NullPointer;
   
   /**
    * Common superclass for Pointers of all kinds.  A NodePointer maps to
  - * a deterministic XPath that represents the location of a node in an object graph.
  - * This XPath uses only simple axes: child, namespace and attribute and only simple,
  - * context-independent predicates.
  + * a deterministic XPath that represents the location of a node in an 
  + * object graph. This XPath uses only simple axes: child, namespace and
  + * attribute and only simple, context-independent predicates.
    *
    * @author Dmitri Plotnikov
    * @version $Revision$ $Date$
  @@ -179,11 +178,18 @@
       public abstract boolean isLeaf();
   
       /**
  -     * If false, this node is axiliary and can only be used as an intermediate
  -     * in the chain of pointers.
  +     * @deprecated Please use !isContainer()
        */
  -    public boolean isNode() {
  -        return true;
  +    public boolean isNode(){
  +        return !isContainer();
  +    }
  +     
  +    /**
  +     * If true, this node is axiliary and can only be used as an intermediate in
  +     * the chain of pointers.
  +     */
  +    public boolean isContainer() {
  +        return false;
       }
   
       /**
  @@ -233,16 +239,17 @@
        * this method returns the pointer to the contents.
        * Only an auxiliary (non-node) pointer can (and should) return a
        * value pointer other than itself.
  -     * Note that you probably don't want to override <code>getValuePointer()</code>
  -     * directly.  Override the <code>getImmediateValuePointer()</code> 
  -     * method instead.  The <code>getValuePointer()</code> method is
  -     * calls <code>getImmediateValuePointer()</code> and, if the result is not
  +     * Note that you probably don't want to override 
  +     * <code>getValuePointer()</code> directly.  Override the
  +     * <code>getImmediateValuePointer()</code> method instead.  The
  +     * <code>getValuePointer()</code> method is calls
  +     * <code>getImmediateValuePointer()</code> and, if the result is not
        * <code>this</code>, invokes <code>getValuePointer()</code> recursively.
  -     * The idea here is to open all nested containers. Let's say we have a 
  -     * container within a container within a container.
  -     * The <code>getValuePointer()</code> method should then open all 
  -     * those containers and return the pointer to the ultimate contents.
  -     * It does so with the above recursion.
  +     * The idea here is to open all nested containers. Let's say we have a
  +     * container within a container within a container. The
  +     * <code>getValuePointer()</code> method should then open all those
  +     * containers and return the pointer to the ultimate contents. It does so
  +     * with the above recursion.
        */
       public NodePointer getValuePointer() {
           NodePointer ivp = getImmediateValuePointer();
  @@ -340,7 +347,7 @@
               return true;
           }
           else if (test instanceof NodeNameTest) {
  -            if (!isNode()) {
  +            if (isContainer()) {
                   return false;
               }
               QName testName = ((NodeNameTest) test).getNodeName();
  @@ -574,35 +581,26 @@
        * Returns an XPath that maps to this Pointer.
        */
       public String asPath() {
  +        // If the parent of this node is a container, it is responsible
  +        // for appended this node's part of the path.
  +        if (parent != null && parent.isContainer()) {
  +            return parent.asPath();
  +        }
  +
           StringBuffer buffer = new StringBuffer();
  -        if (getParent() != null) {
  -            buffer.append(getParent().asPath());
  -            // TBD: the following needs to be redesigned.
  -            // What this condition says is
  -            // "if the parent of this node has already appended this node's
  -            // name, don't do it again".  However, I would hate to add an ugly
  -            // API like "isResponsibleForAppendingChildName()".
  -            if (getParent().isNode() || (parent instanceof NullElementPointer)){
  -                QName name = getName();
  -                if (name != null) {
  -                    if (buffer.length() == 0 ||
  -                            buffer.charAt(buffer.length()-1) != '/'){
  -                        buffer.append('/');
  -                    }
  -                    if (attribute){
  -                        buffer.append('@');
  -                    }
  -                    buffer.append(name);
  -                }
  -            }
  +        if (parent != null) {
  +            buffer.append(parent.asPath());
           }
  -        else {
  -            QName name = getName();
  -            if (attribute){
  -                buffer.append('@');
  -            }
  -            buffer.append(name);
  +
  +        if (buffer.length() == 0
  +            || buffer.charAt(buffer.length() - 1) != '/') {
  +            buffer.append('/');
  +        }
  +        if (attribute) {
  +            buffer.append('@');
           }
  +        buffer.append(getName());
  +
           if (index != WHOLE_COLLECTION && isCollection()) {
               buffer.append('[').append(index + 1).append(']');
           }
  
  
  
  1.9       +6 -6      
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- VariablePointer.java      26 Nov 2002 01:20:06 -0000      1.8
  +++ VariablePointer.java      28 Nov 2002 01:02:04 -0000      1.9
  @@ -95,8 +95,8 @@
           actual = false;
       }
   
  -    public boolean isNode(){
  -        return false;
  +    public boolean isContainer(){
  +        return true;
       }
   
       public QName getName(){
  
  
  
  1.11      +6 -6      
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BeanPropertyPointer.java  26 Nov 2002 01:20:06 -0000      1.10
  +++ BeanPropertyPointer.java  28 Nov 2002 01:02:04 -0000      1.11
  @@ -95,8 +95,8 @@
       /**
        * This type of node is auxiliary.
        */
  -    public boolean isNode(){
  -        return false;
  +    public boolean isContainer(){
  +        return true;
       }
   
       /**
  
  
  
  1.10      +7 -7      
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CollectionPointer.java    26 Nov 2002 01:33:34 -0000      1.9
  +++ CollectionPointer.java    28 Nov 2002 01:02:04 -0000      1.10
  @@ -113,8 +113,8 @@
               || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
       }
   
  -    public boolean isNode(){
  -        return index == WHOLE_COLLECTION;
  +    public boolean isContainer(){
  +        return index != WHOLE_COLLECTION;
       }
   
       public Object getImmediateNode(){
  @@ -269,7 +269,7 @@
           }
           if (index != WHOLE_COLLECTION) {
               // Address the list[1][2] case
  -            if (parent != null && !parent.isNode() &&
  +            if (parent != null && parent.isContainer() &&
                       parent.getIndex() != WHOLE_COLLECTION){
                   buffer.append("/.");
               }
  
  
  
  1.11      +6 -6      
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- NullElementPointer.java   26 Nov 2002 01:20:06 -0000      1.10
  +++ NullElementPointer.java   28 Nov 2002 01:02:04 -0000      1.11
  @@ -128,8 +128,8 @@
           return false;
       }
   
  -    public boolean isNode(){
  -        return false;
  +    public boolean isContainer(){
  +        return true;
       }
   
       public NodePointer createPath(JXPathContext context, Object value){
  
  
  
  1.11      +7 -7      
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- NullPropertyPointer.java  26 Nov 2002 01:20:06 -0000      1.10
  +++ NullPropertyPointer.java  28 Nov 2002 01:02:04 -0000      1.11
  @@ -116,12 +116,12 @@
           return false;
       }
   
  -    public boolean isNode(){
  -        return false;
  +    public boolean isContainer(){
  +        return true;
       }
   
       public void setValue(Object value){
  -        if (parent == null || !parent.isNode()){
  +        if (parent == null || parent.isContainer()){
               throw new JXPathException("Cannot set property " + asPath() +
                   ", the target object is null");
           }
  
  
  
  1.6       +57 -23    
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java
  
  Index: PropertyIterator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PropertyIterator.java     12 Oct 2002 21:02:24 -0000      1.5
  +++ PropertyIterator.java     28 Nov 2002 01:02:04 -0000      1.6
  @@ -90,29 +90,35 @@
           this.name = name;
           this.reverse = reverse;
           this.includeStart = true;
  -        if (reverse){
  +        if (reverse) {
               this.startPropertyIndex = PropertyPointer.UNSPECIFIED_PROPERTY;
               this.startIndex = -1;
           }
  -        if (startWith != null){
  -            while (startWith != null && startWith.getParent() != pointer){
  +        if (startWith != null) {
  +            while (startWith != null && startWith.getParent() != pointer) {
                   startWith = startWith.getParent();
               }
  -            if (startWith == null){
  +            if (startWith == null) {
                   throw new JXPathException(
  -                    "PropertyIerator startWith parameter is not a child of the 
supplied parent");
  +                    "PropertyIerator startWith parameter is "
  +                        + "not a child of the supplied parent");
               }
  -            this.startPropertyIndex = 
((PropertyPointer)startWith).getPropertyIndex();
  +            this.startPropertyIndex =
  +                ((PropertyPointer) startWith).getPropertyIndex();
               this.startIndex = startWith.getIndex();
  -            if (this.startIndex == NodePointer.WHOLE_COLLECTION){
  +            if (this.startIndex == NodePointer.WHOLE_COLLECTION) {
                   this.startIndex = 0;
               }
               this.includeStart = false;
  -            if (reverse && startIndex == -1){
  +            if (reverse && startIndex == -1) {
                   this.includeStart = true;
               }
           }
       }
  +    
  +    protected NodePointer getPropertyPointer(){
  +        return propertyNodePointer;
  +    }
   
       public void reset(){
           position = 0;
  @@ -123,7 +129,7 @@
           if (position == 0){
               if (name != null){
                   if (!targetReady){
  -                    prepare();
  +                    prepareForIndividualProperty(name);
                   }
                   // If there is no such property - return null
                   if (empty){
  @@ -137,7 +143,7 @@
                   reset();
               }
           }
  -        return propertyNodePointer.getValuePointer();
  +        return getValuePointer();       
       }
   
       public int getPosition(){
  @@ -160,14 +166,14 @@
           }
   
           if (!targetReady){
  -            prepare();
  +            prepareForIndividualProperty(name);
           }
   
           if (empty){
               return false;
           }
   
  -        int length = propertyNodePointer.getLength();   // TBD: cache length
  +        int length = getLength();
           int index;
           if (!reverse){
               index = position + startIndex;
  @@ -207,7 +213,7 @@
               int index = 1;
               for (int i = startPropertyIndex; i < count; i++){
                   propertyNodePointer.setPropertyIndex(i);
  -                int length = propertyNodePointer.getLength();
  +                int length = getLength();
                   if (i == startPropertyIndex){
                       length -= startIndex;
                       if (!includeStart){
  @@ -236,7 +242,7 @@
               }
               for (int i = start; i >= 0; i--){
                   propertyNodePointer.setPropertyIndex(i);
  -                int length = propertyNodePointer.getLength();
  +                int length = getLength();
                   if (i == startPropertyIndex){
                       int end = startIndex;
                       if (end == -1){
  @@ -263,13 +269,9 @@
           return false;
       }
   
  -    private void prepare(){
  +    protected void prepareForIndividualProperty(String name){
           targetReady = true;
           empty = true;
  -        // TBD: simplify
  -        if (propertyNodePointer instanceof DynamicPropertyPointer){
  -            propertyNodePointer.setPropertyName(name);
  -        }
   
           String names[] = propertyNodePointer.getPropertyNames();
           if (!reverse){
  @@ -309,6 +311,38 @@
                       break;
                   }
               }
  +        }
  +    }
  +
  +    /**
  +     * Computes length for the current pointer - ignores any exceptions
  +     */
  +    private int getLength() {
  +        int length;
  +        try {
  +            length = propertyNodePointer.getLength();   // TBD: cache length
  +        }
  +        catch (Throwable t){
  +            // @todo: should this exception be reported in any way?
  +            length = 0;
  +        }
  +        return length;
  +    }
  +
  +    /**
  +     * Computes value pointer for the current pointer - ignores any exceptions
  +     */
  +    private NodePointer getValuePointer() {
  +        try {
  +            return propertyNodePointer.getValuePointer();
  +        }
  +        catch (Throwable ex){
  +            // @todo: should this exception be reported in any way?
  +            NullPropertyPointer npp =
  +                new NullPropertyPointer(propertyNodePointer.getParent());
  +            npp.setPropertyName(propertyNodePointer.getPropertyName());
  +            npp.setIndex(propertyNodePointer.getIndex());
  +            return npp.getValuePointer();
           }
       }
   }
  
  
  
  1.11      +16 -8     
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PropertyOwnerPointer.java 26 Nov 2002 01:20:06 -0000      1.10
  +++ PropertyOwnerPointer.java 28 Nov 2002 01:02:04 -0000      1.11
  @@ -84,7 +84,7 @@
   
       public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer 
startWith){
           if (test == null){
  -            return new PropertyIterator(this, null, reverse, startWith);
  +            return createNodeIterator(null, reverse, startWith);
           }
           else if (test instanceof NodeNameTest){
               QName testName = ((NodeNameTest)test).getNodeName();
  @@ -98,16 +98,24 @@
               else {
                   property = testName.getName();
               }
  -            return new PropertyIterator(this, property, reverse, startWith);
  +            return createNodeIterator(property, reverse, startWith);
           }
           else if (test instanceof NodeTypeTest){
               if (((NodeTypeTest)test).getNodeType() == Compiler.NODE_TYPE_NODE){
  -                return new PropertyIterator(this, null, reverse, startWith);
  +                return createNodeIterator(null, reverse, startWith);
               }
           }
           return null;
       }
   
  +    public NodeIterator createNodeIterator(
  +                String property,
  +                boolean reverse,
  +                NodePointer startWith) 
  +    {
  +        return new PropertyIterator(this, property, reverse, startWith);
  +    }
  +
       public NodeIterator attributeIterator(QName name){
           return new BeanAttributeIterator(this, name);
       }
  @@ -150,7 +158,7 @@
        */
       public void setValue(Object value){
           this.value = value;
  -        if (parent instanceof PropertyPointer){
  +        if (parent.isContainer()){
               parent.setValue(value);
           }
           else if (parent != null){
  
  
  
  1.7       +6 -6      
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java
  
  Index: ContainerPointer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContainerPointer.java     26 Nov 2002 01:20:07 -0000      1.6
  +++ ContainerPointer.java     28 Nov 2002 01:02:04 -0000      1.7
  @@ -95,8 +95,8 @@
       /**
        * This type of node is auxiliary.
        */
  -    public boolean isNode(){
  -        return false;
  +    public boolean isContainer(){
  +        return true;
       }
   
       public QName getName(){
  
  
  
  1.5       +6 -6      
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java
  
  Index: DynaBeanPropertyPointer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DynaBeanPropertyPointer.java      26 Nov 2002 01:33:34 -0000      1.4
  +++ DynaBeanPropertyPointer.java      28 Nov 2002 01:02:05 -0000      1.5
  @@ -98,8 +98,8 @@
       /**
        * This type of node is auxiliary.
        */
  -    public boolean isNode(){
  -        return false;
  +    public boolean isContainer(){
  +        return true;
       }
   
       /**
  
  
  
  1.2       +5 -5      
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestSuite.java
  
  Index: JXPathTestSuite.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestSuite.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JXPathTestSuite.java      20 Oct 2002 03:48:21 -0000      1.1
  +++ JXPathTestSuite.java      28 Nov 2002 01:02:05 -0000      1.2
  @@ -75,9 +75,9 @@
   import org.apache.commons.jxpath.ri.compiler.VariableTest;
   import org.apache.commons.jxpath.ri.model.MixedModelTest;
   import org.apache.commons.jxpath.ri.model.beans.BeanModelTest;
  -import org.apache.commons.jxpath.ri.model.beans.DynamicPropertiesModelTest;
   import org.apache.commons.jxpath.ri.model.dom.DOMModelTest;
   import org.apache.commons.jxpath.ri.model.dynabeans.DynaBeanModelTest;
  +import org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertiesModelTest;
   import org.apache.commons.jxpath.ri.model.jdom.JDOMModelTest;
   import org.apache.commons.jxpath.util.BasicTypeConverterTest;
   
  
  
  
  1.4       +2 -0      
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java
  
  Index: SimplePathInterpreterTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimplePathInterpreterTest.java    26 Nov 2002 01:20:08 -0000      1.3
  +++ SimplePathInterpreterTest.java    28 Nov 2002 01:02:05 -0000      1.4
  @@ -9,6 +9,8 @@
   import org.apache.commons.jxpath.ri.model.*;
   import org.apache.commons.jxpath.ri.model.beans.*;
   import org.apache.commons.jxpath.ri.model.dom.*;
  +import org.apache.commons.jxpath.ri.model.dynamic.*;
  +
   import java.util.*;
   
   public class SimplePathInterpreterTest extends TestCase {
  
  
  
  1.2       +35 -18    
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java
  
  Index: MixedModelTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MixedModelTest.java       20 Oct 2002 03:48:22 -0000      1.1
  +++ MixedModelTest.java       28 Nov 2002 01:02:05 -0000      1.2
  @@ -91,8 +91,6 @@
   
   public class MixedModelTest extends JXPathTestCase
   {
  -    private static final boolean enabled = true;
  -
       private JXPathContext context;
   
       /**
  @@ -419,9 +417,6 @@
        * Test JXPath.iterate() with map containing an array
        */
       public void testIterateArray(){
  -        if (!enabled){
  -            return;
  -        }
           Map map = new HashMap();
           map.put("foo", new String[]{"a", "b", "c"});
   
  @@ -433,9 +428,6 @@
       }
   
       public void testIteratePointersArray(){
  -        if (!enabled){
  -            return;
  -        }
           Map map = new HashMap();
           map.put("foo", new String[]{"a", "b", "c"});
   
  @@ -452,9 +444,6 @@
       }
   
       public void testIteratePointersArrayElementWithVariable(){
  -        if (!enabled){
  -            return;
  -        }
           Map map = new HashMap();
           map.put("foo", new String[]{"a", "b", "c"});
   
  @@ -470,9 +459,6 @@
       }
   
       public void testIterateVector(){
  -        if (!enabled){
  -            return;
  -        }
           Map map = new HashMap();
           Vector vec = new Vector();
           vec.add(new HashMap());
  @@ -483,5 +469,36 @@
           assertXPathPointerIterator(context,
               "/vec",
               list("/.[@name='vec'][1]", "/.[@name='vec'][2]"));
  +    }
  +    
  +    public void testErrorProperty(){
  +        context.getVariables().declareVariable(
  +            "e",
  +            new ExceptionPropertyTestBean());
  +         
  +        boolean ex = false;   
  +        try {
  +            assertXPathValue(context, "$e/errorString", null);
  +        }
  +        catch (Throwable t){
  +            ex = true;
  +        }
  +        assertTrue("Legitimate exception accessing property", ex);
  +        
  +        assertXPathPointer(context, 
  +            "$e/errorString", 
  +            "$e/errorString");
  +
  +        assertXPathPointerLenient(context,
  +            "$e/errorStringArray[1]",
  +            "$e/errorStringArray[1]");
  +            
  +        assertXPathPointerIterator(context,
  +            "$e/errorString",
  +            list("$e/errorString"));
  +
  +        assertXPathPointerIterator(context,
  +            "$e//error",
  +            Collections.EMPTY_LIST);
       }
   }
  
  
  
  1.1                  
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/ExceptionPropertyTestBean.java
  
  Index: ExceptionPropertyTestBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.model;
  
  import org.apache.commons.jxpath.TestBean;
  
  /**
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Dmitri Plotnikov</a>
   * @version $Id: ExceptionPropertyTestBean.java,v 1.1 2002/11/28 01:02:05 dmitri Exp 
$
   */
  public class ExceptionPropertyTestBean {
  
      public String getErrorString(){
          throw new RuntimeException("errorString");
      }
      
      public String[] getErrorStringArray(){
          throw new RuntimeException("errorStringArray");
      }
  
      public TestBean getErrorBean(){
          throw new RuntimeException("errorBean");
      }
  }
  
  
  
  1.1                  
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic/TestDynamicPropertyFactory.java
  
  Index: TestDynamicPropertyFactory.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dynamic/TestDynamicPropertyFactory.java,v
 1.1 2002/11/28 01:02:05 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/11/28 01:02:05 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Plotnix, Inc,
   * <http://www.plotnix.com/>.
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.commons.jxpath.ri.model.dynamic;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Vector;
  
  import org.apache.commons.jxpath.*;
  
  /**
   * Test AbstractFactory.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/11/28 01:02:05 $
   */
  public class TestDynamicPropertyFactory extends AbstractFactory {
  
      /**
       * Create a new instance and put it in the collection on the parent object.
       * Return <b>false</b> if this factory cannot create the requested object.
       */
      public boolean createObject(
              JXPathContext context,
              Pointer pointer,
              Object parent,
              String name,
              int index) 
      {
          if (name.equals("map")) {
              ((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;
          } else if (name.equals("TestKey3")) {
              Vector v = new Vector();
              for (int i = 0; i <= index; i++) {
                  v.add(null);
              }
              ((Map) parent).put(name, v);
              return true;
          } else if (name.equals("TestKey4")) {
              ((Map) parent).put(name, new Object[] { new TestBean()});
              return true;
          }
          return false;
      }
  
      public boolean declareVariable(JXPathContext context, String name){
          return false;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to