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/test/org/apache/commons/jxpath/ri/model BeanModelTestCase.java
Date Tue, 18 Feb 2003 18:11:37 GMT
dmitri      2003/02/18 10:11:37

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri
                        JXPathContextReferenceImpl.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        BeanModelTestCase.java
  Log:
  Better error reporting in createPath()
  
  Revision  Changes    Path
  1.27      +25 -7     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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- JXPathContextReferenceImpl.java	30 Jan 2003 23:41:29 -0000	1.26
  +++ JXPathContextReferenceImpl.java	18 Feb 2003 18:11:37 -0000	1.27
  @@ -82,6 +82,7 @@
   import org.apache.commons.jxpath.Variables;
   import org.apache.commons.jxpath.ri.axes.RootContext;
   import org.apache.commons.jxpath.ri.compiler.Expression;
  +import org.apache.commons.jxpath.ri.compiler.LocationPath;
   import org.apache.commons.jxpath.ri.compiler.TreeCompiler;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   import org.apache.commons.jxpath.ri.model.NodePointerFactory;
  @@ -357,13 +358,13 @@
                   pointer = ctx.getSingleNodePointer();
               }
               else {
  +                checkSimplePath(expr);
                   // This should never happen
  -                throw new JXPathException("Expression is not a path:" + xpath);
  +                throw new JXPathException("Cannot create path:" + xpath);
               }
               return ((NodePointer) pointer).createPath(this);
           }
           catch (Throwable ex) {
  -            ex.printStackTrace();
               throw new JXPathException(
                   "Exception trying to create xpath " + xpath,
                   ex);
  @@ -383,7 +384,6 @@
               return setValue(xpath, expr, value, true);
           }
           catch (Throwable ex) {
  -            ex.printStackTrace();
               throw new JXPathException(
                   "Exception trying to create xpath " + xpath,
                   ex);
  @@ -408,6 +408,10 @@
               pointer = ctx.getSingleNodePointer();
           }
           else {
  +            if (create) {
  +                checkSimplePath(expr);
  +            }
  +            
               // This should never happen
               throw new JXPathException("Cannot set value for xpath: " + xpath);
           }
  @@ -418,6 +422,20 @@
               pointer.setValue(value);
           }
           return pointer;
  +    }
  +
  +    /**
  +     * Checks if the path follows the JXPath restrictions on the type
  +     * of path that can be passed to create... methods.
  +     */
  +    private void checkSimplePath(Expression expr) {
  +        if (!(expr instanceof LocationPath)
  +            || !((LocationPath) expr).isSimplePath()) {
  +            throw new JXPathException(
  +                "JXPath can only create a path if it uses exclusively "
  +                    + "the child:: and attribute:: axes and has "
  +                    + "no context-dependent predicates");
  +        }
       }
   
       /**
  
  
  
  1.10      +18 -4     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java
  
  Index: BeanModelTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BeanModelTestCase.java	25 Jan 2003 01:50:37 -0000	1.9
  +++ BeanModelTestCase.java	18 Feb 2003 18:11:37 -0000	1.10
  @@ -828,6 +828,20 @@
               "/nestedBean/int",
               new Integer(1),
               "/nestedBean/int");
  +
  +        boolean ex = false;
  +        try {
  +            assertXPathCreatePath(
  +                context,
  +                "/nestedBean/beans[last() + 1]",
  +                new Integer(1),
  +                "/nestedBean/beans[last() + 1]");
  +        }
  +        catch (Exception e){
  +            ex = true;
  +        }
  +        assertTrue("Exception thrown on invalid path for creation", ex);
  +        
       }
   
       public void testCreatePathAndSetValue() {
  
  
  

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


Mime
View raw message