summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/java-M1-20060522/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/tags/java-M1-20060522/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java')
-rw-r--r--sca-java-1.x/tags/java-M1-20060522/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java
new file mode 100644
index 0000000000..0caf2293d6
--- /dev/null
+++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java
@@ -0,0 +1,104 @@
+/**
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.apache.tuscany.binding.axis2.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.tuscany.core.wire.InvocationRuntimeException;
+import org.apache.tuscany.databinding.sdo.SDOXMLHelper;
+import org.apache.tuscany.sdo.util.SDOUtil;
+import org.osoa.sca.ServiceRuntimeException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+
+/**
+ * DataBinding for converting between AXIOM OMElement and Java Objects
+ */
+public class SDODataBinding {
+
+ private ClassLoader classLoader;
+
+ private TypeHelper typeHelper;
+
+ private QName elementQName;
+
+ private boolean isWrapped;
+
+ public SDODataBinding(ClassLoader classLoader, TypeHelper typeHelper, QName elementQName, boolean isWrapped) {
+ this.classLoader = classLoader;
+ this.typeHelper = typeHelper;
+ this.elementQName = elementQName;
+ this.isWrapped = isWrapped;
+ }
+
+ public Object[] fromOMElement(OMElement omElement) {
+ try {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ omElement.serialize(baos);
+
+ baos.flush();
+ baos.close();
+
+ return SDOXMLHelper.toObjects(classLoader,typeHelper, baos.toByteArray(), isWrapped);
+
+ } catch (IOException e) {
+ throw new InvocationRuntimeException(e);
+ } catch (XMLStreamException e) {
+ throw new InvocationRuntimeException(e);
+ }
+ }
+
+ public OMElement toOMElement(Object[] os) {
+ try {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ DataObject dataObject = SDOXMLHelper.toDataObject(classLoader, typeHelper, os, elementQName, isWrapped);
+ XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper);
+ xmlHelper.save(dataObject, elementQName.getNamespaceURI(), elementQName.getLocalPart(), baos);
+ baos.close();
+
+ XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), xsr);
+ OMElement omElement = builder.getDocumentElement();
+
+ return omElement;
+
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ } catch (XMLStreamException e) {
+ throw new ServiceRuntimeException(e);
+ } catch (FactoryConfigurationError e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+}