camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r903252 - in /camel/trunk: components/ components/camel-dozer/ components/camel-dozer/src/ components/camel-dozer/src/main/ components/camel-dozer/src/main/java/ components/camel-dozer/src/main/java/org/ components/camel-dozer/src/main/java...
Date Tue, 26 Jan 2010 15:02:57 GMT
Author: janstey
Date: Tue Jan 26 15:02:56 2010
New Revision: 903252

URL: http://svn.apache.org/viewvc?rev=903252&view=rev
Log:
CAMEL-2399 - Add type converter for the Dozer framework. Thanks to Stephen Gargan for this!


Added:
    camel/trunk/components/camel-dozer/
    camel/trunk/components/camel-dozer/pom.xml
    camel/trunk/components/camel-dozer/src/
    camel/trunk/components/camel-dozer/src/main/
    camel/trunk/components/camel-dozer/src/main/java/
    camel/trunk/components/camel-dozer/src/main/java/org/
    camel/trunk/components/camel-dozer/src/main/java/org/apache/
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverter.java
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
    camel/trunk/components/camel-dozer/src/test/
    camel/trunk/components/camel-dozer/src/test/java/
    camel/trunk/components/camel-dozer/src/test/java/org/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/CustomerProcessor.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTestArtifactsFactory.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/service/
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/service/Customer.java
    camel/trunk/components/camel-dozer/src/test/resources/
    camel/trunk/components/camel-dozer/src/test/resources/application-context.xml
    camel/trunk/components/camel-dozer/src/test/resources/mapping.xml
Modified:
    camel/trunk/components/pom.xml
    camel/trunk/parent/pom.xml

Added: camel/trunk/components/camel-dozer/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/pom.xml?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/pom.xml (added)
+++ camel/trunk/components/camel-dozer/pom.xml Tue Jan 26 15:02:56 2010
@@ -0,0 +1,64 @@
+<?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.
+-->
+<project>
+  <parent>
+    <artifactId>components</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>2.2-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>camel-dozer</artifactId>
+ 
+  <name>Camel :: Dozer</name>
+  <description>Camel Support for the Dozer type conversion framework</description>
+  
+  <properties>
+    <camel.osgi.export.pkg>org.apache.camel.converter.dozer.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency> 
+    <dependency>
+      <groupId>net.sf.dozer</groupId>
+      <artifactId>dozer</artifactId>
+    </dependency>     
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+    </dependency>      
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>      
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+</project>

Added: camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverter.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverter.java
(added)
+++ camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverter.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,61 @@
+/**
+ * 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.converter.dozer;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConverter;
+import org.dozer.DozerBeanMapper;
+import org.dozer.Mapper;
+
+/**
+ * <code>DozerTypeConverter</code> is a standard {@link TypeConverter} that
+ * delegates to a {@link Mapper} from the Dozer framework to convert between
+ * types. <code>DozerTypeConverter</code>s are created and installed into a
+ * {@link CamelContext} by an instance of {@link DozerTypeConverterLoader}.
+ * <p>
+ * See http://dozer.sourceforge.net} or more information on
+ * configuring Dozer
+ *
+ * @see DozerTypeConverterLoader
+ */
+public class DozerTypeConverter implements TypeConverter {
+
+    private DozerBeanMapper mapper;
+
+    public DozerTypeConverter(DozerBeanMapper mapper) {
+        this.mapper = mapper;
+    }
+
+    public <T> T convertTo(Class<T> type, Object value) {
+        return mapper.map(value, type);
+    }
+
+    public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) throws NoTypeConversionAvailableException
{
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object
value) throws NoTypeConversionAvailableException {
+        return convertTo(type, value);
+    }
+
+}

Added: camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
(added)
+++ camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,130 @@
+/**
+ * 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.converter.dozer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.dozer.DozerBeanMapper;
+import org.dozer.Mapper;
+import org.dozer.classmap.ClassMap;
+import org.dozer.loader.CustomMappingsLoader;
+import org.dozer.loader.LoadMappingsResult;
+
+/**
+ * <code>DozerTypeConverterLoader</code> provides the mechanism for registering
+ * a Dozer {@link Mapper} as {@link TypeConverter} for a {@link CamelContext}.
+ * <p>
+ * While a mapper can be explicitly supplied as a parameter the
+ * {@link CamelContext}'s registry will also be searched for {@link Mapper}
+ * instances. A {@link DozerTypeConverter} is created to wrap each
+ * {@link Mapper} instance and the mapper is queried for the types it converts.
+ * The queried types are used to register the {@link TypeConverter} with the
+ * context via its {@link TypeConverterRegistry}.
+ */
+public class DozerTypeConverterLoader implements CamelContextAware {
+
+    private final Log log = LogFactory.getLog(getClass());
+    private CamelContext camelContext;
+
+    /**
+     * Creates a <code>DozerTypeConverter</code> performing no
+     * {@link TypeConverter} registration.
+     */
+    public DozerTypeConverterLoader() {
+    }
+
+    /**
+     * Creates a <code>DozerTypeConverter</code> that will search the given
+     * {@link CamelContext} for instances of {@link DozerBeanMapper}. Each
+     * discovered instance will be wrapped as a {@link DozerTypeConverter} and
+     * register as a {@link TypeConverter} with the context
+     *
+     * @param camelContext the context to register the
+     *            {@link DozerTypeConverter} in
+     */
+    public DozerTypeConverterLoader(CamelContext camelContext) {
+        init(camelContext, null);
+    }
+
+    /**
+     * Creates a <code>DozerTypeConverter</code> that will wrap the the given
+     * {@link DozerBeanMapper} as a {@link DozerTypeConverter} and register it
+     * with the given context. It will also search the context for
+     *
+     * @param camelContext the context to register the
+     *            {@link DozerTypeConverter} in
+     * @param mapper the DozerMapperBean to be wrapped as a type converter.
+     */
+    public DozerTypeConverterLoader(CamelContext camelContext, DozerBeanMapper mapper) {
+        init(camelContext, mapper);
+    }
+
+    /**
+     * Doses the actual querying and registration of {@link DozerTypeConverter}s
+     * with the {@link CamelContext}.
+     *
+     * @param camelContext the context to register the
+     *            {@link DozerTypeConverter} in
+     * @param mapper the DozerMapperBean to be wrapped as a type converter.
+     */
+    public void init(CamelContext camelContext, DozerBeanMapper mapper) {
+        this.camelContext = camelContext;
+        Map<String, DozerBeanMapper> mappers = new HashMap<String, DozerBeanMapper>(camelContext.getRegistry().lookupByType(DozerBeanMapper.class));
+        if (mapper != null) {
+            mappers.put("parameter", mapper);
+        }
+        if (mappers.size() > 0) {
+            log.warn("Loaded %d dozer mappers from Camel's registry. Dozer is most efficient
when there is a single mapper instance. Consider amalgamating instances.");
+        }
+
+        TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
+        for (DozerBeanMapper dozer : mappers.values()) {
+            Map<String, ClassMap> all = loadMappings(dozer);
+            DozerTypeConverter converter = new DozerTypeConverter(dozer);
+            for (ClassMap map : all.values()) {
+                registry.addTypeConverter(map.getSrcClassToMap(), map.getDestClassToMap(),
converter);
+                registry.addTypeConverter(map.getDestClassToMap(), map.getSrcClassToMap(),
converter);
+            }
+        }
+    }
+
+    private Map<String, ClassMap> loadMappings(DozerBeanMapper mapper) {
+        // TODO: This is a little wasteful as dozer has already parsed this
+        // information, if does not expose it though so it must be done again.
+        // Create a patch for Dozer to expose this.
+        CustomMappingsLoader customMappingsLoader = new CustomMappingsLoader();
+        LoadMappingsResult loadMappingsResult = customMappingsLoader.load(mapper.getMappingFiles());
+        Map<String, ClassMap> all = loadMappingsResult.getCustomMappings().getAll();
+        return all;
+    }
+
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    public void setCamelContext(CamelContext camelContext) {
+        init(camelContext, null);
+    }
+
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/CustomerProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/CustomerProcessor.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/CustomerProcessor.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/CustomerProcessor.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,29 @@
+/**
+ * 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.converter.dozer;
+
+import org.apache.camel.converter.dozer.model.Customer;
+
+import static org.junit.Assert.assertEquals;
+
+public class CustomerProcessor {
+
+    public Customer processCustomer(Customer customer) {
+        assertEquals(DozerTestArtifactsFactory.createModelCustomer(), customer);
+        return customer;
+    }
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTestArtifactsFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTestArtifactsFactory.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTestArtifactsFactory.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTestArtifactsFactory.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,42 @@
+/**
+ * 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.converter.dozer;
+
+import java.util.Arrays;
+
+import org.apache.camel.converter.dozer.model.Address;
+import org.apache.camel.converter.dozer.service.Customer;
+import org.dozer.DozerBeanMapper;
+
+public final class DozerTestArtifactsFactory {
+    
+    private DozerTestArtifactsFactory() {
+    }
+    
+    public static Customer createServiceCustomer() {
+        return new Customer("Bob", "Roberts", "12345", "1 main st");
+    }
+
+    public static org.apache.camel.converter.dozer.model.Customer createModelCustomer() {
+        return new org.apache.camel.converter.dozer.model.Customer("Bob", "Roberts", new
Address("12345", "1 main st"));
+    }
+
+    public static DozerBeanMapper createMapper() {
+        return new DozerBeanMapper(Arrays.asList(new String[]{"mapping.xml"}));
+    }
+
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,71 @@
+/**
+ * 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.converter.dozer;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.dozer.service.Customer;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.dozer.Mapper;
+import org.junit.Test;
+
+import static org.apache.camel.converter.dozer.DozerTestArtifactsFactory.createMapper;
+import static org.apache.camel.converter.dozer.DozerTestArtifactsFactory.createServiceCustomer;
+
+public class DozerTypeConverterTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        new DozerTypeConverterLoader(context, createMapper());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                from("direct:service-in").bean(new CustomerProcessor()).to("mock:verify-model");
+            }
+        };
+    }
+
+    @Test
+    public void verifyCamelConversionViaDozer() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:verify-model");
+        mock.expectedMessageCount(1);
+        template.sendBody("direct:service-in", createServiceCustomer());
+        mock.await(5, TimeUnit.SECONDS);
+        mock.assertIsSatisfied();
+    }
+
+    @Test
+    public void verifyCustomerMapping() throws Exception {
+
+        Mapper mapper = DozerTestArtifactsFactory.createMapper();
+        Customer service = createServiceCustomer();
+        org.apache.camel.converter.dozer.model.Customer model = mapper.map(service, org.apache.camel.converter.dozer.model.Customer.class);
+        Customer roundTrip = mapper.map(model, Customer.class);
+        assertEquals(service, roundTrip);
+    }
+
+
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,44 @@
+/**
+ * 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.converter.dozer;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.apache.camel.converter.dozer.DozerTestArtifactsFactory.createServiceCustomer;
+
+public class SpringDozerTypeConverterTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("application-context.xml");
+    }
+
+    @Test
+    public void verifyCamelConversionViaDozer() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:verify-model");
+        mock.expectedMessageCount(1);
+        template.sendBody("direct:service-in", createServiceCustomer());
+        mock.await(5, TimeUnit.SECONDS);
+        mock.assertIsSatisfied();
+    }
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,68 @@
+/**
+ * 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.converter.dozer.model;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+public class Address {
+
+    private String zipCode;
+
+    private String streetName;
+
+    public Address() {
+    }
+
+    public Address(String zipCode, String streetName) {
+
+        this.zipCode = zipCode;
+        this.streetName = streetName;
+    }
+
+    public String getZipCode() {
+        return zipCode;
+    }
+
+    public void setZipCode(String zipCode) {
+        this.zipCode = zipCode;
+    }
+
+    public String getStreetName() {
+        return streetName;
+    }
+
+    public void setStreetName(String streetName) {
+        this.streetName = streetName;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return EqualsBuilder.reflectionEquals(this, obj);
+    }
+
+    @Override
+    public int hashCode() {
+        return HashCodeBuilder.reflectionHashCode(this);
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
+    }
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,79 @@
+/**
+ * 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.converter.dozer.model;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+public class Customer {
+    private String firstName;
+
+    private String lastName;
+
+    private Address address;
+
+    public Customer() {
+    }
+
+    public Customer(String firstName, String lastName, Address address) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.address = address;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public Address getAddress() {
+        return address;
+    }
+
+    public void setAddress(Address address) {
+        this.address = address;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return EqualsBuilder.reflectionEquals(this, obj);
+    }
+
+    @Override
+    public int hashCode() {
+        return HashCodeBuilder.reflectionHashCode(this);
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
+    }
+
+
+}

Added: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/service/Customer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/service/Customer.java?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/service/Customer.java
(added)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/service/Customer.java
Tue Jan 26 15:02:56 2010
@@ -0,0 +1,90 @@
+/**
+ * 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.converter.dozer.service;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+public class Customer {
+
+    private String firstName;
+
+    private String lastName;
+
+    private String street;
+
+    private String zip;
+
+    public Customer() {
+    }
+
+    public Customer(String firstName, String lastName, String zip, String street) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.zip = zip;
+        this.street = street;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getStreet() {
+        return street;
+    }
+
+    public void setStreet(String street) {
+        this.street = street;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return EqualsBuilder.reflectionEquals(this, obj);
+    }
+
+    @Override
+    public int hashCode() {
+        return HashCodeBuilder.reflectionHashCode(this);
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
+    }
+
+}

Added: camel/trunk/components/camel-dozer/src/test/resources/application-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/resources/application-context.xml?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/resources/application-context.xml (added)
+++ camel/trunk/components/camel-dozer/src/test/resources/application-context.xml Tue Jan
26 15:02:56 2010
@@ -0,0 +1,40 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+  
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:service-in" />
+      <to uri="bean:customer-processor" />
+      <to uri="mock:verify-model" />
+    </route>
+  </camelContext>
+  
+  <bean id="customer-processor"  class="org.apache.camel.converter.dozer.CustomerProcessor"
/>
+  <bean id="dozerConverterLoader"  class="org.apache.camel.converter.dozer.DozerTypeConverterLoader"
/>
+  
+  <bean id="mapper" class="org.dozer.DozerBeanMapper">
+    <property name="mappingFiles">
+      <list>
+        <value>mapping.xml</value>
+      </list>
+    </property>
+  </bean>
+</beans>
\ No newline at end of file

Added: camel/trunk/components/camel-dozer/src/test/resources/mapping.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/resources/mapping.xml?rev=903252&view=auto
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/resources/mapping.xml (added)
+++ camel/trunk/components/camel-dozer/src/test/resources/mapping.xml Tue Jan 26 15:02:56
2010
@@ -0,0 +1,32 @@
+<?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.
+-->
+<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://dozer.sourceforge.net  http://dozer.sourceforge.net/schema/beanmapping.xsd">
+  <mapping>
+    <class-a>org.apache.camel.converter.dozer.service.Customer</class-a>
+    <class-b>org.apache.camel.converter.dozer.model.Customer</class-b>
+    <field>
+      <a>street</a>
+      <b>address.streetName</b>
+    </field>
+    <field>
+      <a>zip</a>
+      <b>address.zipCode</b>
+    </field>
+  </mapping>
+</mappings>
\ No newline at end of file

Modified: camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=903252&r1=903251&r2=903252&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Tue Jan 26 15:02:56 2010
@@ -42,6 +42,7 @@
     <module>camel-castor</module>
     <module>camel-csv</module>
     <module>camel-cxf</module>
+    <module>camel-dozer</module>
     <module>camel-flatpack</module>
     <module>camel-freemarker</module>
     <module>camel-ftp</module>

Modified: camel/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=903252&r1=903251&r2=903252&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Tue Jan 26 15:02:56 2010
@@ -38,9 +38,21 @@
     <activemq-version>5.3.0</activemq-version>
     <apacheds-version>1.5.4</apacheds-version>
     <axiom-version>1.2.8</axiom-version>
+    <cometd-bayeux-version>6.1.11</cometd-bayeux-version>
+    <commons-io-version>1.3.2</commons-io-version>
+    <commons-logging-version>1.1.1</commons-logging-version>
+    <commons-logging-api-version>1.1</commons-logging-api-version>
+    <commons-collections-version>3.2.1</commons-collections-version>
+    <commons-pool-version>1.4</commons-pool-version>
+    <commons-dbcp-version>1.2.2</commons-dbcp-version>
     <cxf-version>2.2.6</cxf-version>
+    <derby-version>10.4.2.0</derby-version>
+    <dozer-version>5.2.0</dozer-version>
+    <easymock-version>2.5.2</easymock-version>
     <felix-osgi-version>1.2.0</felix-osgi-version>
+    <flatpack-version>3.1.1</flatpack-version>
     <fuse-commons-management-version>1.0</fuse-commons-management-version>
+    <freemarker-version>2.3.15</freemarker-version>
     <geronimo-el-spec-version>1.0.1</geronimo-el-spec-version>
     <geronimo-j2ee-connector-spec-version>2.0.0</geronimo-j2ee-connector-spec-version>
     <geronimo-j2ee-jacc-spec-version>1.1</geronimo-j2ee-jacc-spec-version>
@@ -50,55 +62,48 @@
     <geronimo-jsp-spec-version>1.0.1</geronimo-jsp-spec-version>
     <geronimo-jta-spec-version>1.1.1</geronimo-jta-spec-version>
     <geronimo-servlet-spec-version>1.1.1</geronimo-servlet-spec-version>
+    <groovy-version>1.7.0</groovy-version>
+    <guiceyfruit-version>2.0</guiceyfruit-version>
+    <hamcrest-version>1.2-dev1</hamcrest-version>
+    <hibernate-version>3.2.6.ga</hibernate-version>
+    <hibernate-entitymanager-version>3.2.1.ga</hibernate-entitymanager-version>
+    <hsqldb-version>1.8.0.7</hsqldb-version>
+    <httpunit-version>1.6.2</httpunit-version>
     <httpcore-version>4.0</httpcore-version>
     <httpclient-version>3.1</httpclient-version>
-    <jetty-version>6.1.19</jetty-version>
-    <slf4j-version>1.5.8</slf4j-version>
-    <openjpa-version>1.2.1</openjpa-version>
-    <jruby-version>1.2.0</jruby-version>
-    <spring-version>2.5.6</spring-version>
-    <spring-osgi-version>1.2.0</spring-osgi-version>
-    <mina-version>1.1.7</mina-version>
+    <javamail-version>1.4.1</javamail-version>
     <javax-mail-version>1.4.1_2</javax-mail-version>
     <jaxb-version>2.1.12</jaxb-version>
     <jaxb-api-version>2.1</jaxb-api-version>
-    <stax-api-version>1.0.1</stax-api-version>
-    <log4j-version>1.2.14</log4j-version>
-    <lucene-version>3.0.0</lucene-version>
-    <cometd-bayeux-version>6.1.11</cometd-bayeux-version>
-    <commons-io-version>1.3.2</commons-io-version>
-    <commons-logging-version>1.1.1</commons-logging-version>
-    <commons-logging-api-version>1.1</commons-logging-api-version>
-    <commons-collections-version>3.2.1</commons-collections-version>
-    <commons-pool-version>1.4</commons-pool-version>
-    <commons-dbcp-version>1.2.2</commons-dbcp-version>
-    <derby-version>10.4.2.0</derby-version>
-    <easymock-version>2.5.2</easymock-version>
-    <mockito-version>1.8.2</mockito-version>
-    <flatpack-version>3.1.1</flatpack-version>
-    <freemarker-version>2.3.15</freemarker-version>
-    <hamcrest-version>1.2-dev1</hamcrest-version>
-    <hibernate-version>3.2.6.ga</hibernate-version>
-    <hibernate-entitymanager-version>3.2.1.ga</hibernate-entitymanager-version>
-    <httpunit-version>1.6.2</httpunit-version>
-    <hsqldb-version>1.8.0.7</hsqldb-version>
+    <jetty-version>6.1.19</jetty-version>
     <jettison-version>1.2</jettison-version>
-    <groovy-version>1.7.0</groovy-version>
-    <guiceyfruit-version>2.0</guiceyfruit-version>
+    <jruby-version>1.2.0</jruby-version>
+    <juel-version>2.1.2</juel-version>
     <!-- spring 2.5.x is only compatible with junit 4.4 or lower - see SPR-5145 -->
     <junit-version>4.4</junit-version>
+    <log4j-version>1.2.14</log4j-version>
+    <lucene-version>3.0.0</lucene-version>
+    <mina-version>1.1.7</mina-version>
+    <mockito-version>1.8.2</mockito-version>
     <ognl-version>2.7.3_1</ognl-version>
+    <openjpa-version>1.2.1</openjpa-version>
     <pax-exam-version>1.2.0</pax-exam-version>
     <pax-tiny-bundle-version>1.2.0</pax-tiny-bundle-version>
     <qpid-version>0.5.0</qpid-version>
+    <quartz-version>1.6.6</quartz-version>
     <restlet-version>1.1.5</restlet-version>
     <saxon-version>9.1.0.1</saxon-version>
     <scala-version>2.7.7</scala-version>
     <scala-plugin-version>2.9.1</scala-plugin-version>
+    <slf4j-version>1.5.8</slf4j-version>
     <smack-version>3.0.4</smack-version>
+    <snmp4j-version>1.8.1_1</snmp4j-version>
     <spring-ehcache-version>1.6.2</spring-ehcache-version>
     <spring-integration-version>1.0.3.RELEASE</spring-integration-version>
     <spring-javaconfig-version>1.0.0-20090215</spring-javaconfig-version>
+    <spring-version>2.5.6</spring-version>
+    <spring-osgi-version>1.2.0</spring-osgi-version>
+    <stax-api-version>1.0.1</stax-api-version>
     <stringtemplate-version>3.0</stringtemplate-version>
     <tagsoup-version>1.2</tagsoup-version>
     <testng-version>5.8</testng-version>
@@ -106,13 +111,9 @@
     <xbean-spring-version>3.5</xbean-spring-version>
     <xstream-version>1.3.1</xstream-version>
     <xmlsec-version>1.4.2</xmlsec-version>
-    <javamail-version>1.4.1</javamail-version>
     <xerces-version>2.8.1</xerces-version>
     <xalan-version>2.7.1</xalan-version>
     <xmlbeans-version>2.4.0</xmlbeans-version>
-    <snmp4j-version>1.8.1_1</snmp4j-version>
-    <quartz-version>1.6.6</quartz-version>
-    <juel-version>2.1.2</juel-version>
 
     <!-- OSGi bundles properties -->
     <camel.osgi.import.camel.version>version="[$(version;==;${camel.osgi.version.clean}),$(version;=+;${camel.osgi.version.clean}))"</camel.osgi.import.camel.version>
@@ -242,6 +243,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-dozer</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-freemarker</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -866,6 +872,13 @@
         <artifactId>guiceyfruit-junit3</artifactId>
         <version>${guiceyfruit-version}</version>
       </dependency>
+      
+      <!-- optional dozer dependencies -->
+      <dependency>
+        <groupId>net.sf.dozer</groupId>
+        <artifactId>dozer</artifactId>
+        <version>${dozer-version}</version>
+      </dependency>
 
       <!-- optional mina dependencies -->
       <dependency>



Mime
View raw message