[gatein-commits] gatein SVN: r1660 - in portal/trunk: component/common and 12 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Feb 12 05:39:34 EST 2010


Author: julien_viet
Date: 2010-02-12 05:39:33 -0500 (Fri, 12 Feb 2010)
New Revision: 1660

Added:
   portal/trunk/component/management/
   portal/trunk/component/management/pom.xml
   portal/trunk/component/management/src/
   portal/trunk/component/management/src/main/
   portal/trunk/component/management/src/main/java/
   portal/trunk/component/management/src/main/java/org/
   portal/trunk/component/management/src/main/java/org/exoplatform/
   portal/trunk/component/management/src/main/java/org/exoplatform/management/
   portal/trunk/component/management/src/main/java/org/exoplatform/management/ResourceKey.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/Rest.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/RestManagementProvider.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/ValueWrapper.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/data/
   portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethod.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethodParameter.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceProperty.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/
   portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/GetterInvoker.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/MethodInvoker.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/NoSuchMethodInvoker.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SetterInvoker.java
   portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SimpleMethodInvoker.java
   portal/trunk/component/management/src/main/resources/
   portal/trunk/component/management/src/test/
   portal/trunk/component/management/src/test/java/
   portal/trunk/component/management/src/test/resources/
Modified:
   portal/trunk/component/common/pom.xml
   portal/trunk/component/pom.xml
   portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js
   portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml
Log:
GTNPORTAL-639 : Rest management connector


Modified: portal/trunk/component/common/pom.xml
===================================================================
--- portal/trunk/component/common/pom.xml	2010-02-12 09:44:54 UTC (rev 1659)
+++ portal/trunk/component/common/pom.xml	2010-02-12 10:39:33 UTC (rev 1660)
@@ -63,10 +63,6 @@
       <groupId>org.chromattic</groupId>
       <artifactId>chromattic.spi</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.exoplatform.ws</groupId>
-      <artifactId>exo.ws.rest.core</artifactId>
-    </dependency>
 
     <dependency>
       <groupId>org.exoplatform.portal</groupId>

Added: portal/trunk/component/management/pom.xml
===================================================================
--- portal/trunk/component/management/pom.xml	                        (rev 0)
+++ portal/trunk/component/management/pom.xml	2010-02-12 10:39:33 UTC (rev 1660)
@@ -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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.exoplatform.portal</groupId>
+    <artifactId>exo.portal.component</artifactId>
+    <version>3.0.0-CR01-SNAPSHOT</version>
+  </parent> 
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>exo.portal.component.management</artifactId>
+  <packaging>jar</packaging>
+  <name>GateIn Portal Component Management</name>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.exoplatform.portal</groupId>
+      <artifactId>exo.portal.component.common</artifactId>
+      <version>3.0.0-CR01-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.exoplatform.kernel</groupId>
+      <artifactId>exo.kernel.commons</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.exoplatform.ws</groupId>
+      <artifactId>exo.ws.rest.core</artifactId>
+    </dependency>
+
+  </dependencies>
+</project>

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/ResourceKey.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/ResourceKey.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/ResourceKey.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,61 @@
+/*
+ * 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.management;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public final class ResourceKey
+{
+
+   /** . */
+   private final String name;
+
+   public ResourceKey(String name)
+   {
+      if (name == null)
+      {
+         throw new NullPointerException();
+      }
+      this.name = name;
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return name.hashCode();
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+      {
+         return true;
+      }
+      if (obj instanceof ResourceKey)
+      {
+         ResourceKey that = (ResourceKey)obj;
+         return name.equals(that.name);
+      }
+      return false;
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/Rest.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/Rest.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/Rest.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,38 @@
+/*
+ * 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.management;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.TYPE)
+public @interface Rest
+{
+
+   String value();
+
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/RestManagementProvider.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/RestManagementProvider.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/RestManagementProvider.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,101 @@
+/*
+ * 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.management;
+
+import org.exoplatform.management.data.RestResource;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.management.spi.ManagedResource;
+import org.exoplatform.management.spi.ManagementProvider;
+import org.exoplatform.services.rest.resource.ResourceContainer;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Path("management")
+public class RestManagementProvider implements ResourceContainer, ManagementProvider
+{
+
+   /** . */
+   private final ExoContainerContext context;
+
+   /** . */
+   private final Map<ResourceKey, RestResource> resourceMap = new HashMap<ResourceKey, RestResource>();
+
+   public RestManagementProvider(ExoContainerContext context)
+   {
+      this.context = context;
+   }
+
+   @GET
+   @Produces(MediaType.APPLICATION_JSON)
+   public ValueWrapper list()
+   {
+      List<String> list = new ArrayList<String>();
+      for (RestResource mr : resourceMap.values())
+      {
+         list.add(mr.getName());
+      }
+      return ValueWrapper.wrap(list);
+   }
+
+   @Path("{resource}")
+   public RestResource dispatch(@PathParam("resource") String resourceName)
+   {
+      return resourceMap.get(new ResourceKey(resourceName));
+   }
+
+   // ManagementProvider implementation ******************************************************************************** 
+
+   public Object manage(ManagedResource managedResource)
+   {
+      Object resource = managedResource.getResource();
+
+      //
+      Rest annotation = resource.getClass().getAnnotation(Rest.class);
+
+      //
+      if (annotation != null)
+      {
+         String name = annotation.value();
+         ResourceKey key = new ResourceKey(name);
+         resourceMap.put(key, new RestResource(name, managedResource));
+         return key;
+      }
+
+      //
+      return null;
+   }
+
+   public void unmanage(Object key)
+   {
+      resourceMap.remove(key);
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/ValueWrapper.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/ValueWrapper.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/ValueWrapper.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,48 @@
+/*
+ * 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.management;
+
+/**
+ * Temporary class until eXo JSON marshaller supports non java bean objects.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class ValueWrapper<T>
+{
+
+   public static <T> ValueWrapper<T> wrap(T value)
+   {
+      return new ValueWrapper<T>(value);
+   }
+
+   /** . */
+   private final T value;
+
+   public ValueWrapper(T value)
+   {
+      this.value = value;
+   }
+
+   public T getValue()
+   {
+      return value;
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,239 @@
+/*
+ * 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.management.data;
+
+import org.exoplatform.management.ValueWrapper;
+import org.exoplatform.management.invocation.MethodInvoker;
+import org.exoplatform.management.annotations.ImpactType;
+import org.exoplatform.management.spi.ManagedMethodMetaData;
+import org.exoplatform.management.spi.ManagedPropertyMetaData;
+import org.exoplatform.management.spi.ManagedResource;
+import org.exoplatform.management.spi.ManagedTypeMetaData;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RestResource
+{
+
+   /** . */
+   final Map<String, RestResourceProperty> properties;
+
+   /** . */
+   private final List<RestResourceMethod> methods;
+
+   /** . */
+   private final ManagedResource managedResource;
+
+   /** . */
+   private final String name;
+
+   /** . */
+   private final String description;
+
+   public RestResource(String name, ManagedResource managedResource)
+   {
+      ManagedTypeMetaData managedType = managedResource.getMetaData();
+
+      //
+      HashMap<String, RestResourceProperty> properties = new HashMap<String, RestResourceProperty>();
+      for (ManagedPropertyMetaData managedProperty : managedType.getProperties()) {
+         RestResourceProperty resourceProperty = new RestResourceProperty(managedProperty);
+         properties.put(resourceProperty.getName(), resourceProperty);
+      }
+
+      //
+      List<RestResourceMethod> methods = new ArrayList<RestResourceMethod>();
+      for (ManagedMethodMetaData managedMethod : managedType.getMethods()) {
+         RestResourceMethod resourceMethod = new RestResourceMethod(managedMethod);
+         methods.add(resourceMethod);
+      }
+
+      //
+      this.name = name;
+      this.description = managedType.getDescription();
+      this.managedResource = managedResource;
+      this.properties = Collections.unmodifiableMap(properties);
+      this.methods = methods;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public String getDescription()
+   {
+      return description;
+   }
+
+   public Collection<RestResourceProperty> getProperties()
+   {
+      return properties.values();
+   }
+
+   public Collection<RestResourceMethod> getMethods()
+   {
+      return methods;
+   }
+
+   @GET
+   @Produces(MediaType.APPLICATION_JSON)
+   public RestResource get()
+   {
+      return this;
+   }
+
+   @GET
+   @Path("{name}")
+   @Produces(MediaType.APPLICATION_JSON)
+   public Object get(@Context UriInfo info, @PathParam("name") String name)
+   {
+      // Try first to get a property
+      RestResourceProperty property = properties.get(name);
+      if (property != null)
+      {
+         MethodInvoker getter = property.getGetterInvoker();
+         if (getter != null)
+         {
+            return safeInvoke(getter, info.getQueryParameters());
+         }
+      }
+
+      //
+      return tryInvoke(name, info, ImpactType.READ);
+   }
+
+   @PUT
+   @Path("{name}")
+   @Produces(MediaType.APPLICATION_JSON)
+   public Object put(@Context UriInfo info, @PathParam("name") String name)
+   {
+      // Try first to get a property
+      RestResourceProperty property = properties.get(name);
+      if (property != null)
+      {
+         MethodInvoker setter = property.getSetterInvoker();
+         if (setter != null)
+         {
+            return safeInvoke(setter, info.getQueryParameters());
+         }
+      }
+
+      //
+      return tryInvoke(name, info, ImpactType.IDEMPOTENT_WRITE);
+   }
+
+   @POST
+   @Path("{name}")
+   @Produces(MediaType.APPLICATION_JSON)
+   public Object post(@Context UriInfo info, @PathParam("name") String name)
+   {
+      return tryInvoke(name, info, ImpactType.WRITE);
+   }
+
+   /**
+    * Try to invoke a method with matching parameters from the query string
+    *
+    * @param info the uri info
+    * @param impact the expected impact
+    * @return a suitable response
+    */
+   private Object tryInvoke(String methodName, UriInfo info, ImpactType impact)
+   {
+      MultivaluedMap<String, String> parameters = info.getQueryParameters();
+
+      //
+      RestResourceMethod method = lookupMethod(methodName, parameters.keySet(), impact);
+
+      //
+      if (method != null)
+      {
+         MethodInvoker invoker = method.getMethodInvoker();
+         return safeInvoke(invoker, parameters);
+      }
+
+      //
+      return null;
+   }
+
+   private RestResourceMethod lookupMethod(String methodName, Set<String> argNames, ImpactType impact)
+   {
+      for (RestResourceMethod method : methods)
+      {
+         if (method.getName().equals(methodName) && method.metaData.getImpact() == impact && method.parameterNames.equals(argNames))
+         {
+            return method;
+         }
+      }
+      return null;
+   }
+
+   /**
+    * Invoke safely a method.
+    *
+    * @param invoker the method to invoke
+    * @param argMap the arguments
+    * @return the ok response or an object returned by the method wrapped by {@link ValueWrapper}
+    */
+   private Object safeInvoke(MethodInvoker invoker, Map<String, List<String>> argMap)
+   {
+      Object resource = managedResource.getResource();
+
+      //
+      managedResource.beforeInvoke(resource);
+
+      //
+      try
+      {
+         Object ret = invoker.invoke(resource, argMap);
+         return ret == null ? Response.ok() : ValueWrapper.wrap(ret);
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         return Response.serverError();
+      }
+      finally
+      {
+         managedResource.afterInvoke(resource);
+      }
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethod.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethod.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethod.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,113 @@
+/*
+ * 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.management.data;
+
+import org.exoplatform.management.invocation.MethodInvoker;
+import org.exoplatform.management.invocation.SimpleMethodInvoker;
+import org.exoplatform.management.spi.ManagedMethodMetaData;
+import org.exoplatform.management.spi.ManagedMethodParameterMetaData;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RestResourceMethod
+{
+
+   /** . */
+   final ManagedMethodMetaData metaData;
+
+   /** . */
+   final List<RestResourceMethodParameter> parameters;
+
+   /** . */
+   final Set<String> parameterNames;
+
+   /** . */
+   final MethodInvoker methodInvoker;
+
+   public RestResourceMethod(ManagedMethodMetaData metaData)
+   {
+      List<RestResourceMethodParameter> parameters = new ArrayList<RestResourceMethodParameter>();
+      Set<String> parameterNames = new HashSet<String>();
+      for (ManagedMethodParameterMetaData parameterMD : metaData.getParameters())
+      {
+         parameters.add(new RestResourceMethodParameter(parameterMD));
+         parameterNames.add(parameterMD.getName());
+      }
+
+      //
+      this.metaData = metaData;
+      this.parameterNames = Collections.unmodifiableSet(parameterNames);
+      this.parameters = Collections.unmodifiableList(parameters);
+      this.methodInvoker = new SimpleMethodInvoker(metaData.getMethod())
+      {
+         @Override
+         protected String getArgumentName(int index)
+         {
+            RestResourceMethodParameter param = RestResourceMethod.this.parameters.get(index);
+            return param != null ? param.getName() : null;
+         }
+      };
+   }
+
+   public String getName()
+   {
+      return metaData.getName();
+   }
+
+   public String getMethod()
+   {
+      switch (metaData.getImpact())
+      {
+         case READ:
+            return "get";
+         case WRITE:
+            return "post";
+         case IDEMPOTENT_WRITE:
+            return "put";
+         default:
+            throw new AssertionError();
+      }
+   }
+
+   public String getDescription()
+   {
+      return metaData.getDescription();
+   }
+
+   public List<RestResourceMethodParameter> getParameters()
+   {
+      return parameters;
+   }
+
+   // Internal *********************************************************************************************************
+
+   MethodInvoker getMethodInvoker()
+   {
+      return methodInvoker;
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethodParameter.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethodParameter.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceMethodParameter.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,48 @@
+/*
+ * 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.management.data;
+
+import org.exoplatform.management.spi.ManagedMethodParameterMetaData;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RestResourceMethodParameter
+{
+
+   /** . */
+   final ManagedMethodParameterMetaData metaData;
+
+   public RestResourceMethodParameter(ManagedMethodParameterMetaData metaData)
+   {
+      this.metaData = metaData;
+   }
+
+   public String getName()
+   {
+      return metaData.getName();
+   }
+
+   public String getDescription()
+   {
+      return metaData.getDescription();
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceProperty.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceProperty.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResourceProperty.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,82 @@
+/*
+ * 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.management.data;
+
+import org.exoplatform.management.invocation.GetterInvoker;
+import org.exoplatform.management.invocation.MethodInvoker;
+import org.exoplatform.management.invocation.NoSuchMethodInvoker;
+import org.exoplatform.management.invocation.SetterInvoker;
+import org.exoplatform.management.spi.ManagedPropertyMetaData;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RestResourceProperty
+{
+
+   /** . */
+   final ManagedPropertyMetaData metaData;
+
+   /** . */
+   private final MethodInvoker setterInvoker;
+
+   /** . */
+   private final MethodInvoker getterInvoker;
+
+   public RestResourceProperty(ManagedPropertyMetaData metaData)
+   {
+      Method getter = metaData.getGetter();
+      MethodInvoker getterInvoker = getter != null ? new GetterInvoker(getter) : new NoSuchMethodInvoker();
+
+      //
+      Method setter = metaData.getSetter();
+      MethodInvoker setterInvoker = setter != null ? new SetterInvoker(setter) : new NoSuchMethodInvoker();
+
+      //
+      this.metaData = metaData;
+      this.setterInvoker = setterInvoker;
+      this.getterInvoker = getterInvoker;
+   }
+
+   public String getName()
+   {
+      return metaData.getName();
+   }
+
+   public String getDescription()
+   {
+      return metaData.getDescription();
+   }
+
+   // Internal *********************************************************************************************************
+
+   MethodInvoker getSetterInvoker()
+   {
+      return setterInvoker;
+   }
+
+   MethodInvoker getGetterInvoker()
+   {
+      return getterInvoker;
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/GetterInvoker.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/GetterInvoker.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/GetterInvoker.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,41 @@
+/*
+ * 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.management.invocation;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class GetterInvoker extends SimpleMethodInvoker
+{
+
+   public GetterInvoker(Method method)
+   {
+      super(method);
+   }
+
+   @Override
+   protected String getArgumentName(int index)
+   {
+      throw new IndexOutOfBoundsException();
+   }
+}
\ No newline at end of file

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/MethodInvoker.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/MethodInvoker.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/MethodInvoker.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -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.management.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface MethodInvoker
+{
+
+   Object invoke(Object o, Map<String, List<String>> argMap) throws IllegalAccessException, InvocationTargetException;
+
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/NoSuchMethodInvoker.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/NoSuchMethodInvoker.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/NoSuchMethodInvoker.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -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.management.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class NoSuchMethodInvoker implements MethodInvoker
+{
+   public Object invoke(Object o, Map<String, List<String>> argMap) throws IllegalAccessException, InvocationTargetException
+   {
+      throw new UnsupportedOperationException();
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SetterInvoker.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SetterInvoker.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SetterInvoker.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,48 @@
+/*
+ * 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.management.invocation;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class SetterInvoker extends SimpleMethodInvoker
+{
+
+   public SetterInvoker(Method method)
+   {
+      super(method);
+   }
+
+   @Override
+   protected String getArgumentName(int index)
+   {
+      if (index == 0)
+      {
+         return "value";
+      }
+      else
+      {
+         throw new IndexOutOfBoundsException();
+      }
+   }
+}

Added: portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SimpleMethodInvoker.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SimpleMethodInvoker.java	                        (rev 0)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/invocation/SimpleMethodInvoker.java	2010-02-12 10:39:33 UTC (rev 1660)
@@ -0,0 +1,82 @@
+/*
+ * 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.management.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class SimpleMethodInvoker implements MethodInvoker
+{
+
+   /** The method we invoke. */
+   private final Method method;
+
+   public SimpleMethodInvoker(Method method)
+   {
+      if (method == null)
+      {
+         throw new NullPointerException();
+      }
+
+      //
+      this.method = method;
+   }
+
+   public Object invoke(Object o, Map<String, List<String>> argMap) throws IllegalAccessException, InvocationTargetException
+   {
+      Class[] paramTypes = method.getParameterTypes();
+      Object[] args = new Object[paramTypes.length];
+      for (int i = 0;i < paramTypes.length;i++)
+      {
+         String argName = getArgumentName(i);
+         List<String> argValues = argMap.get(argName);
+         Class paramType = paramTypes[i];
+         Object arg;
+         if (paramType.isPrimitive())
+         {
+            throw new UnsupportedOperationException("Todo " + paramType);
+         }
+         else if (paramType.isArray())
+         {
+            throw new UnsupportedOperationException("Todo " + paramType);
+         }
+         else if (paramType == String.class)
+         {
+            arg = (argValues != null && argValues.size() > 0) ? argValues.get(0) : null;
+         }
+         else
+         {
+            throw new UnsupportedOperationException("Todo " + paramType);
+         }
+         args[i] = arg;
+      }
+
+      //
+      return method.invoke(o, args);
+   }
+
+   protected abstract String getArgumentName(int index);
+}
\ No newline at end of file

Modified: portal/trunk/component/pom.xml
===================================================================
--- portal/trunk/component/pom.xml	2010-02-12 09:44:54 UTC (rev 1659)
+++ portal/trunk/component/pom.xml	2010-02-12 10:39:33 UTC (rev 1660)
@@ -45,6 +45,7 @@
       <module>portal</module>
       <module>web</module>
       <module>scripting</module>
+      <module>management</module>
       <module>identity</module>
       <module>dashboard</module>
    </modules>

Modified: portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js
===================================================================
--- portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js	2010-02-12 09:44:54 UTC (rev 1659)
+++ portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js	2010-02-12 10:39:33 UTC (rev 1660)
@@ -97,6 +97,9 @@
       addDependency(new Project("rhino", "js", "jar", rhinoVersion)).
       addDependency(new Project("org.codehaus.groovy", "groovy-all", "jar", groovyVersion));
 
+   module.component.management =
+   new Project("org.exoplatform.portal", "exo.portal.component.management", "jar", module.version);
+
    module.component.web =
    new Project("org.exoplatform.portal", "exo.portal.component.web", "jar", module.version).
       addDependency(module.component.scripting);
@@ -146,6 +149,7 @@
    module.webui.portal =
    new Project("org.exoplatform.portal", "exo.portal.webui.portal", "jar", module.version).
       addDependency(module.component.common).
+      addDependency(module.component.management).
       addDependency(module.component.resources).
       addDependency(module.component.identity).
       addDependency(module.component.pc).

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml	2010-02-12 09:44:54 UTC (rev 1659)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml	2010-02-12 10:39:33 UTC (rev 1660)
@@ -130,4 +130,9 @@
    <type>org.exoplatform.portal.application.ResourceBundleDelegateImpl</type>
   </component>
 
+  <component>
+    <key>org.exoplatform.management.RestManagementProvider</key>
+    <type>org.exoplatform.management.RestManagementProvider</type>
+  </component>
+
 </configuration>



More information about the gatein-commits mailing list