Author: boday
Date: Sun May 22 04:32:32 2011
New Revision: 1125863

URL: http://svn.apache.org/viewvc?rev=1125863&view=rev
Log:
CAMEL-3911: updated @XPath to use the annotated parameter type instead of 
defaulting to NodeList

Added:
    
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathAnnotationResultTypeTest.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java?rev=1125863&r1=1125862&r2=1125863&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
 Sun May 22 04:32:32 2011
@@ -36,7 +36,13 @@ public class XPathAnnotationExpressionFa
     @Override
     public Expression createExpression(CamelContext camelContext, Annotation 
annotation, LanguageAnnotation languageAnnotation, Class<?> 
expressionReturnType) {
         String xpath = getExpressionFromAnnotation(annotation);
-        XPathBuilder builder = XPathBuilder.xpath(xpath, 
getResultType(annotation));
+        
+        Class<?> resultType = getResultType(annotation);
+        if (resultType.equals(Object.class)) {
+            resultType = expressionReturnType;
+        }
+        
+        XPathBuilder builder = XPathBuilder.xpath(xpath, resultType);        
         NamespacePrefix[] namespaces = 
getExpressionNameSpacePrefix(annotation);
         if (namespaces != null) {
             for (NamespacePrefix namespacePrefix : namespaces) {

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java?rev=1125863&r1=1125862&r2=1125863&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java 
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java 
Sun May 22 04:32:32 2011
@@ -22,8 +22,6 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import org.w3c.dom.NodeList;
-
 import org.apache.camel.component.bean.XPathAnnotationExpressionFactory;
 
 /**
@@ -43,5 +41,5 @@ public @interface XPath {
     @NamespacePrefix(prefix = "soap", uri = 
"http://www.w3.org/2003/05/soap-envelope";),
     @NamespacePrefix(prefix = "xsd", uri = 
"http://www.w3.org/2001/XMLSchema";)};
     
-    Class<?> resultType() default NodeList.class;
+    Class<?> resultType() default Object.class;
 }
\ No newline at end of file

Added: 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathAnnotationResultTypeTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathAnnotationResultTypeTest.java?rev=1125863&view=auto
==============================================================================
--- 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathAnnotationResultTypeTest.java
 (added)
+++ 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathAnnotationResultTypeTest.java
 Sun May 22 04:32:32 2011
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder.saxon;
+
+import javax.naming.Context;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.language.XPath;
+import org.apache.camel.test.CamelTestSupport;
+import org.apache.camel.util.jndi.JndiContext;
+
+/**
+ * @version 
+ */
+public class XPathAnnotationResultTypeTest extends CamelTestSupport {
+    protected MyBean myBean = new MyBean();
+
+    public void testSendMessage() throws Exception {
+
+        String response = (String) template.requestBody("direct:in1", 
"<a><b>hello</b></a>");
+        assertEquals("HELLO", response);
+        
+        response = (String) template.requestBody("direct:in2", 
"<a><b>hello</b></a>");
+        assertEquals("HELLO", response);
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+        answer.bind("myBean", myBean);
+        return answer;
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + 
"http://saxon.sf.net/jaxp/xpath/om";, "net.sf.saxon.xpath.XPathFactoryImpl");
+                from("direct:in1").beanRef("myBean", "readImplicit");
+                from("direct:in2").beanRef("myBean", "readExplicit");
+            }
+        };
+    }
+
+    public static class MyBean {
+        public String abText;
+
+        public String readImplicit(@XPath("upper-case(//a/b/text())") String 
abText) {
+            return abText;
+        }
+
+        public String readExplicit(@XPath(value = "upper-case(//a/b/text())", 
resultType = String.class) String abText) {
+            return abText;
+        }
+    }
+}


Reply via email to