Author: julien_viet
Date: 2010-01-13 18:40:46 -0500 (Wed, 13 Jan 2010)
New Revision: 1268
Removed:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/A.java
Log:
remove wrong impl for now
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-13
22:19:50 UTC (rev 1267)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-13
23:40:46 UTC (rev 1268)
@@ -25,32 +25,52 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class FieldModel {
+public class FieldModel
+{
- /** . */
- private final Field field;
+ /** . */
+ private final Field field;
- /** . */
- private final TypeModel type;
+ /** . */
+ private final TypeModel type;
- public FieldModel(Field field, TypeModel type) {
- this.field = field;
- this.type = type;
- }
+ public FieldModel(Field field, TypeModel type)
+ {
+ this.field = field;
+ this.type = type;
+ }
- public String getName() {
- return field.getName();
- }
+ public String getName()
+ {
+ return field.getName();
+ }
- public TypeModel getType() {
- return type;
- }
+ public TypeModel getType()
+ {
+ return type;
+ }
- public Object getValue(Object o) {
- try {
- return field.get(o);
- } catch (IllegalAccessException e) {
- throw new AssertionError(e);
- }
- }
+ public Object getValue(Object o)
+ {
+ try
+ {
+ return field.get(o);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+ public void setValue(Object o, Object value)
+ {
+ try
+ {
+ field.set(o, value);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new AssertionError(e);
+ }
+ }
}
Deleted:
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-13
22:19:50 UTC (rev 1267)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-13
23:40:46 UTC (rev 1268)
@@ -1,127 +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.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();
- }
- }
- }
- }
-}
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-13
22:19:50 UTC (rev 1267)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/A.java 2010-01-13
23:40:46 UTC (rev 1268)
@@ -28,8 +28,8 @@
@ReplicatedType
public class A {
- String a = "a";
- int b = 2;
- boolean c = true;
+ String a;
+ int b;
+ boolean c;
}
Deleted:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-13
22:19:50 UTC (rev 1267)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-13
23:40:46 UTC (rev 1268)
@@ -1,129 +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.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();
- }
-}