RE: svn commit: r695550 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/java/org/apache/camel/spi/ camel

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: svn commit: r695550 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/java/org/apache/camel/spi/ camel

Claus Ibsen
Hi

Great patch. However the comment in the spring xml file in the last example is wrong.
+            <!-- using a child node -->
You are using a ref ;)


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: 15. september 2008 19:02
To: [hidden email]
Subject: svn commit: r695550 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/java/org/apache/camel/spi/ camel-...

Author: janstey
Date: Mon Sep 15 10:02:12 2008
New Revision: 695550

URL: http://svn.apache.org/viewvc?rev=695550&view=rev
Log:
CAMEL-871 - Adding dataFormats element under camelContext.


Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
    activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Mon Sep 15 10:02:12 2008
@@ -18,10 +18,13 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.Callable;
 
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.InterceptStrategy;
@@ -267,4 +270,16 @@
      * @param errorHandlerBuilder  the builder
      */
     void setErrorHandlerBuilder(ErrorHandlerBuilder errorHandlerBuilder);
+    
+    /**
+     * Sets the data formats that can be referenced in the routes.
+     * @param dataFormats the data formats
+     */
+    void setDataFormats(Map<String, DataFormatType> dataFormats);
+
+    /**
+     * Gets the data formats that can be referenced in the routes.
+     * @param dataFormats the data formats
+     */    
+    Map<String, DataFormatType> getDataFormats();
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon Sep 15 10:02:12 2008
@@ -43,9 +43,11 @@
 import org.apache.camel.management.InstrumentationLifecycleStrategy;
 import org.apache.camel.management.JmxSystemPropertyKeys;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
 import org.apache.camel.processor.interceptor.TraceFormatter;
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.InterceptStrategy;
@@ -92,6 +94,7 @@
     private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
     private Boolean trace;
     private ErrorHandlerBuilder errorHandlerBuilder;
+    private Map<String, DataFormatType> dataFormats = new HashMap<String, DataFormatType>();
 
     public DefaultCamelContext() {
         name = NAME_PREFIX + ++nameSuffix;
@@ -681,5 +684,11 @@
         return isStarted() && !isStarting();
     }
 
+    public void setDataFormats(Map<String, DataFormatType> dataFormats) {
+        this.dataFormats = dataFormats;
+    }
 
+    public Map<String, DataFormatType> getDataFormats() {
+        return dataFormats;
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java Mon Sep 15 10:02:12 2008
@@ -18,7 +18,9 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.camel.AsyncProcessor;
 import org.apache.camel.CamelContext;
@@ -32,10 +34,12 @@
 import org.apache.camel.model.FromType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
 import org.apache.camel.processor.Interceptor;
 import org.apache.camel.processor.Pipeline;
 import org.apache.camel.processor.ProceedProcessor;
 import org.apache.camel.processor.UnitOfWorkProcessor;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ErrorHandlerWrappingStrategy;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.RouteContext;
@@ -204,4 +208,13 @@
         routeAdded = b;
         
     }
+
+    public DataFormatType getDataFormat(String ref) {
+        Map<String, DataFormatType> dataFormats = getCamelContext().getDataFormats();
+        if (dataFormats != null) {
+            return dataFormats.get(ref);
+        } else {
+            return null;
+        }
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java Mon Sep 15 10:02:12 2008
@@ -60,6 +60,11 @@
         if (type == null) {
             notNull(ref, "ref or dataFormatType");
             DataFormat dataFormat = routeContext.lookup(ref, DataFormat.class);
+            
+            if (dataFormat == null) {
+                dataFormat = routeContext.getDataFormat(ref);
+            }
+            
             if (dataFormat instanceof DataFormatType) {
                 type = (DataFormatType)dataFormat;
             } else {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java?rev=695550&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java Mon Sep 15 10:02:12 2008
@@ -0,0 +1,57 @@
+package org.apache.camel.model.dataformat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Represents the XML type for a collection of DataFormats.
+ */
+@XmlRootElement(name = "dataFormats")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DataFormatsType {
+
+    // TODO cannot use @XmlElementRef as it doesn't allow optional properties
+    // @XmlElementRef    
+    @XmlElements({
+        @XmlElement(required = false, name = "artixDS", type = ArtixDSDataFormat.class),
+        @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
+        @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
+        @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
+        @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
+        @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
+        @XmlElement(required = false, name = "string", type = StringDataFormat.class),
+        @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
+        @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class)}
+        )
+    private List<DataFormatType> dataFormats;
+
+    
+    public void setDataFormats(List<DataFormatType> dataFormats) {
+        this.dataFormats = dataFormats;
+    }
+
+    public List<DataFormatType> getDataFormats() {
+        return dataFormats;
+    }
+
+    /***
+     * @return A Map of the contained DataFormatType's indexed by id.
+     */
+    public Map<String, DataFormatType> asMap() {
+        Map<String, DataFormatType> dataFormatsAsMap = new HashMap<String, DataFormatType>();
+        for (DataFormatType dataFormatType : getDataFormats()) {
+            dataFormatsAsMap.put(dataFormatType.getId(), dataFormatType);
+        }
+        return dataFormatsAsMap;
+    }    
+}

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

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java Mon Sep 15 10:02:12 2008
@@ -26,6 +26,7 @@
 import org.apache.camel.model.FromType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
 
 /**
  * The context used to activate new routing rules
@@ -174,5 +175,12 @@
      * @return the flag
      */
     boolean isRouteAdded();
-
+    
+    /**
+     * Get a DataFormatType by ref name
+     *
+     * @param ref  the ref name to lookup
+     * @return the found object
+     */
+    DataFormatType getDataFormat(String ref);
 }

Modified: activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index Mon Sep 15 10:02:12 2008
@@ -19,6 +19,7 @@
 CsvDataFormat
 HL7DataFormat
 DataFormatType
+DataFormatsType
 JaxbDataFormat
 SerializationDataFormat
 StringDataFormat

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Sep 15 10:02:12 2008
@@ -17,6 +17,7 @@
 package org.apache.camel.spring;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -42,10 +43,12 @@
 import org.apache.camel.model.RouteBuilderRef;
 import org.apache.camel.model.RouteContainer;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatsType;
 import org.apache.camel.model.dataformat.DataFormatType;
 import org.apache.camel.processor.interceptor.Debugger;
 import org.apache.camel.processor.interceptor.TraceFormatter;
 import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.Registry;
 import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
@@ -54,7 +57,9 @@
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.context.ApplicationEvent;
@@ -96,8 +101,8 @@
     private List<RouteBuilderRef> builderRefs = new ArrayList<RouteBuilderRef>();
     @XmlElement(name = "endpoint", required = false)
     private List<EndpointFactoryBean> endpoints;
-    @XmlElementRef
-    private List<DataFormatType> dataFormats;
+    @XmlElement(name = "dataFormats", required = false)
+    private DataFormatsType dataFormats;
     @XmlElement(name = "intercept", required = false)
     private List<InterceptType> intercepts = new ArrayList<InterceptType>();
     @XmlElement(name = "route", required = false)
@@ -169,8 +174,8 @@
             if (beanPostProcessor instanceof CamelBeanPostProcessor) {
                 ((CamelBeanPostProcessor)beanPostProcessor).setCamelContext(getContext());
             }
-        }
-
+        }      
+        
         // setup the intercepts
         for (RouteType route : routes) {
 
@@ -205,7 +210,12 @@
                 }                
             }
 
+        }        
+        
+        if (dataFormats != null) {
+            getContext().setDataFormats(dataFormats.asMap());
         }
+        
         // lets force any lazy creation
         getContext().addRouteDefinitions(routes);
 
@@ -496,4 +506,12 @@
             finder.appendBuilders(additionalBuilders);
         }
     }
+
+    public void setDataFormats(DataFormatsType dataFormats) {
+        this.dataFormats = dataFormats;
+    }
+
+    public DataFormatsType getDataFormats() {
+        return dataFormats;
+    }
 }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Mon Sep 15 10:02:12 2008
@@ -197,6 +197,7 @@
                 builder.addPropertyValue("id", contextId);
                 builder.addPropertyValue("routes", factoryBean.getRoutes());
                 builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
+                builder.addPropertyValue("dataFormats", factoryBean.getDataFormats());
                 builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());
 
                 if (factoryBean.getPackages().length > 0) {

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java?rev=695550&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java Mon Sep 15 10:02:12 2008
@@ -0,0 +1,14 @@
+package org.apache.camel.spring.dataformat;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.spring.issues.StringDataFormatTest;
+
+public class SpringDataFormatWithNonChildElementTest extends StringDataFormatTest {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml");
+    }    
+}

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

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml?rev=695550&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml Mon Sep 15 10:02:12 2008
@@ -0,0 +1,46 @@
+<?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
+    ">
+
+    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+        
+        <dataFormats>
+          <string id="xs" charset="utf-8"/>
+        </dataFormats>
+                
+        <route>
+            <from uri="direct:marshal"/>
+            <!-- using a bean id -->
+            <marshal ref="xs"/>
+            <to uri="mock:marshal"/>
+        </route>
+
+        <route>
+            <from uri="direct:unmarshal"/>
+            <!-- using a child node -->
+            <unmarshal ref="xs"/>
+            <to uri="mock:unmarshal"/>
+        </route>
+    </camelContext>
+
+</beans>


Reply | Threaded
Open this post in threaded view
|

RE: svn commit: r695550 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/java/org/apache/camel/spi/ camel

Jon Anstey
Good ol' copy and paste errors :) Thanks for pointing this out Claus. Its fixed now.

Cheers,
Jon

Claus Ibsen wrote
Hi

Great patch. However the comment in the spring xml file in the last example is wrong.
+            
You are using a ref ;)


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: janstey@apache.org [mailto:janstey@apache.org]
Sent: 15. september 2008 19:02
To: camel-commits@activemq.apache.org
Subject: svn commit: r695550 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/java/org/apache/camel/spi/ camel-...

Author: janstey
Date: Mon Sep 15 10:02:12 2008
New Revision: 695550

URL: http://svn.apache.org/viewvc?rev=695550&view=rev
Log:
CAMEL-871 - Adding dataFormats element under camelContext.


Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
    activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Mon Sep 15 10:02:12 2008
@@ -18,10 +18,13 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.Callable;
 
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.InterceptStrategy;
@@ -267,4 +270,16 @@
      * @param errorHandlerBuilder  the builder
      */
     void setErrorHandlerBuilder(ErrorHandlerBuilder errorHandlerBuilder);
+    
+    /**
+     * Sets the data formats that can be referenced in the routes.
+     * @param dataFormats the data formats
+     */
+    void setDataFormats(Map<String, DataFormatType> dataFormats);
+
+    /**
+     * Gets the data formats that can be referenced in the routes.
+     * @param dataFormats the data formats
+     */    
+    Map<String, DataFormatType> getDataFormats();
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon Sep 15 10:02:12 2008
@@ -43,9 +43,11 @@
 import org.apache.camel.management.InstrumentationLifecycleStrategy;
 import org.apache.camel.management.JmxSystemPropertyKeys;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
 import org.apache.camel.processor.interceptor.TraceFormatter;
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.InterceptStrategy;
@@ -92,6 +94,7 @@
     private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
     private Boolean trace;
     private ErrorHandlerBuilder errorHandlerBuilder;
+    private Map<String, DataFormatType> dataFormats = new HashMap<String, DataFormatType>();
 
     public DefaultCamelContext() {
         name = NAME_PREFIX + ++nameSuffix;
@@ -681,5 +684,11 @@
         return isStarted() && !isStarting();
     }
 
+    public void setDataFormats(Map<String, DataFormatType> dataFormats) {
+        this.dataFormats = dataFormats;
+    }
 
+    public Map<String, DataFormatType> getDataFormats() {
+        return dataFormats;
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java Mon Sep 15 10:02:12 2008
@@ -18,7 +18,9 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.camel.AsyncProcessor;
 import org.apache.camel.CamelContext;
@@ -32,10 +34,12 @@
 import org.apache.camel.model.FromType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
 import org.apache.camel.processor.Interceptor;
 import org.apache.camel.processor.Pipeline;
 import org.apache.camel.processor.ProceedProcessor;
 import org.apache.camel.processor.UnitOfWorkProcessor;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ErrorHandlerWrappingStrategy;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.RouteContext;
@@ -204,4 +208,13 @@
         routeAdded = b;
         
     }
+
+    public DataFormatType getDataFormat(String ref) {
+        Map<String, DataFormatType> dataFormats = getCamelContext().getDataFormats();
+        if (dataFormats != null) {
+            return dataFormats.get(ref);
+        } else {
+            return null;
+        }
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java Mon Sep 15 10:02:12 2008
@@ -60,6 +60,11 @@
         if (type == null) {
             notNull(ref, "ref or dataFormatType");
             DataFormat dataFormat = routeContext.lookup(ref, DataFormat.class);
+            
+            if (dataFormat == null) {
+                dataFormat = routeContext.getDataFormat(ref);
+            }
+            
             if (dataFormat instanceof DataFormatType) {
                 type = (DataFormatType)dataFormat;
             } else {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java?rev=695550&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java Mon Sep 15 10:02:12 2008
@@ -0,0 +1,57 @@
+package org.apache.camel.model.dataformat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Represents the XML type for a collection of DataFormats.
+ */
+@XmlRootElement(name = "dataFormats")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DataFormatsType {
+
+    // TODO cannot use @XmlElementRef as it doesn't allow optional properties
+    // @XmlElementRef    
+    @XmlElements({
+        @XmlElement(required = false, name = "artixDS", type = ArtixDSDataFormat.class),
+        @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
+        @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
+        @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
+        @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
+        @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
+        @XmlElement(required = false, name = "string", type = StringDataFormat.class),
+        @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
+        @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class)}
+        )
+    private List<DataFormatType> dataFormats;
+
+    
+    public void setDataFormats(List<DataFormatType> dataFormats) {
+        this.dataFormats = dataFormats;
+    }
+
+    public List<DataFormatType> getDataFormats() {
+        return dataFormats;
+    }
+
+    /***
+     * @return A Map of the contained DataFormatType's indexed by id.
+     */
+    public Map<String, DataFormatType> asMap() {
+        Map<String, DataFormatType> dataFormatsAsMap = new HashMap<String, DataFormatType>();
+        for (DataFormatType dataFormatType : getDataFormats()) {
+            dataFormatsAsMap.put(dataFormatType.getId(), dataFormatType);
+        }
+        return dataFormatsAsMap;
+    }    
+}

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

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java Mon Sep 15 10:02:12 2008
@@ -26,6 +26,7 @@
 import org.apache.camel.model.FromType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatType;
 
 /**
  * The context used to activate new routing rules
@@ -174,5 +175,12 @@
      * @return the flag
      */
     boolean isRouteAdded();
-
+    
+    /**
+     * Get a DataFormatType by ref name
+     *
+     * @param ref  the ref name to lookup
+     * @return the found object
+     */
+    DataFormatType getDataFormat(String ref);
 }

Modified: activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index Mon Sep 15 10:02:12 2008
@@ -19,6 +19,7 @@
 CsvDataFormat
 HL7DataFormat
 DataFormatType
+DataFormatsType
 JaxbDataFormat
 SerializationDataFormat
 StringDataFormat

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Sep 15 10:02:12 2008
@@ -17,6 +17,7 @@
 package org.apache.camel.spring;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -42,10 +43,12 @@
 import org.apache.camel.model.RouteBuilderRef;
 import org.apache.camel.model.RouteContainer;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.dataformat.DataFormatsType;
 import org.apache.camel.model.dataformat.DataFormatType;
 import org.apache.camel.processor.interceptor.Debugger;
 import org.apache.camel.processor.interceptor.TraceFormatter;
 import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.Registry;
 import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
@@ -54,7 +57,9 @@
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.context.ApplicationEvent;
@@ -96,8 +101,8 @@
     private List<RouteBuilderRef> builderRefs = new ArrayList<RouteBuilderRef>();
     @XmlElement(name = "endpoint", required = false)
     private List<EndpointFactoryBean> endpoints;
-    @XmlElementRef
-    private List<DataFormatType> dataFormats;
+    @XmlElement(name = "dataFormats", required = false)
+    private DataFormatsType dataFormats;
     @XmlElement(name = "intercept", required = false)
     private List<InterceptType> intercepts = new ArrayList<InterceptType>();
     @XmlElement(name = "route", required = false)
@@ -169,8 +174,8 @@
             if (beanPostProcessor instanceof CamelBeanPostProcessor) {
                 ((CamelBeanPostProcessor)beanPostProcessor).setCamelContext(getContext());
             }
-        }
-
+        }      
+        
         // setup the intercepts
         for (RouteType route : routes) {
 
@@ -205,7 +210,12 @@
                 }                
             }
 
+        }        
+        
+        if (dataFormats != null) {
+            getContext().setDataFormats(dataFormats.asMap());
         }
+        
         // lets force any lazy creation
         getContext().addRouteDefinitions(routes);
 
@@ -496,4 +506,12 @@
             finder.appendBuilders(additionalBuilders);
         }
     }
+
+    public void setDataFormats(DataFormatsType dataFormats) {
+        this.dataFormats = dataFormats;
+    }
+
+    public DataFormatsType getDataFormats() {
+        return dataFormats;
+    }
 }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=695550&r1=695549&r2=695550&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Mon Sep 15 10:02:12 2008
@@ -197,6 +197,7 @@
                 builder.addPropertyValue("id", contextId);
                 builder.addPropertyValue("routes", factoryBean.getRoutes());
                 builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
+                builder.addPropertyValue("dataFormats", factoryBean.getDataFormats());
                 builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());
 
                 if (factoryBean.getPackages().length > 0) {

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java?rev=695550&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/dataformat/SpringDataFormatWithNonChildElementTest.java Mon Sep 15 10:02:12 2008
@@ -0,0 +1,14 @@
+package org.apache.camel.spring.dataformat;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.spring.issues.StringDataFormatTest;
+
+public class SpringDataFormatWithNonChildElementTest extends StringDataFormatTest {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml");
+    }    
+}

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

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml?rev=695550&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/dataformat/dataFormatWithNonChildElementTest.xml Mon Sep 15 10:02:12 2008
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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
+    ">
+
+    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+        
+        <dataFormats>
+          <string id="xs" charset="utf-8"/>
+        </dataFormats> 
+                
+        <route>
+            <from uri="direct:marshal"/>
+            
+            <marshal ref="xs"/>
+            <to uri="mock:marshal"/>
+        </route>
+
+        <route>
+            <from uri="direct:unmarshal"/>
+            
+            <unmarshal ref="xs"/>
+            <to uri="mock:unmarshal"/>
+        </route>
+    </camelContext>
+
+</beans>