Author: janstey
Date: Fri Sep 19 11:11:00 2008
New Revision: 697170

URL: http://svn.apache.org/viewvc?rev=697170&view=rev
Log:
CAMEL-923 - Add setProperty into the Spring DSL

Added:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetPropertyType.java
   (with props)
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetPropertyTest.java
   (with props)
    
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetPropertyTest.java
   (with props)
    
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setProperty.xml
   (with props)
Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=697170&r1=697169&r2=697170&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
 Fri Sep 19 11:11:00 2008
@@ -1265,7 +1265,9 @@
      * Adds a processor which sets the exchange property
      */
     public Type setProperty(String name, Expression expression) {
-        return process(ProcessorBuilder.setProperty(name, expression));
+        SetPropertyType answer = new SetPropertyType(name, expression);
+        addOutput(answer);
+        return (Type) this;
     }
 
 
@@ -1274,8 +1276,9 @@
      */
     public ExpressionClause<ProcessorType<Type>> setProperty(String name) {
         ExpressionClause<ProcessorType<Type>> clause = new 
ExpressionClause<ProcessorType<Type>>((Type) this);
-        process(ProcessorBuilder.setProperty(name, clause));
-        return clause;
+        SetPropertyType answer = new SetPropertyType(name, clause);
+        addOutput(answer);
+        return clause;        
     }
 
     /**

Added: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetPropertyType.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetPropertyType.java?rev=697170&view=auto
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetPropertyType.java
 (added)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetPropertyType.java
 Fri Sep 19 11:11:00 2008
@@ -0,0 +1,81 @@
+/**
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.ProcessorBuilder;
+import org.apache.camel.model.language.ExpressionType;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * Represents an XML &lt;setProperty/&gt; element
+ */
[EMAIL PROTECTED](name = "setProperty")
[EMAIL PROTECTED](XmlAccessType.FIELD)
+public class SetPropertyType extends ExpressionNode {
+    @XmlAttribute
+    private String propertyName;
+    
+    public SetPropertyType() {
+    }
+
+    public SetPropertyType(String propertyName, ExpressionType expression) {
+        super(expression);
+        setPropertyName(propertyName);
+    }
+
+    public SetPropertyType(String propertyName, Expression expression) {
+        super(expression);
+        setPropertyName(propertyName);        
+    }
+
+    public SetPropertyType(String propertyName, String value) {
+        super(ExpressionBuilder.constantExpression(value));
+        setPropertyName(propertyName);        
+    }   
+    
+    @Override
+    public String toString() {
+        return "SetProperty[ " + getPropertyName() + ", " + getExpression() + 
"]";
+    }
+
+    @Override
+    public String getShortName() {
+        return "setProperty";
+    }
+
+    @Override
+    public Processor createProcessor(RouteContext routeContext) throws 
Exception {
+        Expression expr = getExpression().createExpression(routeContext);
+        return ProcessorBuilder.setProperty(getPropertyName(), expr);
+    }
+
+    public void setPropertyName(String propertyName) {
+        this.propertyName = propertyName;
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+}

Propchange: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetPropertyType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?rev=697170&r1=697169&r2=697170&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
 Fri Sep 19 11:11:00 2008
@@ -50,6 +50,7 @@
 SetBodyType
 SetHeaderType
 SetOutHeaderType
+SetPropertyType
 SplitterType
 ThrottlerType
 ThreadType

Added: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetPropertyTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetPropertyTest.java?rev=697170&view=auto
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetPropertyTest.java
 (added)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetPropertyTest.java
 Fri Sep 19 11:11:00 2008
@@ -0,0 +1,63 @@
+/**
+ * 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.processor;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class SetPropertyTest extends ContextTestSupport {
+    private MockEndpoint end;
+    private String propertyName = "foo";
+    private String expectedPropertyValue = "bar";
+
+    public void testSetExchangePropertyMidRoute() throws Exception {
+        end.expectedMessageCount(1);
+
+        template.sendBody("direct:start", "<blah/>");
+
+        // make sure we got the message
+        assertMockEndpointsSatisfied();
+        
+        // lets get the property value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);        
+        String actualPropertyValue = exchange.getProperty(propertyName, 
String.class);
+        
+        assertEquals(expectedPropertyValue, actualPropertyValue);
+    }
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        end = getMockEndpoint("mock:end");
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").
+                  setProperty(propertyName).constant(expectedPropertyValue).
+                  to("mock:end");
+            }
+        };
+    }
+}

Propchange: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetPropertyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetPropertyTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetPropertyTest.java?rev=697170&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetPropertyTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetPropertyTest.java
 Fri Sep 19 11:11:00 2008
@@ -0,0 +1,28 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.SetPropertyTest;
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringSetPropertyTest extends SetPropertyTest {
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this,
+                "org/apache/camel/spring/processor/setProperty.xml");
+    }
+}

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetPropertyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setProperty.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setProperty.xml?rev=697170&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setProperty.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setProperty.xml
 Fri Sep 19 11:11:00 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.5.xsd
+       http://activemq.apache.org/camel/schema/spring 
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <route>
+      <from uri="direct:start"/>
+      <setProperty propertyName="foo">
+        <constant>bar</constant>
+      </setProperty>
+      <to uri="mock:end"/>     
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+</beans>

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setProperty.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to