Author: davsclaus
Date: Sun Nov 1 13:28:16 2009
New Revision: 831674
URL: http://svn.apache.org/viewvc?rev=831674&view=rev
Log:
CAMEL-2122: Added resultType to @XPath. Thanks to Maciej Prochniak for patch.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java
(with props)
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
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.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=831674&r1=831673&r2=831674&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 Nov 1 13:28:16 2009
@@ -36,7 +36,7 @@
@Override
public Expression createExpression(CamelContext camelContext, Annotation
annotation, LanguageAnnotation languageAnnotation, Class expressionReturnType) {
String xpath = getExpressionFromAnnotation(annotation);
- XPathBuilder builder = XPathBuilder.xpath(xpath);
+ XPathBuilder builder = XPathBuilder.xpath(xpath,
getResultType(annotation));
NamespacePrefix[] namespaces =
getExpressionNameSpacePrefix(annotation);
if (namespaces != null) {
for (NamespacePrefix namespacePrefix : namespaces) {
@@ -46,14 +46,24 @@
}
return builder;
}
-
+
+ protected Class<?> getResultType(Annotation annotation) {
+ try {
+ Method method = annotation.getClass().getMethod("resultType");
+ Object value = ObjectHelper.invokeMethod(method, annotation);
+ return (Class<?>) value;
+ } catch (NoSuchMethodException e) {
+ throw new IllegalArgumentException("Cannot determine the
annotation: " + annotation + " as it does not have an resultType() method", e);
+ }
+ }
+
protected NamespacePrefix[] getExpressionNameSpacePrefix(Annotation
annotation) {
try {
Method method = annotation.getClass().getMethod("namespaces");
Object value = ObjectHelper.invokeMethod(method, annotation);
- return (NamespacePrefix[])value;
+ return (NamespacePrefix[]) value;
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Cannot determine the
annotation: " + annotation + " as it does not have an namespaces() method", e);
- }
+ }
}
}
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=831674&r1=831673&r2=831674&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 Nov 1 13:28:16 2009
@@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.w3c.dom.NodeList;
+
import org.apache.camel.component.bean.XPathAnnotationExpressionFactory;
/**
@@ -40,4 +42,6 @@
NamespacePrefix[] namespaces() default {
@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;
}
\ No newline at end of file
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java?rev=831674&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java
Sun Nov 1 13:28:16 2009
@@ -0,0 +1,52 @@
+/**
+ * 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.component.bean;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.language.XPath;
+import org.apache.camel.util.jndi.JndiContext;
+
+public class BeanWithXPathInjectionUsingResultTypeTest extends
ContextTestSupport {
+
+ protected MyBean myBean = new MyBean();
+
+ public void testSendMessage() throws Exception {
+ template.sendBody("bean:myBean", "<a><b>12</b></a>");
+ assertEquals("bean ab: " + myBean, "12", myBean.ab);
+ assertEquals("bean abText: " + myBean, "a12", myBean.abText);
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ JndiContext answer = new JndiContext();
+ answer.bind("myBean", myBean);
+ return answer;
+ }
+
+ public static class MyBean {
+ public String ab;
+ public String abText;
+
+ public void read(@XPath("//a/b") String ab,
+ @XPath(value = "concat('a',//a/b)", resultType = String.class)
String abText) {
+ this.ab = ab;
+ this.abText = abText;
+ }
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java?rev=831674&r1=831673&r2=831674&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java
Sun Nov 1 13:28:16 2009
@@ -29,12 +29,12 @@
private int size = 100;
public void testThrottelingRoutePolicy() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(size);
-
for (int i = 0; i < size; i++) {
template.sendBody(url, "Message " + i);
}
+ getMockEndpoint("mock:result").expectedMessageCount(size);
+
// now start the route
context.startRoute("myRoute");