You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by fr...@apache.org on 2007/02/13 18:40:21 UTC
svn commit: r507115 - in /incubator/tuscany/java/sdo/impl/src:
main/java/org/apache/tuscany/sdo/helper/
main/java/org/apache/tuscany/sdo/impl/
main/java/org/apache/tuscany/sdo/model/impl/
main/java/org/apache/tuscany/sdo/util/ main/java/org/apache/tusc...
Author: frankb
Date: Tue Feb 13 09:40:11 2007
New Revision: 507115
URL: http://svn.apache.org/viewvc?view=rev&rev=507115
Log:
Fix for TUSCANY-1086
Added:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectInputStream.java
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectOutputStream.java
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java
Modified:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataGraphImpl.java
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/impl/ModelFactoryImpl.java
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java?view=diff&rev=507115&r1=507114&r2=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java Tue Feb 13 09:40:11 2007
@@ -32,6 +32,7 @@
import org.apache.tuscany.sdo.util.DataObjectUtil;
import org.apache.tuscany.sdo.util.SDOUtil;
+import org.apache.tuscany.sdo.util.resource.SDOObjectInputStream;
import commonj.sdo.DataGraph;
import commonj.sdo.DataObject;
@@ -176,8 +177,12 @@
ByteArrayOutputStream compressedByteArrayOutputStream = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedByteArrayOutputStream);
-
- xmlHelper.save(dataObject, "commonj.sdo", "dataObject", gzipOutputStream);
+ XMLHelper xmlHelperLocal = xmlHelper;
+ if(objectOutput instanceof SDOObjectInputStream)
+ {
+ xmlHelperLocal = ((SDOObjectInputStream)objectOutput).getHelperContext().getXMLHelper();
+ }
+ xmlHelperLocal.save(dataObject, "commonj.sdo", "dataObject", gzipOutputStream);
gzipOutputStream.close(); // Flush the contents
byte[] byteArray = compressedByteArrayOutputStream.toByteArray();
@@ -197,8 +202,12 @@
objectInput.read(compressedBytes, 0, length);
GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedBytes));
-
- XMLDocument doc = xmlHelper.load(gzipInputStream);
+ XMLHelper xmlHelperLocal = xmlHelper;
+ if(objectInput instanceof SDOObjectInputStream)
+ {
+ xmlHelperLocal = ((SDOObjectInputStream)objectInput).getHelperContext().getXMLHelper();
+ }
+ XMLDocument doc = xmlHelperLocal.load(gzipInputStream);
gzipInputStream.close();
return doc.getRootObject();
Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataGraphImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataGraphImpl.java?view=diff&rev=507115&r1=507114&r2=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataGraphImpl.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataGraphImpl.java Tue Feb 13 09:40:11 2007
@@ -27,12 +27,15 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.tuscany.sdo.SDOFactory;
import org.apache.tuscany.sdo.SDOPackage;
+import org.apache.tuscany.sdo.helper.TypeHelperImpl;
import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.apache.tuscany.sdo.util.resource.SDOObjectInputStream;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
@@ -684,7 +687,15 @@
ResourceSet resourceSet = createResourceSet();
Resource resource = resourceSet.createResource(URI.createURI("all.datagraph"));
- resource.load(new ByteArrayInputStream(bytes), null);
+
+ HashMap map = null;
+ if(objectInput instanceof SDOObjectInputStream)
+ {
+ TypeHelperImpl th = (TypeHelperImpl)((SDOObjectInputStream)objectInput).getHelperContext().getTypeHelper();
+ map = new HashMap();
+ map.put("EXTENDED_META_DATA", th.getExtendedMetaData());
+ }
+ resource.load(new ByteArrayInputStream(bytes), map);
eDataGraph = (DataGraphImpl)resource.getContents().get(0);
}
Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/impl/ModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/impl/ModelFactoryImpl.java?view=diff&rev=507115&r1=507114&r2=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/impl/ModelFactoryImpl.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/impl/ModelFactoryImpl.java Tue Feb 13 09:40:11 2007
@@ -49,7 +49,9 @@
* 6. Delete all the createXXXFromString() and convertXXXToString() methods in the newly generated ModelFactoryImpl and
* replace them with the ones from this file (resolve any missing imports).
* 7. Comment out the call to registerStaticTypes of ModelFactory.class in the init() method
- * 8. Move this JavaDoc comment into the newly generated ModelFactoryImpl class.
+ * 8. Change org.apache.tuscany.sdo.model.DataObject.class to commonj.sdo.DataObject.class for the following method found in method initializeMetaData();
+ * initializeType(dataObjectType, commonj.sdo.DataObject.class, "DataObject", true); // generated as org.apache.tuscany.sdo.model.DataObject.class
+ * 9. Move this JavaDoc comment into the newly generated ModelFactoryImpl class.
* <!-- end-user-doc -->
* @generated
*/
@@ -830,7 +832,7 @@
property = (commonj.sdo.Property)dataGraphTypeType.getProperties().get(DataGraphTypeImpl.ANY);
initializeProperty(property, getSequence(), "any", null, 0, 1, DataGraphType.class, false, false, false);
- initializeType(dataObjectType, org.apache.tuscany.sdo.model.DataObject.class, "DataObject", true);
+ initializeType(dataObjectType, commonj.sdo.DataObject.class, "DataObject", true);
initializeType(modelsTypeType, ModelsType.class, "ModelsType", false);
property = (commonj.sdo.Property)modelsTypeType.getProperties().get(ModelsTypeImpl.ANY);
Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java?view=diff&rev=507115&r1=507114&r2=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java Tue Feb 13 09:40:11 2007
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.math.BigDecimal;
@@ -53,6 +55,8 @@
import org.apache.tuscany.sdo.impl.DynamicDataObjectImpl;
import org.apache.tuscany.sdo.model.ModelFactory;
import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl;
+import org.apache.tuscany.sdo.util.resource.SDOObjectInputStream;
+import org.apache.tuscany.sdo.util.resource.SDOObjectOutputStream;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
@@ -365,6 +369,26 @@
public static CopyHelper createCrossScopeCopyHelper(TypeHelper targetScope)
{
return new CrossScopeCopyHelperImpl(targetScope);
+ }
+
+ /**
+ * Create a new ObjectInputStream, under the helperContextScope
+ * @param scope the TypeHelper to use for locating types.
+ * @return the new XMLStreamHelper.
+ */
+ public static ObjectInputStream createObjectInputStream(InputStream inputStream, HelperContext helperContext) throws IOException
+ {
+ return new SDOObjectInputStream(inputStream, helperContext);
+ }
+
+ /**
+ * Create a new ObjectOutputStream, under the helperContextScope.
+ * @param scope the TypeHelper to use for locating types.
+ * @return the new XMLStreamHelper.
+ */
+ public static ObjectOutputStream createObjectOutputStream(OutputStream outputStream, HelperContext helperContext) throws IOException
+ {
+ return new SDOObjectOutputStream(outputStream, helperContext);
}
/**
Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectInputStream.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectInputStream.java?view=auto&rev=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectInputStream.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectInputStream.java Tue Feb 13 09:40:11 2007
@@ -0,0 +1,51 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.sdo.util.resource;
+
+/**
+ * This class inherites off of ObjectInputStream providing a way to store the scope under which
+ * this inputStream has been created.
+ *
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+
+import commonj.sdo.helper.HelperContext;
+
+public class SDOObjectInputStream extends ObjectInputStream {
+
+ private HelperContext helperContext;
+
+ public SDOObjectInputStream(InputStream in, HelperContext helperContext) throws IOException{
+ super(in);
+ this.helperContext = helperContext;
+ }
+
+ public HelperContext getHelperContext() {
+ return helperContext;
+ }
+
+ public void setHelperContext(HelperContext helperContext) {
+ this.helperContext = helperContext;
+ }
+
+}
Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectOutputStream.java?view=auto&rev=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectOutputStream.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOObjectOutputStream.java Tue Feb 13 09:40:11 2007
@@ -0,0 +1,51 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.sdo.util.resource;
+
+/**
+ * This class inherites off of ObjectInputStream providing a way to store the scope under which
+ * this inputStream has been created.
+ *
+ */
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+import commonj.sdo.helper.HelperContext;
+
+public class SDOObjectOutputStream extends ObjectOutputStream {
+
+ private HelperContext helperContext;
+
+ public SDOObjectOutputStream(OutputStream os, HelperContext helperContext) throws IOException{
+ super(os);
+ this.helperContext = helperContext;
+ }
+
+ public HelperContext getHelperContext() {
+ return helperContext;
+ }
+
+ public void setHelperContext(HelperContext helperContext) {
+ this.helperContext = helperContext;
+ }
+
+}
Added: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java?view=auto&rev=507115
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java (added)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java Tue Feb 13 09:40:11 2007
@@ -0,0 +1,222 @@
+package org.apache.tuscany.sdo.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+
+public class JavaSerializeDeserializeTestCase extends TestCase
+{
+
+ public void testScopeDefinedSerializeDeserializeOfDataObject()
+ {
+ HelperContext hc = SDOUtil.createHelperContext();
+ Object originalDataObject = createDynamically(hc,true);
+
+ runSerializeDeserialize((DataObject)originalDataObject, hc);
+ }
+
+ public void testScopeDefinedSerializeDeserializeOfDataGraph()
+ {
+ HelperContext hc = SDOUtil.createHelperContext();
+ DataGraph testDO = (DataGraph)createDynamically(hc,false);
+
+ runSerializeDeserializeWithDataGraph(testDO, hc);
+ }
+
+
+ /**
+ * Serialize the DataObject then Deserialize the output.
+ * to testDO.
+ * @param testDO
+ * @param scope
+ */
+
+ public void runSerializeDeserialize(DataObject originalDataObject, HelperContext hc)
+ {
+
+ populateFields(originalDataObject);
+ DataObject tempDO = null;
+ ByteArrayOutputStream baos = null;
+
+ try
+ {
+ baos = serialize(originalDataObject, hc);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("An Exception occurred while serializing the DataObject: " + e.toString());
+ }
+
+ try
+ {
+ tempDO = deserialize(baos, hc);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("An Exception occurred while deserializing the output of the serialization: " + e.toString());
+ }
+
+ assertNotNull("Deserialization returned a null value.", tempDO);
+
+ assertSame(tempDO.getType(), originalDataObject.getType());
+
+
+ }
+
+ /**
+ * Serialize the DataGraph
+ * @param dataGraph
+ * @param scope
+ */
+ public void runSerializeDeserializeWithDataGraph(DataGraph dataGraph, HelperContext hc)
+ {
+ DataObject originalDataObject = dataGraph.getRootObject();
+ populateFields(originalDataObject);
+ DataObject tempDO = null;
+ ByteArrayOutputStream baos = null;
+
+ try
+ {
+ baos = serialize(dataGraph, hc);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("An Exception occurred while serializing the DataObject: " + e.toString());
+ }
+
+ try
+ {
+ tempDO = deserialize(baos, hc);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("An Exception occurred while deserializing the output of the serialization: " + e.toString());
+ }
+
+ assertNotNull("Deserialization returned a null value.", tempDO);
+
+ assertSame(tempDO.getType(), originalDataObject.getType());
+
+
+
+ }
+
+ /**
+ * serializeDataObject is a private method to be called by the other methods
+ * in the ScrenarioLibrary
+ *
+ * @param dataObject
+ * @param fileName
+ * @throws IOException
+ */
+ public ByteArrayOutputStream serialize(Object object, HelperContext hc) throws IOException
+ {
+ //FileOutputStream fos = new FileOutputStream("temp");
+ ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
+ ObjectOutputStream out = SDOUtil.createObjectOutputStream(byteArrayOutput, hc);
+ out.writeObject(object);
+ out.close();
+ return byteArrayOutput;
+ }
+
+ /**
+ * deserializeDataObject is a private method to be called by the other
+ * methods in the ScrenarioLibrary
+ *
+ * @param fileName
+ * @return
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public DataObject deserialize(ByteArrayOutputStream baos, HelperContext hc) throws IOException, ClassNotFoundException
+ {
+ //FileInputStream fis = new FileInputStream("temp");
+ ObjectInputStream input = null;
+ ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(baos.toByteArray());
+
+ input = SDOUtil.createObjectInputStream(byteArrayInput, hc);
+
+ Object object = input.readObject();
+ input.close();
+ if(object instanceof DataGraph)
+ return ((DataGraph)object).getRootObject();
+ else
+ return (DataObject)object;
+ }
+
+ /**
+ * populateFields uses set<Type> to set each of the fields in the
+ * DataObject. It is used to ensure a known set of expected values that are
+ * not other than the default values for the various fields.
+ *
+ * @param testDO
+ * @throws ExpectedConditionError
+ */
+ public static void populateFields(DataObject testDO)
+ {
+
+ testDO.setString("stringVal", "Testing");
+
+ }
+ /**
+ * createDynamically() creates the SDO Types using the TypeHelper. This method should be kept in
+ * synch with the XSD used for createDynamicallyWithStaticResources. The same XSD is used for
+ * the static generation of SDO Types using XSD2JavaGenerator.
+ */
+ public Object createDynamically(HelperContext hc, boolean createDataObject)
+ {
+
+ TypeHelper types = hc.getTypeHelper();
+ DataFactory dataFactory = hc.getDataFactory();
+
+ Type stringType = types.getType("commonj.sdo", "String");
+
+ DataObject testType = dataFactory.create("commonj.sdo", "Type");
+ testType.set("uri", "http://www.example.com/api_test");
+ testType.set("name", "APITest");
+
+ DataObject stringProperty = testType.createDataObject("property");
+ stringProperty.set("name", "stringVal");
+ stringProperty.set("type", stringType);
+
+
+ List types2Define = new ArrayList();
+ types2Define.add(testType);
+ List apiXSD = types.define(types2Define);
+ Type apiXSDType = (Type) apiXSD.get(0);
+
+ if(createDataObject)
+ return dataFactory.create(apiXSDType);;
+
+ // Create an empty DataGraph and attach the document root to it. Otherwise, where is the documentRoot ?
+ DataGraph dataGraph = SDOUtil.createDataGraph();
+ /*DataObject testDO =*/ dataGraph.createRootObject(apiXSDType);
+
+
+ return dataGraph;
+
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org