camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r582840 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/spi/ camel-core/src/main/java/org/apache/camel/util/ componen...
Date Mon, 08 Oct 2007 15:11:14 GMT
Author: jstrachan
Date: Mon Oct  8 08:11:12 2007
New Revision: 582840

URL: http://svn.apache.org/viewvc?rev=582840&view=rev
Log:
added an initial cut of a marshaller implementation using serialization and JAXB2 for CAMEL-165

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationMarshaller.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationUnmarshaller.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java   (with
props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbMarshaller.java
  (with props)
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbUnmarshaller.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Unmarshaller.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=582840&r1=582839&r2=582840&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
Mon Oct  8 08:11:12 2007
@@ -154,4 +154,23 @@
         return new ByteArrayInputStream(data);
     }
 
+    @Converter
+    public static ObjectOutput toObjectOutput(OutputStream stream) throws IOException {
+        if (stream instanceof ObjectOutput) {
+            return (ObjectOutput) stream;
+        }
+        else {
+            return new ObjectOutputStream(stream);
+        }
+    }
+
+    @Converter
+    public static ObjectInput toObjectInput(InputStream stream) throws IOException {
+        if (stream instanceof ObjectInput) {
+            return (ObjectInput) stream;
+        }
+        else {
+            return new ObjectInputStream(stream);
+        }
+    }
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationMarshaller.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationMarshaller.java?rev=582840&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationMarshaller.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationMarshaller.java
Mon Oct  8 08:11:12 2007
@@ -0,0 +1,39 @@
+/**
+ *
+ * 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.impl;
+
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.OutputStream;
+
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.spi.Marshaller;
+
+/**
+ * A {@link Marshaller} which uses Java Object Serialization
+ *
+ * @version $Revision: 1.1 $
+ */
+public class SerializationMarshaller implements Marshaller {
+
+    public void marshal(Object graph, OutputStream stream) throws IOException {
+        ObjectOutput out = IOConverter.toObjectOutput(stream);
+        out.writeObject(graph);
+        out.flush();
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationUnmarshaller.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationUnmarshaller.java?rev=582840&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationUnmarshaller.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationUnmarshaller.java
Mon Oct  8 08:11:12 2007
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.spi.Unmarshaller;
+
+/**
+ * A {@link Unmarshaller} which uses Java Object Serialization
+ *
+ * @version $Revision: 1.1 $
+ */
+public class SerializationUnmarshaller implements Unmarshaller {
+
+    public Object unmarshal(InputStream stream) throws IOException, ClassNotFoundException
{
+        ObjectInput in = IOConverter.toObjectInput(stream);
+        return in.readObject();
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationUnmarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Unmarshaller.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Unmarshaller.java?rev=582840&r1=582839&r2=582840&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Unmarshaller.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Unmarshaller.java Mon
Oct  8 08:11:12 2007
@@ -27,6 +27,6 @@
     /**
      * Unmarshals the given stream into an object.
      */
-    Object unmarshal(InputStream stream) throws IOException;
+    Object unmarshal(InputStream stream) throws IOException, ClassNotFoundException;
 
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java?rev=582840&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java Mon
Oct  8 08:11:12 2007
@@ -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.util;
+
+import java.io.IOException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class IOHelper {
+
+    /**
+     * A factory method which creates an {@link IOException} from the given
+     * exception and message
+     */
+    public static IOException createIOException(Throwable cause) {
+        return createIOException(cause.getMessage(), cause);
+    }
+
+    /**
+     * A factory method which creates an {@link IOException} from the given
+     * exception and message
+     */
+    public static IOException createIOException(String message, Throwable cause) {
+        IOException answer = new IOException(message);
+        answer.initCause(cause);
+        return answer;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbMarshaller.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbMarshaller.java?rev=582840&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbMarshaller.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbMarshaller.java
Mon Oct  8 08:11:12 2007
@@ -0,0 +1,48 @@
+/**
+ *
+ * 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 java.io.IOException;
+import java.io.OutputStream;
+
+import javax.xml.bind.JAXBException;
+
+import org.apache.camel.spi.Marshaller;
+import org.apache.camel.util.IOHelper;
+
+/**
+ * A {@link Marshaller} which uses JAXB2
+ *
+ * @version $Revision: 1.1 $
+ */
+public class JaxbMarshaller implements Marshaller {
+    javax.xml.bind.Marshaller marshaller;
+
+    public JaxbMarshaller(javax.xml.bind.Marshaller marshaller) {
+        this.marshaller = marshaller;
+    }
+
+    public void marshal(Object graph, OutputStream stream) throws IOException {
+        try {
+            marshaller.marshal(graph, stream);
+        }
+        catch (JAXBException e) {
+            throw IOHelper.createIOException(e);
+        }
+    }
+}

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

Added: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbUnmarshaller.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbUnmarshaller.java?rev=582840&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbUnmarshaller.java
(added)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbUnmarshaller.java
Mon Oct  8 08:11:12 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 java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBException;
+
+import org.apache.camel.spi.Unmarshaller;
+import org.apache.camel.util.IOHelper;
+
+/**
+ * An {@link Unmarshaller} which uses JAXB2
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class JaxbUnmarshaller implements Unmarshaller {
+    javax.xml.bind.Unmarshaller unmarshaller;
+
+    public JaxbUnmarshaller(javax.xml.bind.Unmarshaller unmarshaller) {
+        this.unmarshaller = unmarshaller;
+    }
+
+
+    public Object unmarshal(InputStream stream) throws IOException, ClassNotFoundException
{
+        try {
+            return unmarshaller.unmarshal(stream);
+        }
+        catch (JAXBException e) {
+            throw IOHelper.createIOException(e);
+        }
+    }
+}
\ No newline at end of file

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



Mime
View raw message