You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/07/31 22:05:33 UTC

svn commit: r1367737 - /webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java

Author: veithen
Date: Tue Jul 31 20:05:33 2012
New Revision: 1367737

URL: http://svn.apache.org/viewvc?rev=1367737&view=rev
Log:
Finalized JAXBOMDataSource.

Modified:
    webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java

Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java?rev=1367737&r1=1367736&r2=1367737&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java Tue Jul 31 20:05:33 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.axiom.om.ds.jaxb;
 
+import javax.activation.DataHandler;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -27,17 +28,46 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMDataSourceExt;
 import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.QNameAwareOMDataSource;
 import org.apache.axiom.om.ds.AbstractPushOMDataSource;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.util.stax.xop.XOPDecodingStreamWriter;
 
+/**
+ * {@link OMDataSource} backed by a JAXB object. This class can be used both for plain JAXB objects
+ * and for {@link JAXBElement} instances. It implements {@link QNameAwareOMDataSource} so that it
+ * can be used with {@link OMFactory#createOMElement(OMDataSource)}, i.e. it is not necessary to
+ * supply the QName during construction of the {@link OMSourcedElement}. It also has full support
+ * for XOP/MTOM. It is implemented as a push-style {@link OMDataSource} so that an
+ * {@link OMSourcedElement} backed by an instance of this class can be expanded in an efficient way
+ * (including the case where the JAXB object contains base64 binary data represented as
+ * {@link DataHandler} instances or byte arrays).
+ * <p>
+ * The JAXB object encapsulated by an instance of this class can be retrieved using
+ * {@link OMDataSourceExt#getObject()}. Note that modifying the JAXB object after passing it to the
+ * constructor may result in unexpected behavior and should be avoided.
+ * <p>
+ * Instances of this class are non destructive, in the sense defined by
+ * {@link OMDataSourceExt#isDestructiveWrite()}.
+ */
 public class JAXBOMDataSource extends AbstractPushOMDataSource implements QNameAwareOMDataSource {
     private final JAXBContext context;
     private final Object object;
     private QName cachedQName;
     
+    /**
+     * Constructor.
+     * 
+     * @param context
+     *            the JAXB context to which the object is known
+     * @param object
+     *            the JAXB object; this may be a plain Java bean or a {@link JAXBElement}
+     */
     public JAXBOMDataSource(JAXBContext context, Object object) {
         this.context = context;
         this.object = object;
@@ -102,4 +132,14 @@ public class JAXBOMDataSource extends Ab
     public String getPrefix() {
         return null;
     }
+
+    @Override
+    public Object getObject() {
+        return object;
+    }
+
+    @Override
+    public OMDataSourceExt copy() {
+        return new JAXBOMDataSource(context, object);
+    }
 }