Author: julien_viet
Date: 2010-01-15 07:59:40 -0500 (Fri, 15 Jan 2010)
New Revision: 1313
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/F.java
Removed:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.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
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java
Log:
need to add those files for unit test
Copied:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
(from rev 1303,
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java)
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -0,0 +1,32 @@
+/*
+ * 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.model;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public final class ClassTypeModel extends TypeModel
+{
+ ClassTypeModel(Class<?> type, TypeModel superType)
+ {
+ super(type, superType);
+ }
+}
\ No newline at end of file
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java 2010-01-15
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -34,9 +34,6 @@
private final Class<O> objectType;
/** . */
- private final TypeModel superType;
-
- /** . */
private final Map<String, FieldModel> fields;
/** . */
@@ -47,11 +44,10 @@
TypeModel superType,
Map<String, FieldModel> fields)
{
- super(javaType);
+ super(javaType, superType);
//
this.objectType = javaType;
- this.superType = superType;
this.fields = fields;
this.immutableFields = Collections.unmodifiableMap(fields);
}
@@ -61,11 +57,6 @@
return objectType;
}
- public TypeModel getSuperType()
- {
- return superType;
- }
-
public Collection<FieldModel> getFields()
{
return immutableFields.values();
Deleted:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java 2010-01-15
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -1,34 +0,0 @@
-/*
- * 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.model;
-
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public final class SerializableTypeModel extends TypeModel
-{
- SerializableTypeModel(Class<? extends Serializable> serializable)
- {
- super(serializable);
- }
-}
\ No newline at end of file
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-15
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -78,7 +78,7 @@
return typeModelMap.get(typeName);
}
- public TypeModel getTypeModel(Class javaType)
+ public TypeModel getTypeModel(Class<?> javaType)
{
if (javaType == null)
{
@@ -110,23 +110,15 @@
ReplicatedType replicatedType = javaType.getAnnotation(ReplicatedType.class);
if (replicatedType != null)
{
- return buildClassTypeModel(javaType, addedTypeModels);
+ return buildReplicatableTypeModel(javaType, addedTypeModels);
}
- else if (javaType.isPrimitive())
- {
- return buildSerializable(javaType, addedTypeModels);
- }
- else if (Serializable.class.isAssignableFrom(javaType))
- {
- return buildSerializable(javaType, addedTypeModels);
- }
else
{
- return null;
+ return buildClassTypeModel(javaType, addedTypeModels);
}
}
- private <O> ReplicatableTypeModel<O> buildClassTypeModel(Class<O>
javaType, Map<String, TypeModel> addedTypeModels)
+ private <O> ReplicatableTypeModel<O>
buildReplicatableTypeModel(Class<O> javaType, Map<String, TypeModel>
addedTypeModels)
{
ReplicatableTypeModel typeModel = (ReplicatableTypeModel) get(javaType,
addedTypeModels);
if (typeModel == null)
@@ -170,12 +162,17 @@
return (ReplicatableTypeModel<O>)typeModel;
}
- private SerializableTypeModel buildSerializable(Class<?> javaType,
Map<String, TypeModel> addedTypeModels)
+ private ClassTypeModel buildClassTypeModel(Class<?> javaType, Map<String,
TypeModel> addedTypeModels)
{
- SerializableTypeModel typeModel = (SerializableTypeModel) get(javaType,
addedTypeModels);
+ ClassTypeModel typeModel = (ClassTypeModel) get(javaType, addedTypeModels);
if (typeModel == null)
{
- typeModel = new SerializableTypeModel((Class<Serializable>)javaType);
+ TypeModel superTypeModel = null;
+ if (javaType.getSuperclass() != null)
+ {
+ superTypeModel = build(javaType.getSuperclass(), addedTypeModels);
+ }
+ typeModel = new ClassTypeModel(javaType, superTypeModel);
addedTypeModels.put(javaType.getName(), typeModel);
}
return typeModel;
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.java 2010-01-15
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -29,9 +29,13 @@
/** . */
private final Class<?> javaType;
- TypeModel(Class<?> javaType)
+ /** . */
+ private final TypeModel superType;
+
+ TypeModel(Class<?> javaType, TypeModel superType)
{
this.javaType = javaType;
+ this.superType = superType;
}
public String getName()
@@ -44,6 +48,11 @@
return javaType;
}
+ public TypeModel getSuperType()
+ {
+ return superType;
+ }
+
@Override
public String toString()
{
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
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -101,49 +101,40 @@
//
Map<FieldModel, Object> state = new HashMap<FieldModel,
Object>();
- ReplicatableTypeModel<?> currentTypeModel = typeModel;
+ TypeModel currentTypeModel = typeModel;
List<Bilto> biltos = new ArrayList<Bilto>();
- while (true)
+ while (currentTypeModel != null)
{
- for (FieldModel fieldModel : (currentTypeModel).getFields())
+ if (currentTypeModel instanceof ReplicatableTypeModel)
{
- switch (container.readInt())
+ for (FieldModel fieldModel :
((ReplicatableTypeModel<?>)currentTypeModel).getFields())
{
- 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;
+ }
}
}
- TypeModel currentSuperTypeModel = currentTypeModel.getSuperType();
- if (currentSuperTypeModel == null)
- {
- break;
- }
- if (currentSuperTypeModel instanceof ReplicatableTypeModel)
- {
- currentTypeModel = (ReplicatableTypeModel)currentSuperTypeModel;
- }
- else
- {
- throw new UnsupportedOperationException();
- }
+ currentTypeModel = currentTypeModel.getSuperType();
}
//
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
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -93,48 +93,37 @@
output.writeObject(obj.getClass());
//
- ReplicatableTypeModel<?> currentTypeModel = typeModel;
- while (true)
+ TypeModel currentTypeModel = typeModel;
+ while (currentTypeModel != null)
{
- for (FieldModel fieldModel : (currentTypeModel).getFields())
+ if (currentTypeModel instanceof ReplicatableTypeModel)
{
- Object fieldValue = fieldModel.getValue(obj);
- if (fieldValue == null)
+ for (FieldModel fieldModel :
((ReplicatableTypeModel<?>)currentTypeModel).getFields())
{
- 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);
+ }
}
}
}
//
- TypeModel currentSuperTypeModel = currentTypeModel.getSuperType();
- if (currentSuperTypeModel == null)
- {
- break;
- }
-
- //
- if (currentSuperTypeModel instanceof ReplicatableTypeModel)
- {
- currentTypeModel = (ReplicatableTypeModel)currentSuperTypeModel;
- }
- else
- {
- throw new UnsupportedOperationException();
- }
+ currentTypeModel = currentTypeModel.getSuperType();
}
}
Added: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/F.java
===================================================================
--- portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/F.java
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/F.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@ReplicatedType
+public class F
+{
+
+ List<F> children = new ArrayList<F>();
+
+ F parent;
+
+}
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
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -30,7 +30,7 @@
public class TestSerialization extends TestCase
{
- public void testBar() throws Exception
+ public void testState() throws Exception
{
TypeDomain domain = new TypeDomain();
domain.add(A.class);
@@ -45,7 +45,7 @@
assertEquals(true, a.c);
}
- public void testFoo() throws Exception
+ public void testMultipleReference1() throws Exception
{
TypeDomain domain = new TypeDomain();
domain.add(B.class);
@@ -71,7 +71,7 @@
assertEquals("bar", d.b);
}
- public void testAAA() throws Exception
+ public void testMultipleReference2() throws Exception
{
TypeDomain domain = new TypeDomain();
domain.add(E2.class);
@@ -88,25 +88,26 @@
assertSame(((E2)e.left).right, ((E2)e.right).right);
}
-/*
public void testListOfReplicatable() throws Exception
{
TypeDomain domain = new TypeDomain();
- domain.add(F1.class);
- domain.add(F2.class);
+ domain.add(F.class);
//
- F1 f1 = new F1();
- F2 f2 = new F2();
- f1.values.add(f2);
+ F f1 = new F();
+ F f2 = new F();
+ f1.children.add(f2);
+ f2.parent = f1;
//
SerializationContext context = new SerializationContext(domain);
f1 = context.clone(f1);
//
- assertNotNull(f1.values);
- assertEquals(1, f1.values.size());
+ assertNotNull(f1.children);
+ assertNull(f1.parent);
+ assertEquals(1, f1.children.size());
+ assertNotNull(f1.children.get(0));
+ assertSame(f1, f1.children.get(0).parent);
}
-*/
}
Modified:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-15
11:42:30 UTC (rev 1312)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-15
12:59:40 UTC (rev 1313)
@@ -43,17 +43,18 @@
{
TypeDomain domain = new TypeDomain();
assertType(String.class, domain.add(String.class));
- assertEquals(1, domain.getSize());
+ assertEquals(2, domain.getSize());
assertType(String.class, domain.getTypeModel(String.class));
+ assertType(Object.class, domain.getTypeModel(Object.class));
}
public void testJuu()
{
TypeDomain domain = new TypeDomain();
ReplicatableTypeModel aTM = (ReplicatableTypeModel) domain.add(A.class);
- assertEquals(4, domain.getSize());
+ assertEquals(5, domain.getSize());
assertEquals(A.class.getName(), aTM.getName());
-
assertEquals(SetBuilder.create(domain.getTypeModel(int.class)).with(aTM).with(domain.getTypeModel(boolean.class)).build(domain.getTypeModel(String.class)),
domain.getTypeModels());
+
assertEquals(SetBuilder.create(domain.getTypeModel(int.class)).with(aTM).with(domain.getTypeModel(boolean.class)).with(domain.getTypeModel(Object.class)).build(domain.getTypeModel(String.class)),
domain.getTypeModels());
Map<String, FieldModel> fieldMap = aTM.getFieldMap();
assertEquals(3, fieldMap.size());
FieldModel aFM = fieldMap.get("a");
@@ -67,11 +68,10 @@
assertEquals(domain.getTypeModel(boolean.class), cFM.getType());
}
- private void assertType(Class<? extends Serializable> javaType, TypeModel
typeModel)
+ private void assertType(Class<?> javaType, TypeModel typeModel)
{
- assertTrue(typeModel instanceof SerializableTypeModel);
- SerializableTypeModel serializableTypeModel = (SerializableTypeModel)typeModel;
+ assertTrue(typeModel instanceof ClassTypeModel);
+ ClassTypeModel serializableTypeModel = (ClassTypeModel)typeModel;
assertEquals(javaType, serializableTypeModel.getJavaType());
}
-
}