Author: julien_viet
Date: 2010-01-15 11:26:23 -0500 (Fri, 15 Jan 2010)
New Revision: 1317
Added:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/G.java
Modified:
portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java
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:
support for transient fields in serialization
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2010-01-15
14:47:57 UTC (rev 1316)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2010-01-15
16:26:23 UTC (rev 1317)
@@ -29,8 +29,9 @@
</init-params>
<ui-component-root>org.exoplatform.portal.webui.workspace.UIPortalApplication</ui-component-root>
-
<state-manager>org.exoplatform.portal.application.PortalStateManager</state-manager>
-
+
<!--<state-manager>org.exoplatform.portal.application.PortalStateManager</state-manager>-->
+
<state-manager>org.exoplatform.portal.application.ReplicatingStateManager</state-manager>
+
<application-lifecycle-listeners>
<listener>org.exoplatform.portal.application.PortalStatisticLifecycle</listener>
<listener>org.exoplatform.portal.application.PortalApplicationLifecycle</listener>
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-15
14:47:57 UTC (rev 1316)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-15
16:26:23 UTC (rev 1317)
@@ -20,6 +20,7 @@
package org.exoplatform.webui.application.replication.model;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -34,10 +35,14 @@
/** . */
private final TypeModel type;
+ /** . */
+ private boolean _transient;
+
FieldModel(Field field, TypeModel type)
{
this.field = field;
this.type = type;
+ this._transient = Modifier.isTransient(field.getModifiers());
}
public String getName()
@@ -45,6 +50,11 @@
return field.getName();
}
+ public boolean isTransient()
+ {
+ return _transient;
+ }
+
public TypeModel getType()
{
return type;
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-15
14:47:57 UTC (rev 1316)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-15
16:26:23 UTC (rev 1317)
@@ -109,28 +109,31 @@
{
for (FieldModel fieldModel : currentTypeModel.getFields())
{
- switch (container.readInt())
+ if (!fieldModel.isTransient())
{
- case DataKind.NULL_VALUE:
- state.put(fieldModel, null);
- break;
- case DataKind.OBJECT_REF:
- int refId = container.readInt();
- Object refO = idToObject.get(refId);
- if (refO != null)
- {
- state.put(fieldModel, refO);
- }
- else
- {
- biltos.add(new Bilto(refId, fieldModel));
- }
- break;
- case DataKind.OBJECT:
- Object o = container.readObject();
- state.put(fieldModel, o);
- break;
+ switch (container.readInt())
+ {
+ case DataKind.NULL_VALUE:
+ state.put(fieldModel, null);
+ break;
+ case DataKind.OBJECT_REF:
+ int refId = container.readInt();
+ Object refO = idToObject.get(refId);
+ if (refO != null)
+ {
+ state.put(fieldModel, refO);
+ }
+ else
+ {
+ biltos.add(new Bilto(refId, fieldModel));
+ }
+ break;
+ case DataKind.OBJECT:
+ Object o = container.readObject();
+ state.put(fieldModel, o);
+ break;
+ }
}
}
}
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
14:47:57 UTC (rev 1316)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15
16:26:23 UTC (rev 1317)
@@ -105,23 +105,26 @@
{
for (FieldModel fieldModel : currentTypeModel.getFields())
{
- Object fieldValue = fieldModel.getValue(obj);
- if (fieldValue == null)
+ if (!fieldModel.isTransient())
{
- output.writeObject(DataKind.NULL_VALUE);
- }
- else
- {
- Integer fieldValueId = objectToId.get(fieldValue);
- if (fieldValueId != null)
+ Object fieldValue = fieldModel.getValue(obj);
+ if (fieldValue == null)
{
- output.writeObject(DataKind.OBJECT_REF);
- output.writeInt(fieldValueId);
+ output.writeObject(DataKind.NULL_VALUE);
}
else
{
- output.writeObject(DataKind.OBJECT);
- output.writeObject(fieldValue);
+ Integer fieldValueId = objectToId.get(fieldValue);
+ if (fieldValueId != null)
+ {
+ output.writeObject(DataKind.OBJECT_REF);
+ output.writeInt(fieldValueId);
+ }
+ else
+ {
+ output.writeObject(DataKind.OBJECT);
+ output.writeObject(fieldValue);
+ }
}
}
}
Added: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/G.java
===================================================================
--- portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/G.java
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/G.java 2010-01-15
16:26:23 UTC (rev 1317)
@@ -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.replication;
+
+import org.exoplatform.webui.application.replication.annotations.ReplicatedType;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@ReplicatedType
+public class G
+{
+
+ String a;
+ transient Thread b;
+
+}
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
14:47:57 UTC (rev 1316)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-15
16:26:23 UTC (rev 1317)
@@ -130,4 +130,17 @@
{
}
}
+
+ public void testTransientField() throws Exception
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(G.class);
+ SerializationContext context = new SerializationContext(domain);
+ G g = new G();
+ g.a = "foo";
+ g.b = new Thread();
+ g = context.clone(g);
+ assertEquals("foo", g.a);
+ assertEquals(null, g.b);
+ }
}