Author: julien_viet
Date: 2010-01-16 09:24:10 -0500 (Sat, 16 Jan 2010)
New Revision: 1334
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Converted.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Serialized.java
Removed:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedField.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedType.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/impl/api/DefaultTypeConverter.java
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/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/A.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/B.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C1.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C2.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E1.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E2.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/F.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/G.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/A2.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/B.java
Log:
refactored a bit the type system to simplify it and add notion of converted type
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Converted.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Converted.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Converted.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -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.api.annotations;
+
+import org.exoplatform.webui.application.replication.api.TypeConverter;
+import org.exoplatform.webui.application.replication.impl.api.DefaultTypeConverter;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public @interface Converted
+{
+ Class<? extends TypeConverter<?, ?>> value();
+}
Deleted:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedField.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedField.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedField.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -1,36 +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.api.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotates a field
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-(a)Target(ElementType.FIELD)
-(a)Retention(RetentionPolicy.RUNTIME)
-public @interface ReplicatedField {
-}
Deleted:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedType.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedType.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedType.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -1,42 +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.api.annotations;
-
-import org.exoplatform.webui.application.replication.api.TypeConverter;
-import org.exoplatform.webui.application.replication.impl.api.DefaultTypeConverter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotates a field
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-(a)Target(ElementType.TYPE)
-(a)Retention(RetentionPolicy.RUNTIME)
-public @interface ReplicatedType {
-
- Class<? extends TypeConverter<?, ?>> convertedBy() default
DefaultTypeConverter.class;
-
-}
\ No newline at end of file
Copied:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Serialized.java
(from rev 1333,
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/ReplicatedType.java)
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Serialized.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/api/annotations/Serialized.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -0,0 +1,37 @@
+/*
+ * 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.api.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotates a type to be serializable.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Serialized
+{
+}
\ No newline at end of file
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/impl/api/DefaultTypeConverter.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/impl/api/DefaultTypeConverter.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/impl/api/DefaultTypeConverter.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -25,16 +25,16 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class DefaultTypeConverter extends TypeConverter<Object, Object>
+public class DefaultTypeConverter<O> extends TypeConverter<O, O>
{
@Override
- public Object write(Object input) throws Exception
+ public O write(O input) throws Exception
{
return input;
}
@Override
- public Object read(Object output) throws Exception
+ public O read(O output) throws Exception
{
return output;
}
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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,6 +19,8 @@
package org.exoplatform.webui.application.replication.model;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
/**
@@ -27,8 +29,49 @@
*/
public final class ClassTypeModel<O> extends TypeModel<O>
{
- ClassTypeModel(Class<O> type, TypeModel<? super O> superType,
Map<String, FieldModel<O, ?>> fields)
+
+ /** . */
+ private final ClassTypeModel<? super O> superType;
+
+ /** . */
+ private final Map<String, FieldModel<O, ?>> fields;
+
+ /** . */
+ private final Map<String, FieldModel<O, ?>> immutableFields;
+
+ /** . */
+ private final boolean serialized;
+
+ ClassTypeModel(Class<O> type, ClassTypeModel<? super O> superType,
Map<String, FieldModel<O, ?>> fields, boolean serialized)
{
super(type, superType, fields);
+
+ //
+ this.superType = superType;
+ this.fields = fields;
+ this.immutableFields = Collections.unmodifiableMap(fields);
+ this.serialized = serialized;
}
+
+ @Override
+ public ClassTypeModel<? super O> getSuperType()
+ {
+ return superType;
+ }
+
+ public boolean isSerialized()
+ {
+ return serialized;
+ }
+
+ public Collection<FieldModel<O, ?>> getFields()
+ {
+ return immutableFields.values();
+ }
+
+ public Map<String, FieldModel<O, ?>> getFieldMap()
+ {
+ return immutableFields;
+ }
+
}
\ No newline at end of file
Deleted:
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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -1,38 +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.util.Map;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public final class ReplicatableTypeModel<O> extends TypeModel<O>
-{
-
- ReplicatableTypeModel(
- Class<O> javaType,
- TypeModel<? super O> superType,
- Map<String, FieldModel<O, ?>> fields)
- {
- super(javaType, superType, fields);
- }
-}
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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,7 +19,7 @@
package org.exoplatform.webui.application.replication.model;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -123,7 +123,7 @@
}
// For now that operation is synchronized
- public synchronized TypeModel add(Class<?> javaType)
+ public synchronized <O> TypeModel<O> add(Class<O> javaType)
{
if (javaType == null)
{
@@ -132,8 +132,8 @@
// Build the missing types required to have knowledge about the
// provided java type
- Map<String, TypeModel> addedTypeModels = new HashMap<String,
TypeModel>();
- TypeModel model = build(javaType, addedTypeModels);
+ Map<String, TypeModel<?>> addedTypeModels = new HashMap<String,
TypeModel<?>>();
+ TypeModel<O> model = build(javaType, addedTypeModels);
// Perform merge
typeModelMap.putAll(addedTypeModels);
@@ -150,7 +150,7 @@
return typeModelMap.size();
}
- private <O> TypeModel build(Class<O> javaType, Map<String,
TypeModel> addedTypeModels)
+ private <O> TypeModel<O> build(Class<O> javaType, Map<String,
TypeModel<?>> addedTypeModels)
{
if (javaType.isPrimitive())
{
@@ -163,31 +163,28 @@
//
if (typeModel == null)
{
- boolean replicated = javaType.getAnnotation(ReplicatedType.class) != null;
+ boolean replicated = javaType.getAnnotation(Serialized.class) != null;
//
- TypeModel<?> superTypeModel = null;
- for (Class<?> ancestor = javaType.getSuperclass();ancestor !=
null;ancestor = ancestor.getSuperclass())
+ ClassTypeModel<? super O> superTypeModel = null;
+ if (javaType.getSuperclass() != null)
{
- superTypeModel = build(ancestor, addedTypeModels);
- if (superTypeModel != null)
+ TypeModel<? super O> builtType = build(javaType.getSuperclass(),
addedTypeModels);
+ if (builtType instanceof ClassTypeModel)
{
- break;
+ superTypeModel = (ClassTypeModel<? super O>)builtType;
}
+ else
+ {
+ throw new TypeException();
+ }
}
//
TreeMap<String, FieldModel<O, ?>> fieldModels = new
TreeMap<String, FieldModel<O, ?>>();
//
- if (replicated)
- {
- typeModel = new ReplicatableTypeModel<O>(javaType, (TypeModel<?
super O>)superTypeModel, fieldModels);
- }
- else
- {
- typeModel = new ClassTypeModel<O>(javaType, (TypeModel<? super
O>)superTypeModel, fieldModels);
- }
+ typeModel = new ClassTypeModel<O>(javaType, superTypeModel, fieldModels,
replicated);
//
addedTypeModels.put(javaType.getName(), typeModel);
@@ -224,13 +221,14 @@
return new FieldModel<O, V>(owner, field, fieldTypeModel);
}
- private TypeModel get(Class<?> javaType, Map<String, TypeModel>
addedTypeModels)
+ private <O> TypeModel<O> get(Class<O> javaType, Map<String,
TypeModel<?>> addedTypeModels)
{
- TypeModel typeModel = typeModelMap.get(javaType.getName());
+ TypeModel<?> typeModel = typeModelMap.get(javaType.getName());
if (typeModel == null)
{
typeModel = addedTypeModels.get(javaType.getName());
}
- return typeModel;
+ // Cast OK
+ return (TypeModel<O>)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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -36,30 +36,12 @@
/** . */
private final TypeModel<? super O> superType;
- /** . */
- private final Map<String, FieldModel<O, ?>> fields;
-
- /** . */
- private final Map<String, FieldModel<O, ?>> immutableFields;
-
TypeModel(Class<O> javaType, TypeModel<? super O> superType,
Map<String, FieldModel<O, ?>> fields)
{
this.javaType = javaType;
this.superType = superType;
- this.fields = fields;
- this.immutableFields = Collections.unmodifiableMap(fields);
}
- public Collection<FieldModel<O, ?>> getFields()
- {
- return immutableFields.values();
- }
-
- public Map<String, FieldModel<O, ?>> 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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -21,9 +21,8 @@
import org.exoplatform.webui.application.replication.SerializationContext;
import org.exoplatform.webui.application.replication.api.factory.ObjectFactory;
-import org.exoplatform.webui.application.replication.model.ReplicatableTypeModel;
+import org.exoplatform.webui.application.replication.model.ClassTypeModel;
import org.exoplatform.webui.application.replication.model.FieldModel;
-import org.exoplatform.webui.application.replication.model.TypeModel;
import java.io.*;
import java.util.*;
@@ -57,7 +56,7 @@
this.idToResolutions = new HashMap<Integer,
List<FutureFieldUpdate<?>>>();
}
- private <O> O instantiate(ReplicatableTypeModel<O> typeModel,
Map<FieldModel<? super O, ?>, ?> state) throws InvalidClassException
+ private <O> O instantiate(ClassTypeModel<O> typeModel,
Map<FieldModel<? super O, ?>, ?> state) throws InvalidClassException
{
try
{
@@ -74,14 +73,14 @@
}
}
- protected <O> O instantiate(int id, DataContainer container,
ReplicatableTypeModel<O> typeModel) throws IOException
+ protected <O> O instantiate(int id, DataContainer container,
ClassTypeModel<O> typeModel) throws IOException
{
Map<FieldModel<? super O, ?>, Object> state = new
HashMap<FieldModel<? super O, ?>, Object>();
- TypeModel<? super O> currentTypeModel = typeModel;
+ ClassTypeModel<? super O> currentTypeModel = typeModel;
List<FieldUpdate<O>> sets = new
ArrayList<FieldUpdate<O>>();
while (currentTypeModel != null)
{
- if (currentTypeModel instanceof ReplicatableTypeModel)
+ if (currentTypeModel instanceof ClassTypeModel)
{
for (FieldModel<? super O, ?> fieldModel :
currentTypeModel.getFields())
{
@@ -200,7 +199,7 @@
case DataKind.OBJECT:
id = container.readInt();
Class<?> clazz = (Class) container.readObject();
- ReplicatableTypeModel<?> typeModel =
(ReplicatableTypeModel)context.getTypeDomain().getTypeModel(clazz);
+ ClassTypeModel<?> typeModel =
(ClassTypeModel<?>)context.getTypeDomain().getTypeModel(clazz);
return instantiate(id, container, typeModel);
default:
throw new StreamCorruptedException("Unrecognized data " + sw);
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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -20,9 +20,8 @@
package org.exoplatform.webui.application.replication.serial;
import org.exoplatform.webui.application.replication.SerializationContext;
-import org.exoplatform.webui.application.replication.model.ReplicatableTypeModel;
+import org.exoplatform.webui.application.replication.model.ClassTypeModel;
import org.exoplatform.webui.application.replication.model.FieldModel;
-import org.exoplatform.webui.application.replication.model.TypeModel;
import java.io.*;
import java.util.IdentityHashMap;
@@ -59,6 +58,83 @@
return nextId;
}
+ private <O> void write(DataContainer output, ClassTypeModel<O> typeModel,
O obj) throws IOException
+ {
+ if (!typeModel.isSerialized())
+ {
+ throw new NotSerializableException("Type " + typeModel + " cannot
be serialized");
+ }
+
+ //
+ output.writeInt(DataKind.OBJECT);
+ output.writeInt(register(obj));
+ output.writeObject(typeModel.getJavaType());
+
+ //
+ SerializationStatus status = SerializationStatus.NONE;
+ for (ClassTypeModel<? super O> currentTypeModel = typeModel;currentTypeModel
!= null;currentTypeModel = currentTypeModel.getSuperType())
+ {
+ if (currentTypeModel instanceof ClassTypeModel<?>)
+ {
+ for (FieldModel<?, ?> fieldModel : currentTypeModel.getFields())
+ {
+ if (!fieldModel.isTransient())
+ {
+ Object fieldValue = fieldModel.get(obj);
+ if (fieldValue == null)
+ {
+ output.writeObject(DataKind.NULL_VALUE);
+ }
+ else
+ {
+ Integer fieldValueId = objectToId.get(fieldValue);
+ if (fieldValueId != null)
+ {
+ output.writeObject(DataKind.OBJECT_REF);
+ output.writeInt(fieldValueId);
+ }
+ else
+ {
+ output.writeObject(DataKind.OBJECT);
+ output.writeObject(fieldValue);
+ }
+ }
+ }
+ }
+ switch (status)
+ {
+ case NONE:
+ status = SerializationStatus.FULL;
+ break;
+ }
+ }
+ else
+ {
+ if (!currentTypeModel.getFields().isEmpty())
+ {
+ switch (status)
+ {
+ case FULL:
+ status = SerializationStatus.PARTIAL;
+ break;
+ }
+ }
+ }
+ }
+
+ //
+ switch (status)
+ {
+ case FULL:
+ break;
+ case PARTIAL:
+ System.out.println("Partial serialization of object " + obj);
+ break;
+ case NONE:
+ throw new NotSerializableException("Type " + typeModel + " is
not serializable");
+ }
+ }
+
@Override
protected Object replaceObject(final Object obj) throws IOException
{
@@ -83,8 +159,8 @@
}
else
{
- Class<?> objClass = obj.getClass();
- TypeModel<?> typeModel = context.getTypeDomain().getTypeModel(objClass);
+ Class objClass = obj.getClass();
+ ClassTypeModel typeModel =
(ClassTypeModel)context.getTypeDomain().getTypeModel(objClass);
//
if (typeModel == null)
@@ -92,74 +168,9 @@
throw new NotSerializableException("Object " + obj + " does
not have its type described");
}
- //
- output.writeInt(DataKind.OBJECT);
- output.writeInt(register(obj));
- output.writeObject(objClass);
-
- //
- SerializationStatus status = SerializationStatus.NONE;
- for (TypeModel<?> currentTypeModel = typeModel;currentTypeModel !=
null;currentTypeModel = currentTypeModel.getSuperType())
- {
- if (currentTypeModel instanceof ReplicatableTypeModel<?>)
- {
- for (FieldModel<?, ?> fieldModel : currentTypeModel.getFields())
- {
- if (!fieldModel.isTransient())
- {
- Object fieldValue = fieldModel.get(obj);
- if (fieldValue == null)
- {
- output.writeObject(DataKind.NULL_VALUE);
- }
- else
- {
- Integer fieldValueId = objectToId.get(fieldValue);
- if (fieldValueId != null)
- {
- output.writeObject(DataKind.OBJECT_REF);
- output.writeInt(fieldValueId);
- }
- else
- {
- output.writeObject(DataKind.OBJECT);
- output.writeObject(fieldValue);
- }
- }
- }
- }
- switch (status)
- {
- case NONE:
- status = SerializationStatus.FULL;
- break;
- }
- }
- else
- {
- if (!currentTypeModel.getFields().isEmpty())
- {
- switch (status)
- {
- case FULL:
- status = SerializationStatus.PARTIAL;
- break;
- }
- }
- }
- }
-
- //
- 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");
- }
+ // This is obviously unchecked because of the fact that Object.getClass()
returns Class<?>
+ // need to find a work around for that
+ write(output, typeModel, obj);
}
//
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/A.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/A.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/A.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class A {
String a;
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/B.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/B.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/B.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class B
{
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C1.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C1.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C1.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class C1
{
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C2.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C2.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C2.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class C2 extends C1
{
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class D
{
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E1.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E1.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E1.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class E1
{
}
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E2.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E2.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/E2.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class E2 extends E1
{
Modified: 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 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/F.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,7 +19,7 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
import java.util.ArrayList;
import java.util.List;
@@ -28,7 +28,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class F
{
Modified: 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 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/G.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class G
{
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-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -54,7 +54,7 @@
public void testJuu()
{
TypeDomain domain = new TypeDomain();
- ReplicatableTypeModel<A> aTM = (ReplicatableTypeModel) domain.add(A.class);
+ ClassTypeModel<A> aTM = (ClassTypeModel<A>)domain.add(A.class);
assertEquals(A.class.getName(), aTM.getName());
/*
assertEquals(SetBuilder.
Modified:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/A2.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/A2.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/A2.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication.factory;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class A2
{
}
\ No newline at end of file
Modified:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/B.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/B.java 2010-01-16
13:19:15 UTC (rev 1333)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/factory/B.java 2010-01-16
14:24:10 UTC (rev 1334)
@@ -19,13 +19,13 @@
package org.exoplatform.webui.replication.factory;
-import org.exoplatform.webui.application.replication.api.annotations.ReplicatedType;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-@ReplicatedType
+@Serialized
public class B
{
public B()