You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2007/11/07 19:13:07 UTC
svn commit: r592840 - in
/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding:
ADBDataSource.java ADBHelperDataSource.java
Author: scheu
Date: Wed Nov 7 10:13:06 2007
New Revision: 592840
URL: http://svn.apache.org/viewvc?rev=592840&view=rev
Log:
WSCOMMONS-234
Contributor:Rich Scheuerle
Upgraded the ADBDataSource to use the OMDataSourceExt interface.
Modified:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBHelperDataSource.java
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java?rev=592840&r1=592839&r2=592840&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java Wed Nov 7 10:13:06 2007
@@ -19,7 +19,10 @@
package org.apache.axis2.databinding;
import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axis2.databinding.utils.writer.OMElementStreamWriter;
import org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter;
@@ -30,12 +33,20 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.util.HashMap;
-public abstract class ADBDataSource implements OMDataSource {
+public abstract class ADBDataSource implements OMDataSourceExt {
protected QName parentQName;
private ADBBean bean;
+
+ HashMap map = null; // Map of properties
/**
* Constructor taking in an ADBBean
@@ -67,7 +78,9 @@
* @see OMDataSource#serialize(java.io.Writer, org.apache.axiom.om.OMOutputFormat)
*/
public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
- serialize(StAXUtils.createXMLStreamWriter(writer));
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
+ serialize(xmlStreamWriter);
+ xmlStreamWriter.flush();
}
/**
@@ -80,6 +93,7 @@
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException{
MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new MTOMAwareXMLSerializer(xmlWriter);
serialize(mtomAwareXMLStreamWriter);
+ mtomAwareXMLStreamWriter.flush();
}
public abstract void serialize(MTOMAwareXMLStreamWriter xmlWriter) throws XMLStreamException;
@@ -97,4 +111,93 @@
return mtomAwareOMBuilder.getOMElement().getXMLStreamReader();
}
+ /**
+ * Returns the backing Object.
+ * @return Object
+ */
+ public Object getObject() {
+ return bean;
+ }
+
+ /**
+ * Returns true if reading the backing object is destructive.
+ * An example of an object with a destructive read is an InputSteam.
+ * The owning OMSourcedElement uses this information to detemine if OM tree
+ * expansion is needed when reading the OMDataSourceExt.
+ * @return boolean
+ */
+ public boolean isDestructiveRead() {
+ return false;
+ }
+
+ /**
+ * Returns true if writing the backing object is destructive.
+ * An example of an object with a destructive write is an InputStream.
+ * The owning OMSourcedElement uses this information to detemine if OM tree
+ * expansion is needed when writing the OMDataSourceExt.
+ * @return boolean
+ */
+ public boolean isDestructiveWrite() {
+ return false;
+ }
+
+ /**
+ * Returns a InputStream representing the xml data
+ * @param encoding String encoding of InputStream
+ * @return InputStream
+ */
+ public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+ return new ByteArrayInputStream(getXMLBytes(encoding));
+ }
+
+ /**
+ * Returns a byte[] representing the xml data
+ * @param encoding String encoding of InputStream
+ * @return byte[]
+ * @see getXMLInputStream
+ */
+ public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OMOutputFormat format = new OMOutputFormat();
+ format.setCharSetEncoding(encoding);
+ try {
+ serialize(baos, format);
+ } catch (XMLStreamException e) {
+ new OMException(e);
+ }
+ return baos.toByteArray();
+ }
+
+ /**
+ * Close the DataSource and free its resources.
+ */
+ public void close() {
+ parentQName = null;
+ bean = null;
+ }
+
+ public OMDataSourceExt copy() {
+ return null;
+ }
+
+ public Object getProperty(String key) {
+ if (map == null) {
+ return null;
+ }
+ return map.get(key);
+ }
+
+ public Object setProperty(String key, Object value) {
+ if (map == null) {
+ map = new HashMap();
+ }
+ return map.put(key, value);
+ }
+
+ public boolean hasProperty(String key) {
+ if (map == null) {
+ return false;
+ }
+ return map.containsKey(key);
+ }
}
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBHelperDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBHelperDataSource.java?rev=592840&r1=592839&r2=592840&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBHelperDataSource.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBHelperDataSource.java Wed Nov 7 10:13:06 2007
@@ -19,6 +19,8 @@
package org.apache.axis2.databinding;
import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.util.StAXUtils;
@@ -26,16 +28,24 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.HashMap;
-public abstract class ADBHelperDataSource implements OMDataSource {
+public abstract class ADBHelperDataSource implements OMDataSourceExt {
protected QName parentQName;
protected Object bean;
protected String helperClassName;
+
+ HashMap map = null; // Map of properties
/**
* Constructor taking in an ADBBean
@@ -57,7 +67,9 @@
* @see OMDataSource#serialize(java.io.OutputStream, org.apache.axiom.om.OMOutputFormat)
*/
public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
- serialize(StAXUtils.createXMLStreamWriter(output));
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
+ serialize(xmlStreamWriter);
+ xmlStreamWriter.flush();
}
/**
@@ -67,7 +79,9 @@
* @see OMDataSource#serialize(java.io.Writer, org.apache.axiom.om.OMOutputFormat)
*/
public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
- serialize(StAXUtils.createXMLStreamWriter(writer));
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
+ serialize(xmlStreamWriter);
+ xmlStreamWriter.flush();
}
/**
@@ -104,4 +118,93 @@
}
+ /**
+ * Returns the backing Object.
+ * @return Object
+ */
+ public Object getObject() {
+ return bean;
+ }
+
+ /**
+ * Returns true if reading the backing object is destructive.
+ * An example of an object with a destructive read is an InputSteam.
+ * The owning OMSourcedElement uses this information to detemine if OM tree
+ * expansion is needed when reading the OMDataSourceExt.
+ * @return boolean
+ */
+ public boolean isDestructiveRead() {
+ return false;
+ }
+
+ /**
+ * Returns true if writing the backing object is destructive.
+ * An example of an object with a destructive write is an InputStream.
+ * The owning OMSourcedElement uses this information to detemine if OM tree
+ * expansion is needed when writing the OMDataSourceExt.
+ * @return boolean
+ */
+ public boolean isDestructiveWrite() {
+ return false;
+ }
+
+ /**
+ * Returns a InputStream representing the xml data
+ * @param encoding String encoding of InputStream
+ * @return InputStream
+ */
+ public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+ return new ByteArrayInputStream(getXMLBytes(encoding));
+ }
+
+ /**
+ * Returns a byte[] representing the xml data
+ * @param encoding String encoding of InputStream
+ * @return byte[]
+ * @see getXMLInputStream
+ */
+ public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OMOutputFormat format = new OMOutputFormat();
+ format.setCharSetEncoding(encoding);
+ try {
+ serialize(baos, format);
+ } catch (XMLStreamException e) {
+ new OMException(e);
+ }
+ return baos.toByteArray();
+ }
+
+ /**
+ * Close the DataSource and free its resources.
+ */
+ public void close() {
+ parentQName = null;
+ bean = null;
+ }
+
+ public OMDataSourceExt copy() {
+ return null;
+ }
+
+ public Object getProperty(String key) {
+ if (map == null) {
+ return null;
+ }
+ return map.get(key);
+ }
+
+ public Object setProperty(String key, Object value) {
+ if (map == null) {
+ map = new HashMap();
+ }
+ return map.put(key, value);
+ }
+
+ public boolean hasProperty(String key) {
+ if (map == null) {
+ return false;
+ }
+ return map.containsKey(key);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org