[gatein-commits] gatein SVN: r6646 - in components/mop/trunk: core/src/main/java/org/gatein/mop/core/api and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jun 14 10:05:40 EDT 2011


Author: julien_viet
Date: 2011-06-14 10:05:40 -0400 (Tue, 14 Jun 2011)
New Revision: 6646

Added:
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/AdapterFactoryRegistration.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Bar.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Foo.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Juu.java
   components/mop/trunk/core/src/test/resources/META-INF/
   components/mop/trunk/core/src/test/resources/META-INF/services/
   components/mop/trunk/core/src/test/resources/META-INF/services/org.gatein.mop.spi.AdapterFactory
   components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/AdapterFactory.java
Removed:
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/SecuredImpl.java
Modified:
   components/mop/trunk/api/src/main/java/org/gatein/mop/api/Adaptable.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/MOPService.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/util/Tools.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AdapterTestCase.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Secured.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java
Log:
GTNMOP-40 : Adapter pattern support for non mixin types


Modified: components/mop/trunk/api/src/main/java/org/gatein/mop/api/Adaptable.java
===================================================================
--- components/mop/trunk/api/src/main/java/org/gatein/mop/api/Adaptable.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/api/src/main/java/org/gatein/mop/api/Adaptable.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -20,7 +20,7 @@
 package org.gatein.mop.api;
 
 /**
- * The adapter pattern for the MOP.
+ * The adapter pattern.
  *
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -29,19 +29,20 @@
 {
 
    /**
-    * Returns an adapter for the specified type.
+    * Returns an adaptee for the specified type.
     *
-    * @param adaptedType the adapted type class
-    * @param <A> the adapted type
-    * @return the adapter or null
+    * @param adapterType the adapter type class
+    * @param <A> the adapter type
+    * @return the adaptee or null
     */
-   <A> A adapt(Class<A> adaptedType);
+   <A> A adapt(Class<A> adapterType);
 
    /**
     * Returns true if the workspace object is adapted to the specified type.
     *
-    * @param adaptedType the adapted type
+    * @param adapterType the adapter type
     * @return the adaptability of the current object
     */
-   boolean isAdapted(Class<?> adaptedType);
+   boolean isAdapted(Class<?> adapterType);
+
 }

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/AdapterFactoryRegistration.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/AdapterFactoryRegistration.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/AdapterFactoryRegistration.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -0,0 +1,72 @@
+/**
+ * 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.gatein.mop.core.api;
+
+import org.gatein.mop.core.util.Tools;
+import org.gatein.mop.spi.AdapterFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class AdapterFactoryRegistration<T, A>
+{
+
+   /** . */
+   private static final Map<Class<?>, AdapterFactoryRegistration<?, ?>> instances;
+
+   static
+   {
+      ServiceLoader<AdapterFactory> loader = ServiceLoader.load(AdapterFactory.class);
+      Map<Class<?>, AdapterFactoryRegistration<?, ?>> map = new HashMap<Class<?>, AdapterFactoryRegistration<?, ?>>();
+      for (AdapterFactory factory : loader)
+      {
+         AdapterFactoryRegistration registration = new AdapterFactoryRegistration(factory);
+         map.put(registration.adapterType, registration);
+      }
+
+      //
+      instances = map;
+   }
+
+   static <A> AdapterFactoryRegistration<Object, A> getInstance(Class<A> type)
+   {
+      return (AdapterFactoryRegistration<Object, A>)instances.get(type);
+   }
+
+   /** . */
+   final AdapterFactory<T, A> factory;
+
+   /** . */
+   final Class<T> adapteeType;
+
+   /** . */
+   final Class<A> adapterType;
+
+   AdapterFactoryRegistration(AdapterFactory<T, A> factory)
+   {
+      this.factory = factory;
+      this.adapteeType = (Class<T>)Tools.resolve(factory.getClass(), AdapterFactory.class, 0);
+      this.adapterType = (Class<A>)Tools.resolve(factory.getClass(), AdapterFactory.class, 1);
+   }
+}

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/MOPService.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/MOPService.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/MOPService.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -78,10 +78,6 @@
       //
    }
 
-   protected <A> Class<? extends A> getConcreteAdapterType(Class<A> adapterType) {
-      return null;
-   }
-
    protected abstract Chromattic getChromattic();
 
    public void start() throws Exception

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -123,22 +123,31 @@
       return getWorkspaceImpl();
    }
 
-   public <A> A getAdapter(Object o, Class<A> adaptedType, boolean adapt)
+   public <A> A getAdapter(Object o, Class<A> adapterType)
    {
-      Class<? extends A> adapterType = mop.getConcreteAdapterType(adaptedType);
-      if (adapterType == null) {
-         adapterType = adaptedType;
+      AdapterFactoryRegistration<Object, A> registration = AdapterFactoryRegistration.getInstance(adapterType);
+
+      //
+      if (registration != null)
+      {
+         if (registration.adapteeType.isInstance(o))
+         {
+            return registration.factory.getAdapter(o, adapterType);
+         }
+         else
+         {
+            return null;
+         }
       }
-      return _getAdapter(o, adapterType, adapt);
+      else
+      {
+         return null;
+      }
    }
 
-   private <A> A _getAdapter(Object o, Class<A> type, boolean adapt) {
-      A a = session.getEmbedded(o, type);
-      if (a == null && adapt) {
-         a = session.create(type);
-         session.setEmbedded(o, type, a);
-      }
-      return a;
+   public <A> boolean isAdaptable(Class<A> adapterType)
+   {
+      return AdapterFactoryRegistration.getInstance(adapterType) != null;
    }
 
    private WorkspaceImpl getWorkspaceImpl()

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -18,6 +18,7 @@
  */
 package org.gatein.mop.core.api.workspace;
 
+import org.chromattic.api.ChromatticSession;
 import org.chromattic.api.annotations.*;
 import org.chromattic.ext.format.BaseEncodingObjectFormatter;
 import org.gatein.mop.api.workspace.WorkspaceObject;
@@ -26,6 +27,9 @@
 import org.gatein.mop.core.api.AttributesImpl;
 import org.gatein.mop.core.api.ModelImpl;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -39,6 +43,9 @@
    /** . */
    public ModelImpl model;
 
+   /** . */
+   private Map adapters;
+
    @Name
    public abstract String getNodeName();
 
@@ -52,16 +59,74 @@
    @Owner
    public abstract AttributesImpl getAttributes();
 
-   public <A> A adapt(Class<A> adaptedType)
+   public final <A> A adapt(Class<A> adapterType)
    {
-      return model.getAdapter(this, adaptedType, true);
+      // Lookup in map first
+      if (adapters != null)
+      {
+         Object adapter = adapters.get(adapterType);
+         if (adapter != null)
+         {
+            return (A)adapter;
+         }
+      }
+
+      //
+      A adapter;
+      if (model.isAdaptable(adapterType))
+      {
+         adapter = model.getAdapter(this, adapterType);
+         if (adapter != null)
+         {
+            if (adapters == null)
+            {
+               adapters = new HashMap();
+            }
+            adapters.put(adapterType, adapter);
+         }
+      }
+      else
+      {
+         adapter = getMixin(adapterType, true);
+      }
+
+      //
+      return adapter;
    }
 
-   public boolean isAdapted(Class<?> adaptedType)
+   public final boolean isAdapted(Class<?> adapterType)
    {
-      return model.getAdapter(this, adaptedType, false) != null;
+      if (adapters != null)
+      {
+         if (adapters.containsKey(adapterType))
+         {
+            return true;
+         }
+      }
+
+      //
+      if (model.isAdaptable(adapterType))
+      {
+         return false;
+      }
+      else
+      {
+         return getMixin(adapterType, false) != null;
+      }
    }
 
+   private <A> A getMixin(Class<A> type, boolean adapt)
+   {
+      ChromatticSession session = model.getSession();
+      A a = session.getEmbedded(this, type);
+      if (a == null && adapt)
+      {
+         a = session.create(type);
+         session.setEmbedded(this, type, a);
+      }
+      return a;
+   }
+
    public String getName()
    {
       return getNodeName();

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/util/Tools.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/util/Tools.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/util/Tools.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -18,6 +18,9 @@
  */
 package org.gatein.mop.core.util;
 
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -140,4 +143,67 @@
          }
       };
    }
+
+   /**
+    * A simplistic implementation, it may not handle all cases but it should handle enough.
+    *
+    * @param implementation the type for which the parameter requires a resolution
+    * @param type the type that owns the parameter
+    * @param parameterIndex the parameter index
+    * @return the resolved type
+    */
+   public static Type resolve(Type implementation, Class<?> type, int parameterIndex) {
+     if (implementation == null) {
+       throw new NullPointerException();
+     }
+
+     //
+     if (implementation == type) {
+       TypeVariable<? extends Class<?>>[] tp = type.getTypeParameters();
+       if (parameterIndex < tp.length) {
+         return tp[parameterIndex];
+       } else {
+         throw new IllegalArgumentException();
+       }
+     } else if (implementation instanceof Class<?>) {
+       Class<?> c = (Class<?>) implementation;
+       Type gsc = c.getGenericSuperclass();
+       Type resolved = null;
+       if (gsc != null) {
+         resolved = resolve(gsc, type, parameterIndex);
+         if (resolved == null) {
+           // Try with interface
+         }
+       }
+       return resolved;
+     } else if (implementation instanceof ParameterizedType) {
+       ParameterizedType pt = (ParameterizedType) implementation;
+       Type[] typeArgs = pt.getActualTypeArguments();
+       Type rawType = pt.getRawType();
+       if (rawType == type) {
+         return typeArgs[parameterIndex];
+       } else if (rawType instanceof Class<?>) {
+         Class<?> classRawType = (Class<?>)rawType;
+         Type resolved = resolve(classRawType, type, parameterIndex);
+         if (resolved == null) {
+           return null;
+         } else if (resolved instanceof TypeVariable) {
+           TypeVariable resolvedTV = (TypeVariable)resolved;
+           TypeVariable[] a = classRawType.getTypeParameters();
+           for (int i = 0;i < a.length;i++) {
+             if (a[i].equals(resolvedTV)) {
+               return resolve(implementation, classRawType, i);
+             }
+           }
+           throw new AssertionError();
+         } else {
+           throw new UnsupportedOperationException("Cannot support resolution of " + resolved);
+         }
+       } else {
+         throw new UnsupportedOperationException();
+       }
+     } else {
+       throw new UnsupportedOperationException("todo " + implementation + " " + implementation.getClass());
+     }
+   }
 }

Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AdapterTestCase.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AdapterTestCase.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AdapterTestCase.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -37,11 +37,10 @@
 
    public void testSecured() throws Exception
    {
-      pomService.addAdapter(Secured.class, SecuredImpl.class);
       ModelImpl model = pomService.getModel();
       Workspace workspace = model.getWorkspace();
-      Site site = workspace.addSite(ObjectType.PORTAL_SITE, "adaptablefoo");
-      assertFalse(site.isAdapted(SecuredImpl.class));
+      Site site = workspace.addSite(ObjectType.PORTAL_SITE, "adaptable_secured");
+      assertFalse(site.isAdapted(Secured.class));
       Secured secured = site.adapt(Secured.class);
       assertNotNull(secured);
       assertTrue(site.isAdapted(Secured.class));
@@ -51,4 +50,48 @@
       permissions.add("FOO");
       model.save();
    }
+
+   public void testWorkspaceObjectType() throws Exception
+   {
+      ModelImpl model = pomService.getModel();
+      Workspace workspace = model.getWorkspace();
+      Site site = workspace.addSite(ObjectType.PORTAL_SITE, "adaptable_foo");
+      assertFalse(site.isAdapted(Foo.class));
+      Foo foo = site.adapt(Foo.class);
+      assertNotNull(foo);
+      assertSame(foo, site.adapt(Foo.class));
+      assertSame(site, foo.adaptee);
+      assertSame(Foo.class, foo.adapterType);
+      assertTrue(site.isAdapted(Foo.class));
+   }
+
+   public void testWorkspaceObjectImplType() throws Exception
+   {
+      ModelImpl model = pomService.getModel();
+      Workspace workspace = model.getWorkspace();
+      Site site = workspace.addSite(ObjectType.PORTAL_SITE, "adaptable_bar");
+      assertFalse(site.isAdapted(Bar.class));
+      Bar bar = site.adapt(Bar.class);
+      assertNotNull(bar);
+      assertSame(bar, site.adapt(Bar.class));
+      assertSame(site, bar.adaptee);
+      assertSame(Bar.class, bar.adapterType);
+      assertTrue(site.isAdapted(Bar.class));
+   }
+
+   public void testSiteType() throws Exception
+   {
+      ModelImpl model = pomService.getModel();
+      Workspace workspace = model.getWorkspace();
+      assertNull(workspace.adapt(Juu.class));
+
+      Site site = workspace.addSite(ObjectType.PORTAL_SITE, "adaptable_juu");
+      assertFalse(site.isAdapted(Juu.class));
+      Juu juu = site.adapt(Juu.class);
+      assertNotNull(juu);
+      assertSame(juu, site.adapt(Juu.class));
+      assertSame(site, juu.adaptee);
+      assertSame(Juu.class, juu.adapterType);
+      assertTrue(site.isAdapted(Juu.class));
+   }
 }

Added: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Bar.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Bar.java	                        (rev 0)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Bar.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2010 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.gatein.mop.core.api.workspace;
+
+import org.gatein.mop.spi.AdapterFactory;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class Bar
+{
+
+   /** . */
+   final WorkspaceObjectImpl adaptee;
+
+   /** . */
+   final Class<Bar> adapterType;
+
+   public Bar(WorkspaceObjectImpl adaptee, Class<Bar> adapterType)
+   {
+      this.adaptee = adaptee;
+      this.adapterType = adapterType;
+   }
+
+   public static class Factory extends AdapterFactory<WorkspaceObjectImpl, Bar>
+   {
+      public Bar getAdapter(WorkspaceObjectImpl adaptee, Class<Bar> adapterType)
+      {
+         return new Bar(adaptee, adapterType);
+      }
+   }
+}

Added: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Foo.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Foo.java	                        (rev 0)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Foo.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 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.gatein.mop.core.api.workspace;
+
+import org.gatein.mop.api.workspace.WorkspaceObject;
+import org.gatein.mop.spi.AdapterFactory;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class Foo
+{
+
+   /** . */
+   final WorkspaceObject adaptee;
+
+   /** . */
+   final Class<Foo> adapterType;
+
+   public Foo(WorkspaceObject adaptee, Class<Foo> adapterType)
+   {
+      this.adaptee = adaptee;
+      this.adapterType = adapterType;
+   }
+
+   public static class Factory extends AdapterFactory<WorkspaceObject, Foo>
+   {
+      @Override
+      public Foo getAdapter(WorkspaceObject adaptee, Class<Foo> adapterType)
+      {
+         return new Foo(adaptee, adapterType);
+      }
+   }
+}

Added: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Juu.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Juu.java	                        (rev 0)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Juu.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 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.gatein.mop.core.api.workspace;
+
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.spi.AdapterFactory;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class Juu
+{
+
+   /** . */
+   final Site adaptee;
+
+   /** . */
+   final Class<Juu> adapterType;
+
+   public Juu(Site adaptee, Class<Juu> adapterType)
+   {
+      this.adaptee = adaptee;
+      this.adapterType = adapterType;
+   }
+
+   public static class Factory extends AdapterFactory<Site, Juu>
+   {
+      @Override
+      public Juu getAdapter(Site adaptee, Class<Juu> adapterType)
+      {
+         return new Juu(adaptee, adapterType);
+      }
+   }
+}

Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Secured.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Secured.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/Secured.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -19,16 +19,21 @@
 
 package org.gatein.mop.core.api.workspace;
 
+import org.chromattic.api.annotations.MixinType;
+import org.chromattic.api.annotations.Property;
+
 import java.util.List;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
  */
-public interface Secured
+ at MixinType(name = "mop:secured")
+public abstract class Secured
 {
 
-   List<String> getPermissions();
+   @Property(name = "mop:permissions")
+   public abstract List<String> getPermissions();
 
-   void setPermissions(List<String> permissions);
+   public abstract void setPermissions(List<String> permissions);
 }

Deleted: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/SecuredImpl.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/SecuredImpl.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/SecuredImpl.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2010 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.gatein.mop.core.api.workspace;
-
-import org.chromattic.api.annotations.MixinType;
-import org.chromattic.api.annotations.Property;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
- at MixinType(name = "mop:secured")
-public abstract class SecuredImpl implements Secured
-{
-
-   @Property(name = "mop:permissions")
-   public abstract List<String> getPermissions();
-
-}

Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java	2011-06-14 08:48:03 UTC (rev 6645)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -38,8 +38,8 @@
 import org.gatein.mop.core.api.workspace.PageLinkImpl;
 import org.gatein.mop.core.api.workspace.PortalSite;
 import org.gatein.mop.core.api.workspace.PortalSiteContainer;
-import org.gatein.mop.core.api.workspace.SecuredImpl;
 import org.gatein.mop.core.api.StringAttribute;
+import org.gatein.mop.core.api.workspace.Secured;
 import org.gatein.mop.core.api.workspace.SiteContainer;
 import org.gatein.mop.core.api.workspace.SiteImpl;
 import org.gatein.mop.core.api.workspace.TemplatizedImpl;
@@ -83,9 +83,6 @@
    /** . */
    private final Chromattic chromattic;
 
-   /** . */
-   private final Map<Class<?>, Class<?>> adapterMap;
-
    public TestMOPService() throws Exception
    {
       ChromatticBuilder builder = ChromatticBuilder.create();
@@ -146,24 +143,13 @@
       builder.add(GadgetState.class);
 
       //
-      builder.add(SecuredImpl.class);
+      builder.add(Secured.class);
 
       //
       this.chromattic = builder.build();
-      this.adapterMap = new HashMap<Class<?>, Class<?>>();
    }
 
-   public <A> void addAdapter(Class<A> adaptedType, Class<? extends A> adapterType) {
-      adapterMap.put(adaptedType, adapterType);
-   }
-
    @Override
-   protected <A> Class<? extends A> getConcreteAdapterType(Class<A> adapterType)
-   {
-      return (Class<A>)adapterMap.get(adapterType);
-   }
-
-   @Override
    protected Chromattic getChromattic()
    {
       return chromattic;

Added: components/mop/trunk/core/src/test/resources/META-INF/services/org.gatein.mop.spi.AdapterFactory
===================================================================
--- components/mop/trunk/core/src/test/resources/META-INF/services/org.gatein.mop.spi.AdapterFactory	                        (rev 0)
+++ components/mop/trunk/core/src/test/resources/META-INF/services/org.gatein.mop.spi.AdapterFactory	2011-06-14 14:05:40 UTC (rev 6646)
@@ -0,0 +1,3 @@
+org.gatein.mop.core.api.workspace.Foo$Factory
+org.gatein.mop.core.api.workspace.Bar$Factory
+org.gatein.mop.core.api.workspace.Juu$Factory

Added: components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/AdapterFactory.java
===================================================================
--- components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/AdapterFactory.java	                        (rev 0)
+++ components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/AdapterFactory.java	2011-06-14 14:05:40 UTC (rev 6646)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2010 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.gatein.mop.spi;
+
+/**
+ * The adapter factory.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class AdapterFactory<T, A>
+{
+
+   public abstract A getAdapter(T adaptee, Class<A> adapterType);
+
+}



More information about the gatein-commits mailing list