camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r719864 - in /activemq/camel/trunk/components/camel-jaxb/src: main/java/org/apache/camel/converter/jaxb/ test/java/org/apache/camel/foo/ test/java/org/apache/camel/foo/bar/ test/java/org/apache/camel/jaxb/
Date Sat, 22 Nov 2008 15:34:18 GMT
Author: ningjiang
Date: Sat Nov 22 07:34:17 2008
New Revision: 719864

URL: http://svn.apache.org/viewvc?rev=719864&view=rev
Log:
CAMEL-1074 return the JAXBElement value by default

Added:
    activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/
    activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/
    activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/ObjectFactory.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/PersonType.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
  (with props)
Modified:
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java

Modified: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java?rev=719864&r1=719863&r2=719864&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
(original)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
Sat Nov 22 07:34:17 2008
@@ -21,6 +21,7 @@
 import java.io.OutputStream;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
@@ -39,6 +40,7 @@
     private JAXBContext context;
     private String contextPath;
     private boolean prettyPrint = true;
+    private boolean ignoreJAXBElement = true;
     private Marshaller marshaller;
     private Unmarshaller unmarshaller;
 
@@ -63,14 +65,26 @@
 
     public Object unmarshal(Exchange exchange, InputStream stream) throws IOException, ClassNotFoundException
{
         try {
-            return getUnmarshaller().unmarshal(stream);
+            Object answer = getUnmarshaller().unmarshal(stream);
+            if (answer instanceof JAXBElement && isIgnoreJAXBElement()) {
+                answer = ((JAXBElement)answer).getValue();
+            }
+            return answer;
         } catch (JAXBException e) {
             throw IOHelper.createIOException(e);
         }
-    }
+    }    
 
     // Properties
     // -------------------------------------------------------------------------
+    public boolean isIgnoreJAXBElement() {        
+        return ignoreJAXBElement;
+    }
+    
+    public void setIgnoreJAXBElement(boolean flag) {
+        ignoreJAXBElement = flag;
+    }
+    
     public JAXBContext getContext() throws JAXBException {
         if (context == null) {
             context = createContext();

Added: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/ObjectFactory.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/ObjectFactory.java?rev=719864&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/ObjectFactory.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/ObjectFactory.java
Sat Nov 22 07:34:17 2008
@@ -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.foo.bar;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlElementDecl;
+import javax.xml.bind.annotation.XmlRegistry;
+import javax.xml.namespace.QName;
+
+
+/**
+ * This object contains factory methods for each 
+ * Java content interface and Java element interface 
+ * generated in the org.apache.camel.foo.bar package. 
+ * <p>An ObjectFactory allows you to programatically 
+ * construct new instances of the Java representation 
+ * for XML content. The Java representation of XML 
+ * content can consist of schema derived interfaces 
+ * and classes representing the binding of schema 
+ * type definitions, element declarations and model 
+ * groups.  Factory methods for each of these are 
+ * provided in this class.
+ * 
+ */
+@XmlRegistry
+public class ObjectFactory {
+
+    private final QName personQNAME = new QName("", "Person");
+
+    /**
+     * Create a new ObjectFactory that can be used to create new instances of schema derived
classes for package: com.foo.bar
+     * 
+     */
+    public ObjectFactory() {
+    }
+
+    /**
+     * Create an instance of {@link PersonType }
+     * 
+     */
+    public PersonType createPersonType() {
+        return new PersonType();
+    }
+
+    /**
+     * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}}
+     */ 
+     
+    @XmlElementDecl(namespace = "", name = "Person")
+    public JAXBElement<PersonType> createPerson(PersonType value) {
+        return new JAXBElement<PersonType>(personQNAME, PersonType.class, null, value);
+    }
+
+}

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

Propchange: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/ObjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/PersonType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/PersonType.java?rev=719864&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/PersonType.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/PersonType.java
Sat Nov 22 07:34:17 2008
@@ -0,0 +1,123 @@
+/**
+ * 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.foo.bar;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.camel.util.ObjectHelper;
+
+
+/**
+ * <p>Java class for PersonType complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within
this class.
+ * 
+ * <pre>
+ * &lt;complexType name="PersonType">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="firstName" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         &lt;element name="lastName" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *       &lt;/sequence>
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+@XmlRootElement(name = "Person")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "PersonType", propOrder = {"firstName", "lastName"})
+public class PersonType {
+
+    @XmlElement(required = true)
+    protected String firstName;
+    @XmlElement(required = true)
+    protected String lastName;
+
+    /**
+     * Gets the value of the firstName property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getFirstName() {
+        return firstName;
+    }
+
+    /**
+     * Sets the value of the firstName property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setFirstName(String value) {
+        this.firstName = value;
+    }
+
+    /**
+     * Gets the value of the lastName property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getLastName() {
+        return lastName;
+    }
+
+    /**
+     * Sets the value of the lastName property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setLastName(String value) {
+        this.lastName = value;
+    }
+   
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof PersonType) {
+            PersonType that = (PersonType)o;
+            return ObjectHelper.equal(this.firstName, that.firstName) 
+                && ObjectHelper.equal(this.lastName, that.lastName);            
    
+        }
+        return false;
+    }
+    
+    @Override
+    public int hashCode() {
+        return firstName.hashCode() + lastName.hashCode() * 100;
+    }
+    
+
+}

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

Propchange: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/foo/bar/PersonType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java?rev=719864&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
Sat Nov 22 07:34:17 2008
@@ -0,0 +1,67 @@
+/**
+ * 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.jaxb;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxb.JaxbDataFormat;
+import org.apache.camel.foo.bar.PersonType;
+
+
+public class CamelJaxbTest extends ContextTestSupport {
+    
+    public void testConvertor() throws Exception {
+        TypeConverter converter = context.getTypeConverter();
+        PersonType person = converter.convertTo(PersonType.class, 
+            "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>");
+        assertNotNull("Person should not be null ", person);
+        assertEquals("Get the wrong first name ", person.getFirstName(), "FOO");
+        assertEquals("Get the wrong second name ", person.getLastName(), "BAR");
+    }
+
+    public void testUnmarshal() throws Exception {
+        final String xml = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>";
+        PersonType expected = new PersonType();
+        expected.setFirstName("FOO");
+        expected.setLastName("BAR");
+        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+        resultEndpoint.expectedBodiesReceived(expected);
+
+        template.sendBody("direct:start", xml);
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            public void configure() throws Exception {
+                JaxbDataFormat dataFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
+                dataFormat.setIgnoreJAXBElement(true);
+                from("direct:start")
+                    .unmarshal(dataFormat)                        
+                        .to("mock:result");
+            }
+        };
+    }
+    
+}

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

Propchange: activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message