Author: julien_viet
Date: 2010-01-01 09:50:44 -0500 (Fri, 01 Jan 2010)
New Revision: 1153
Added:
portal/branches/management/
portal/branches/management/component/common/src/main/java/conf/portal/
portal/branches/management/component/common/src/main/java/conf/portal/configuration.xml
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ResourceKey.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/Rest.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/RestManagementProvider.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/TestService.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ValueWrapper.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResource.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethod.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethodParameter.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceProperty.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/GetterInvoker.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/MethodInvoker.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/NoSuchMethodInvoker.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SetterInvoker.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SimpleMethodInvoker.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/JsonGeneratorExt.java
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/MessageBodyWriterImpl.java
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/Visit.java
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/XMLVisitor.java
Modified:
portal/branches/management/component/common/pom.xml
portal/branches/management/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/branches/management/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
portal/branches/management/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java
portal/branches/management/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
portal/branches/management/pom.xml
portal/branches/management/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java
portal/branches/management/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java
portal/branches/portalsession/component/application-registry/src/main/java/org/exoplatform/application/registry/Application.java
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIComponent.java
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIContainer.java
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
Log:
working branch based on trunk revision 1148 + the kernel 2.2.0-Beta06-SNAPSHOT
Copied: portal/branches/management (from rev 1148, portal/trunk)
Modified: portal/branches/management/component/common/pom.xml
===================================================================
--- portal/trunk/component/common/pom.xml 2009-12-29 02:50:05 UTC (rev 1148)
+++ portal/branches/management/component/common/pom.xml 2010-01-01 14:50:44 UTC (rev
1153)
@@ -32,6 +32,12 @@
<dependencies>
<dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ </dependency>
+
+
+ <dependency>
<groupId>org.gatein.common</groupId>
<artifactId>common-logging</artifactId>
</dependency>
Added:
portal/branches/management/component/common/src/main/java/conf/portal/configuration.xml
===================================================================
---
portal/branches/management/component/common/src/main/java/conf/portal/configuration.xml
(rev 0)
+++
portal/branches/management/component/common/src/main/java/conf/portal/configuration.xml 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ 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.
+ -->
+
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+ <key>org.exoplatform.commons.management.RestManagementProvider</key>
+ <type>org.exoplatform.commons.management.RestManagementProvider</type>
+ </component>
+
+ <component>
+ <key>org.exoplatform.commons.management.TestService</key>
+ <type>org.exoplatform.commons.management.TestService</type>
+ </component>
+
+</configuration>
Added:
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ResourceKey.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ResourceKey.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ResourceKey.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management;
+
+/**
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/Rest.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/Rest.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/Rest.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.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@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.TYPE)
+public @interface Rest
+{
+
+ String value();
+
+}
Added:
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/RestManagementProvider.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/RestManagementProvider.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/RestManagementProvider.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,108 @@
+/*
+ * 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.commons.management;
+
+import org.exoplatform.commons.management.data.RestResource;
+import org.exoplatform.commons.management.rs.MessageBodyWriterImpl;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.management.spi.ManagedResource;
+import org.exoplatform.management.spi.ManagementProvider;
+import org.exoplatform.services.rest.impl.ProviderBinder;
+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@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@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)
+ {
+ //
+ ProviderBinder binders = ProviderBinder.getInstance();
+ binders.addMessageBodyWriter(MessageBodyWriterImpl.class);
+
+ //
+ 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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/TestService.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/TestService.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/TestService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,47 @@
+/*
+ * 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.commons.management;
+
+import org.exoplatform.management.annotations.Managed;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@Managed
+@Rest("test")
+public class TestService
+{
+
+ /** . */
+ private String foo;
+
+ @Managed
+ public String getFoo()
+ {
+ return foo;
+ }
+
+ @Managed
+ public void setFoo(String foo)
+ {
+ this.foo = foo;
+ }
+}
Added:
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ValueWrapper.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ValueWrapper.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/ValueWrapper.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management;
+
+/**
+ * Temporary class until eXo JSON marshaller supports non java bean objects.
+ *
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResource.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResource.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResource.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.data;
+
+import org.exoplatform.commons.management.ValueWrapper;
+import org.exoplatform.commons.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@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethod.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethod.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethod.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.data;
+
+import org.exoplatform.commons.management.invocation.MethodInvoker;
+import org.exoplatform.commons.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@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethodParameter.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethodParameter.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceMethodParameter.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.data;
+
+import org.exoplatform.management.spi.ManagedMethodParameterMetaData;
+
+/**
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceProperty.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceProperty.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/data/RestResourceProperty.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.data;
+
+import org.exoplatform.commons.management.invocation.GetterInvoker;
+import org.exoplatform.commons.management.invocation.MethodInvoker;
+import org.exoplatform.commons.management.invocation.NoSuchMethodInvoker;
+import org.exoplatform.commons.management.invocation.SetterInvoker;
+import org.exoplatform.management.spi.ManagedPropertyMetaData;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/GetterInvoker.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/GetterInvoker.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/GetterInvoker.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.invocation;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/MethodInvoker.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/MethodInvoker.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/MethodInvoker.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface MethodInvoker
+{
+
+ Object invoke(Object o, Map<String, List<String>> argMap) throws
IllegalAccessException, InvocationTargetException;
+
+}
Added:
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/NoSuchMethodInvoker.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/NoSuchMethodInvoker.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/NoSuchMethodInvoker.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SetterInvoker.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SetterInvoker.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SetterInvoker.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.commons.management.invocation;
+
+import org.exoplatform.commons.management.invocation.MethodInvoker;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien.viet@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/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SimpleMethodInvoker.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SimpleMethodInvoker.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/invocation/SimpleMethodInvoker.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.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@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
Added:
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/JsonGeneratorExt.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/JsonGeneratorExt.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/JsonGeneratorExt.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -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.commons.management.rs;
+
+import org.exoplatform.ws.frameworks.json.impl.JsonException;
+import org.exoplatform.ws.frameworks.json.impl.JsonGeneratorImpl;
+import org.exoplatform.ws.frameworks.json.value.JsonValue;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class JsonGeneratorExt extends JsonGeneratorImpl
+{
+
+ @Override
+ public JsonValue createJsonValue(Object object) throws JsonException
+ {
+ return super.createJsonValue(object);
+ }
+}
Added:
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/MessageBodyWriterImpl.java
===================================================================
---
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/MessageBodyWriterImpl.java
(rev 0)
+++
portal/branches/management/component/common/src/main/java/org/exoplatform/commons/management/rs/MessageBodyWriterImpl.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,57 @@
+/*
+ * 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.commons.management.rs;
+
+import org.exoplatform.services.rest.impl.provider.JsonEntityProvider;
+import org.exoplatform.ws.frameworks.json.JsonWriter;
+import org.exoplatform.ws.frameworks.json.impl.JsonException;
+import org.exoplatform.ws.frameworks.json.impl.JsonWriterImpl;
+import org.exoplatform.ws.frameworks.json.value.JsonValue;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class MessageBodyWriterImpl extends JsonEntityProvider
+{
+
+ @Override
+ public void writeTo(Object t, Class<?> type, Type genericType, Annotation[]
annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException
+ {
+ try
+ {
+ JsonValue jv = new JsonGeneratorExt().createJsonValue(t);
+ JsonWriter jsonWriter = new JsonWriterImpl(entityStream);
+ jv.writeTo(jsonWriter);
+ jsonWriter.flush();
+ }
+ catch (JsonException e)
+ {
+ throw new IOException("Can't write to output stream " + e);
+ }
+ }
+}
Modified:
portal/branches/management/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,9 +19,12 @@
package org.exoplatform.portal.resource;
+import org.exoplatform.commons.management.Rest;
import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.commons.utils.Safe;
import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -56,6 +59,7 @@
@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "management"),
@Property(key = "type", value = "skin")})
@ManagedDescription("Skin service")
+@Rest("skinservice")
public class SkinService implements Startable
{
@@ -558,6 +562,7 @@
@Managed
@ManagedDescription("Reload all skins")
+ @Impact(type = ImpactType.WRITE)
public void reloadSkins()
{
// remove all ltCache, rtCache
@@ -567,6 +572,7 @@
@Managed
@ManagedDescription("Reload a specified skin")
+ @Impact(type = ImpactType.WRITE)
public void reloadSkin(@ManagedDescription("The skin id")
@ManagedName("skinId")
String skinId)
Modified:
portal/branches/management/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -22,10 +22,13 @@
import groovy.lang.Writable;
import groovy.text.Template;
+import org.exoplatform.commons.management.Rest;
import org.exoplatform.commons.utils.IOUtil;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.groovyscript.GroovyTemplate;
import org.exoplatform.groovyscript.GroovyTemplateEngine;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -36,6 +39,7 @@
import org.exoplatform.services.cache.ExoCache;
import java.io.InputStream;
+import java.util.ArrayList;
/**
* Created by The eXo Platform SAS Dec 26, 2005
@@ -44,6 +48,7 @@
@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "management"),
@Property(key = "type", value = "template")})
@ManagedDescription("Template management service")
+@Rest("templateservice")
public class TemplateService
{
@@ -172,6 +177,7 @@
*/
@Managed
@ManagedDescription("Clear the template cache for a specified template
identifier")
+ @Impact(type = ImpactType.IDEMPOTENT_WRITE)
public void reloadTemplate(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
try
@@ -185,4 +191,25 @@
e.printStackTrace();
}
}
+
+ @Managed
+ @ManagedDescription("List the identifiers of the cached templates")
+ @Impact(type = ImpactType.READ)
+ public String[] listCachedTemplates()
+ {
+ try
+ {
+ ArrayList<String> list = new ArrayList<String>();
+ for (GroovyTemplate template : templatesCache_.getCachedObjects())
+ {
+ list.add(template.getId());
+ }
+ return list.toArray(new String[list.size()]);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
}
Modified:
portal/branches/management/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,12 +19,16 @@
package org.exoplatform.groovyscript.text;
+import org.exoplatform.commons.management.Rest;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -40,9 +44,12 @@
*/
@Managed
-@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "statistic"),
- @Property(key = "type", value = "template")})
@ManagedDescription("Template statistic service")
+@NameTemplate({
+ @Property(key = "view", value = "portal"),
+ @Property(key = "service", value = "statistic"),
+ @Property(key = "type", value = "template")})
+@Rest("templatestatistics")
public class TemplateStatisticService
{
@@ -95,6 +102,7 @@
*/
@Managed
@ManagedDescription("The maximum rendering time of a specified template in
seconds")
+ @Impact(type = ImpactType.READ)
public double getMaxTime(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -106,6 +114,7 @@
*/
@Managed
@ManagedDescription("The minimum rendering time of a specified template in
seconds")
+ @Impact(type = ImpactType.READ)
public double getMinTime(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -117,6 +126,7 @@
*/
@Managed
@ManagedDescription("The rendering count of a specified template")
+ @Impact(type = ImpactType.READ)
public long getExecutionCount(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -128,6 +138,7 @@
*/
@Managed
@ManagedDescription("The average rendering time of a specified template in
seconds")
+ @Impact(type = ImpactType.READ)
public double getAverageTime(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -142,12 +153,10 @@
public String[] getSlowestTemplates()
{
- Map application = new HashMap();
- List<Object> list = new LinkedList<Object>(apps.entrySet());
- for (Iterator it = list.iterator(); it.hasNext();)
+ Map<String, Double> application = new HashMap<String, Double>();
+ for (Map.Entry<String, TemplateStatistic> entry : apps.entrySet())
{
- Map.Entry entry = (Map.Entry)it.next();
- String url = (String)entry.getKey();
+ String url = entry.getKey();
application.put(url, getAverageTime(url));
}
@@ -162,12 +171,10 @@
public String[] getMostExecutedTemplates()
{
- Map application = new HashMap();
- List<Object> list = new LinkedList<Object>(apps.entrySet());
- for (Iterator it = list.iterator(); it.hasNext();)
+ Map<String, Long> application = new HashMap<String, Long>();
+ for (Map.Entry<String, TemplateStatistic> entry : apps.entrySet())
{
- Map.Entry entry = (Map.Entry)it.next();
- String url = (String)entry.getKey();
+ String url = entry.getKey();
application.put(url, getExecutionCount(url));
}
@@ -182,74 +189,39 @@
public String[] getFastestTemplates()
{
- Map application = new HashMap();
- List<Object> list = new LinkedList<Object>(apps.entrySet());
- for (Iterator it = list.iterator(); it.hasNext();)
+ Map<String, Double> application = new HashMap<String, Double>();
+ for (Map.Entry<String, TemplateStatistic> entry : apps.entrySet())
{
- Map.Entry entry = (Map.Entry)it.next();
- String url = (String)entry.getKey();
+ String url = entry.getKey();
application.put(url, getAverageTime(url));
}
return sort(application, ASC);
}
- private String[] sort(Map source, String order)
+ private <T extends Comparable<T>> String[] sort(Map<String, T>
source, final String order)
{
String[] app = new String[10];
- List<Object> list = new LinkedList<Object>(source.entrySet());
- if (order.equals(ASC))
+ List<Map.Entry<String, T>> list = new ArrayList<Map.Entry<String,
T>>(source.entrySet());
+ Collections.sort(list, new Comparator<Map.Entry<String, T>>()
{
- Collections.sort(list, new Comparator<Object>()
+ public int compare(Map.Entry<String, T> o1, Map.Entry<String, T>
o2)
{
- public int compare(Object o1, Object o2)
+ T value1 = o1.getValue();
+ T value2 = o2.getValue();
+ if (DESC.equals(order))
{
- double value1 =
Double.parseDouble(((Map.Entry)(o1)).getValue().toString());
- double value2 =
Double.parseDouble(((Map.Entry)(o2)).getValue().toString());
- if (value1 > value2)
- {
- return 1;
- }
- else if (value1 < value2)
- {
- return -1;
- }
- else
- {
- return 0;
- }
+ T tmp = value1;
+ value1 = value2;
+ value2 = tmp;
}
- });
- }
- else if (order.equals(DESC))
- {
- Collections.sort(list, new Comparator<Object>()
- {
- public int compare(Object o1, Object o2)
- {
- double value1 =
Double.parseDouble(((Map.Entry)(o1)).getValue().toString());
- double value2 =
Double.parseDouble(((Map.Entry)(o2)).getValue().toString());
- if (value2 > value1)
- {
- return 1;
- }
- else if (value2 < value1)
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
- });
- }
-
+ return value1.compareTo(value2);
+ }
+ });
int index = 0;
- for (Iterator it = list.iterator(); it.hasNext();)
+ for (Map.Entry<String, T> entry : list)
{
- Map.Entry entry = (Map.Entry)it.next();
- app[index] = (String)entry.getKey();
+ app[index] = entry.getKey();
index++;
if (index >= app.length)
{
@@ -257,7 +229,6 @@
}
}
return app;
-
}
private double toSeconds(double value)
Modified:
portal/branches/management/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -69,7 +69,7 @@
String cookieToken = tokenService.createToken(credentials);
Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, cookieToken);
cookie.setPath(req.getContextPath());
- cookie.setMaxAge((int)tokenService.getExpiredPeriodTime() / 1000);
+ cookie.setMaxAge((int)tokenService.getValidityTime() / 1000);
resp.addCookie(cookie);
}
}
Modified:
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -21,6 +21,8 @@
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -41,10 +43,17 @@
/**
* Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
* 2009
+ *
+ * todo julien :
+ * - make delay configuration from init param and @Managed setter
+ * - start/stop expiration daemon
+ * - manually invoke the daemon via @Managed
*/
@Managed
-@NameTemplate({@Property(key = "service", value = "TokenStore"),
@Property(key = "name", value = "{Name}")})
@ManagedDescription("Token Store Service")
+@NameTemplate({
+ @Property(key = "service", value = "TokenStore"),
+ @Property(key = "name", value = "{Name}")})
public abstract class AbstractTokenService implements Startable, TokenStore
{
@@ -134,9 +143,10 @@
@Managed
@ManagedDescription("Clean all tokens are expired")
+ @Impact(type = ImpactType.IDEMPOTENT_WRITE)
public void cleanExpiredTokens()
{
- String[] ids = getAllTokens();
+ String[] ids = listTokens();
for (String s : ids)
{
Token token = getToken(s);
@@ -148,35 +158,49 @@
}
@Managed
- @ManagedDescription("Get period time of expired token")
- public long getExpiredPeriodTime()
+ @ManagedDescription("Get time for token expiration in seconds")
+ public long getValidityTime()
{
- return validityMillis;
+ return validityMillis / 1000;
}
@Managed
- @ManagedName("Name")
+ @ManagedDescription("The expiration daemon period time in seconds")
+ public long getPeriodTime()
+ {
+ return DELAY_TIME;
+ }
+
+ @Managed
@ManagedDescription("The token service name")
public String getName()
{
return name;
}
- @Managed
- @ManagedDescription("get a token by id")
public abstract Token getToken(String id);
@Managed
- @ManagedDescription("Delete a token by id")
+ @ManagedDescription("Destroy a token by id")
+ @Impact(type = ImpactType.IDEMPOTENT_WRITE)
+ public void destroyToken(@ManagedName("tokenId")
@ManagedDescription("The token id") String id)
+ {
+ deleteToken(id);
+ }
+
public abstract Token deleteToken(String id);
+ // We don't make it a property as retrieving the value can be an expensive
operation
@Managed
@ManagedDescription("The list of all tokens")
- public abstract String[] getAllTokens();
+ @Impact(type = ImpactType.READ)
+ public abstract String[] listTokens();
+ // We don't make it a property as retrieving the value can be an expensive
operation
@Managed
@ManagedDescription("The number of tokens")
- public abstract long getNumberTokens() throws Exception;
+ @Impact(type = ImpactType.READ)
+ public abstract long size() throws Exception;
private enum TimeoutEnum {
SECOND(1000), MINUTE(1000 * 60), HOUR(1000 * 60 * 60), DAY(1000 * 60 * 60 * 24);
Modified:
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -102,7 +102,7 @@
}
@Override
- public String[] getAllTokens()
+ public String[] listTokens()
{
return new TokenTask<String[]>() {
@Override
@@ -122,7 +122,7 @@
}
@Override
- public long getNumberTokens() throws Exception
+ public long size() throws Exception
{
return new TokenTask<Long>() {
@Override
Modified:
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -70,13 +70,13 @@
}
@Override
- public String[] getAllTokens()
+ public String[] listTokens()
{
return tokens.keySet().toArray(new String[]{});
}
@Override
- public long getNumberTokens() throws Exception
+ public long size() throws Exception
{
return tokens.size();
}
Modified: portal/branches/management/pom.xml
===================================================================
--- portal/trunk/pom.xml 2009-12-29 02:50:05 UTC (rev 1148)
+++ portal/branches/management/pom.xml 2010-01-01 14:50:44 UTC (rev 1153)
@@ -37,7 +37,7 @@
<name>GateIn - Portal</name>
<properties>
-
<org.exoplatform.kernel.version>2.2.0-Beta05</org.exoplatform.kernel.version>
+
<org.exoplatform.kernel.version>2.2.0-Beta06-SNAPSHOT</org.exoplatform.kernel.version>
<org.exoplatform.core.version>2.3.0-Beta05</org.exoplatform.core.version>
<org.exoplatform.ws.version>2.1.0-Beta05</org.exoplatform.ws.version>
<org.exoplatform.jcr.version>1.12.0-Beta05</org.exoplatform.jcr.version>
@@ -175,6 +175,11 @@
<artifactId>exo.ws.frameworks.servlet</artifactId>
<version>${org.exoplatform.ws.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ <version>${org.exoplatform.ws.version}</version>
+ </dependency>
<!-- GateIn components -->
<dependency>
Modified:
portal/branches/management/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,6 +19,9 @@
package org.exoplatform.portal.application;
+import org.exoplatform.commons.management.Rest;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -38,9 +41,12 @@
* @version $Revision$
*/
@Managed
-@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "statistic"),
+@ManagedDescription("Application statistic service")
+@NameTemplate({
+ @Property(key = "view", value = "portal"),
+ @Property(key = "service", value = "statistic"),
@Property(key = "type", value = "application")})
-@ManagedDescription("Application statistic service")
+@Rest("applicationstatistic")
public class ApplicationStatisticService implements Startable
{
@@ -66,8 +72,7 @@
/*
* get ApplicationStatistic by application id, if it isn't exits, create a new
one
*/
- public ApplicationStatistic getApplicationStatistic(
- @ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
+ public ApplicationStatistic getApplicationStatistic(String appId)
{
ApplicationStatistic app = apps.get(appId);
if (app == null)
@@ -87,6 +92,7 @@
*/
@Managed
@ManagedDescription("The maximum execution time of a specified application in
seconds")
+ @Impact(type = ImpactType.READ)
public double getMaxTime(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
@@ -98,6 +104,7 @@
*/
@Managed
@ManagedDescription("The minimum execution time of a specified application in
seconds")
+ @Impact(type = ImpactType.READ)
public double getMinTime(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
@@ -109,6 +116,7 @@
*/
@Managed
@ManagedDescription("Return the average execution time of a specified application
in seconds")
+ @Impact(type = ImpactType.READ)
public double getAverageTime(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
@@ -120,6 +128,7 @@
*/
@Managed
@ManagedDescription("The execution count of a specified application")
+ @Impact(type = ImpactType.READ)
public long getExecutionCount(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
Modified:
portal/branches/management/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java 2009-12-29
02:50:05 UTC (rev 1148)
+++
portal/branches/management/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,6 +19,9 @@
package org.exoplatform.portal.application;
+import org.exoplatform.commons.management.Rest;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -36,9 +39,12 @@
* @version $Revision$
*/
@Managed
-@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "statistic"),
+@ManagedDescription("The portal statistic service")
+@NameTemplate({
+ @Property(key = "view", value = "portal"),
+ @Property(key = "service", value = "statistic"),
@Property(key = "type", value = "portal")})
-@ManagedDescription("The portal statistic service")
+@Rest("portalstatistic")
public class PortalStatisticService implements Startable
{
@@ -94,6 +100,7 @@
*/
@Managed
@ManagedDescription("The maximum execution time of a specified portal in
seconds")
+ @Impact(type = ImpactType.READ)
public double getMaxTime(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return toSeconds(getPortalStatistic(id).getMaxTime());
@@ -104,6 +111,7 @@
*/
@Managed
@ManagedDescription("The mininum execution time of a specified portal in
seconds")
+ @Impact(type = ImpactType.READ)
public double getMinTime(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return toSeconds(getPortalStatistic(id).getMinTime());
@@ -114,6 +122,7 @@
*/
@Managed
@ManagedDescription("The average execution time of a specified portal in
seconds")
+ @Impact(type = ImpactType.READ)
public double getAverageTime(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return toSeconds(getPortalStatistic(id).getAverageTime());
@@ -124,6 +133,7 @@
*/
@Managed
@ManagedDescription("The number of request per second of a specified
portal")
+ @Impact(type = ImpactType.READ)
public double getThroughput(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return getPortalStatistic(id).getThroughput();
@@ -134,6 +144,7 @@
*/
@Managed
@ManagedDescription("The execution count of a specified portal")
+ @Impact(type = ImpactType.READ)
public long getExecutionCount(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return getPortalStatistic(id).viewCount();
Modified:
portal/branches/portalsession/component/application-registry/src/main/java/org/exoplatform/application/registry/Application.java
===================================================================
---
portal/branches/portalsession/component/application-registry/src/main/java/org/exoplatform/application/registry/Application.java 2009-12-31
13:16:36 UTC (rev 1152)
+++
portal/branches/portalsession/component/application-registry/src/main/java/org/exoplatform/application/registry/Application.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,6 +19,7 @@
package org.exoplatform.application.registry;
+import org.exoplatform.commons.Visit;
import org.exoplatform.portal.config.model.ApplicationType;
import java.util.ArrayList;
@@ -30,6 +31,7 @@
* Date: 15 juin 2004
*
*/
+@Visit
public class Application
{
Added:
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/Visit.java
===================================================================
---
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/Visit.java
(rev 0)
+++
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/Visit.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons;
+
+import org.dom4j.Element;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+(a)Target({ElementType.TYPE,ElementType.FIELD})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Visit
+{
+
+
+}
Added:
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/XMLVisitor.java
===================================================================
---
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/XMLVisitor.java
(rev 0)
+++
portal/branches/portalsession/component/common/src/main/java/org/exoplatform/commons/XMLVisitor.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons;
+
+import org.dom4j.Element;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class XMLVisitor
+{
+
+ public static Element build(Element parent, Object object)
+ {
+ Class<?> klass = object.getClass();
+
+ //
+ String name = klass.getSimpleName();
+ Element elt = parent.addElement(name);
+
+ // Add all relevant attributes via reflection
+ for (Class<?> current = klass;current != Object.class;current =
current.getSuperclass())
+ {
+ for (Field field : current.getDeclaredFields())
+ {
+ Class fieldClass = field.getType();
+ int modifiers = field.getModifiers();
+ if (!Modifier.isStatic(modifiers) &&
!(Modifier.isTransient(modifiers)))
+ {
+ field.setAccessible(true);
+ Object o = null;
+ try
+ {
+ o = field.get(object);
+ }
+ catch (IllegalAccessException ignore)
+ {
+ }
+
+ //
+ if (o != null)
+ {
+ if ((fieldClass.isPrimitive() || fieldClass == String.class))
+ {
+ String value = o.toString();
+ elt.addAttribute(field.getName(), value);
+ }
+ else if (isPrinted(field))
+ {
+ if (o instanceof Iterable<?>)
+ {
+ Element childrenElt = null;
+ for (Object child : (Iterable)o)
+ {
+ if (childrenElt == null)
+ {
+ childrenElt = elt.addElement(field.getName());
+ }
+ build(childrenElt, child);
+ }
+ }
+ else
+ {
+ Element composedElt = elt.addElement(field.getName());
+ build(composedElt, o);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //
+ return elt;
+ }
+
+ private static boolean isPrinted(Field field)
+ {
+ return field.getAnnotation(Visit.class) != null || isFollowed(field.getType());
+ }
+
+ private static boolean isFollowed(Class<?> clazz)
+ {
+ return clazz != null && (clazz.getAnnotation(Visit.class) != null ||
isFollowed(clazz.getSuperclass()));
+ }
+}
Modified:
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIComponent.java
===================================================================
---
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIComponent.java 2009-12-31
13:16:36 UTC (rev 1152)
+++
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIComponent.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,6 +19,7 @@
package org.exoplatform.webui.core;
+import org.exoplatform.commons.Visit;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.resolver.ResourceResolver;
import org.exoplatform.web.application.Parameter;
@@ -38,6 +39,7 @@
* Created by The eXo Platform SAS
* May 7, 2006
*/
+@Visit
abstract public class UIComponent
{
Modified:
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIContainer.java
===================================================================
---
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIContainer.java 2009-12-31
13:16:36 UTC (rev 1152)
+++
portal/branches/portalsession/webui/core/src/main/java/org/exoplatform/webui/core/UIContainer.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,6 +19,7 @@
package org.exoplatform.webui.core;
+import org.exoplatform.commons.Visit;
import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
@@ -37,6 +38,7 @@
public class UIContainer extends UIComponent
{
+ @Visit
private List<UIComponent> children;
public void visit() throws Exception
Modified:
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
===================================================================
---
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2009-12-31
13:16:36 UTC (rev 1152)
+++
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -19,6 +19,12 @@
package org.exoplatform.portal.application;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
+import org.exoplatform.commons.XMLVisitor;
import org.exoplatform.commons.utils.Safe;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.SessionManagerContainer;
@@ -33,9 +39,12 @@
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.application.portlet.PortletRequestContext;
import org.exoplatform.webui.core.UIApplication;
+import org.exoplatform.webui.core.UIComponent;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -58,6 +67,19 @@
@SuppressWarnings("unchecked")
public UIApplication restoreUIRootComponent(WebuiRequestContext context) throws
Exception
{
+ UIApplication app = _restoreUIRootComponent(context);
+ Document document = DocumentHelper.createDocument();
+ Element rootElt =
document.addElement(context.getApplication().getApplicationId());
+ XMLVisitor.build(rootElt, app);
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ format.setIndentSize(1);
+ XMLWriter writer = new XMLWriter(System.out, format);
+ writer.write(document);
+ return app;
+ }
+
+ private UIApplication _restoreUIRootComponent(WebuiRequestContext context) throws
Exception
+ {
context.setStateManager(this);
WebuiApplication app = (WebuiApplication)context.getApplication();
Modified:
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
===================================================================
---
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java 2009-12-31
13:16:36 UTC (rev 1152)
+++
portal/branches/portalsession/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java 2010-01-01
14:50:44 UTC (rev 1153)
@@ -108,6 +108,11 @@
private UIComponent maximizedUIComponent;
+ public UIPortal()
+ {
+ System.out.println("Constructed portal");
+ }
+
public String getStorageId()
{
return storageId;