You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2008/03/07 16:15:19 UTC
svn commit: r634709 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/model/language/
components/camel-saxon/src/test/java/org/apache/camel/component/xquery/
components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/
Author: hadrian
Date: Fri Mar 7 07:15:18 2008
New Revision: 634709
URL: http://svn.apache.org/viewvc?rev=634709&view=rev
Log:
CAMEL-373. Comes with small change in the schema: xquery/@type replaces xquery/@resultType.
Added:
activemq/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryWithExplicitTypeTest.java
activemq/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java?rev=634709&r1=634708&r2=634709&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java Fri Mar 7 07:15:18 2008
@@ -20,10 +20,14 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
-import org.apache.camel.impl.RouteContext;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
+import org.apache.camel.impl.RouteContext;
+import org.apache.camel.model.OutputType;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* For XQuery expresions and predicates
@@ -33,7 +37,11 @@
@XmlRootElement(name = "xquery")
@XmlAccessorType(XmlAccessType.FIELD)
public class XQueryExpression extends NamespaceAwareExpression {
+ private static final transient Log LOG = LogFactory.getLog(XQueryExpression.class);
+
@XmlAttribute(required = false)
+ private String type;
+ @XmlTransient
private Class resultType;
public XQueryExpression() {
@@ -47,6 +55,14 @@
return "xquery";
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
public Class getResultType() {
return resultType;
}
@@ -58,6 +74,7 @@
@Override
protected void configureExpression(RouteContext routeContext, Expression expression) {
super.configureExpression(routeContext, expression);
+ updateResultType();
if (resultType != null) {
setProperty(expression, "resultType", resultType);
}
@@ -66,8 +83,19 @@
@Override
protected void configurePredicate(RouteContext routeContext, Predicate predicate) {
super.configurePredicate(routeContext, predicate);
+ updateResultType();
if (resultType != null) {
setProperty(predicate, "resultType", resultType);
}
+ }
+
+ private void updateResultType() {
+ if (resultType == null && type != null) {
+ try {
+ resultType = Class.forName(type);
+ } catch (ClassNotFoundException e) {
+ LOG.error("ClassNotFoundException creating class: " + type);
+ }
+ }
}
}
Added: activemq/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryWithExplicitTypeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryWithExplicitTypeTest.java?rev=634709&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryWithExplicitTypeTest.java (added)
+++ activemq/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryWithExplicitTypeTest.java Fri Mar 7 07:15:18 2008
@@ -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.xquery;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 35332 $
+ */
+public class XQueryWithExplicitTypeTest extends SpringTestSupport {
+ protected MockEndpoint raleighEndpoint;
+ protected MockEndpoint tampaEndpoint;
+
+ public void testFunctions() throws Exception {
+ raleighEndpoint.expectedMessageCount(1);
+ tampaEndpoint.expectedMessageCount(0);
+
+ template.sendBody("direct:start", "<person name='Hadrian' city='Raleigh'/>");
+
+ assertMockEndpointsSatisifed();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ raleighEndpoint = getMockEndpoint("mock:foo.Raleigh");
+ tampaEndpoint = getMockEndpoint("mock:foo.Tampa");
+ }
+
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml");
+ }
+}
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml?rev=634709&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml (added)
+++ activemq/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml Fri Mar 7 07:15:18 2008
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <recipientList>
+ <xquery type="java.lang.String">concat('mock:foo.', /person/@city)</xquery>
+ </recipientList>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+
+</beans>