Title: [772] trunk/components/jaxws/src/main/java/org/servicemix/components: add a JAXB 2.0 version of JavaSource and Marshaler to make it easy to work with JAXB 2 POJOs with the ServiceMixClient and other components
- Revision
- 772
- Author
- jstrachan
- Date
- 2005-11-09 10:27:21 -0500 (Wed, 09 Nov 2005)
Log Message
add a JAXB 2.0 version of JavaSource and Marshaler to make it easy to work with JAXB 2 POJOs with the ServiceMixClient and other components
fix for SM-168
Added Paths
Diff
Added: trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/JAXBJavaSource.java (771 => 772)
--- trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/JAXBJavaSource.java 2005-11-09 09:57:16 UTC (rev 771)
+++ trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/JAXBJavaSource.java 2005-11-09 15:27:21 UTC (rev 772)
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed 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.servicemix.components.jaxb;
+
+import org.servicemix.JavaSource;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.util.JAXBSource;
+
+/**
+ * An extension of the [EMAIL PROTECTED] JAXBSource} which also implements the [EMAIL PROTECTED] JavaSource} interface
+ *
+ * @version $Revision: 1.1 $
+ */
+public class JAXBJavaSource extends JAXBSource implements JavaSource {
+
+ private Object object;
+
+ public JAXBJavaSource(JAXBContext context, Object object) throws JAXBException {
+ super(context, object);
+ this.object = object;
+ }
+
+ public JAXBJavaSource(Marshaller marshaller, Object object) throws JAXBException {
+ super(marshaller, object);
+ this.object = object;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public void setObject(Object object) {
+ this.object = object;
+ }
+}
Added: trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/JAXBMarshaler.java (771 => 772)
--- trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/JAXBMarshaler.java 2005-11-09 09:57:16 UTC (rev 771)
+++ trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/JAXBMarshaler.java 2005-11-09 15:27:21 UTC (rev 772)
@@ -0,0 +1,101 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed 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.servicemix.components.jaxb;
+
+import org.servicemix.jbi.jaxp.SourceTransformer;
+import org.servicemix.jbi.messaging.DefaultMarshaler;
+import org.servicemix.jbi.messaging.Marshaler;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.util.JAXBResult;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+/**
+ * A [EMAIL PROTECTED] Marshaler} for <a href=""
+ * which streams the object to an a W3C DOM Document so that other components
+ * can access the XML without an extra parse.
+ *
+ * @version $Revision: 697 $
+ */
+public class JAXBMarshaler extends DefaultMarshaler {
+
+ private JAXBContext context;
+ private SourceTransformer transformer = new SourceTransformer();
+
+ public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException {
+ if (body != null) {
+ try {
+ JAXBSource source = createSource(body);
+ message.setContent(source);
+ }
+ catch (JAXBException e) {
+ throw new MessagingException(e);
+ }
+ }
+ }
+
+ public Object unmarshal(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ Source content = message.getContent();
+ if (content != null) {
+ try {
+ JAXBResult result = new JAXBResult(getContext());
+ getTransformer().toResult(content, result);
+ return result.getResult();
+ }
+ catch (JAXBException e) {
+ throw new MessagingException(e);
+ }
+ catch (TransformerException e) {
+ throw new MessagingException(e);
+ }
+
+ }
+ return super.unmarshal(exchange, message);
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public JAXBContext getContext() {
+ return context;
+ }
+
+ public void setContext(JAXBContext context) {
+ this.context = context;
+ }
+
+ public SourceTransformer getTransformer() {
+ return transformer;
+ }
+
+ public void setTransformer(SourceTransformer transformer) {
+ this.transformer = transformer;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ protected JAXBSource createSource(Object body) throws JAXBException {
+ JAXBSource source = new JAXBJavaSource(getContext(), body);
+ return source;
+ }
+}
Added: trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/package.html (771 => 772)
--- trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/package.html 2005-11-09 09:57:16 UTC (rev 771)
+++ trunk/components/jaxws/src/main/java/org/servicemix/components/jaxb/package.html 2005-11-09 15:27:21 UTC (rev 772)
@@ -0,0 +1,9 @@
+<html>
+<head>
+</head>
+<body>
+
+Plugin strategies for <a href="" 2.0</a> to make it easy to work with POJOs which are XML/XSD/WSDL compliant on Java 5 or later.
+
+</body>
+</html>