Author: aparfonov
Date: 2009-10-19 03:03:07 -0400 (Mon, 19 Oct 2009)
New Revision: 292
Added:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinderImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentResolver.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java
Removed:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencyInjector.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencyInjector.java
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerDependencyInjector.java
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FilterDescriptorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ProviderBinder.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/ProviderDescriptorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/wadl/WadlProcessor.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/ResourceBinderTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorValidatorTest.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/wadl/WadlProcessorTest.java
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/RestInitializer.java
ws/branches/2.2.x/rest/ext/src/test/java/conf/standalone/test-configuration.xml
Log:
EXOJCR-185 :
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -82,7 +82,7 @@
GenericContainerResponse getContainerResponse();
- DependencyInjector getDependencyInjector();
+ DependencySupplier getDependencyInjector();
/**
* @return See {@link HttpHeaders}
@@ -126,7 +126,7 @@
*/
UriInfo getUriInfo();
- void setDependencyInjector(DependencyInjector depInjector);
+ void setDependencyInjector(DependencySupplier depInjector);
/**
* Pass in context list of path template parameters @see {@link UriPattern}.
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -30,8 +30,4 @@
* Singleton lifecycle.
*/
SINGLETON,
- /**
- * Inversion-of-control framework controls component's lifecycle.
- */
- IOC
}
Deleted:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencyInjector.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencyInjector.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencyInjector.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.rest;
-
-import java.lang.reflect.Type;
-
-/**
- * Implementation of DependencyInjector should be able to provide
- * objects that required for constructors or fields of Resource or Provider.
- *
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public interface DependencyInjector
-{
-
- /**
- * Get single parameter of type <code>type</code>.
- *
- * @param type class of required parameter
- * @param the type of object to be produced
- * @return object of required type or null if instance of
<code>type</code>
- * may not be produced
- */
- Object getInjectableParameter(Class<?> type, Type genericType);
-
-}
Copied:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java
(from rev 291,
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencyInjector.java)
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -0,0 +1,40 @@
+/*
+ * 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.services.rest;
+
+/**
+ * Implementation of DependencySupplier should be able to provide
+ * objects that required for constructors or fields of Resource or Provider.
+ *
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public interface DependencySupplier
+{
+
+ /**
+ * Get object of <code>type</code>.
+ *
+ * @param parameter required parameter description
+ * @return object of required type or null if instance described by
+ * <code>parameter</code> may not be produced
+ */
+ Object getInstanceOfType(Parameter parameter);
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -25,7 +25,7 @@
/**
* Used to annotate fields that should be injected with instances
- * provided by {@link DependencyInjector}. If DependencyInjector
+ * provided by {@link DependencySupplier}. If DependencyInjector
* is not available than field will be not initialized
* @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -22,8 +22,6 @@
import java.util.List;
-import javax.ws.rs.core.Application;
-
/**
* Manages root resources.
*
@@ -33,12 +31,6 @@
public interface ResourceBinder
{
/**
- * @param application Application
- * @see Application
- */
- void addApplication(Application application);
-
- /**
* @param resourceClass class of candidate to be root resource
* @return true if resource was bound and false if resource was not bound
* cause it is not root resource
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -19,7 +19,7 @@
package org.exoplatform.services.rest.impl;
import org.exoplatform.services.rest.ApplicationContext;
-import org.exoplatform.services.rest.DependencyInjector;
+import org.exoplatform.services.rest.DependencySupplier;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.InitialProperties;
@@ -159,7 +159,7 @@
*/
private MultivaluedMap<String, String> queryParameters;
- private DependencyInjector depInjector;
+ private DependencySupplier depInjector;
/**
* Constructs new instance of ApplicationContext.
@@ -255,7 +255,7 @@
/**
* {@inheritDoc}
*/
- public DependencyInjector getDependencyInjector()
+ public DependencySupplier getDependencyInjector()
{
return depInjector;
}
@@ -484,7 +484,7 @@
/**
* {@inheritDoc}
*/
- public void setDependencyInjector(DependencyInjector depInjector)
+ public void setDependencyInjector(DependencySupplier depInjector)
{
this.depInjector = depInjector;
}
Added:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -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.services.rest.impl;
+
+import org.exoplatform.services.rest.ResourceBinder;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id: $
+ */
+public class ApplicationDeployer extends RestComponentDeployer
+{
+
+ public ApplicationDeployer(ResourceBinder resources, ProviderBinder providers)
+ {
+ super(resources, providers);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void deploy(Application application)
+ {
+ for (Object instance : application.getSingletons())
+ {
+ deploy(instance);
+ }
+ for (Class clazz : application.getClasses())
+ {
+ deploy(clazz);
+ }
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -1,435 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.rest.impl;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.Filter;
-import org.exoplatform.services.rest.ObjectFactory;
-import org.exoplatform.services.rest.PerRequestObjectFactory;
-import org.exoplatform.services.rest.RequestFilter;
-import org.exoplatform.services.rest.ResourceBinder;
-import org.exoplatform.services.rest.ResponseFilter;
-import org.exoplatform.services.rest.SingletonObjectFactory;
-import org.exoplatform.services.rest.impl.resource.AbstractResourceDescriptorImpl;
-import org.exoplatform.services.rest.impl.resource.ResourceDescriptorValidator;
-import org.exoplatform.services.rest.method.MethodInvokerFilter;
-import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
-import org.exoplatform.services.rest.resource.ResourceDescriptorVisitor;
-import org.exoplatform.services.rest.uri.UriPattern;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.ext.ContextResolver;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-import javax.ws.rs.ext.RuntimeDelegate;
-
-/**
- * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public class BaseResourceBinder implements ResourceBinder
-{
-
- /**
- * Logger.
- */
- private static final Log LOG =
ExoLogger.getLogger(BaseResourceBinder.class.getName());
-
- private static final Comparator<ObjectFactory<AbstractResourceDescriptor>>
RESOURCE_COMPARATOR =
- new ResourceComparator();
-
- /**
- * Compare two {@link SingletonResourceFactory}.
- */
- private static final class ResourceComparator implements
Comparator<ObjectFactory<AbstractResourceDescriptor>>
- {
- /**
- * Compare two ResourceClass for order.
- *
- * @param o1 first ResourceClass to be compared
- * @param o2 second ResourceClass to be compared
- * @return positive , zero or negative dependent of {@link UriPattern}
- * comparison
- * @see Comparator#compare(Object, Object)
- * @see UriPattern
- * @see UriPattern#URIPATTERN_COMPARATOR
- */
- public int compare(ObjectFactory<AbstractResourceDescriptor> o1,
ObjectFactory<AbstractResourceDescriptor> o2)
- {
- return
UriPattern.URIPATTERN_COMPARATOR.compare(o1.getObjectModel().getUriPattern(),
o2.getObjectModel()
- .getUriPattern());
- }
- };
-
- /**
- * Root resource descriptors.
- */
- private final List<ObjectFactory<AbstractResourceDescriptor>>
rootResources =
- new ArrayList<ObjectFactory<AbstractResourceDescriptor>>();
-
- /**
- * Validator.
- */
- private final ResourceDescriptorVisitor rdv =
ResourceDescriptorValidator.getInstance();
-
- private int size = 0;
-
- public BaseResourceBinder()
- {
- // Initialize RuntimeDelegate instance
- // This is first component in life cycle what needs.
- // TODO better solution to initialize RuntimeDelegate
- RuntimeDelegate rd = new RuntimeDelegateImpl();
- RuntimeDelegate.setInstance(rd);
- }
-
- /**
- * @param application Application
- * @see Application
- */
- @SuppressWarnings("unchecked")
- public void addApplication(Application application)
- {
- ProviderBinder providers = ProviderBinder.getInstance();
- for (Object obj : application.getSingletons())
- {
- if (obj.getClass().getAnnotation(Provider.class) != null)
- {
- // singleton provider
- if (obj instanceof ContextResolver)
- {
- providers.addContextResolver((ContextResolver)obj);
- }
- if (obj instanceof ExceptionMapper)
- {
- providers.addExceptionMapper((ExceptionMapper)obj);
- }
- if (obj instanceof MessageBodyReader)
- {
- providers.addMessageBodyReader((MessageBodyReader)obj);
- }
- if (obj instanceof MessageBodyWriter)
- {
- providers.addMessageBodyWriter((MessageBodyWriter)obj);
- }
- }
- else if (obj.getClass().getAnnotation(Filter.class) != null)
- {
- // singleton filter
- if (obj instanceof MethodInvokerFilter)
- {
- providers.addMethodInvokerFilter((MethodInvokerFilter)obj);
- }
- if (obj instanceof RequestFilter)
- {
- providers.addRequestFilter((RequestFilter)obj);
- }
- if (obj instanceof ResponseFilter)
- {
- providers.addResponseFilter((ResponseFilter)obj);
- }
- }
- else
- {
- bind(obj); // singleton resource
- }
- }
- for (Class clazz : application.getClasses())
- {
- if (clazz.getAnnotation(Provider.class) != null)
- {
- // per-request provider
- if (ContextResolver.class.isAssignableFrom(clazz))
- {
- providers.addContextResolver(clazz);
- }
- if (ExceptionMapper.class.isAssignableFrom(clazz))
- {
- providers.addExceptionMapper(clazz);
- }
- if (MessageBodyReader.class.isAssignableFrom(clazz))
- {
- providers.addMessageBodyReader(clazz);
- }
- if (MessageBodyWriter.class.isAssignableFrom(clazz))
- {
- providers.addMessageBodyWriter(clazz);
- }
- }
- else if (clazz.getAnnotation(Filter.class) != null)
- {
- // per-request filter
- if (MethodInvokerFilter.class.isAssignableFrom(clazz))
- {
- providers.addMethodInvokerFilter(clazz);
- }
- if (RequestFilter.class.isAssignableFrom(clazz))
- {
- providers.addRequestFilter(clazz);
- }
- if (ResponseFilter.class.isAssignableFrom(clazz))
- {
- providers.addResponseFilter(clazz);
- }
- }
- else
- {
- bind(clazz); // per-request resource
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean bind(final Object resource)
- {
- final Path path = resource.getClass().getAnnotation(Path.class);
-
- AbstractResourceDescriptor descriptor = null;
- if (path != null)
- {
- try
- {
- descriptor = new AbstractResourceDescriptorImpl(resource);
- }
- catch (Exception e)
- {
- String msg = "Unexpected error occurs when process resource class "
+ resource.getClass().getName();
- LOG.error(msg, e);
- return false;
- }
- }
- else
- {
- String msg =
- "Resource class " + resource.getClass().getName() + " it is
not root resource. "
- + "Path annotation javax.ws.rs.Path is not specified for this
class.";
- LOG.warn(msg);
- return false;
- }
-
- // validate AbstractResourceDescriptor
- try
- {
- descriptor.accept(rdv);
- }
- catch (Exception e)
- {
- LOG.error("Validation of root resource failed. ", e);
- return false;
- }
-
- synchronized (rootResources)
- {
- // check does exist other resource with the same URI pattern
- for (ObjectFactory<AbstractResourceDescriptor> exist : rootResources)
- {
- if
(exist.getObjectModel().getUriPattern().equals(descriptor.getUriPattern()))
- {
- String msg =
- "Resource class " + descriptor.getObjectClass().getName() +
" can't be registered. Resource class "
- + exist.getClass().getName() + " with the same pattern "
- + exist.getObjectModel().getUriPattern().getTemplate() + "
already registered.";
- LOG.warn(msg);
- return false;
- }
- }
-
- // Singleton resource
- ObjectFactory<AbstractResourceDescriptor> res =
- new SingletonObjectFactory<AbstractResourceDescriptor>(descriptor,
resource);
- rootResources.add(res);
- Collections.sort(rootResources, RESOURCE_COMPARATOR);
- LOG.info("Bind new resource " +
res.getObjectModel().getUriPattern().getTemplate() + " : "
- + descriptor.getObjectClass());
- }
- size++;
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean bind(final Class<?> resourceClass)
- {
- final Path path = resourceClass.getAnnotation(Path.class);
-
- AbstractResourceDescriptor descriptor = null;
- if (path != null)
- {
- try
- {
- descriptor = new AbstractResourceDescriptorImpl(resourceClass);
- }
- catch (Exception e)
- {
- String msg = "Unexpected error occurs when process resource class "
+ resourceClass.getName();
- LOG.error(msg, e);
- return false;
- }
- }
- else
- {
- String msg =
- "Resource class " + resourceClass.getName() + " it is not root
resource. "
- + "Path annotation javax.ws.rs.Path is not specified for this
class.";
- LOG.warn(msg);
- return false;
- }
-
- // validate AbstractResourceDescriptor
- try
- {
- descriptor.accept(rdv);
- }
- catch (Exception e)
- {
- LOG.error("Validation of root resource failed. ", e);
- return false;
- }
-
- synchronized (rootResources)
- {
- // check does exist other resource with the same URI pattern
- for (ObjectFactory<AbstractResourceDescriptor> exist : rootResources)
- {
- AbstractResourceDescriptor existDescriptor = exist.getObjectModel();
- if
(exist.getObjectModel().getUriPattern().equals(descriptor.getUriPattern()))
- {
-
- String msg =
- "Resource class " + descriptor.getObjectClass().getName() +
" can't be registered. Resource class "
- + existDescriptor.getObjectClass().getName() + " with the same
pattern "
- + exist.getObjectModel().getUriPattern().getTemplate() + "
already registered.";
- LOG.warn(msg);
- return false;
- }
- }
- // per-request resource
- ObjectFactory<AbstractResourceDescriptor> res =
- new PerRequestObjectFactory<AbstractResourceDescriptor>(descriptor);
- rootResources.add(res);
- Collections.sort(rootResources, RESOURCE_COMPARATOR);
- LOG.info("Bind new resource " +
res.getObjectModel().getUriPattern().getRegex() + " : " + resourceClass);
- }
- size++;
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public boolean unbind(Class clazz)
- {
- synchronized (rootResources)
- {
- Iterator<ObjectFactory<AbstractResourceDescriptor>> i =
rootResources.iterator();
- while (i.hasNext())
- {
- ObjectFactory<AbstractResourceDescriptor> res = i.next();
- Class c = res.getObjectModel().getObjectClass();
- if (clazz.equals(c))
- {
- i.remove();
- LOG.info("Remove ResourceContainer " +
res.getObjectModel().getUriPattern().getTemplate() + " : " + c);
- size--;
- return true;
- }
- }
- return false;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean unbind(String uriTemplate)
- {
- synchronized (rootResources)
- {
- Iterator<ObjectFactory<AbstractResourceDescriptor>> i =
rootResources.iterator();
- while (i.hasNext())
- {
- ObjectFactory<AbstractResourceDescriptor> res = i.next();
- String t = res.getObjectModel().getUriPattern().getTemplate();
- if (t.equals(uriTemplate))
- {
- i.remove();
- LOG.info("Remove ResourceContainer " +
res.getObjectModel().getUriPattern().getTemplate());
- size--;
- return true;
- }
- }
- return false;
- }
- }
-
- /**
- * Clear the list of ResourceContainer description.
- */
- public void clear()
- {
- rootResources.clear();
- size = 0;
- }
-
- /**
- * {@inheritDoc}
- */
- public List<ObjectFactory<AbstractResourceDescriptor>> getResources()
- {
- return rootResources;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getSize()
- {
- return size;
- }
-
- /**
- * @return all registered root resources
- */
- @Deprecated
- public List<AbstractResourceDescriptor> getRootResources()
- {
- List<AbstractResourceDescriptor> l = new
ArrayList<AbstractResourceDescriptor>(rootResources.size());
- synchronized (rootResources)
- {
- for (ObjectFactory<AbstractResourceDescriptor> f : rootResources)
- l.add(f.getObjectModel());
- }
- return l;
- }
-
-}
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -254,7 +254,7 @@
.type(MediaType.TEXT_PLAIN).build());
}
- Object tmp =
context.getDependencyInjector().getInjectableParameter(cp.getParameterClass(), null);
+ Object tmp = context.getDependencyInjector().getInstanceOfType(cp);
if (tmp == null)
{
String msg =
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -74,7 +74,6 @@
*/
private final boolean encoded;
-
/** See {@link java.lang.reflect.Field} . */
private final java.lang.reflect.Field jfield;
@@ -225,7 +224,29 @@
throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST).build());
}
}
+ else
+ {
+ if (context.getDependencyInjector() != null)
+ {
+ Object tmp = context.getDependencyInjector().getInstanceOfType(this);
+ if (tmp != null)
+ {
+ try
+ {
+ if (!Modifier.isPublic(jfield.getModifiers()))
+ jfield.setAccessible(true);
+ jfield.set(resource, tmp);
+ }
+ catch (Throwable e)
+ {
+ // TODO check exception type
+ throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST).build());
+ }
+ }
+ }
+ }
+
}
/**
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FilterDescriptorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FilterDescriptorImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FilterDescriptorImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -68,27 +68,11 @@
private final List<FieldInjector> fields;
/**
- * @param filterClass {@link Class} of filter
- */
- public FilterDescriptorImpl(Class<?> filterClass)
- {
- this(filterClass, ComponentLifecycleScope.PER_REQUEST);
- }
-
- /**
- * @param filter instance
- */
- public FilterDescriptorImpl(Object filter)
- {
- this(filter.getClass(), ComponentLifecycleScope.SINGLETON);
- }
-
- /**
* @param filterClass filter class
* @param scope filter scope
* @see ComponentLifecycleScope
*/
- private FilterDescriptorImpl(Class<?> filterClass, ComponentLifecycleScope
scope)
+ public FilterDescriptorImpl(Class<?> filterClass, ComponentLifecycleScope
scope)
{
final Path p = filterClass.getAnnotation(Path.class);
if (p != null)
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ProviderBinder.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ProviderBinder.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ProviderBinder.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -20,6 +20,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.FilterDescriptor;
import org.exoplatform.services.rest.ObjectFactory;
import org.exoplatform.services.rest.PerRequestObjectFactory;
@@ -241,7 +242,7 @@
{
try
{
- ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz);
+ ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz,
ComponentLifecycleScope.PER_REQUEST);
descriptor.accept(rdv);
addContextResolver(new
PerRequestObjectFactory<ProviderDescriptor>(descriptor));
@@ -263,7 +264,7 @@
Class<? extends ContextResolver> clazz = instance.getClass();
try
{
- ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz);
+ ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz,
ComponentLifecycleScope.SINGLETON);
descriptor.accept(rdv);
addContextResolver(new
SingletonObjectFactory<ProviderDescriptor>(descriptor, instance));
@@ -325,7 +326,8 @@
{
try
{
- addExceptionMapper(new PerRequestObjectFactory(new
ProviderDescriptorImpl(clazz)));
+ addExceptionMapper(new PerRequestObjectFactory(new
ProviderDescriptorImpl(clazz,
+ ComponentLifecycleScope.PER_REQUEST)));
}
catch (Exception e)
{
@@ -344,7 +346,8 @@
Class<? extends ExceptionMapper> clazz = instance.getClass();
try
{
- addExceptionMapper(new SingletonObjectFactory(new ProviderDescriptorImpl(clazz),
instance));
+ addExceptionMapper(new SingletonObjectFactory(new ProviderDescriptorImpl(clazz,
+ ComponentLifecycleScope.SINGLETON), instance));
}
catch (Exception e)
{
@@ -389,7 +392,7 @@
{
try
{
- ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz);
+ ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz,
ComponentLifecycleScope.PER_REQUEST);
descriptor.accept(rdv);
addMessageBodyReader(new
PerRequestObjectFactory<ProviderDescriptor>(descriptor));
@@ -411,7 +414,7 @@
Class<? extends MessageBodyReader> clazz = instance.getClass();
try
{
- ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz);
+ ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz,
ComponentLifecycleScope.SINGLETON);
descriptor.accept(rdv);
addMessageBodyReader(new SingletonObjectFactory(descriptor, instance));
@@ -442,9 +445,9 @@
{
try
{
- ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz);
+ ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz,
ComponentLifecycleScope.PER_REQUEST);
descriptor.accept(rdv);
-
+
addMessageBodyWriter(new
PerRequestObjectFactory<ProviderDescriptor>(descriptor));
}
catch (Exception e)
@@ -464,7 +467,7 @@
Class<? extends MessageBodyWriter> clazz = instance.getClass();
try
{
- ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz);
+ ProviderDescriptor descriptor = new ProviderDescriptorImpl(clazz,
ComponentLifecycleScope.SINGLETON);
descriptor.accept(rdv);
addMessageBodyWriter(new
SingletonObjectFactory<ProviderDescriptor>(descriptor, instance));
@@ -484,8 +487,7 @@
for (MediaType mime : writerFactory.getObjectModel().produces())
writeProviders.getList(mime).add(writerFactory);
}
-
-
+
/**
* Get list of most acceptable writer's media type for specified type.
*
@@ -596,9 +598,9 @@
{
try
{
- FilterDescriptor descriptor = new FilterDescriptorImpl(clazz);
+ FilterDescriptor descriptor = new FilterDescriptorImpl(clazz,
ComponentLifecycleScope.PER_REQUEST);
descriptor.accept(rdv);
-
+
addMethodInvokerFilter(new
PerRequestObjectFactory<FilterDescriptor>(descriptor));
}
catch (Exception e)
@@ -617,9 +619,9 @@
Class<? extends MethodInvokerFilter> clazz = instance.getClass();
try
{
- FilterDescriptor descriptor = new FilterDescriptorImpl(clazz);
+ FilterDescriptor descriptor = new FilterDescriptorImpl(clazz,
ComponentLifecycleScope.SINGLETON);
descriptor.accept(rdv);
-
+
addMethodInvokerFilter(new
SingletonObjectFactory<FilterDescriptor>(descriptor, instance));
}
catch (Exception e)
@@ -627,7 +629,7 @@
LOG.error("Failed add RequestFilter " + clazz.getName(), e);
}
}
-
+
protected void addMethodInvokerFilter(ObjectFactory<FilterDescriptor>
filterFactory)
{
invokerFilters.getList(filterFactory.getObjectModel().getUriPattern()).add(filterFactory);
@@ -642,7 +644,7 @@
{
try
{
- FilterDescriptor descriptor = new FilterDescriptorImpl(clazz);
+ FilterDescriptor descriptor = new FilterDescriptorImpl(clazz,
ComponentLifecycleScope.PER_REQUEST);
descriptor.accept(rdv);
addRequestFilter(new
PerRequestObjectFactory<FilterDescriptor>(descriptor));
@@ -663,7 +665,7 @@
Class<? extends RequestFilter> clazz = instance.getClass();
try
{
- FilterDescriptor descriptor = new FilterDescriptorImpl(clazz);
+ FilterDescriptor descriptor = new FilterDescriptorImpl(clazz,
ComponentLifecycleScope.SINGLETON);
descriptor.accept(rdv);
addRequestFilter(new SingletonObjectFactory<FilterDescriptor>(descriptor,
instance));
@@ -673,8 +675,8 @@
LOG.error("Failed add RequestFilter " + clazz.getName(), e);
}
}
-
- protected void addRequestFilter(ObjectFactory<FilterDescriptor> filterFactory)
+
+ protected void addRequestFilter(ObjectFactory<FilterDescriptor> filterFactory)
{
requestFilters.getList(filterFactory.getObjectModel().getUriPattern()).add(filterFactory);
}
@@ -688,7 +690,7 @@
{
try
{
- FilterDescriptor descriptor = new FilterDescriptorImpl(clazz);
+ FilterDescriptor descriptor = new FilterDescriptorImpl(clazz,
ComponentLifecycleScope.PER_REQUEST);
descriptor.accept(rdv);
addResponseFilter(new
PerRequestObjectFactory<FilterDescriptor>(descriptor));
@@ -709,7 +711,7 @@
Class<? extends ResponseFilter> clazz = instance.getClass();
try
{
- FilterDescriptor descriptor = new FilterDescriptorImpl(clazz);
+ FilterDescriptor descriptor = new FilterDescriptorImpl(clazz,
ComponentLifecycleScope.SINGLETON);
descriptor.accept(rdv);
addResponseFilter(new SingletonObjectFactory<FilterDescriptor>(descriptor,
instance));
@@ -719,7 +721,7 @@
LOG.error("Failed add ResponseFilter " + clazz.getName(), e);
}
}
-
+
protected void addResponseFilter(ObjectFactory<FilterDescriptor> filterFactory)
{
responseFilters.getList(filterFactory.getObjectModel().getUriPattern()).add(filterFactory);
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -21,6 +21,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.ApplicationContext;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.ObjectFactory;
@@ -332,7 +333,8 @@
MethodInvoker invoker = srld.getMethodInvoker();
resource = invoker.invokeMethod(resource, srld, context);
- AbstractResourceDescriptor descriptor = new
AbstractResourceDescriptorImpl(resource);
+ AbstractResourceDescriptor descriptor =
+ new AbstractResourceDescriptorImpl(resource.getClass(),
ComponentLifecycleScope.SINGLETON);
SingletonObjectFactory<AbstractResourceDescriptor> locResource =
new SingletonObjectFactory<AbstractResourceDescriptor>(descriptor,
resource);
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -33,7 +33,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.ApplicationContext;
-import org.exoplatform.services.rest.DependencyInjector;
+import org.exoplatform.services.rest.DependencySupplier;
import org.exoplatform.services.rest.FilterDescriptor;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.GenericContainerResponse;
@@ -114,9 +114,9 @@
*/
private final ResourceBinder binder;
- private final DependencyInjector depInjector;
+ private final DependencySupplier depInjector;
- public RequestHandlerImpl(ResourceBinder binder, DependencyInjector depInjector)
+ public RequestHandlerImpl(ResourceBinder binder, DependencySupplier depInjector)
{
this.binder = binder;
this.dispatcher = new RequestDispatcher(binder);
Copied:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinderImpl.java
(from rev 291,
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java)
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinderImpl.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinderImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -0,0 +1,330 @@
+/*
+ * 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.services.rest.impl;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
+import org.exoplatform.services.rest.ObjectFactory;
+import org.exoplatform.services.rest.PerRequestObjectFactory;
+import org.exoplatform.services.rest.ResourceBinder;
+import org.exoplatform.services.rest.SingletonObjectFactory;
+import org.exoplatform.services.rest.impl.resource.AbstractResourceDescriptorImpl;
+import org.exoplatform.services.rest.impl.resource.ResourceDescriptorValidator;
+import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
+import org.exoplatform.services.rest.resource.ResourceDescriptorVisitor;
+import org.exoplatform.services.rest.uri.UriPattern;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.ext.RuntimeDelegate;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class ResourceBinderImpl implements ResourceBinder
+{
+
+ /**
+ * Logger.
+ */
+ private static final Log LOG =
ExoLogger.getLogger(ResourceBinderImpl.class.getName());
+
+ private static final Comparator<ObjectFactory<AbstractResourceDescriptor>>
RESOURCE_COMPARATOR =
+ new ResourceComparator();
+
+ /**
+ * Compare two {@link SingletonResourceFactory}.
+ */
+ private static final class ResourceComparator implements
Comparator<ObjectFactory<AbstractResourceDescriptor>>
+ {
+ /**
+ * Compare two ResourceClass for order.
+ *
+ * @param o1 first ResourceClass to be compared
+ * @param o2 second ResourceClass to be compared
+ * @return positive , zero or negative dependent of {@link UriPattern}
+ * comparison
+ * @see Comparator#compare(Object, Object)
+ * @see UriPattern
+ * @see UriPattern#URIPATTERN_COMPARATOR
+ */
+ public int compare(ObjectFactory<AbstractResourceDescriptor> o1,
ObjectFactory<AbstractResourceDescriptor> o2)
+ {
+ return
UriPattern.URIPATTERN_COMPARATOR.compare(o1.getObjectModel().getUriPattern(),
o2.getObjectModel()
+ .getUriPattern());
+ }
+ };
+
+ /**
+ * Root resource descriptors.
+ */
+ private final List<ObjectFactory<AbstractResourceDescriptor>>
rootResources =
+ new ArrayList<ObjectFactory<AbstractResourceDescriptor>>();
+
+ /**
+ * Validator.
+ */
+ private final ResourceDescriptorVisitor rdv =
ResourceDescriptorValidator.getInstance();
+
+ private int size = 0;
+
+ public ResourceBinderImpl()
+ {
+ // Initialize RuntimeDelegate instance
+ // This is first component in life cycle what needs.
+ // TODO better solution to initialize RuntimeDelegate
+ RuntimeDelegate rd = new RuntimeDelegateImpl();
+ RuntimeDelegate.setInstance(rd);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean bind(final Object resource)
+ {
+ final Path path = resource.getClass().getAnnotation(Path.class);
+
+ AbstractResourceDescriptor descriptor = null;
+ if (path != null)
+ {
+ try
+ {
+ descriptor = new AbstractResourceDescriptorImpl(resource.getClass(),
ComponentLifecycleScope.SINGLETON);
+ }
+ catch (Exception e)
+ {
+ String msg = "Unexpected error occurs when process resource class "
+ resource.getClass().getName();
+ LOG.error(msg, e);
+ return false;
+ }
+ }
+ else
+ {
+ String msg =
+ "Resource class " + resource.getClass().getName() + " it is
not root resource. "
+ + "Path annotation javax.ws.rs.Path is not specified for this
class.";
+ LOG.warn(msg);
+ return false;
+ }
+
+ // validate AbstractResourceDescriptor
+ try
+ {
+ descriptor.accept(rdv);
+ }
+ catch (Exception e)
+ {
+ LOG.error("Validation of root resource failed. ", e);
+ return false;
+ }
+
+ synchronized (rootResources)
+ {
+ // check does exist other resource with the same URI pattern
+ for (ObjectFactory<AbstractResourceDescriptor> exist : rootResources)
+ {
+ if
(exist.getObjectModel().getUriPattern().equals(descriptor.getUriPattern()))
+ {
+ String msg =
+ "Resource class " + descriptor.getObjectClass().getName() +
" can't be registered. Resource class "
+ + exist.getClass().getName() + " with the same pattern "
+ + exist.getObjectModel().getUriPattern().getTemplate() + "
already registered.";
+ LOG.warn(msg);
+ return false;
+ }
+ }
+
+ // Singleton resource
+ ObjectFactory<AbstractResourceDescriptor> res =
+ new SingletonObjectFactory<AbstractResourceDescriptor>(descriptor,
resource);
+ rootResources.add(res);
+ Collections.sort(rootResources, RESOURCE_COMPARATOR);
+ LOG.info("Bind new resource " +
res.getObjectModel().getUriPattern().getTemplate() + " : "
+ + descriptor.getObjectClass());
+ }
+ size++;
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean bind(final Class<?> resourceClass)
+ {
+ final Path path = resourceClass.getAnnotation(Path.class);
+
+ AbstractResourceDescriptor descriptor = null;
+ if (path != null)
+ {
+ try
+ {
+ descriptor = new AbstractResourceDescriptorImpl(resourceClass,
ComponentLifecycleScope.PER_REQUEST);
+ }
+ catch (Exception e)
+ {
+ String msg = "Unexpected error occurs when process resource class "
+ resourceClass.getName();
+ LOG.error(msg, e);
+ return false;
+ }
+ }
+ else
+ {
+ String msg =
+ "Resource class " + resourceClass.getName() + " it is not root
resource. "
+ + "Path annotation javax.ws.rs.Path is not specified for this
class.";
+ LOG.warn(msg);
+ return false;
+ }
+
+ // validate AbstractResourceDescriptor
+ try
+ {
+ descriptor.accept(rdv);
+ }
+ catch (Exception e)
+ {
+ LOG.error("Validation of root resource failed. ", e);
+ return false;
+ }
+
+ synchronized (rootResources)
+ {
+ // check does exist other resource with the same URI pattern
+ for (ObjectFactory<AbstractResourceDescriptor> exist : rootResources)
+ {
+ AbstractResourceDescriptor existDescriptor = exist.getObjectModel();
+ if
(exist.getObjectModel().getUriPattern().equals(descriptor.getUriPattern()))
+ {
+
+ String msg =
+ "Resource class " + descriptor.getObjectClass().getName() +
" can't be registered. Resource class "
+ + existDescriptor.getObjectClass().getName() + " with the same
pattern "
+ + exist.getObjectModel().getUriPattern().getTemplate() + "
already registered.";
+ LOG.warn(msg);
+ return false;
+ }
+ }
+ // per-request resource
+ ObjectFactory<AbstractResourceDescriptor> res =
+ new PerRequestObjectFactory<AbstractResourceDescriptor>(descriptor);
+ rootResources.add(res);
+ Collections.sort(rootResources, RESOURCE_COMPARATOR);
+ LOG.info("Bind new resource " +
res.getObjectModel().getUriPattern().getRegex() + " : " + resourceClass);
+ }
+ size++;
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public boolean unbind(Class clazz)
+ {
+ synchronized (rootResources)
+ {
+ Iterator<ObjectFactory<AbstractResourceDescriptor>> i =
rootResources.iterator();
+ while (i.hasNext())
+ {
+ ObjectFactory<AbstractResourceDescriptor> res = i.next();
+ Class c = res.getObjectModel().getObjectClass();
+ if (clazz.equals(c))
+ {
+ i.remove();
+ LOG.info("Remove ResourceContainer " +
res.getObjectModel().getUriPattern().getTemplate() + " : " + c);
+ size--;
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean unbind(String uriTemplate)
+ {
+ synchronized (rootResources)
+ {
+ Iterator<ObjectFactory<AbstractResourceDescriptor>> i =
rootResources.iterator();
+ while (i.hasNext())
+ {
+ ObjectFactory<AbstractResourceDescriptor> res = i.next();
+ String t = res.getObjectModel().getUriPattern().getTemplate();
+ if (t.equals(uriTemplate))
+ {
+ i.remove();
+ LOG.info("Remove ResourceContainer " +
res.getObjectModel().getUriPattern().getTemplate());
+ size--;
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Clear the list of ResourceContainer description.
+ */
+ public void clear()
+ {
+ rootResources.clear();
+ size = 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<ObjectFactory<AbstractResourceDescriptor>> getResources()
+ {
+ return rootResources;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getSize()
+ {
+ return size;
+ }
+
+ /**
+ * @return all registered root resources
+ */
+ @Deprecated
+ public List<AbstractResourceDescriptor> getRootResources()
+ {
+ List<AbstractResourceDescriptor> l = new
ArrayList<AbstractResourceDescriptor>(rootResources.size());
+ synchronized (rootResources)
+ {
+ for (ObjectFactory<AbstractResourceDescriptor> f : rootResources)
+ l.add(f.getObjectModel());
+ }
+ return l;
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinderImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -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.services.rest.impl;
+
+import org.exoplatform.services.rest.ResourceBinder;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id: $
+ */
+public abstract class RestComponentDeployer
+{
+
+ protected RestComponentResolver resolver;
+
+ public RestComponentDeployer(ResourceBinder resources, ProviderBinder providers)
+ {
+ resolver = new RestComponentResolver(resources, providers);
+ }
+
+ public void deploy(Object instance)
+ {
+ resolver.addSingleton(instance);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void deploy(Class clazz)
+ {
+ resolver.addPerRequest(clazz);
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentResolver.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentResolver.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentResolver.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -0,0 +1,146 @@
+/*
+ * 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.services.rest.impl;
+
+import org.exoplatform.services.rest.Filter;
+import org.exoplatform.services.rest.RequestFilter;
+import org.exoplatform.services.rest.ResourceBinder;
+import org.exoplatform.services.rest.ResponseFilter;
+import org.exoplatform.services.rest.method.MethodInvokerFilter;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id: $
+ */
+public final class RestComponentResolver
+{
+
+ private ResourceBinder resources;
+
+ private ProviderBinder providers;
+
+ public RestComponentResolver(ResourceBinder resources, ProviderBinder providers)
+ {
+ this.resources = resources;
+ this.providers = providers;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addSingleton(Object instance)
+ {
+ Class clazz = instance.getClass();
+ if (clazz.getAnnotation(Provider.class) != null)
+ {
+ // singleton provider
+ if (instance instanceof ContextResolver)
+ {
+ providers.addContextResolver((ContextResolver)instance);
+ }
+ if (instance instanceof ExceptionMapper)
+ {
+ providers.addExceptionMapper((ExceptionMapper)instance);
+ }
+ if (instance instanceof MessageBodyReader)
+ {
+ providers.addMessageBodyReader((MessageBodyReader)instance);
+ }
+ if (instance instanceof MessageBodyWriter)
+ {
+ providers.addMessageBodyWriter((MessageBodyWriter)instance);
+ }
+ }
+ else if (clazz.getAnnotation(Filter.class) != null)
+ {
+ // singleton filter
+ if (instance instanceof MethodInvokerFilter)
+ {
+ providers.addMethodInvokerFilter((MethodInvokerFilter)instance);
+ }
+ if (instance instanceof RequestFilter)
+ {
+ providers.addRequestFilter((RequestFilter)instance);
+ }
+ if (instance instanceof ResponseFilter)
+ {
+ providers.addResponseFilter((ResponseFilter)instance);
+ }
+ }
+ else if (clazz.getAnnotation(Path.class) != null)
+ {
+ // singleton resource
+ resources.bind(instance);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addPerRequest(Class clazz)
+ {
+ if (clazz.getAnnotation(Provider.class) != null)
+ {
+ // per-request provider
+ if (ContextResolver.class.isAssignableFrom(clazz))
+ {
+ providers.addContextResolver(clazz);
+ }
+ if (ExceptionMapper.class.isAssignableFrom(clazz))
+ {
+ providers.addExceptionMapper(clazz);
+ }
+ if (MessageBodyReader.class.isAssignableFrom(clazz))
+ {
+ providers.addMessageBodyReader(clazz);
+ }
+ if (MessageBodyWriter.class.isAssignableFrom(clazz))
+ {
+ providers.addMessageBodyWriter(clazz);
+ }
+ }
+ else if (clazz.getAnnotation(Filter.class) != null)
+ {
+ // per-request filter
+ if (MethodInvokerFilter.class.isAssignableFrom(clazz))
+ {
+ providers.addMethodInvokerFilter(clazz);
+ }
+ if (RequestFilter.class.isAssignableFrom(clazz))
+ {
+ providers.addRequestFilter(clazz);
+ }
+ if (ResponseFilter.class.isAssignableFrom(clazz))
+ {
+ providers.addResponseFilter(clazz);
+ }
+ }
+ else if (clazz.getAnnotation(Path.class) != null)
+ {
+ // per-request resource
+ resources.bind(clazz);
+ }
+
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencyInjector.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencyInjector.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencyInjector.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.rest.impl;
-
-import org.exoplatform.services.rest.DependencyInjector;
-
-import java.lang.reflect.Type;
-import java.util.HashMap;
-
-/**
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public class SimpleDependencyInjector extends HashMap<Class<?>, Object>
implements DependencyInjector
-{
-
- private static final long serialVersionUID = 8212609178539168377L;
-
- public Object getInjectableParameter(Class<?> type, Type genericType)
- {
- return get(type);
- }
-
-}
Copied:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java
(from rev 291,
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencyInjector.java)
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -0,0 +1,40 @@
+/*
+ * 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.services.rest.impl;
+
+import org.exoplatform.services.rest.DependencySupplier;
+import org.exoplatform.services.rest.Parameter;
+
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class SimpleDependencySupplier extends HashMap<Class<?>, Object>
implements DependencySupplier
+{
+
+ private static final long serialVersionUID = 8212609178539168377L;
+
+ public Object getInstanceOfType(Parameter parameter)
+ {
+ return get(parameter.getParameterClass());
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -40,7 +40,7 @@
public Object resolve(Parameter parameter, ApplicationContext context) throws
Exception
{
if (context.getDependencyInjector() != null)
- return
context.getDependencyInjector().getInjectableParameter(parameter.getParameterClass(),
null);
+ return context.getDependencyInjector().getInstanceOfType(parameter);
return null;
}
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,7 +18,6 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.Inject;
import org.exoplatform.services.rest.Property;
import org.exoplatform.services.rest.method.TypeProducer;
@@ -89,8 +88,7 @@
static
{
PROVIDER_FIELDS_ANNOTATIONS =
- Collections.unmodifiableList(Arrays.asList(Context.class.getName(),
Property.class.getName(), Inject.class
- .getName()));
+ Collections.unmodifiableList(Arrays.asList(Context.class.getName(),
Property.class.getName()));
PROVIDER_CONSTRUCTOR_PARAMETER_ANNOTATIONS =
Collections.unmodifiableList(Arrays.asList(Context.class.getName(),
Property.class.getName()));
@@ -103,7 +101,6 @@
tmp1.add(PathParam.class.getName());
tmp1.add(QueryParam.class.getName());
tmp1.add(Property.class.getName());
- tmp1.add(Inject.class.getName());
RESOURCE_FIELDS_ANNOTATIONS = Collections.unmodifiableList(tmp1);
RESOURCE_CONSTRUCTOR_PARAMETER_ANNOTATIONS = Collections.unmodifiableList(tmp1);
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -28,7 +28,6 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
-import org.exoplatform.services.rest.Inject;
import org.exoplatform.services.rest.Property;
/**
@@ -71,8 +70,8 @@
return new QueryParameterResolver((QueryParam)annotation);
if (clazz == Property.class)
return new PropertyResolver((Property)annotation);
- if (clazz == Inject.class)
- return new InjectableProvider((Inject)annotation);
+// if (clazz == Inject.class)
+// return new InjectableProvider((Inject)annotation);
return null;
}
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/ProviderDescriptorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/ProviderDescriptorImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/ProviderDescriptorImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -74,26 +74,9 @@
/**
* @param providerClass provider class
- */
- public ProviderDescriptorImpl(Class<?> providerClass)
- {
- this(providerClass, ComponentLifecycleScope.PER_REQUEST);
- }
-
- /**
- * @param provider provider instance
- */
- @Deprecated
- public ProviderDescriptorImpl(Object provider)
- {
- this(provider.getClass(), ComponentLifecycleScope.SINGLETON);
- }
-
- /**
- * @param providerClass provider class
* @param scope provider scope
*/
- private ProviderDescriptorImpl(Class<?> providerClass, ComponentLifecycleScope
scope)
+ public ProviderDescriptorImpl(Class<?> providerClass, ComponentLifecycleScope
scope)
{
this.providerClass = providerClass;
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -133,23 +133,12 @@
*
* @param resourceClass resource class
*/
- public AbstractResourceDescriptorImpl(Class<?> resourceClass)
+ public AbstractResourceDescriptorImpl(Class<?> resourceClass,
ComponentLifecycleScope scope)
{
- this(resourceClass.getAnnotation(Path.class), resourceClass,
ComponentLifecycleScope.PER_REQUEST);
+ this(resourceClass.getAnnotation(Path.class), resourceClass, scope);
}
/**
- * Constructs new instance of AbstractResourceDescriptor without path
- * (sub-resource).
- *
- * @param resource resource instance
- */
- public AbstractResourceDescriptorImpl(Object resource)
- {
- this(resource.getClass().getAnnotation(Path.class), resource.getClass(),
ComponentLifecycleScope.SINGLETON);
- }
-
- /**
* @param path the path value
* @param resourceClass resource class
* @param scope resource scope
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,10 +18,10 @@
*/
package org.exoplatform.services.rest.servlet;
-import org.exoplatform.services.rest.DependencyInjector;
+import org.exoplatform.services.rest.DependencySupplier;
import org.exoplatform.services.rest.RequestHandler;
import org.exoplatform.services.rest.ResourceBinder;
-import org.exoplatform.services.rest.impl.BaseResourceBinder;
+import org.exoplatform.services.rest.impl.ResourceBinderImpl;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
import javax.servlet.ServletContextEvent;
@@ -41,14 +41,14 @@
public void contextInitialized(ServletContextEvent event)
{
- String dependencyInjectorFQN =
event.getServletContext().getInitParameter(DependencyInjector.class.getName());
- DependencyInjector dependencyInjector = null;
+ String dependencyInjectorFQN =
event.getServletContext().getInitParameter(DependencySupplier.class.getName());
+ DependencySupplier dependencyInjector = null;
if (dependencyInjectorFQN != null)
{
try
{
Class<?> cl =
Thread.currentThread().getContextClassLoader().loadClass(dependencyInjectorFQN.trim());
- dependencyInjector = (DependencyInjector)cl.newInstance();
+ dependencyInjector = (DependencySupplier)cl.newInstance();
}
catch (ClassNotFoundException cnfe)
{
@@ -64,7 +64,7 @@
}
}
- ResourceBinder binder = new BaseResourceBinder();
+ ResourceBinder binder = new ResourceBinderImpl();
String applicationFQN =
event.getServletContext().getInitParameter("javax.ws.rs.Application");
if (applicationFQN != null)
{
@@ -72,7 +72,7 @@
{
Class<?> cl =
Thread.currentThread().getContextClassLoader().loadClass(applicationFQN.trim());
Application application = (Application)cl.newInstance();
- binder.addApplication(application);
+// binder.addApplication(application);
}
catch (ClassNotFoundException cnfe)
{
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/wadl/WadlProcessor.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/wadl/WadlProcessor.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/wadl/WadlProcessor.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.wadl;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.impl.resource.AbstractResourceDescriptorImpl;
import org.exoplatform.services.rest.method.MethodParameter;
import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
@@ -216,7 +217,7 @@
for (SubResourceLocatorDescriptor srld :
resourceDescriptor.getSubResourceLocators().values())
{
AbstractResourceDescriptor subResourceDescriptor =
- new AbstractResourceDescriptorImpl(srld.getMethod().getReturnType());
+ new AbstractResourceDescriptorImpl(srld.getMethod().getReturnType(),
ComponentLifecycleScope.SINGLETON);
org.exoplatform.services.rest.wadl.research.Resource wadlSubResource =
processResource(subResourceDescriptor);
wadlSubResource.setPath(srld.getPathValue().getPath());
wadlResource.getMethodOrResource().add(wadlSubResource);
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -22,7 +22,7 @@
//import org.exoplatform.container.StandaloneContainer;
import org.exoplatform.services.rest.impl.ApplicationContextImpl;
-import org.exoplatform.services.rest.impl.BaseResourceBinder;
+import org.exoplatform.services.rest.impl.ResourceBinderImpl;
import org.exoplatform.services.rest.impl.ProviderBinder;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
@@ -37,7 +37,7 @@
protected ProviderBinder providers;
- protected BaseResourceBinder binder;
+ protected ResourceBinderImpl resources;
protected RequestHandlerImpl requestHandler;
@@ -45,8 +45,8 @@
{
//
StandaloneContainer.setConfigurationPath("src/test/java/conf/standalone/test-configuration.xml");
// container = StandaloneContainer.getInstance();
- binder = new BaseResourceBinder();
- requestHandler = new RequestHandlerImpl(binder, new SimpleDependencyInjector());
+ resources = new ResourceBinderImpl();
+ requestHandler = new RequestHandlerImpl(resources, new
SimpleDependencySupplier());
requestHandler.init();
// reset providers to be sure it is clean
@@ -70,25 +70,25 @@
public boolean registry(Object resource) throws Exception
{
// container.registerComponentInstance(resource);
- return binder.bind(resource);
+ return resources.bind(resource);
}
public boolean registry(Class<?> resourceClass) throws Exception
{
// container.registerComponentImplementation(resourceClass.getName(),
resourceClass);
- return binder.bind(resourceClass);
+ return resources.bind(resourceClass);
}
public boolean unregistry(Object resource)
{
// container.unregisterComponentByInstance(resource);
- return binder.unbind(resource.getClass());
+ return resources.unbind(resource.getClass());
}
public boolean unregistry(Class<?> resourceClass)
{
// container.unregisterComponent(resourceClass.getName());
- return binder.unbind(resourceClass);
+ return resources.unbind(resourceClass);
}
}
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -44,12 +44,12 @@
public void setUp() throws Exception
{
- binder = new BaseResourceBinder();
- SimpleDependencyInjector depInjector = new SimpleDependencyInjector();
+ resources = new ResourceBinderImpl();
+ SimpleDependencySupplier depInjector = new SimpleDependencySupplier();
depInjector.put(InjectableComponent1.class, new InjectableComponent1());
depInjector.put(InjectableComponent2.class, new InjectableComponent2());
- requestHandler = new RequestHandlerImpl(binder, depInjector);
+ requestHandler = new RequestHandlerImpl(resources, depInjector);
requestHandler.init();
// reset providers to be sure it is clean
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/ResourceBinderTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/ResourceBinderTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/ResourceBinderTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -44,15 +44,15 @@
public void testBind()
{
- binder.bind(Resource.class);
- assertEquals(1, binder.getSize());
+ resources.bind(Resource.class);
+ assertEquals(1, resources.getSize());
}
public void testUnbind()
{
- binder.bind(Resource.class);
- binder.unbind(Resource.class);
- assertEquals(0, binder.getSize());
+ resources.bind(Resource.class);
+ resources.unbind(Resource.class);
+ assertEquals(0, resources.getSize());
}
@Path("/a/b/{c}")
@@ -94,25 +94,25 @@
public void testSameResourceURI()
{
- assertTrue(binder.bind(SameURIResource1.class));
- assertEquals(1, binder.getSize());
- assertFalse(binder.bind(SameURIResource2.class));
- assertEquals(1, binder.getSize());
- binder.clear();
- assertTrue(binder.bind(SameURIResource2.class));
- assertEquals(1, binder.getSize());
- assertFalse(binder.bind(SameURIResource1.class));
- assertEquals(1, binder.getSize());
- binder.clear();
- assertTrue(binder.bind(new SameURIResource1()));
- assertEquals(1, binder.getSize());
- assertFalse(binder.bind(new SameURIResource2()));
- assertEquals(1, binder.getSize());
- binder.clear();
- assertTrue(binder.bind(new SameURIResource2()));
- assertEquals(1, binder.getSize());
- assertFalse(binder.bind(new SameURIResource1()));
- assertEquals(1, binder.getSize());
+ assertTrue(resources.bind(SameURIResource1.class));
+ assertEquals(1, resources.getSize());
+ assertFalse(resources.bind(SameURIResource2.class));
+ assertEquals(1, resources.getSize());
+ resources.clear();
+ assertTrue(resources.bind(SameURIResource2.class));
+ assertEquals(1, resources.getSize());
+ assertFalse(resources.bind(SameURIResource1.class));
+ assertEquals(1, resources.getSize());
+ resources.clear();
+ assertTrue(resources.bind(new SameURIResource1()));
+ assertEquals(1, resources.getSize());
+ assertFalse(resources.bind(new SameURIResource2()));
+ assertEquals(1, resources.getSize());
+ resources.clear();
+ assertTrue(resources.bind(new SameURIResource2()));
+ assertEquals(1, resources.getSize());
+ assertFalse(resources.bind(new SameURIResource1()));
+ assertEquals(1, resources.getSize());
}
@Path("/a/b/c/{d}/e")
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.impl.AbstractResourceTest;
import javax.ws.rs.GET;
@@ -87,7 +88,7 @@
{
try
{
- new AbstractResourceDescriptorImpl(Resource3.class);
+ new AbstractResourceDescriptorImpl(Resource3.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, equivocality annotation on method m0");
}
catch (RuntimeException e)
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -24,6 +24,7 @@
import org.exoplatform.services.rest.RequestFilter;
import org.exoplatform.services.rest.ResponseFilter;
import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.ApplicationDeployer;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.method.MethodInvokerFilter;
import org.exoplatform.services.rest.resource.GenericMethodResource;
@@ -187,8 +188,9 @@
public void testRegistry()
{
- binder.addApplication(new Application1());
- assertEquals(4, binder.getSize());
+ ApplicationDeployer deployer = new ApplicationDeployer(resources, providers);
+ deployer.deploy(new Application1());
+ assertEquals(4, resources.getSize());
assertEquals(1, providers.getRequestFilters(null).size());
assertEquals(1, providers.getResponseFilters(null).size());
assertEquals(1, providers.getMethodInvokerFilters(null).size());
@@ -202,7 +204,8 @@
public void testAsResources() throws Exception
{
- binder.addApplication(new Application1());
+ ApplicationDeployer deployer = new ApplicationDeployer(resources, providers);
+ deployer.deploy(new Application1());
// per-request
ContainerResponse resp = service("GET", "/a", "",
null, null);
assertEquals(200, resp.getStatus());
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.ConstructorDescriptor;
import org.exoplatform.services.rest.FieldInjector;
import org.exoplatform.services.rest.impl.BaseTest;
@@ -68,7 +69,7 @@
{
try
{
- new AbstractResourceDescriptorImpl(Resource1.class);
+ new AbstractResourceDescriptorImpl(Resource1.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource does not contains JAX-RS
methods");
}
catch (RuntimeException e)
@@ -80,7 +81,7 @@
{
try
{
- new AbstractResourceDescriptorImpl(Resource2.class);
+ new AbstractResourceDescriptorImpl(Resource2.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource does not have public
constructor");
}
catch (RuntimeException e)
@@ -92,15 +93,15 @@
{
try
{
- new AbstractResourceDescriptorImpl(Resource3.class);
+ new AbstractResourceDescriptorImpl(Resource3.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource has two methods that have tha same
HTTP method, consumes and produces annotation");
- new AbstractResourceDescriptorImpl(Resource4.class);
+ new AbstractResourceDescriptorImpl(Resource4.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource has two methods that have tha same
HTTP method, consumes and produces annotation");
- new AbstractResourceDescriptorImpl(Resource5.class);
+ new AbstractResourceDescriptorImpl(Resource5.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource has two methods that have tha same
HTTP method, path, consumes and produces annotation");
- new AbstractResourceDescriptorImpl(Resource6.class);
+ new AbstractResourceDescriptorImpl(Resource6.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource has two methods that have tha same
HTTP method, path, consumes and produces annotation");
- new AbstractResourceDescriptorImpl(Resource7.class);
+ new AbstractResourceDescriptorImpl(Resource7.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, resource has two methods that have tha same
path");
}
catch (RuntimeException e)
@@ -112,35 +113,35 @@
{
try
{
- new AbstractResourceDescriptorImpl(Resource8.class);
+ new AbstractResourceDescriptorImpl(Resource8.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, method has two JAX-RS annotation on the same
parameter");
}
catch (RuntimeException e)
{
}
// must warn
- new AbstractResourceDescriptorImpl(Resource9.class);
+ new AbstractResourceDescriptorImpl(Resource9.class,
ComponentLifecycleScope.PER_REQUEST);
}
public void testFailedCreation5()
{
try
{
- new AbstractResourceDescriptorImpl(Resource10.class);
+ new AbstractResourceDescriptorImpl(Resource10.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, constructor of per-request resource has two
JAX-RS annotation on the same parameter");
}
catch (RuntimeException e)
{
}
// must warn
- new AbstractResourceDescriptorImpl(Resource11.class);
+ new AbstractResourceDescriptorImpl(Resource11.class,
ComponentLifecycleScope.PER_REQUEST);
}
public void testFailedCreation6()
{
try
{
- new AbstractResourceDescriptorImpl(Resource12.class);
+ new AbstractResourceDescriptorImpl(Resource12.class,
ComponentLifecycleScope.PER_REQUEST);
fail("Should be failed here, fields of per-request resource has two JAX-RS
annotation on the same parameter");
}
catch (RuntimeException e)
@@ -153,7 +154,7 @@
// TODO Mechanism for checking log messages. There is some sections in
// JAX-RS specification that said 'should warn...'. Need control this
// messages in some way.
- new AbstractResourceDescriptorImpl(Resource14.class);
+ new AbstractResourceDescriptorImpl(Resource14.class,
ComponentLifecycleScope.PER_REQUEST);
}
// ====================== all of this resource are not valid
=========================
@@ -360,7 +361,8 @@
public void testCreateAbstractResourceDescriptor()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource.class,
ComponentLifecycleScope.PER_REQUEST);
assertTrue(resource.isRootResource());
assertEquals("/a/{b}/", resource.getPathValue().getPath());
assertEquals(SampleResource.class, resource.getObjectClass());
@@ -372,7 +374,8 @@
public void testResourceMethods()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource.class,
ComponentLifecycleScope.PER_REQUEST);
// GET
ResourceMethodDescriptor methodDescriptor =
resource.getResourceMethods().getFirst("GET");
assertEquals("GET", methodDescriptor.getHttpMethod());
@@ -405,7 +408,8 @@
public void testSubResourceMethods()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource.class,
ComponentLifecycleScope.PER_REQUEST);
Collection<ResourceMethodMap<SubResourceMethodDescriptor>> subRes =
resource.getSubResourceMethods().values();
// POST
SubResourceMethodDescriptor subResourceMethodDescriptor =
subRes.iterator().next().getFirst("POST");
@@ -457,7 +461,8 @@
public void testSubResourceLocators()
{
// sub-resource method SampleResource#get2()
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource.class,
ComponentLifecycleScope.PER_REQUEST);
SubResourceLocatorDescriptor subResourceLocatorDescriptor =
resource.getSubResourceLocators().values().iterator().next();
assertEquals("{c}/d",
subResourceLocatorDescriptor.getPathValue().getPath());
@@ -474,7 +479,8 @@
public void testFields()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource.class,
ComponentLifecycleScope.PER_REQUEST);
List<FieldInjector> fields = resource.getFieldInjectors();
assertEquals(1, fields.size());
FieldInjector f = fields.get(0);
@@ -488,7 +494,8 @@
public void testConstructors()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource.class,
ComponentLifecycleScope.PER_REQUEST);
assertEquals(3, resource.getConstructorDescriptors().size());
List<ConstructorDescriptor> c = resource.getConstructorDescriptors();
assertEquals(2, c.get(0).getParameters().size());
@@ -563,7 +570,8 @@
public void testResourceMethodSorting()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource1.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource1.class,
ComponentLifecycleScope.PER_REQUEST);
List<ResourceMethodDescriptor> l =
resource.getResourceMethods().get("GET");
assertEquals("m4", l.get(0).getMethod().getName());
assertEquals("m3", l.get(1).getMethod().getName());
@@ -624,7 +632,8 @@
public void testSubResourceMethodSorting()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource2.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource2.class,
ComponentLifecycleScope.PER_REQUEST);
SubResourceMethodMap srmm = resource.getSubResourceMethods();
Collection<UriPattern> uris = srmm.keySet();
Iterator<UriPattern> i = uris.iterator();
@@ -705,7 +714,8 @@
public void testSubResourceLocatorSorting()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(SampleResource3.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(SampleResource3.class,
ComponentLifecycleScope.PER_REQUEST);
SubResourceLocatorMap locs = resource.getSubResourceLocators();
Collection<UriPattern> uris = locs.keySet();
Iterator<UriPattern> i = uris.iterator();
@@ -757,7 +767,8 @@
public void testInitializeFieldSuperClass()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(EndResource.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(EndResource.class,
ComponentLifecycleScope.PER_REQUEST);
assertEquals(6, resource.getFieldInjectors().size());
}
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorValidatorTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorValidatorTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ResourceDescriptorValidatorTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
import org.exoplatform.services.rest.resource.ResourceMethodDescriptor;
@@ -46,7 +47,8 @@
public void testAbstractResourceDescriptorValidator()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(Resource2.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(Resource2.class,
ComponentLifecycleScope.PER_REQUEST);
try
{
resource.accept(new ResourceDescriptorValidator());
@@ -59,7 +61,8 @@
public void testResourceMethodDescriptorValidator()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(Resource3.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(Resource3.class,
ComponentLifecycleScope.PER_REQUEST);
for (List<ResourceMethodDescriptor> l :
resource.getResourceMethods().values())
{
ResourceDescriptorValidator validator = new ResourceDescriptorValidator();
@@ -88,7 +91,8 @@
public void testSubResourceMethodDescriptorValidator()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(Resource4.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(Resource4.class,
ComponentLifecycleScope.PER_REQUEST);
ResourceDescriptorValidator validator = new ResourceDescriptorValidator();
for (ResourceMethodMap<SubResourceMethodDescriptor> srmm :
resource.getSubResourceMethods().values())
{
@@ -117,7 +121,8 @@
public void testSubResourceLocatorDescriptorValidator()
{
- AbstractResourceDescriptor resource = new
AbstractResourceDescriptorImpl(Resource5.class);
+ AbstractResourceDescriptor resource =
+ new AbstractResourceDescriptorImpl(Resource5.class,
ComponentLifecycleScope.PER_REQUEST);
ResourceDescriptorValidator validator = new ResourceDescriptorValidator();
for (SubResourceLocatorDescriptor rmd :
resource.getSubResourceLocators().values())
{
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/wadl/WadlProcessorTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/wadl/WadlProcessorTest.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/wadl/WadlProcessorTest.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.wadl;
+import org.exoplatform.services.rest.ComponentLifecycleScope;
import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.resource.AbstractResourceDescriptorImpl;
import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
@@ -124,7 +125,7 @@
public void testBaseWadlGenerator() throws Exception
{
- AbstractResourceDescriptor ard = new
AbstractResourceDescriptorImpl(Resource1.class);
+ AbstractResourceDescriptor ard = new
AbstractResourceDescriptorImpl(Resource1.class, ComponentLifecycleScope.PER_REQUEST);
WadlProcessor wadlProcessor = new WadlProcessor();
Application app = wadlProcessor.process(ard, new
URI("http://localhost:8080/ws/rs"));
Deleted:
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
===================================================================
---
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.rest;
-
-import org.exoplatform.container.ExoContainerContext;
-
-/**
- * Factory provides object that is created and is manageable by
- * inversion-of-control container.
- *
- * @param <T> any extension of {@link ObjectModel}
- * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public class ContainerObjectFactory<T extends ObjectModel> implements
ObjectFactory<T>
-{
-
- /**
- * Object model.
- */
- protected final T model;
-
- /**
- * @param model object model
- * @see ObjectModel
- */
- public ContainerObjectFactory(T model)
- {
- this.model = model;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getInstance(ApplicationContext context)
- {
- Class<?> clazz = model.getObjectClass();
- return
ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(clazz);
- }
-
- /**
- * {@inheritDoc}
- */
- public T getObjectModel()
- {
- return model;
- }
-
-}
Deleted:
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerDependencyInjector.java
===================================================================
---
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerDependencyInjector.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerDependencyInjector.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.rest.impl;
-
-import java.lang.reflect.Type;
-
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.services.rest.DependencyInjector;
-
-/**
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public class ExoContainerDependencyInjector implements DependencyInjector
-{
-
- /**
- * {@inheritDoc}
- */
- public Object getInjectableParameter(Class<?> type, Type genericType)
- {
- ExoContainer container = ExoContainerContext.getCurrentContainer();
- return container.getComponentInstanceOfType(type);
- }
-
-}
Deleted:
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java
===================================================================
---
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.rest.impl;
-
-import java.util.List;
-
-import javax.ws.rs.core.Application;
-import javax.ws.rs.ext.RuntimeDelegate;
-
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.resource.ResourceContainer;
-
-/**
- * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public class ExoContainerResourceBinder extends BaseResourceBinder
-{
-
- /**
- * Logger.
- */
- private static final Log LOG =
ExoLogger.getLogger(ExoContainerResourceBinder.class.getName());
-
- /**
- * @param containerContext eXo container context
- * @throws Exception if can't set instance of {@link RuntimeDelegate}
- */
- @SuppressWarnings("unchecked")
- public ExoContainerResourceBinder(ExoContainerContext containerContext) throws
Exception
- {
- super();
- ExoContainer container = containerContext.getContainer();
-
- // Lookup Applications
- List<Application> applications =
container.getComponentInstancesOfType(Application.class);
- for (Application a : applications)
- {
- try
- {
- addApplication(a);
- }
- catch (Exception e)
- {
- LOG.error("Failed add JAX-RS application " +
a.getClass().getName(), e);
- }
- }
-
- // Lookup all object which implements ResourceContainer interface and
- // process them to be add as root resources.
- for (Object resource :
container.getComponentInstancesOfType(ResourceContainer.class))
- {
- bind(resource);
- }
-
- }
-
-}
Modified:
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/RestInitializer.java
===================================================================
---
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/RestInitializer.java 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/RestInitializer.java 2009-10-19
07:03:07 UTC (rev 292)
@@ -18,26 +18,26 @@
*/
package org.exoplatform.services.rest.impl;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.ContextResolver;
-import javax.xml.bind.JAXBException;
-
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.RequestFilter;
-import org.exoplatform.services.rest.RequestHandler;
-import org.exoplatform.services.rest.ResponseFilter;
-import org.exoplatform.services.rest.impl.provider.JAXBContextResolver;
-import org.exoplatform.services.rest.method.MethodInvokerFilter;
-import org.exoplatform.services.rest.provider.EntityProvider;
+import org.exoplatform.services.rest.DependencySupplier;
+import org.exoplatform.services.rest.Parameter;
+import org.exoplatform.services.rest.ResourceBinder;
+import org.exoplatform.services.rest.resource.ResourceContainer;
import org.picocontainer.Startable;
+import java.util.List;
+
+import javax.ws.rs.core.Application;
+
/**
* @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
* @version $Id$
*/
-public class RestInitializer implements Startable
+public class RestInitializer extends ApplicationDeployer implements DependencySupplier,
Startable
{
/**
@@ -46,18 +46,17 @@
private static final Log LOG = ExoLogger.getLogger(RestInitializer.class.getName());
@SuppressWarnings("unchecked")
- public RestInitializer(RequestHandler requestHandler, InitParams initParams)
+ public RestInitializer(ResourceBinder resources, InitParams initParams,
ExoContainerContext containerContext)
{
-
- ProviderBinder providers = ProviderBinder.getInstance();
-
+ super(resources, ProviderBinder.getInstance());
+ ExoContainer container = containerContext.getContainer();
if (initParams != null)
{
- for (Object cl :
initParams.getValuesParam("ws.rs.request.filter").getValues())
+ for (Object cl :
initParams.getValuesParam("ws.rest.components").getValues())
{
try
{
- providers.addRequestFilter((Class<? extends
RequestFilter>)Class.forName((String)cl));
+ deploy(Class.forName((String)cl));
}
catch (ClassNotFoundException e)
{
@@ -65,69 +64,22 @@
}
}
}
- for (Object cl :
initParams.getValuesParam("ws.rs.response.filter").getValues())
+ List<Application> applications =
container.getComponentInstancesOfType(Application.class);
+ for (Application a : applications)
{
- try
- {
- providers.addResponseFilter((Class<? extends
ResponseFilter>)Class.forName((String)cl));
- }
- catch (ClassNotFoundException e)
- {
- LOG.error("Failed load class " + cl, e);
- }
+ deploy(a);
}
- for (Object cl :
initParams.getValuesParam("ws.rs.method.filter").getValues())
+ for (Object resource :
container.getComponentInstancesOfType(ResourceContainer.class))
{
- try
- {
- providers.addMethodInvokerFilter((Class<? extends
MethodInvokerFilter>)Class.forName((String)cl));
- }
- catch (ClassNotFoundException e)
- {
- LOG.error("Failed load class " + cl, e);
- }
+ deploy(resource);
}
- for (Object cl :
initParams.getValuesParam("ws.rs.entity.provider").getValues())
- {
- try
- {
- Class<? extends EntityProvider> prov = (Class<? extends
EntityProvider>)Class.forName((String)cl);
- providers.addMessageBodyReader(prov);
- providers.addMessageBodyWriter(prov);
- }
- catch (ClassNotFoundException e)
- {
- LOG.error("Failed load class " + cl, e);
- }
- }
- for (Object cl :
initParams.getValuesParam("ws.rs.jaxb.context").getValues())
- {
- try
- {
- ContextResolver<JAXBContextResolver> resolver =
- providers.getContextResolver(JAXBContextResolver.class,
MediaType.WILDCARD_TYPE);
- if (resolver == null)
- {
- LOG.error("Not found JAXBContextResolver.");
- }
- else
- {
- JAXBContextResolver contextResolver = resolver.getContext(null);
-
contextResolver.createJAXBContext((Class<?>)Class.forName((String)cl));
- }
- }
- catch (ClassNotFoundException e)
- {
- LOG.error("Failed load class " + cl, e);
- }
- catch (JAXBException jaxbe)
- {
- LOG.error("Failed add JAXBContext for class " + cl, jaxbe);
- }
- }
-
}
+ public Object getInstanceOfType(Parameter parameter)
+ {
+ return null;
+ }
+
public void start()
{
}
Modified: ws/branches/2.2.x/rest/ext/src/test/java/conf/standalone/test-configuration.xml
===================================================================
---
ws/branches/2.2.x/rest/ext/src/test/java/conf/standalone/test-configuration.xml 2009-10-16
15:45:39 UTC (rev 291)
+++
ws/branches/2.2.x/rest/ext/src/test/java/conf/standalone/test-configuration.xml 2009-10-19
07:03:07 UTC (rev 292)
@@ -22,36 +22,18 @@
<type>org.exoplatform.services.rest.impl.RestInitializer</type>
<init-params>
<values-param>
- <name>ws.rs.entity.provider</name>
+ <name>ws.rest.components</name>
<value>org.exoplatform.services.rest.ext.provider.HierarchicalPropertyEntityProvider</value>
-<!-- Add own entity providers here -->
- </values-param>
- <values-param>
- <name>ws.rs.request.filter</name>
<value>org.exoplatform.services.rest.ext.filter.MethodOverrideFilter</value>
-<!-- Add own request filters here -->
- </values-param>
- <values-param>
- <name>ws.rs.response.filter</name>
-<!-- Add own response filters here -->
- </values-param>
- <values-param>
- <name>ws.rs.method.filter</name>
<value>org.exoplatform.services.rest.impl.method.MethodInvokerFilterComponentPlugin</value>
-<!-- Add own method filters here -->
</values-param>
- <values-param>
- <name>ws.rs.jaxb.context</name>
- <value>org.exoplatform.services.rest.wadl.research.Application</value>
-<!-- Add own jaxb context here -->
- </values-param>
</init-params>
</component>
<component>
<type>org.exoplatform.services.rest.impl.RequestHandlerImpl</type>
</component>
<component>
- <type>org.exoplatform.services.rest.impl.ExoContainerResourceBinder</type>
+ <type>org.exoplatform.services.rest.impl.BaseResourceBinder</type>
</component>
<component>
<type>org.exoplatform.services.rest.impl.ExoContainerDependencyInjector</type>