From do-not-reply at jboss.org Tue Sep 13 02:16:51 2011 Content-Type: multipart/mixed; boundary="===============5860985321486130021==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r7369 - in components/mop/trunk: core/src/test/java/org/gatein/mop/core/api/workspace and 1 other directory. Date: Tue, 13 Sep 2011 02:16:50 -0400 Message-ID: <201109130616.p8D6GoVj005320@svn01.web.mwc.hst.phx2.redhat.com> --===============5860985321486130021== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien_viet Date: 2011-09-13 02:16:50 -0400 (Tue, 13 Sep 2011) New Revision: 7369 Modified: components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Obje= ctType.java components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspac= e/ObjectTypeTestCase.java Log: GTNMOP-43 : ObjectType should implement java.io.Serializable Modified: components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspa= ce/ObjectType.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Obj= ectType.java 2011-09-13 05:57:01 UTC (rev 7368) +++ components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Obj= ectType.java 2011-09-13 06:16:50 UTC (rev 7369) @@ -25,6 +25,8 @@ import org.gatein.mop.api.workspace.link.PageLink; import org.gatein.mop.api.workspace.link.URLLink; = +import java.io.InvalidObjectException; +import java.io.Serializable; import java.util.Set; import java.util.HashSet; = @@ -34,58 +36,80 @@ * @author Julien Viet * @version $Revision$ */ -public class ObjectType +public class ObjectType implements Serializable { = /** . */ - public static final ObjectType ANY =3D new ObjectType<= WorkspaceObject>(WorkspaceObject.class); + public static final ObjectType ANY =3D new ObjectType<= WorkspaceObject>(0, WorkspaceObject.class); = /** . */ - public static final ObjectType WORKSPACE =3D new ObjectType<= Workspace>(Workspace.class); + public static final ObjectType WORKSPACE =3D new ObjectType<= Workspace>(1, Workspace.class); = /** . */ - public static final ObjectType SITE =3D new ObjectType(Site= .class); + public static final ObjectType SITE =3D new ObjectType(2, S= ite.class); = /** . */ - public static final ObjectType PORTAL_SITE =3D new ObjectType(Site.class, SITE); + public static final ObjectType PORTAL_SITE =3D new ObjectType(3, Site.class, SITE); = /** . */ - public static final ObjectType GROUP_SITE =3D new ObjectType(Site.class, SITE); + public static final ObjectType GROUP_SITE =3D new ObjectType(4, Site.class, SITE); = /** . */ - public static final ObjectType USER_SITE =3D new ObjectType= (Site.class, SITE); + public static final ObjectType USER_SITE =3D new ObjectType= (5, Site.class, SITE); = /** . */ - public static final ObjectType PAGE =3D new ObjectType(Page= .class); + public static final ObjectType PAGE =3D new ObjectType(6, P= age.class); = /** . */ - public static final ObjectType NAVIGATION =3D new ObjectTyp= e(Navigation.class); + public static final ObjectType NAVIGATION =3D new ObjectTyp= e(7, Navigation.class); = /** . */ - public static final ObjectType COMPONENT =3D new ObjectTyp= e(UIComponent.class); + public static final ObjectType COMPONENT =3D new ObjectTyp= e(8, UIComponent.class); = /** . */ - public static final ObjectType BODY =3D new ObjectType(= UIBody.class, COMPONENT); + public static final ObjectType BODY =3D new ObjectType(= 9, UIBody.class, COMPONENT); = /** . */ - public static final ObjectType CONTAINER =3D new ObjectTyp= e(UIContainer.class, COMPONENT); + public static final ObjectType CONTAINER =3D new ObjectTyp= e(10, UIContainer.class, COMPONENT); = /** . */ - public static final ObjectType WINDOW =3D new ObjectType(UIWindow.class, COMPONENT); + public static final ObjectType WINDOW =3D new ObjectType(11, UIWindow.class, COMPONENT); = /** . */ - public static final ObjectType PAGE_LINK =3D new ObjectType(PageLink.class); + public static final ObjectType PAGE_LINK =3D new ObjectType(12, PageLink.class); = /** . */ - public static final ObjectType URL_LINK =3D new ObjectType(URLLink.class); + public static final ObjectType URL_LINK =3D new ObjectType(13, URLLink.class); = /** . */ - private final Class javaType; + private static final ObjectType[] ENUMERATION =3D + { + ANY, + WORKSPACE, + SITE, + PORTAL_SITE, + GROUP_SITE, + USER_SITE, + PAGE, + NAVIGATION, + COMPONENT, + BODY, + CONTAINER, + WINDOW, + PAGE_LINK, + URL_LINK + }; = /** . */ - private final Set> superTypes; + private final int ordinal; = - private ObjectType(Class javaType, ObjectType... superTypes) + /** . */ + private final transient Class javaType; + + /** . */ + private final transient Set> superTypes; + + private ObjectType(int ordinal, Class javaType, ObjectType... sup= erTypes) { for (ObjectType superType : superTypes) { @@ -103,6 +127,7 @@ } = // + this.ordinal =3D ordinal; this.javaType =3D javaType; this.superTypes =3D tmp; } @@ -141,6 +166,18 @@ } } = + private Object readResolve () throws java.io.ObjectStreamException + { + if (ordinal >=3D 0 || ordinal < ENUMERATION.length) + { + return ENUMERATION[ordinal]; + } + else + { + throw new InvalidObjectException("Corrupted ordinal value" + ordi= nal); + } + } + @Override public String toString() { Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/w= orkspace/ObjectTypeTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspa= ce/ObjectTypeTestCase.java 2011-09-13 05:57:01 UTC (rev 7368) +++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspa= ce/ObjectTypeTestCase.java 2011-09-13 06:16:50 UTC (rev 7369) @@ -21,6 +21,11 @@ import junit.framework.TestCase; import org.gatein.mop.api.workspace.ObjectType; = +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + /** * @author Julien Viet * @version $Revision$ @@ -44,4 +49,16 @@ assertTrue(ObjectType.SITE.isAssignableFrom(ObjectType.GROUP_SITE)); assertFalse(ObjectType.GROUP_SITE.isAssignableFrom(ObjectType.SITE)); } + + public void testSerialization() throws Exception + { + ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); + ObjectOutputStream out =3D new ObjectOutputStream(baos); + out.writeObject(ObjectType.PAGE); + out.close(); + ByteArrayInputStream bais =3D new ByteArrayInputStream(baos.toByteAr= ray()); + ObjectInputStream in =3D new ObjectInputStream(bais); + Object o =3D in.readObject(); + assertSame(ObjectType.PAGE, o); + } } --===============5860985321486130021==--