Author: julien_viet
Date: 2010-01-15 09:47:57 -0500 (Fri, 15 Jan 2010)
New Revision: 1316
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
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/main/java/org/exoplatform/webui/application/replication/serial/SerializationStatus.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java
Log:
better support for serialization status detection
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-15
14:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -19,14 +19,16 @@
package org.exoplatform.webui.application.replication.model;
+import java.util.Map;
+
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public final class ClassTypeModel extends TypeModel
+public final class ClassTypeModel<O> extends TypeModel
{
- ClassTypeModel(Class<?> type, TypeModel superType)
+ ClassTypeModel(Class<?> type, TypeModel superType, Map<String, FieldModel>
fields)
{
- super(type, superType);
+ super(type, superType, fields);
}
}
\ 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
14:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -19,8 +19,6 @@
package org.exoplatform.webui.application.replication.model;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
/**
@@ -33,37 +31,20 @@
/** . */
private final Class<O> objectType;
- /** . */
- private final Map<String, FieldModel> fields;
-
- /** . */
- private final Map<String, FieldModel> immutableFields;
-
ReplicatableTypeModel(
Class<O> javaType,
TypeModel superType,
Map<String, FieldModel> fields)
{
- super(javaType, superType);
+ super(javaType, superType, fields);
//
this.objectType = javaType;
- this.fields = fields;
- this.immutableFields = Collections.unmodifiableMap(fields);
}
- public Class<O> getObjectType()
+ @Override
+ public Class<O> getJavaType()
{
return objectType;
}
-
- public Collection<FieldModel> getFields()
- {
- return immutableFields.values();
- }
-
- public Map<String, FieldModel> getFieldMap()
- {
- return immutableFields;
- }
}
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
14:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -21,7 +21,6 @@
import org.exoplatform.webui.application.replication.annotations.ReplicatedType;
-import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
@@ -105,24 +104,16 @@
return typeModelMap.size();
}
- private TypeModel build(Class<?> javaType, Map<String, TypeModel>
addedTypeModels)
+ private <O> TypeModel build(Class<O> javaType, Map<String,
TypeModel> addedTypeModels)
{
- ReplicatedType replicatedType = javaType.getAnnotation(ReplicatedType.class);
- if (replicatedType != null)
- {
- return buildReplicatableTypeModel(javaType, addedTypeModels);
- }
- else
- {
- return buildClassTypeModel(javaType, addedTypeModels);
- }
- }
+ TypeModel typeModel = get(javaType, addedTypeModels);
- private <O> ReplicatableTypeModel<O>
buildReplicatableTypeModel(Class<O> javaType, Map<String, TypeModel>
addedTypeModels)
- {
- ReplicatableTypeModel typeModel = (ReplicatableTypeModel) get(javaType,
addedTypeModels);
+ //
if (typeModel == null)
{
+ boolean replicated = javaType.getAnnotation(ReplicatedType.class) != null;
+
+ //
TypeModel superTypeModel = null;
for (Class<?> ancestor = javaType.getSuperclass();ancestor !=
null;ancestor = ancestor.getSuperclass())
{
@@ -137,7 +128,14 @@
TreeMap<String, FieldModel> fieldModels = new TreeMap<String,
FieldModel>();
//
- typeModel = new ReplicatableTypeModel<O>(javaType, superTypeModel,
fieldModels);
+ if (replicated)
+ {
+ typeModel = new ReplicatableTypeModel<O>(javaType, superTypeModel,
fieldModels);
+ }
+ else
+ {
+ typeModel = new ClassTypeModel(javaType, superTypeModel, fieldModels);
+ }
//
addedTypeModels.put(javaType.getName(), typeModel);
@@ -158,23 +156,7 @@
}
}
- // It must be good
- return (ReplicatableTypeModel<O>)typeModel;
- }
-
- private ClassTypeModel buildClassTypeModel(Class<?> javaType, Map<String,
TypeModel> addedTypeModels)
- {
- ClassTypeModel typeModel = (ClassTypeModel) get(javaType, addedTypeModels);
- if (typeModel == null)
- {
- 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
14:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -19,6 +19,10 @@
package org.exoplatform.webui.application.replication.model;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -32,12 +36,30 @@
/** . */
private final TypeModel superType;
- TypeModel(Class<?> javaType, TypeModel superType)
+ /** . */
+ private final Map<String, FieldModel> fields;
+
+ /** . */
+ private final Map<String, FieldModel> immutableFields;
+
+ TypeModel(Class<?> javaType, TypeModel superType, Map<String, FieldModel>
fields)
{
this.javaType = javaType;
this.superType = superType;
+ this.fields = fields;
+ this.immutableFields = Collections.unmodifiableMap(fields);
}
+ public Collection<FieldModel> getFields()
+ {
+ return immutableFields.values();
+ }
+
+ public Map<String, FieldModel> getFieldMap()
+ {
+ return immutableFields;
+ }
+
public String getName()
{
return javaType.getName();
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:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -61,14 +61,14 @@
{
try
{
- ObjectFactory<? super O> factory =
context.getFactory(typeModel.getObjectType());
+ ObjectFactory<? super O> factory =
context.getFactory(typeModel.getJavaType());
//
- return factory.create(typeModel.getObjectType(), state);
+ return factory.create(typeModel.getJavaType(), state);
}
catch (Exception e)
{
- InvalidClassException ice = new InvalidClassException("Cannot instantiate
object from class " + typeModel.getObjectType().getName());
+ InvalidClassException ice = new InvalidClassException("Cannot instantiate
object from class " + typeModel.getJavaType().getName());
ice.initCause(e);
throw ice;
}
@@ -107,7 +107,7 @@
{
if (currentTypeModel instanceof ReplicatableTypeModel)
{
- for (FieldModel fieldModel :
((ReplicatableTypeModel<?>)currentTypeModel).getFields())
+ for (FieldModel fieldModel : currentTypeModel.getFields())
{
switch (container.readInt())
{
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:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -103,7 +103,7 @@
{
if (currentTypeModel instanceof ReplicatableTypeModel)
{
- for (FieldModel fieldModel :
((ReplicatableTypeModel<?>)currentTypeModel).getFields())
+ for (FieldModel fieldModel : currentTypeModel.getFields())
{
Object fieldValue = fieldModel.getValue(obj);
if (fieldValue == null)
@@ -134,11 +134,14 @@
}
else
{
- switch (status)
+ if (!currentTypeModel.getFields().isEmpty())
{
- case FULL:
- status = SerializationStatus.PARTIAL;
- break;
+ switch (status)
+ {
+ case FULL:
+ status = SerializationStatus.PARTIAL;
+ break;
+ }
}
}
}
Modified:
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 2010-01-15
14:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/SerializationStatus.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -23,7 +23,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public enum SerializationStatus
+enum SerializationStatus
{
NONE,
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
14:44:11 UTC (rev 1315)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-15
14:47:57 UTC (rev 1316)
@@ -43,18 +43,26 @@
{
TypeDomain domain = new TypeDomain();
assertType(String.class, domain.add(String.class));
- assertEquals(2, domain.getSize());
+ assertEquals(4, domain.getSize());
assertType(String.class, domain.getTypeModel(String.class));
assertType(Object.class, domain.getTypeModel(Object.class));
+ assertType(int.class, domain.getTypeModel(int.class));
+ assertType(char[].class, domain.getTypeModel(char[].class));
}
public void testJuu()
{
TypeDomain domain = new TypeDomain();
ReplicatableTypeModel aTM = (ReplicatableTypeModel) domain.add(A.class);
- assertEquals(5, domain.getSize());
assertEquals(A.class.getName(), aTM.getName());
-
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());
+ assertEquals(SetBuilder.
+ create(domain.getTypeModel(Object.class)).
+ with(domain.getTypeModel(int.class)).
+ with(domain.getTypeModel(char[].class)).
+ with(aTM).
+ with(domain.getTypeModel(boolean.class)).
+ build(domain.getTypeModel(String.class))
+ , domain.getTypeModels());
Map<String, FieldModel> fieldMap = aTM.getFieldMap();
assertEquals(3, fieldMap.size());
FieldModel aFM = fieldMap.get("a");