tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fra...@apache.org
Subject svn commit: r412225 - in /incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo: helper/HelperProviderImpl.java impl/DataObjectImpl.java util/DataObjectUtil.java
Date Tue, 06 Jun 2006 21:53:34 GMT
Author: frankb
Date: Tue Jun  6 14:53:34 2006
New Revision: 412225

URL: http://svn.apache.org/viewvc?rev=412225&view=rev
Log:
Fix for TUSCANY-22

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/DataObjectImpl.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.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?rev=412225&r1=412224&r2=412225&view=diff
==============================================================================
--- 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 Jun  6 14:53:34 2006
@@ -1,6 +1,6 @@
 /**
  *
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *  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.
@@ -17,20 +17,30 @@
 package org.apache.tuscany.sdo.helper;
 
 
-import org.apache.tuscany.sdo.helper.CopyHelperImpl;
-import org.apache.tuscany.sdo.helper.DataHelperImpl;
-import org.apache.tuscany.sdo.helper.EqualityHelperImpl;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import org.apache.tuscany.sdo.util.DataObjectUtil;
 import org.apache.tuscany.sdo.util.SDOUtil;
 
+import commonj.sdo.DataObject;
 import commonj.sdo.helper.CopyHelper;
 import commonj.sdo.helper.DataFactory;
 import commonj.sdo.helper.DataHelper;
 import commonj.sdo.helper.EqualityHelper;
 import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
 import commonj.sdo.helper.XMLHelper;
 import commonj.sdo.helper.XSDHelper;
-import commonj.sdo.impl.ExternalizableDelegator.Resolvable;
 import commonj.sdo.impl.HelperProvider;
+import commonj.sdo.impl.ExternalizableDelegator.Resolvable;
 
 
 /**
@@ -100,11 +110,95 @@
 
   public Resolvable resolvable()
   {
-    throw new UnsupportedOperationException(); //TODO
+    return new ResolvableImpl();
   }
 
   public Resolvable resolvable(Object target)
   {
-    throw new UnsupportedOperationException(); //TODO
+    return new ResolvableImpl(target);
+  }
+
+  protected class ResolvableImpl implements Resolvable
+  {
+    protected Object target;
+    
+    public ResolvableImpl(Object target) { this.target = target; }
+    
+    public ResolvableImpl() { this.target = null; }
+
+    public void writeExternal(ObjectOutput out) throws IOException
+    {
+      if (target instanceof DataObject)
+      {
+        writeDataObject((DataObject)target, out);
+      }
+      else
+      {
+        throw new NotSerializableException(); // should never happen
+      }
+    }
+
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+    {
+      target = readDataObject(in);
+    }
+
+    public Object readResolve() throws ObjectStreamException
+    {
+      return target;
+    }
+    
+    protected void writeDataObject(DataObject dataObject, ObjectOutput objectOutput) throws
IOException
+    {
+      DataObject container = dataObject.getContainer();
+      if (container == null)
+      {
+        // Root object
+        objectOutput.writeByte(1);
+
+        ByteArrayOutputStream compressedByteArrayOutputStream = new ByteArrayOutputStream();
+        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedByteArrayOutputStream);
+        
+        xmlHelper.save(dataObject, "commonj.sdo", "dataObject", gzipOutputStream);
+        gzipOutputStream.close(); // Flush the contents
+
+        byte[] byteArray = compressedByteArrayOutputStream.toByteArray();
+        objectOutput.writeInt(byteArray.length);
+        objectOutput.write(byteArray);
+      }
+      else
+      {
+        objectOutput.writeByte(0);
+        objectOutput.writeUTF(DataObjectUtil.getXPath(dataObject));
+        objectOutput.writeObject(dataObject.getRootObject());
+      }
+    }
+
+    protected DataObject readDataObject(ObjectInput objectInput) throws IOException, ClassNotFoundException
+    {
+      boolean isRoot = objectInput.readByte() == 1;
+      if (isRoot)
+      {
+        // Root object: [rootXML] = length + XML contents
+        int length = objectInput.readInt();
+        byte[] compressedBytes = new byte [length];
+        objectInput.read(compressedBytes, 0, length);
+        
+        GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedBytes));
+
+        XMLDocument doc = xmlHelper.load(gzipInputStream);
+        gzipInputStream.close();
+
+        return doc.getRootObject();
+      }
+      else
+      {
+        // Non root object: [path] [root]
+        String xpath = objectInput.readUTF();
+        DataObject root = (DataObject)objectInput.readObject();
+
+        return root.getDataObject(xpath);
+      }
+    }
   }
 }

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java?rev=412225&r1=412224&r2=412225&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
Tue Jun  6 14:53:34 2006
@@ -46,6 +46,7 @@
 import commonj.sdo.Property;
 import commonj.sdo.Sequence;
 import commonj.sdo.Type;
+import commonj.sdo.impl.ExternalizableDelegator;
 
 
 /**
@@ -189,9 +190,6 @@
     return (Type)eClass();
   }
 
-  
-  // Remaining DataObject methods are (will be) implemented as straight delegation to DataObjectUtil
-
   /**
    * <!-- begin-user-doc -->
    * <!-- end-user-doc -->
@@ -199,8 +197,11 @@
    */
   public Object writeReplace() throws ObjectStreamException
   {
-    return DataObjectUtil.writeReplace(this);
+    return new ExternalizableDelegator(this);
   }
+
+  
+  // Remaining DataObject methods are (will be) implemented as straight delegation to DataObjectUtil
 
   /**
    * <!-- begin-user-doc -->

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java?rev=412225&r1=412224&r2=412225&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
Tue Jun  6 14:53:34 2006
@@ -2444,30 +2444,19 @@
   protected static StringBuffer getXPath(DataObject dataObject, StringBuffer path)
   {
     DataObject container = dataObject.getContainer();
+    if (container == null) return path;
 
-    if (container == null)
-    {
-      //      path.insert(0, "/" + dataObject.getType().getName());
-      return path;
-    }
-
+    boolean first = path.length() == 0;
     Property property = dataObject.getContainmentProperty();
-    //System.out.println("Containment property: " + property);
-
     if (property.isMany())
     {
       List list = container.getList(property);
-      for (int i = 0; i < list.size(); i++)
-      {
-        if (dataObject == list.get(i))
-        {
-          path.insert(0, "/" + property.getName() + "." + i);
-        }
-      } // for
+      int pos = list.indexOf(dataObject);
+      path.insert(0, property.getName() + "." + pos + (first ? "" : "/"));
     }
     else
     {
-      path.insert(0, "/" + property.getName());
+      path.insert(0, property.getName() + (first ? "" : "/"));
     }
 
     return getXPath(container, path);



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message