camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r567411 - in /activemq/camel/trunk: camel-core/src/test/java/org/apache/camel/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ components/camel-jaxb/src/main/resource...
Date Sun, 19 Aug 2007 14:41:41 GMT
Author: jstrachan
Date: Sun Aug 19 07:41:39 2007
New Revision: 567411

URL: http://svn.apache.org/viewvc?view=rev&rev=567411
Log:
added a JAXB marshalling support for Camel messages

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ExchangeTestSupport.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ExchangeType.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/HeaderType.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/IntegerHeader.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/LongHeader.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ObjectHeader.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/PropertyType.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/StringHeader.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/
    activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/
    activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/
    activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/
    activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/jaxb/
    activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/jaxb/jaxb.index
    activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/MessageTypeTest.java
  (with props)
Removed:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExpressionInjectionTest.java
Modified:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ExchangeTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ExchangeTestSupport.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ExchangeTestSupport.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ExchangeTestSupport.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * 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;
+
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * A base class for a test which requires a {@link CamelContext} and
+ * a populated {@link Exchange}
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ExchangeTestSupport extends ContextTestSupport {
+    protected Exchange exchange;
+
+    /**
+     * A factory method to create an Exchange implementation
+     */
+    protected Exchange createExchange() {
+        return new DefaultExchange(context);
+    }
+
+    /**
+     * A strategy method to populate an exchange with some example values for use
+     * by language plugins
+     */
+    protected void populateExchange(Exchange exchange) {
+        Message in = exchange.getIn();
+        in.setHeader("foo", "abc");
+        in.setHeader("bar", 123);
+        in.setBody("<hello id='m123'>world!</hello>");
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        exchange = createExchange();
+        assertNotNull("No exchange created!", exchange);
+        populateExchange(exchange);
+    }
+}

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

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java?view=diff&rev=567411&r1=567410&r2=567411
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java
Sun Aug 19 07:41:39 2007
@@ -22,9 +22,7 @@
  * A useful base class for testing the language plugins in Camel
  * @version $Revision: $
  */
-public abstract class LanguageTestSupport extends ContextTestSupport {
-    protected Exchange exchange;
-
+public abstract class LanguageTestSupport extends ExchangeTestSupport {
     protected abstract String getLanguageName();
 
 
@@ -61,32 +59,5 @@
      */
     protected void assertExpression(String expressionText, Object expectedValue) {
         assertExpression(exchange, expressionText, expectedValue);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        exchange = createExchange();
-        assertNotNull("No exchange created!", exchange);
-        populateExchange(exchange);
-    }
-
-    /**
-     * A factory method to create an Exchange implementation
-     */
-    protected Exchange createExchange() {
-        return new DefaultExchange(context);
-    }
-
-
-    /**
-     * A strategy method to populate an exchange with some example values for use
-     * by language plugins
-     */
-    protected void populateExchange(Exchange exchange) {
-        Message in = exchange.getIn();
-        in.setHeader("foo", "abc");
-        in.setHeader("bar", 123);
-        in.setBody("<hello id='m123'>world!</hello>");
     }
 }

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ExchangeType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ExchangeType.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ExchangeType.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ExchangeType.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @version $Revision: $
+ */
+@XmlRootElement(name = "exchange")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class ExchangeType {
+    @XmlElement(name = "property", required = false)
+    List<PropertyType> properties = new ArrayList<PropertyType>();
+    @XmlAnyElement(lax = true)
+    private Object body;
+
+    public Object getBody() {
+        return body;
+    }
+
+    public void setBody(Object body) {
+        this.body = body;
+    }
+
+    public List<PropertyType> getProperties() {
+        return properties;
+    }
+
+    public void setProperties(List<PropertyType> properties) {
+        this.properties = properties;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ExchangeType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java?view=diff&rev=567411&r1=567410&r2=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
(original)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
Sun Aug 19 07:41:39 2007
@@ -16,24 +16,23 @@
  */
 package org.apache.camel.converter.jaxb;
 
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.TypeConverterAware;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.util.JAXBSource;
 import javax.xml.transform.Source;
-
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.TypeConverter;
-import org.apache.camel.spi.TypeConverterAware;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
 
 /**
  * @version $Revision: 1.1 $
@@ -66,7 +65,8 @@
                 }
             }
             return null;
-        } catch (JAXBException e) {
+        }
+        catch (JAXBException e) {
             throw new RuntimeCamelException(e);
         }
     }
@@ -102,14 +102,14 @@
             }
         }
         if (value instanceof String) {
-            value = new StringReader((String)value);
+            value = new StringReader((String) value);
         }
         if (value instanceof InputStream) {
-            Object unmarshalled = unmarshaller.unmarshal((InputStream)value);
+            Object unmarshalled = unmarshaller.unmarshal((InputStream) value);
             return type.cast(unmarshalled);
         }
         if (value instanceof Reader) {
-            Object unmarshalled = unmarshaller.unmarshal((Reader)value);
+            Object unmarshalled = unmarshaller.unmarshal((Reader) value);
             return type.cast(unmarshalled);
         }
         return null;

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/HeaderType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/HeaderType.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/HeaderType.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/HeaderType.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * 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.jaxb;
+
+import org.apache.camel.Message;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Represents a JAXB2 representation of a Camel {@link Message} header
+ *
+ * @version $Revision: 1.1 $
+ */
+@XmlType(name = "headerType")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public abstract class HeaderType {
+    @XmlAttribute
+    private String name;
+
+    public HeaderType() {
+    }
+
+    protected HeaderType(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public abstract Object getValue();
+
+    public abstract void setValue(Object value);
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/HeaderType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/IntegerHeader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/IntegerHeader.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/IntegerHeader.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/IntegerHeader.java
Sun Aug 19 07:41:39 2007
@@ -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.converter.jaxb;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAccessType;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "intHeader")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class IntegerHeader extends HeaderType {
+    @XmlAttribute(name = "value")
+    private Integer number;
+
+    public IntegerHeader() {
+    }
+
+    public IntegerHeader(String name, Integer number) {
+        super(name);
+        this.number = number;
+    }
+
+    public Integer getNumber() {
+        return number;
+    }
+
+    public void setNumber(Integer number) {
+        this.number = number;
+    }
+
+    public Object getValue() {
+        return getNumber();
+    }
+
+    public void setValue(Object value) {
+        if (value instanceof Number) {
+            Number n = (Number) value;
+            setNumber(n.intValue());
+        }
+        else {
+            throw new IllegalArgumentException("Value must be an Integer");
+        }
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/IntegerHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java?view=diff&rev=567411&r1=567410&r2=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java
(original)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java
Sun Aug 19 07:41:39 2007
@@ -16,6 +16,13 @@
  */
 package org.apache.camel.converter.jaxb;
 
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.converter.HasAnnotation;
+import org.apache.camel.converter.jaxp.XmlConverter;
+import org.w3c.dom.Document;
+
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
@@ -23,11 +30,6 @@
 import javax.xml.bind.util.JAXBSource;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.w3c.dom.Document;
-
-import org.apache.camel.converter.HasAnnotation;
-import org.apache.camel.converter.jaxp.XmlConverter;
-
 /**
  * @version $Revision$
  */
@@ -45,12 +47,15 @@
         this.jaxbConverter = jaxbConverter;
     }
 
+    @Converter
     public static JAXBSource toSource(@HasAnnotation(XmlRootElement.class)Object value) throws
JAXBException {
         JAXBContext context = createJaxbContext(value);
         return new JAXBSource(context, value);
     }
 
-    public Document toDocument(@HasAnnotation(XmlRootElement.class)Object value) throws JAXBException,
ParserConfigurationException {
+    @Converter
+    public Document toDocument(
+            @HasAnnotation(XmlRootElement.class)Object value) throws JAXBException, ParserConfigurationException
{
         JAXBContext context = createJaxbContext(value);
         Marshaller marshaller = context.createMarshaller();
 
@@ -59,6 +64,18 @@
         return doc;
     }
 
+    @Converter
+    public static MessageType toMessageType(Exchange exchange) {
+        return toMessageType(exchange.getIn());
+    }
+
+    @Converter
+    public static MessageType toMessageType(Message in) {
+        MessageType answer = new MessageType();
+        answer.copyFrom(in);
+        return answer;
+    }
+
     protected static JAXBContext createJaxbContext(Object value) throws JAXBException {
         if (value == null) {
             throw new IllegalArgumentException("Cannot convert from null value to JAXBSource");
@@ -73,5 +90,4 @@
 //        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 //        marshaller.marshal(value, out);
 //    }
-
 }

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/LongHeader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/LongHeader.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/LongHeader.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/LongHeader.java
Sun Aug 19 07:41:39 2007
@@ -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.converter.jaxb;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAccessType;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "longHeader")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class LongHeader extends HeaderType {
+    @XmlAttribute(name = "value")
+    private Long number;
+
+    public LongHeader() {
+    }
+
+    public LongHeader(String name, Long number) {
+        super(name);
+        this.number = number;
+    }
+
+    public Long getNumber() {
+        return number;
+    }
+
+    public void setNumber(Long number) {
+        this.number = number;
+    }
+
+    public Object getValue() {
+        return getNumber();
+    }
+
+    public void setValue(Object value) {
+        if (value instanceof Number) {
+            Number n = (Number) value;
+            setNumber(n.longValue());
+        }
+        else {
+            throw new IllegalArgumentException("Value must be a Long");
+        }
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/LongHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ObjectHeader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ObjectHeader.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ObjectHeader.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ObjectHeader.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,49 @@
+/**
+ *
+ * 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.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "objectHeader")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class ObjectHeader extends HeaderType {
+    @XmlAnyElement(lax = true)
+    private Object value;
+
+    public ObjectHeader() {
+    }
+
+    public ObjectHeader(String name, Object value) {
+        super(name);
+        this.value = value;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ObjectHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/PropertyType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/PropertyType.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/PropertyType.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/PropertyType.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,52 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "property")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class PropertyType {
+    @XmlAttribute
+    private String key;
+    @XmlAnyElement(lax = true)
+    private Object value;
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/PropertyType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/StringHeader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/StringHeader.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/StringHeader.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/StringHeader.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,62 @@
+/**
+ *
+ * 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.jaxb;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAccessType;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "header")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class StringHeader extends HeaderType {
+    @XmlAttribute(name = "value", required = true)
+    private String text;
+
+    public StringHeader() {
+    }
+
+    public StringHeader(String name, String text) {
+        super(name);
+        this.text = text;
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public void setText(String text) {
+        this.text = text;
+    }
+
+    public Object getValue() {
+        return getText();
+    }
+
+    public void setValue(Object value) {
+        if (value instanceof String) {
+            setText((String) value);
+        }
+        else {
+            throw new IllegalArgumentException("Value must be a String");
+        }
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/StringHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/jaxb/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/jaxb/jaxb.index?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/jaxb/jaxb.index
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/resources/org/apache/camel/converter/jaxb/jaxb.index
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,7 @@
+ExchangeType
+HeaderType
+IntegerHeader
+LongHeader
+MessageType
+PropertyType
+StringHeader

Added: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/MessageTypeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/MessageTypeTest.java?view=auto&rev=567411
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/MessageTypeTest.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/MessageTypeTest.java
Sun Aug 19 07:41:39 2007
@@ -0,0 +1,58 @@
+/**
+ *
+ * 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.jaxb;
+
+import org.apache.camel.ExchangeTestSupport;
+import org.apache.camel.model.RouteContainer;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import java.io.StringWriter;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MessageTypeTest extends ExchangeTestSupport {
+    protected JAXBContext jaxbContext;
+
+    public void testCamelToJaxbUsingExplicitJaxbConverter() throws Exception {
+        MessageType messageType = JaxbConverter.toMessageType(exchange);
+
+        assertNotNull("Should have created a valid message Type");
+
+        log.info("headers: " + messageType.getHeaderMap());
+        log.info("body: " + messageType.getBody());
+        
+        dump(messageType);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        jaxbContext = JAXBContext.newInstance("org.apache.camel.converter.jaxb");
+    }
+
+    protected void dump(Object object) throws Exception {
+        Marshaller marshaller = jaxbContext.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+        StringWriter buffer = new StringWriter();
+        marshaller.marshal(object, buffer);
+        log.info("Created: " + buffer);
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/MessageTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message