Author: julien_viet
Date: 2010-01-15 08:49:37 -0500 (Fri, 15 Jan 2010)
New Revision: 1314
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/SerializationStatus.java
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java
Log:
preliminary support for serialization status detection
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15
12:59:40 UTC (rev 1313)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15
13:49:37 UTC (rev 1314)
@@ -60,8 +60,12 @@
}
@Override
- protected Object replaceObject(Object obj) throws IOException
+ protected Object replaceObject(final Object obj) throws IOException
{
+ if (obj == null)
+ {
+ return null;
+ }
if (obj instanceof Serializable)
{
return obj;
@@ -79,22 +83,23 @@
}
else
{
- ReplicatableTypeModel<?> typeModel =
(ReplicatableTypeModel<?>)context.getTypeDomain().getTypeModel(obj.getClass());
+ Class<? extends Object> objClass = obj.getClass();
+ TypeModel typeModel = context.getTypeDomain().getTypeModel(objClass);
//
if (typeModel == null)
{
- throw new NotSerializableException("Object " + obj + " is not
serializable");
+ throw new NotSerializableException("Object " + obj + " does
not have its type described");
}
//
output.writeInt(DataKind.OBJECT);
output.writeInt(register(obj));
- output.writeObject(obj.getClass());
+ output.writeObject(objClass);
//
- TypeModel currentTypeModel = typeModel;
- while (currentTypeModel != null)
+ SerializationStatus status = SerializationStatus.NONE;
+ for (TypeModel currentTypeModel = typeModel;currentTypeModel !=
null;currentTypeModel = currentTypeModel.getSuperType())
{
if (currentTypeModel instanceof ReplicatableTypeModel)
{
@@ -120,10 +125,34 @@
}
}
}
+ switch (status)
+ {
+ case NONE:
+ status = SerializationStatus.FULL;
+ break;
+ }
}
+ else
+ {
+ switch (status)
+ {
+ case FULL:
+ status = SerializationStatus.PARTIAL;
+ break;
+ }
+ }
+ }
- //
- currentTypeModel = currentTypeModel.getSuperType();
+ //
+ switch (status)
+ {
+ case FULL:
+ break;
+ case PARTIAL:
+ System.out.println("Partial serialization of object " + obj);
+ break;
+ case NONE:
+ throw new NotSerializableException("Type " + objClass.getName()
+ " is not serializable");
}
}
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/SerializationStatus.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/SerializationStatus.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/SerializationStatus.java 2010-01-15
13:49:37 UTC (rev 1314)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.webui.application.replication.serial;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public enum SerializationStatus
+{
+
+ NONE,
+
+ PARTIAL,
+
+ FULL
+
+}
Modified:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-15
12:59:40 UTC (rev 1313)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-15
13:49:37 UTC (rev 1314)
@@ -23,6 +23,10 @@
import org.exoplatform.webui.application.replication.SerializationContext;
import org.exoplatform.webui.application.replication.model.TypeDomain;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -110,4 +114,20 @@
assertNotNull(f1.children.get(0));
assertSame(f1, f1.children.get(0).parent);
}
+
+ public void testNotSerializable() throws Exception
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(ByteArrayInputStream.class);
+
+ SerializationContext context = new SerializationContext(domain);
+ try
+ {
+ context.write(new ByteArrayInputStream(new byte[0]));
+ fail();
+ }
+ catch (NotSerializableException e)
+ {
+ }
+ }
}