You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2007/04/05 19:10:25 UTC

svn commit: r525892 - in /activemq/camel/trunk/camel-jaxb: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/camel/ src/main/java/org/apache/camel/converter/ src/main/java/org/apache/camel/converter/...

Author: jstrachan
Date: Thu Apr  5 10:10:23 2007
New Revision: 525892

URL: http://svn.apache.org/viewvc?view=rev&rev=525892
Log:
added a really simple start of a JAXB2 module

Added:
    activemq/camel/trunk/camel-jaxb/
    activemq/camel/trunk/camel-jaxb/pom.xml   (with props)
    activemq/camel/trunk/camel-jaxb/src/
    activemq/camel/trunk/camel-jaxb/src/main/
    activemq/camel/trunk/camel-jaxb/src/main/java/
    activemq/camel/trunk/camel-jaxb/src/main/java/org/
    activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/
    activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/
    activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/
    activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/
    activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java   (with props)
    activemq/camel/trunk/camel-jaxb/src/main/resources/
    activemq/camel/trunk/camel-jaxb/src/test/
    activemq/camel/trunk/camel-jaxb/src/test/java/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/converter/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/
    activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java   (with props)
    activemq/camel/trunk/camel-jaxb/src/test/resources/

Added: activemq/camel/trunk/camel-jaxb/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jaxb/pom.xml?view=auto&rev=525892
==============================================================================
--- activemq/camel/trunk/camel-jaxb/pom.xml (added)
+++ activemq/camel/trunk/camel-jaxb/pom.xml Thu Apr  5 10:10:23 2007
@@ -0,0 +1,96 @@
+<?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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-jaxb</artifactId>
+  <name>Camel :: JAXB</name>
+  <description>Camel JAXB support</description>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.xml</groupId>
+      <artifactId>jaxb-api</artifactId>
+      <version>2.0</version>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.xml</groupId>
+          <artifactId>jsr173</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.activation</groupId>
+          <artifactId>activation</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>stax</groupId>
+      <artifactId>stax-api</artifactId>
+      <version>1.0.1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.sun.xml.bind</groupId>
+      <artifactId>jaxb-impl</artifactId>
+      <version>2.0.1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.xml</groupId>
+          <artifactId>jsr173</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.jws</groupId>
+          <artifactId>jsr181-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.activation</groupId>
+          <artifactId>activation</artifactId>
+        </exclusion>
+      </exclusions>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Propchange: activemq/camel/trunk/camel-jaxb/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jaxb/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jaxb/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java?view=auto&rev=525892
==============================================================================
--- activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java (added)
+++ activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java Thu Apr  5 10:10:23 2007
@@ -0,0 +1,78 @@
+/**
+ *
+ * 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.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;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * @version $Revision$
+ */
+public class JaxbConverter {
+    private XmlConverter jaxbConverter;
+
+    public XmlConverter getJaxbConverter() {
+        if (jaxbConverter == null) {
+            jaxbConverter = new XmlConverter();
+        }
+        return jaxbConverter;
+    }
+
+    public void setJaxbConverter(XmlConverter jaxbConverter) {
+        this.jaxbConverter = jaxbConverter;
+    }
+
+    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 {
+        JAXBContext context = createJaxbContext(value);
+        Marshaller marshaller = context.createMarshaller();
+
+        Document doc = getJaxbConverter().createDocument();
+        marshaller.marshal(value, doc);
+        return doc;
+    }
+
+    protected static JAXBContext createJaxbContext(Object value) throws JAXBException {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot convert from null value to JAXBSource");
+        }
+        JAXBContext context = JAXBContext.newInstance(value.getClass());
+        return context;
+    }
+
+/*
+    public void write(OutputStream out, Object value) throws JAXBException {
+        JAXBContext context = JAXBContext.newInstance(value.getClass());
+        Marshaller marshaller = context.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+		marshaller.marshal(value, out);
+    }
+*/
+}

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

Propchange: activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java?view=auto&rev=525892
==============================================================================
--- activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java (added)
+++ activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java Thu Apr  5 10:10:23 2007
@@ -0,0 +1,54 @@
+/**
+ *
+ * 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.example;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @version $Revision$
+ */
+@XmlRootElement
+public class PurchaseOrder {
+    private String name;
+    private double price;
+    private double amount;
+
+    public double getAmount() {
+        return amount;
+    }
+
+    public void setAmount(double amount) {
+        this.amount = amount;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public double getPrice() {
+        return price;
+    }
+
+    public void setPrice(double price) {
+        this.price = price;
+    }
+}

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

Propchange: activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jaxb/src/test/java/org/apache/camel/example/PurchaseOrder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain