Author: julien_viet
Date: 2010-01-13 07:19:46 -0500 (Wed, 13 Jan 2010)
New Revision: 1253
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/Replicatable.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/ReplicatingStateManager.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedField.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedType.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/
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/FieldModel.java
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/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/
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataKind.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataOutput.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/
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/DataOutputImpl.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/MapBuilder.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/SetBuilder.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:
work on the replication framework
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/Replicatable.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/Replicatable.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/Replicatable.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface Replicatable
+{
+}
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/ReplicatingStateManager.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/ReplicatingStateManager.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/ReplicatingStateManager.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import org.exoplatform.webui.application.StateManager;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.core.UIApplication;
+
+/**
+ * The basis is either {@link org.exoplatform.webui.core.UIPortletApplication} or
+ * {@link org.exoplatform.portal.webui.workspace.UIPortalApplication}.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ReplicatingStateManager extends StateManager {
+
+ @Override
+ public UIApplication restoreUIRootComponent(WebuiRequestContext context) throws
Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void storeUIRootComponent(WebuiRequestContext context) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void expire(String sessionId, WebuiApplication app) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedField.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedField.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedField.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,36 @@
+/*
+ * 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.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 {
+}
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedType.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedType.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/annotations/ReplicatedType.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,36 @@
+/*
+ * 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.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.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface ReplicatedType {
+}
\ No newline at end of file
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,63 @@
+/*
+ * 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 org.exoplatform.webui.application.replication.serial.ObjectWriter;
+
+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$
+ */
+public class ClassTypeModel extends TypeModel {
+
+ /** . */
+ private final TypeModel superType;
+
+ /** . */
+ private final Map<String, FieldModel> fields;
+
+ /** . */
+ private final Map<String, FieldModel> immutableFields;
+
+ ClassTypeModel(Class<?> javaType, TypeModel superType, Map<String,
FieldModel> fields) {
+ super(javaType);
+
+ //
+ this.superType = superType;
+ this.fields = fields;
+ this.immutableFields = Collections.unmodifiableMap(fields);
+ }
+
+ public TypeModel getSuperType() {
+ return superType;
+ }
+
+ public Collection<FieldModel> getFields() {
+ return immutableFields.values();
+ }
+
+ public Map<String, FieldModel> getFieldMap() {
+ return immutableFields;
+ }
+}
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,56 @@
+/*
+ * 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.lang.reflect.Field;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class FieldModel {
+
+ /** . */
+ private final Field field;
+
+ /** . */
+ private final TypeModel type;
+
+ public FieldModel(Field field, TypeModel type) {
+ this.field = field;
+ this.type = type;
+ }
+
+ public String getName() {
+ return field.getName();
+ }
+
+ public TypeModel getType() {
+ return type;
+ }
+
+ public Object getValue(Object o) {
+ try {
+ return field.get(o);
+ } catch (IllegalAccessException e) {
+ throw new AssertionError(e);
+ }
+ }
+}
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,34 @@
+/*
+ * 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 class SerializableTypeModel extends TypeModel
+{
+ SerializableTypeModel(Class<? extends Serializable> serializable)
+ {
+ super(serializable);
+ }
+}
\ No newline at end of file
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,183 @@
+/*
+ * 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 org.exoplatform.webui.application.replication.annotations.ReplicatedType;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.*;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TypeDomain
+{
+
+ /** . */
+ private final Map<String, TypeModel> typeModelMap;
+
+ /** . */
+ private final Map<String, TypeModel> immutableTypeModelMap;
+
+ /** . */
+ private final Set<TypeModel> typeModelSet;
+
+ /** . */
+ private final Set<TypeModel> immutableTypeModelSet;
+
+ public TypeDomain()
+ {
+ HashMap<String, TypeModel> typeModelMap = new HashMap<String,
TypeModel>();
+ Map<String, TypeModel> immutableTypeModelMap =
Collections.unmodifiableMap(typeModelMap);
+ HashSet<TypeModel> typeModelSet = new HashSet<TypeModel>();
+ Set<TypeModel> immutableTypeModelSet =
Collections.unmodifiableSet(typeModelSet);
+
+ //
+ this.typeModelMap = typeModelMap;
+ this.immutableTypeModelMap = immutableTypeModelMap;
+ this.typeModelSet = typeModelSet;
+ this.immutableTypeModelSet = immutableTypeModelSet;
+ }
+
+ public Map<String, TypeModel> getTypeModelMap()
+ {
+ return immutableTypeModelMap;
+ }
+
+ public Set<TypeModel> getTypeModels()
+ {
+ return immutableTypeModelSet;
+ }
+
+ public TypeModel getTypeModel(String typeName)
+ {
+ if (typeName == null)
+ {
+ throw new NullPointerException();
+ }
+ return typeModelMap.get(typeName);
+ }
+
+ public TypeModel getTypeModel(Class javaType)
+ {
+ if (javaType == null)
+ {
+ throw new NullPointerException();
+ }
+ return typeModelMap.get(javaType.getName());
+ }
+
+ public TypeModel add(Class<?> javaType)
+ {
+ if (javaType == null)
+ {
+ throw new NullPointerException();
+ }
+ Map<String, TypeModel> addedTypeModels = new HashMap<String,
TypeModel>();
+ TypeModel model = build(javaType, addedTypeModels);
+ typeModelMap.putAll(addedTypeModels);
+ typeModelSet.addAll(addedTypeModels.values());
+ return model;
+ }
+
+ public int getSize()
+ {
+ return typeModelMap.size();
+ }
+
+ private TypeModel build(Class<?> javaType, Map<String, TypeModel>
addedTypeModels)
+ {
+ ReplicatedType replicatedType = javaType.getAnnotation(ReplicatedType.class);
+ if (replicatedType != null)
+ {
+ return buildClassTypeModel(javaType, addedTypeModels);
+ }
+ else if (javaType.isPrimitive())
+ {
+ return buildSerializable(javaType, addedTypeModels);
+ }
+ else if (Serializable.class.isAssignableFrom(javaType))
+ {
+ return buildSerializable(javaType, addedTypeModels);
+ }
+ return null;
+ }
+
+ private ClassTypeModel buildClassTypeModel(Class<?> javaType, Map<String,
TypeModel> addedTypeModels)
+ {
+ ClassTypeModel typeModel = (ClassTypeModel) get(javaType, addedTypeModels);
+ if (typeModel == null)
+ {
+ TypeModel superTypeModel = null;
+ for (Class<?> ancestor = javaType.getSuperclass();ancestor !=
null;ancestor = ancestor.getSuperclass())
+ {
+ superTypeModel = build(ancestor, addedTypeModels);
+ if (superTypeModel != null)
+ {
+ break;
+ }
+ }
+
+ //
+ TreeMap<String, FieldModel> fieldModels = new TreeMap<String,
FieldModel>();
+
+ //
+ typeModel = new ClassTypeModel(javaType, superTypeModel, fieldModels);
+ addedTypeModels.put(javaType.getName(), typeModel);
+
+ //
+ for (Field field : javaType.getDeclaredFields())
+ {
+ field.setAccessible(true);
+ Class<?> fieldJavaType = field.getType();
+ TypeModel fieldTypeModel = build(fieldJavaType, addedTypeModels);
+ if (fieldTypeModel != null)
+ {
+ fieldModels.put(field.getName(), new FieldModel(field, fieldTypeModel));
+ }
+ }
+ }
+ return typeModel;
+ }
+
+ private SerializableTypeModel buildSerializable(Class<?> javaType,
Map<String, TypeModel> addedTypeModels)
+ {
+ SerializableTypeModel typeModel = (SerializableTypeModel) get(javaType,
addedTypeModels);
+ if (typeModel == null)
+ {
+ typeModel = new SerializableTypeModel((Class<Serializable>)javaType);
+ addedTypeModels.put(javaType.getName(), typeModel);
+ }
+ return typeModel;
+ }
+
+ private TypeModel get(Class<?> javaType, Map<String, TypeModel>
addedTypeModels)
+ {
+ TypeModel typeModel = typeModelMap.get(javaType.getName());
+ if (typeModel == null)
+ {
+ typeModel = addedTypeModels.get(javaType.getName());
+ }
+ return typeModel;
+ }
+}
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeModel.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,52 @@
+/*
+ * 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 abstract class TypeModel
+{
+
+ /** . */
+ private final Class<?> javaType;
+
+ TypeModel(Class<?> javaType)
+ {
+ this.javaType = javaType;
+ }
+
+ public String getName()
+ {
+ return javaType.getName();
+ }
+
+ public Class<?> getJavaType()
+ {
+ return javaType;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "TypeModel[name=" + javaType.getName() + "]";
+ }
+}
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataKind.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataKind.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataKind.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,34 @@
+/*
+ * 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 class DataKind
+{
+
+ public static final int OBJECT = 0;
+ public static final int NULL_VALUE = 1;
+ public static final int OBJECT_REF = 2;
+ public static final int SERIALIZABLE_OBJECT = 3;
+
+}
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataOutput.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataOutput.java
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/DataOutput.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -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;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface DataOutput
+{
+
+ void writeInt(int i);
+ void writeString(String s);
+ void writeSerializable(Serializable serializable);
+
+}
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import org.exoplatform.webui.application.replication.model.ClassTypeModel;
+import org.exoplatform.webui.application.replication.model.FieldModel;
+import org.exoplatform.webui.application.replication.model.TypeDomain;
+import org.exoplatform.webui.application.replication.model.TypeModel;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ObjectWriter
+{
+
+ /** . */
+ private final TypeDomain domain;
+
+ /** . */
+ private final IdentityHashMap<Object, Integer> objectToId;
+
+ /** . */
+ private final Map<Integer, Object> idToObject;
+
+ public ObjectWriter(TypeDomain domain)
+ {
+ this.domain = domain;
+ this.objectToId = new IdentityHashMap<Object, Integer>();
+ this.idToObject = new HashMap<Integer, Object>();
+ }
+
+ private int register(Object o)
+ {
+ int nextId = objectToId.size();
+ objectToId.put(o, nextId);
+ idToObject.put(nextId, o);
+ return nextId;
+ }
+
+ public void write(Object o, DataOutput output)
+ {
+ if (o == null)
+ {
+ output.writeInt(DataKind.NULL_VALUE);
+ }
+ else
+ {
+ Integer id = objectToId.get(o);
+ if (id != null)
+ {
+ output.writeInt(DataKind.OBJECT_REF);
+ output.writeInt(id);
+ }
+ else
+ {
+ TypeModel typeModel = domain.getTypeModel(o.getClass());
+ if (typeModel instanceof ClassTypeModel)
+ {
+ ClassTypeModel classTypeModel = (ClassTypeModel)typeModel;
+
+ //
+ output.writeInt(DataKind.OBJECT);
+ output.writeInt(register(o));
+ output.writeSerializable(o.getClass());
+
+ //
+ ClassTypeModel currentTypeModel = classTypeModel;
+ while (true)
+ {
+ for (FieldModel fieldModel : (currentTypeModel).getFields())
+ {
+ Object fieldValue = fieldModel.getValue(o);
+ write(fieldValue, output);
+ }
+ TypeModel currentSuperTypeModel = currentTypeModel.getSuperType();
+ if (currentSuperTypeModel == null)
+ {
+ break;
+ }
+ if (currentSuperTypeModel instanceof ClassTypeModel)
+ {
+ currentTypeModel = (ClassTypeModel)currentSuperTypeModel;
+ }
+ else
+ {
+ output.writeInt(DataKind.SERIALIZABLE_OBJECT);
+ output.writeSerializable((Serializable)o);
+ break;
+ }
+ }
+ }
+ else if (o instanceof Serializable)
+ {
+ output.writeInt(DataKind.SERIALIZABLE_OBJECT);
+ output.writeSerializable((Serializable)o);
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+ }
+}
Added: 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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/A.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -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 A {
+
+ String a = "a";
+ int b = 2;
+ boolean c = true;
+
+}
Added: 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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/B.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,42 @@
+/*
+ * 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 B
+{
+
+ B ref;
+
+ public B(B ref)
+ {
+ this.ref = ref;
+ }
+
+ public B()
+ {
+ }
+}
Added: 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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C1.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,34 @@
+/*
+ * 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 C1
+{
+
+ String a = "a1";
+
+}
Added: 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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/C2.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,34 @@
+/*
+ * 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 C2 extends C1
+{
+
+ String a = "a2";
+
+}
Added: 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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@ReplicatedType
+public class D extends ArrayList
+{
+
+ String a = "a";
+
+}
Added:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/DataOutputImpl.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/DataOutputImpl.java
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/DataOutputImpl.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,81 @@
+/*
+ * 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 junit.framework.Assert;
+import org.exoplatform.webui.application.replication.serial.DataOutput;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class DataOutputImpl implements DataOutput
+{
+
+ /** . */
+ private LinkedList<Object> stream = new LinkedList<Object>();
+
+ public void writeInt(int i)
+ {
+ stream.add(0);
+ stream.addLast(i);
+ }
+
+ public void writeString(String s)
+ {
+ stream.add(1);
+ stream.addLast(s);
+ }
+
+ public void writeSerializable(Serializable serializable)
+ {
+ stream.add(2);
+ stream.addLast(serializable);
+ }
+
+ public void assertEmpty()
+ {
+ Assert.assertEquals(0, stream.size());
+ }
+
+ public void assertInt(int i)
+ {
+ assertElement(0, i);
+ }
+
+ public void assertString(String s)
+ {
+ assertElement(1, s);
+ }
+
+ public void assertSerializable(Serializable s)
+ {
+ assertElement(2, s);
+ }
+
+ private void assertElement(int type, Object o)
+ {
+ Assert.assertEquals(type, stream.removeFirst());
+ Assert.assertEquals(o, stream.removeFirst());
+ }
+}
Added:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/MapBuilder.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/MapBuilder.java
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/MapBuilder.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class MapBuilder<K, V> {
+
+ private final HashMap<K, V> map = new HashMap<K,V>();
+
+ public static <K, V> MapBuilder<K, V> create(K key, V value) {
+ return new MapBuilder<K,V>().with(key, value);
+ }
+
+ public MapBuilder<K, V> with(K key, V value) {
+ map.put(key, value);
+ return this;
+ }
+
+ public Map<K, V> build(K key, V value) {
+ map.put(key, value);
+ return map;
+ }
+}
Added:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/SetBuilder.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/SetBuilder.java
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/SetBuilder.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class SetBuilder<E> {
+
+ private final HashSet<E> map = new HashSet<E>();
+
+ public static <E> SetBuilder<E> create(E element) {
+ return new SetBuilder<E>().with(element);
+ }
+
+ public SetBuilder<E> with(E element) {
+ map.add(element);
+ return this;
+ }
+
+ public Set<E> build(E element) {
+ map.add(element);
+ return map;
+ }
+}
\ No newline at end of file
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,129 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.exoplatform.webui.application.replication.model.TypeDomain;
+import org.exoplatform.webui.application.replication.serial.DataKind;
+import org.exoplatform.webui.application.replication.serial.ObjectWriter;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestSerialization extends TestCase
+{
+
+ public void testBar()
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(A.class);
+ A a = new A();
+ ObjectWriter writer = new ObjectWriter(domain);
+ DataOutputImpl output = new DataOutputImpl();
+ writer.write(a, output);
+ output.assertInt(DataKind.OBJECT);
+ output.assertInt(0);
+ output.assertSerializable(A.class);
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable("a");
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable(2);
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable(true);
+ output.assertEmpty();
+
+ //
+ writer.write(a, output);
+ output.assertInt(DataKind.OBJECT_REF);
+ output.assertInt(0);
+ output.assertEmpty();
+ }
+
+ public void testFoo()
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(B.class);
+
+ B b = new B();
+ B b2 = new B(b);
+ b.ref = b2;
+
+ ObjectWriter writer = new ObjectWriter(domain);
+ DataOutputImpl output = new DataOutputImpl();
+ writer.write(b, output);
+
+ output.assertInt(DataKind.OBJECT);
+ output.assertInt(0);
+ output.assertSerializable(B.class);
+
+ output.assertInt(DataKind.OBJECT);
+ output.assertInt(1);
+ output.assertSerializable(B.class);
+
+ output.assertInt(DataKind.OBJECT_REF);
+ output.assertInt(0);
+ output.assertEmpty();
+ }
+
+ public void testJuu()
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(C2.class);
+
+ C2 c = new C2();
+
+ ObjectWriter writer = new ObjectWriter(domain);
+ DataOutputImpl output = new DataOutputImpl();
+ writer.write(c, output);
+
+ output.assertInt(DataKind.OBJECT);
+ output.assertInt(0);
+ output.assertSerializable(C2.class);
+
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable("a2");
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable("a1");
+ output.assertEmpty();
+ }
+
+ public void testDaa()
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(D.class);
+
+ D c = new D();
+
+ ObjectWriter writer = new ObjectWriter(domain);
+ DataOutputImpl output = new DataOutputImpl();
+ writer.write(c, output);
+
+ output.assertInt(DataKind.OBJECT);
+ output.assertInt(0);
+ output.assertSerializable(D.class);
+
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable("a");
+ output.assertInt(DataKind.SERIALIZABLE_OBJECT);
+ output.assertSerializable(c);
+ output.assertEmpty();
+ }
+}
Added:
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
(rev 0)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-13
12:19:46 UTC (rev 1253)
@@ -0,0 +1,77 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.exoplatform.webui.application.replication.model.*;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestTypeModel extends TestCase
+{
+
+
+ public void testBar()
+ {
+ TypeDomain domain = new TypeDomain();
+ assertEquals(0, domain.getSize());
+ }
+
+ public void testFoo()
+ {
+ TypeDomain domain = new TypeDomain();
+ assertType(String.class, domain.add(String.class));
+ assertEquals(1, domain.getSize());
+ assertType(String.class, domain.getTypeModel(String.class));
+ }
+
+ public void testJuu()
+ {
+ TypeDomain domain = new TypeDomain();
+ ClassTypeModel aTM = (ClassTypeModel) domain.add(A.class);
+ assertEquals(4, 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());
+ Map<String, FieldModel> fieldMap = aTM.getFieldMap();
+ assertEquals(3, fieldMap.size());
+ FieldModel aFM = fieldMap.get("a");
+ assertEquals("a", aFM.getName());
+ assertEquals(domain.getTypeModel(String.class), aFM.getType());
+ FieldModel bFM = fieldMap.get("b");
+ assertEquals("b", bFM.getName());
+ assertEquals(domain.getTypeModel(int.class), bFM.getType());
+ FieldModel cFM = fieldMap.get("c");
+ assertEquals("c", cFM.getName());
+ assertEquals(domain.getTypeModel(boolean.class), cFM.getType());
+ }
+
+ private void assertType(Class<? extends Serializable> javaType, TypeModel
typeModel)
+ {
+ assertTrue(typeModel instanceof SerializableTypeModel);
+ SerializableTypeModel serializableTypeModel = (SerializableTypeModel)typeModel;
+ assertEquals(javaType, serializableTypeModel.getJavaType());
+ }
+
+}