[exo-jcr-commits] exo-jcr SVN: r2278 - in ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest: impl/resource and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Apr 13 11:05:37 EDT 2010
Author: yakimenko
Date: 2010-04-13 11:05:36 -0400 (Tue, 13 Apr 2010)
New Revision: 2278
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/resource/AbstractResourceDescriptor.java
Log:
EXOJCR-663: was removed finalization of classes RequestDispatcher and ResourceBinder. Was added two methods getProperties and getProperty for getting properties in AbstractResourceDescriptor and in AbstractResourceDescriptorImpl.
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java 2010-04-13 13:10:14 UTC (rev 2277)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java 2010-04-13 15:05:36 UTC (rev 2278)
@@ -69,7 +69,7 @@
/**
* See {@link ResourceBinder}.
*/
- private final ResourceBinder resourceBinder;
+ protected final ResourceBinder resourceBinder;
/**
* Constructs new instance of RequestDispatcher.
@@ -93,45 +93,9 @@
String requestPath = context.getPath(false);
List<String> parameterValues = context.getParameterValues();
- ObjectFactory<AbstractResourceDescriptor> resourceFactory = null;
+ // Get root resource
+ ObjectFactory<AbstractResourceDescriptor> resourceFactory = getRootResourse(parameterValues, requestPath);
- List<ObjectFactory<AbstractResourceDescriptor>> resources = resourceBinder.getResources();
- // be sure no new entries added
- synchronized (resources)
- {
- for (ObjectFactory<AbstractResourceDescriptor> rc : resources)
- {
- if (rc.getObjectModel().getUriPattern().match(requestPath, parameterValues))
- {
- // all times will at least 1
- int len = parameterValues.size();
- // If capturing group contains last element and this element is
- // neither null nor '/' then ResourceClass must contains at least one
- // sub-resource method or sub-resource locator.
- if (parameterValues.get(len - 1) != null && !parameterValues.get(len - 1).equals("/"))
- {
- int subresnum =
- rc.getObjectModel().getSubResourceMethods().size()
- + rc.getObjectModel().getSubResourceLocators().size();
- if (subresnum == 0)
- continue;
- }
- resourceFactory = rc;
- break;
- }
- }
-
- }
-
- if (resourceFactory == null)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Root resource not found for " + requestPath);
-
- // Stop here, there is no matched root resource
- throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
- }
-
// Take the tail of the request path, the tail will be requested path
// for lower resources, e. g. ResourceClass -> Sub-resource method/locator
String newRequestPath = getPathTail(parameterValues);
@@ -563,5 +527,55 @@
return !locators.isEmpty();
}
+
+ /**
+ * Get root resource
+ *
+ * @param parameterValues is taken from context
+ * @param requestPath is taken from context
+ * @return root resource
+ */
+ protected ObjectFactory<AbstractResourceDescriptor> getRootResourse(List<String> parameterValues, String requestPath)
+ {
+ ObjectFactory<AbstractResourceDescriptor> resourceFactory = null;
+ List<ObjectFactory<AbstractResourceDescriptor>> resources = resourceBinder.getResources();
+ // be sure no new entries added
+ synchronized (resources)
+ {
+ for (ObjectFactory<AbstractResourceDescriptor> rc : resources)
+ {
+ if (rc.getObjectModel().getUriPattern().match(requestPath, parameterValues))
+ {
+ // all times will at least 1
+ int len = parameterValues.size();
+ // If capturing group contains last element and this element is
+ // neither null nor '/' then ResourceClass must contains at least one
+ // sub-resource method or sub-resource locator.
+ if (parameterValues.get(len - 1) != null && !parameterValues.get(len - 1).equals("/"))
+ {
+ int subresnum =
+ rc.getObjectModel().getSubResourceMethods().size()
+ + rc.getObjectModel().getSubResourceLocators().size();
+ if (subresnum == 0)
+ continue;
+ }
+ resourceFactory = rc;
+ break;
+ }
+ }
+ }
+
+ if (resourceFactory == null)
+ {
+
+ if (LOG.isDebugEnabled())
+ LOG.debug("Root resource not found for " + requestPath);
+
+ // Stop here, there is no matched root resource
+ throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
+ }
+ else
+ return resourceFactory;
+ }
}
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java 2010-04-13 13:10:14 UTC (rev 2277)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java 2010-04-13 15:05:36 UTC (rev 2278)
@@ -60,7 +60,7 @@
* @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public final class ResourceBinder
+public class ResourceBinder
{
/**
@@ -68,7 +68,7 @@
*/
private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.core.ResourceBinder");
- private static final Comparator<ObjectFactory<AbstractResourceDescriptor>> RESOURCE_COMPARATOR =
+ protected static final Comparator<ObjectFactory<AbstractResourceDescriptor>> RESOURCE_COMPARATOR =
new ResourceComparator();
/**
@@ -97,20 +97,20 @@
/**
* Root resource descriptors.
*/
- private final List<ObjectFactory<AbstractResourceDescriptor>> rootResources =
+ protected final List<ObjectFactory<AbstractResourceDescriptor>> rootResources =
new ArrayList<ObjectFactory<AbstractResourceDescriptor>>();
/**
* Validator.
*/
- private final ResourceDescriptorVisitor rdv = ResourceDescriptorValidator.getInstance();
+ protected final ResourceDescriptorVisitor rdv = ResourceDescriptorValidator.getInstance();
- private int size = 0;
+ protected int size = 0;
/**
* @see RuntimeDelegate
*/
- private final RuntimeDelegate rd;
+ protected final RuntimeDelegate rd;
/**
* @param containerContext eXo container context
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java 2010-04-13 13:10:14 UTC (rev 2277)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/resource/AbstractResourceDescriptorImpl.java 2010-04-13 15:05:36 UTC (rev 2278)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.ComponentLifecycleScope;
@@ -66,6 +67,7 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
/**
* @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
@@ -126,6 +128,11 @@
* Resource class fields.
*/
private final List<FieldInjector> fields;
+
+ /**
+ * Optional data
+ */
+ private MultivaluedMap<String, String> properties;
/**
* Constructs new instance of AbstractResourceDescriptor without path
@@ -223,6 +230,26 @@
/**
* {@inheritDoc}
*/
+ public MultivaluedMap<String, String> getProperties()
+ {
+ if (properties == null)
+ properties = new MultivaluedMapImpl();
+ return properties;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<String> getProperty(String key)
+ {
+ if (properties != null)
+ return properties.get(key);
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void accept(ResourceDescriptorVisitor visitor)
{
visitor.visitAbstractResourceDescriptor(this);
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/resource/AbstractResourceDescriptor.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/resource/AbstractResourceDescriptor.java 2010-04-13 13:10:14 UTC (rev 2277)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/resource/AbstractResourceDescriptor.java 2010-04-13 15:05:36 UTC (rev 2278)
@@ -22,6 +22,10 @@
import org.exoplatform.services.rest.impl.resource.PathValue;
import org.exoplatform.services.rest.uri.UriPattern;
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedMap;
+
/**
* Describe Resource Class or Root Resource Class. Resource Class is any Java
* class that uses JAX-RS annotations to implement corresponding Web resource.
@@ -54,6 +58,21 @@
* @return sub-resource methods
*/
SubResourceMethodMap getSubResourceMethods();
+
+ /**
+ * Optional data
+ *
+ * @param key
+ * @return property by key
+ */
+ List<String> getProperty(String key);
+
+ /**
+ * Optional data
+ *
+ * @return all properties
+ */
+ MultivaluedMap<String,String> getProperties();
/**
* @return See {@link UriPattern}
More information about the exo-jcr-commits
mailing list