summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org')
-rw-r--r--tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java106
-rw-r--r--tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java45
-rw-r--r--tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOXMLHelper.java264
3 files changed, 0 insertions, 415 deletions
diff --git a/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java
deleted file mode 100644
index 519d256036..0000000000
--- a/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- *
- * Copyright 2006 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.databinding.sdo;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import commonj.sdo.helper.XSDHelper;
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.config.SidefileLoadException;
-import org.apache.tuscany.core.loader.LoaderContext;
-import org.apache.tuscany.core.loader.StAXUtil;
-import org.apache.tuscany.core.loader.assembly.AbstractLoader;
-import org.apache.tuscany.core.loader.assembly.AssemblyConstants;
-import org.apache.tuscany.model.assembly.AssemblyContext;
-import org.apache.tuscany.model.assembly.AssemblyObject;
-import org.apache.tuscany.sdo.util.SDOUtil;
-import org.osoa.sca.annotations.Scope;
-
-/**
- * Loader that handles <import.sdo> elements.
- *
- * @version $Rev$ $Date$
- */
-@Scope("MODULE")
-public class ImportSDOLoader extends AbstractLoader {
- public static final QName IMPORT_SDO = new QName(AssemblyConstants.SCA_NAMESPACE, "import.sdo");
-
- public QName getXMLType() {
- return IMPORT_SDO;
- }
-
- public AssemblyObject load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException {
- assert IMPORT_SDO.equals(reader.getName());
- importFactory(reader, loaderContext);
- importWSDLOrXSD(reader, loaderContext);
- StAXUtil.skipToEndElement(reader);
- return null;
- }
-
- private void importFactory(XMLStreamReader reader, LoaderContext loaderContext) throws ConfigurationLoadException {
- String factoryName = reader.getAttributeValue(null, "factory");
- if (factoryName != null) {
- ResourceLoader resourceLoader = loaderContext.getResourceLoader();
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- try {
- // set TCCL as SDO needs it
- Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader());
- Class<?> factoryClass = resourceLoader.loadClass(factoryName);
- SDOUtil.registerStaticTypes(factoryClass);
- } catch (ClassNotFoundException e) {
- throw new ConfigurationLoadException(e.getMessage(), e);
- } finally {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- private void importWSDLOrXSD(XMLStreamReader reader, LoaderContext loaderContext) throws ConfigurationLoadException {
- String location = reader.getAttributeValue(null, "wsdlLocation");
- if (location == null)
- location = reader.getAttributeValue(null, "schemaLocation");
- if (location != null) {
- ResourceLoader resourceLoader = loaderContext.getResourceLoader();
- URL wsdlURL = resourceLoader.getResource(location);
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- try {
-// Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader());
- InputStream xsdInputStream = wsdlURL.openStream();
- try {
- AssemblyContext context = registry.getContext();
- XSDHelper xsdHelper = SDOUtil.createXSDHelper(context.getTypeHelper());
- xsdHelper.define(xsdInputStream, null);
- } finally {
- xsdInputStream.close();
- }
- } catch (IOException e) {
- SidefileLoadException sfe = new SidefileLoadException(e.getMessage());
- sfe.setResourceURI(location);
- throw sfe;
- } finally {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- }
- }
-}
diff --git a/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java b/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java
deleted file mode 100644
index 0f0cc13fd8..0000000000
--- a/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- * 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.databinding.sdo;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.CopyHelper;
-import org.apache.tuscany.core.builder.ObjectFactory;
-import org.apache.tuscany.core.injection.ObjectCreationException;
-
-/**
- * Creates new instances of an SDO
- *
- * @version $Rev$ $Date$
- */
-public class SDOObjectFactory implements ObjectFactory<DataObject> {
-
- private DataObject dataObject;
-
- public SDOObjectFactory(DataObject dataObject) {
- this.dataObject = dataObject;
- }
-
- public DataObject getInstance() throws ObjectCreationException {
- return CopyHelper.INSTANCE.copy(dataObject);
- }
-
- public void releaseInstance(DataObject instance) {
- }
-
-}
-
diff --git a/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOXMLHelper.java b/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOXMLHelper.java
deleted file mode 100644
index d732676c76..0000000000
--- a/tags/java-M1-20060522/java/sca/databinding/sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOXMLHelper.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- *
- * 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.databinding.sdo;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.tuscany.core.wire.InvocationRuntimeException;
-import org.apache.tuscany.sdo.util.SDOUtil;
-import org.osoa.sca.ServiceRuntimeException;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.helper.XSDHelper;
-
-/**
- * Utility methods to convert between XML byte arrays, SDO DataObjects, and Java objects.
- *
- * Most of these methods rely on the schemas having been registered with XSDHelper.define
- */
-public final class SDOXMLHelper {
-
- private SDOXMLHelper() {
- // utility class, never contructed
- }
-
- /**
- * Deserialize an XML byte array into Java Objects
- *
- * @param xmlBytes
- * the byte array containing the XML
- * @param isWrapped
- *
- * @return the array of deserialized Java objects
- * @deprecated TUSCANY-333 use the method that takes a ClassLoader
- */
- public static Object[] toObjects(TypeHelper typeHelper, byte[] xmlBytes, boolean isWrapped) {
- DataObject dataObject = toDataObject(typeHelper, xmlBytes);
- return toObjects(dataObject, isWrapped);
- }
-
- /**
- * Convert a typed DataObject to Java objects
- *
- * @param dataObject
- * @param isWrapped
- * @return the array of Objects from the DataObject
- */
- public static Object[] toObjects(DataObject dataObject, boolean isWrapped) {
- if (isWrapped) {
- List ips = dataObject.getInstanceProperties();
- Object[] os = new Object[ips.size()];
- for (int i = 0; i < ips.size(); i++) {
- os[i] = dataObject.get((Property) ips.get(i));
- }
- return os;
- } else {
- Object object = dataObject;
- Type type = dataObject.getType();
- if (type.isSequenced()) {
- object = dataObject.getSequence().getValue(0);
- }
- return new Object[] { object };
- }
- }
-
- /**
- * Serializes objects to an XML byte array
- *
- * @param os
- * @param typeNS
- * @param typeName
- * @return a byte array containing the XML
- * @deprecated TUSCANY-333 use the method that takes a ClassLoader
- */
- public static byte[] toXMLBytes(TypeHelper typeHelper, Object[] os, QName elementQName, boolean isWrapped) {
- DataObject dataObject = toDataObject(typeHelper, os, elementQName, isWrapped);
- return toXMLbytes(typeHelper, dataObject, elementQName);
- }
-
- /**
- * Convert a DataObject to an XML byte array
- *
- * @param dataObject
- * @param typeNS
- * @param typeName
- * @return a byte array containing the XML bytes
- * @deprecated TUSCANY-333 use the method that takes a ClassLoader
- */
- public static byte[] toXMLbytes(TypeHelper typeHelper, DataObject dataObject, QName elementQName) {
- try {
-
- ByteArrayOutputStream pos = new ByteArrayOutputStream();
- XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper);
- xmlHelper.save(dataObject, elementQName.getNamespaceURI(), elementQName.getLocalPart(), pos);
- pos.close();
-
- return pos.toByteArray();
-
- } catch (IOException e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- /**
- * Deserialize an XML byte array into a DataObject
- *
- * @param xmlBytes
- * @return a DataObject
- * @deprecated TUSCANY-333 use the method that takes a ClassLoader
- */
- public static DataObject toDataObject(TypeHelper typeHelper, byte[] xmlBytes) {
- try {
-
- XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper);
- XMLDocument document = xmlHelper.load(new ByteArrayInputStream(xmlBytes));
-
- return document.getRootObject();
-
- } catch (IOException e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- /**
- * Convert objects to typed DataObject
- *
- * @param typeNS
- * @param typeName
- * @param os
- * @return the DataObject
- * @deprecated TUSCANY-333 use the method that takes a ClassLoader
- */
- public static DataObject toDataObject(TypeHelper typeHelper, Object[] os, QName elementQName, boolean isWrapped) {
- XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
-
- Property property = xsdHelper.getGlobalProperty(elementQName.getNamespaceURI(), elementQName.getLocalPart(), true);
- if (null == property) {
- throw new InvocationRuntimeException("Type '" + elementQName.toString() + "' not found in registered SDO types.");
- }
- if (isWrapped) {
- DataFactory dataFactory = SDOUtil.createDataFactory(typeHelper);
- DataObject dataObject = dataFactory.create(property.getType());
- List ips = dataObject.getInstanceProperties();
- for (int i = 0; i < ips.size(); i++) {
- dataObject.set(i, os[i]);
- }
- return dataObject;
- } else {
- Object value = os[0];
- Type type = property.getType();
- if (!type.isDataType()) {
- return (DataObject) value;
- } else {
- return SDOUtil.createDataTypeWrapper(type, value);
- }
- }
- }
-
-// ---
-
- public static DataObject toDataObject(ClassLoader classLoader, TypeHelper typeHelper, Object[] os, QName elementQName, boolean isWrapped) {
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- return toDataObject(typeHelper, os, elementQName, isWrapped);
-
- } finally {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(tccl);
- }
- }
- }
-
- public static DataObject toDataObject(ClassLoader classLoader, TypeHelper typeHelper, byte[] xmlBytes) {
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- return toDataObject(typeHelper, xmlBytes);
-
- } finally {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(tccl);
- }
- }
- }
-
- public static byte[] toXMLbytes(ClassLoader classLoader, TypeHelper typeHelper, DataObject dataObject, QName elementQName) {
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- return toXMLbytes(typeHelper, dataObject, elementQName);
-
- } finally {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(tccl);
- }
- }
- }
-
- public static byte[] toXMLBytes(ClassLoader classLoader, TypeHelper typeHelper, Object[] os, QName elementQName, boolean isWrapped) {
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- return toXMLBytes(typeHelper, os, elementQName, isWrapped);
-
- } finally {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(tccl);
- }
- }
- }
-
- public static Object[] toObjects(ClassLoader classLoader, TypeHelper typeHelper, byte[] xmlBytes, boolean isWrapped) {
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- return toObjects(typeHelper, xmlBytes, isWrapped);
-
- } finally {
- if (tccl != classLoader) {
- Thread.currentThread().setContextClassLoader(tccl);
- }
- }
- }
-}