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/compiler ExtensionFunction.java
Date Thu, 25 Mar 2004 05:42:01 GMT
dmitri      2004/03/24 21:42:01

  Modified:    jxpath/src/java/org/apache/commons/jxpath/util
                        BasicTypeConverter.java
               jxpath/src/test/org/apache/commons/jxpath/ri/compiler
                        TestFunctions.java ExtensionFunctionTest.java
               jxpath/src/java/org/apache/commons/jxpath/ri/axes
                        InitialContext.java RootContext.java
                        NamespaceContext.java
               jxpath/src/java/org/apache/commons/jxpath
                        PackageFunctions.java
               jxpath/src/java/org/apache/commons/jxpath/ri
                        EvalContext.java
               jxpath/src/java/org/apache/commons/jxpath/ri/compiler
                        ExtensionFunction.java
  Log:
  Improved type conversion for extenstion functions
  
  Revision  Changes    Path
  1.13      +7 -1      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java
  
  Index: BasicTypeConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BasicTypeConverter.java	29 Feb 2004 14:17:43 -0000	1.12
  +++ BasicTypeConverter.java	25 Mar 2004 05:42:01 -0000	1.13
  @@ -177,6 +177,12 @@
           }
   
           if (toType == Object.class) {
  +            if (object instanceof NodeSet) {
  +                return convert(((NodeSet) object).getValues(), toType);
  +            }
  +            else if (object instanceof Pointer) {
  +                return convert(((Pointer) object).getValue(), toType);
  +            }
               return object;
           }
   
  
  
  
  1.10      +6 -1      jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/TestFunctions.java
  
  Index: TestFunctions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/TestFunctions.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestFunctions.java	29 Feb 2004 14:17:42 -0000	1.9
  +++ TestFunctions.java	25 Mar 2004 05:42:01 -0000	1.10
  @@ -49,6 +49,11 @@
               ((Number) context.getContextNodePointer().getValue()).intValue();
           this.bar = bar;
       }
  +    
  +    public TestFunctions(int foo, Object object, boolean another) {
  +        this.foo = foo;
  +        bar = String.valueOf(object);
  +    }
   
       public int getFoo() {
           return foo;
  
  
  
  1.15      +9 -11     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
  
  Index: ExtensionFunctionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ExtensionFunctionTest.java	29 Feb 2004 14:17:42 -0000	1.14
  +++ ExtensionFunctionTest.java	25 Mar 2004 05:42:01 -0000	1.15
  @@ -170,6 +170,12 @@
   
           // Allocate new object using a custom constructor - type conversion
           assertXPathValue(context, "string(test:new('3', 4))", "foo=3; bar=4.0");
  +        
  +        context.getVariables().declareVariable("A", "baz");        
  +        assertXPathValue(
  +                context,
  +                "string(test:new(2, $A, false))",
  +                "foo=2; bar=baz");
       }
   
       public void testMethodCall() {
  @@ -210,16 +216,8 @@
               "size(beans)", 
               new Integer(2));
               
  -        boolean exception = false;
  -        try {
  -            assertXPathValue(context, "add($myList, 'hello')", Boolean.TRUE);
  -        }
  -        catch (Exception ex) {
  -            exception = true;
  -        }
  -        assertTrue(
  -            "Exception trying to add to an unmodifiable list",
  -            exception);
  +        context.getValue("add($myList, 'hello')");
  +        assertEquals("After adding an element", 2, list.size());
       }
   
       public void testStaticMethodCall() {
  
  
  
  1.14      +6 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/InitialContext.java
  
  Index: InitialContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/InitialContext.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- InitialContext.java	29 Feb 2004 14:17:37 -0000	1.13
  +++ InitialContext.java	25 Mar 2004 05:42:01 -0000	1.14
  @@ -50,7 +50,11 @@
       public NodePointer getCurrentNodePointer() {
           return nodePointer;
       }
  -
  +    
  +    public Object getValue() {
  +        return nodePointer;
  +    }
  +    
       public boolean nextNode() {
           return setPosition(position + 1);
       }
  
  
  
  1.17      +6 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java
  
  Index: RootContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- RootContext.java	29 Feb 2004 14:17:38 -0000	1.16
  +++ RootContext.java	25 Mar 2004 05:42:01 -0000	1.17
  @@ -61,7 +61,11 @@
       public NodePointer getCurrentNodePointer() {
           return pointer;
       }
  -
  +    
  +    public Object getValue() {
  +        return pointer;
  +    }
  +    
       public int getCurrentPosition() {
           throw new UnsupportedOperationException();
       }
  
  
  
  1.10      +5 -5      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
  
  Index: NamespaceContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- NamespaceContext.java	29 Feb 2004 14:17:38 -0000	1.9
  +++ NamespaceContext.java	25 Mar 2004 05:42:01 -0000	1.10
  @@ -74,19 +74,19 @@
                   return false;
               }
   
  -            QName testName = ((NodeNameTest) nodeTest).getNodeName();
  +            NodeNameTest nodeNameTest = (NodeNameTest) nodeTest;
  +            QName testName = nodeNameTest.getNodeName();
               if (testName.getPrefix() != null) {
                   return false;
               }
  -            String testLocalName = testName.getName();
  -            if (testLocalName.equals("*")) {
  +            if (nodeNameTest.isWildcard()) {
                   iterator =
                       parentContext.getCurrentNodePointer().namespaceIterator();
               }
               else {
                   currentNodePointer =
                       parentContext.getCurrentNodePointer().namespacePointer(
  -                        testLocalName);
  +                            testName.getName());
                   return currentNodePointer != null;
               }
           }
  
  
  
  1.13      +3 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java
  
  Index: PackageFunctions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PackageFunctions.java	29 Feb 2004 14:17:42 -0000	1.12
  +++ PackageFunctions.java	25 Mar 2004 05:42:01 -0000	1.13
  @@ -25,6 +25,7 @@
   import org.apache.commons.jxpath.functions.ConstructorFunction;
   import org.apache.commons.jxpath.functions.MethodFunction;
   import org.apache.commons.jxpath.util.MethodLookupUtils;
  +import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
    * Extension functions provided by Java classes.  The class prefix specified
  @@ -119,7 +120,7 @@
           }
   
           if (parameters.length >= 1) {
  -            Object target = parameters[0];
  +            Object target = TypeUtils.convert(parameters[0], Object.class);
               if (target != null) {
                   Method method =
                       MethodLookupUtils.lookupMethod(
  
  
  
  1.30      +10 -1     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java
  
  Index: EvalContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- EvalContext.java	29 Feb 2004 14:17:45 -0000	1.29
  +++ EvalContext.java	25 Mar 2004 05:42:01 -0000	1.30
  @@ -244,6 +244,15 @@
   
           return set;
       }
  +    
  +    /**
  +     * Typically returns the NodeSet by calling getNodeSet(), 
  +     * but will be overridden for contexts that more naturally produce
  +     * individual values, e.g. VariableContext
  +     */
  +    public Object getValue() {
  +        return getNodeSet();
  +    }
   
       public String toString() {
           Pointer ptr = getContextNodePointer();
  
  
  
  1.13      +2 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java
  
  Index: ExtensionFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExtensionFunction.java	29 Feb 2004 14:17:38 -0000	1.12
  +++ ExtensionFunction.java	25 Mar 2004 05:42:01 -0000	1.13
  @@ -94,7 +94,7 @@
       
       private Object convert(Object object) {
           if (object instanceof EvalContext) {
  -            return ((EvalContext) object).getNodeSet();
  +            return ((EvalContext) object).getValue();
           }
           return object;
       }  
  
  
  

---------------------------------------------------------------------
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