You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by el...@apache.org on 2009/08/09 09:50:27 UTC

svn commit: r802500 - in /incubator/wink/trunk: wink-common/src/main/java/org/apache/wink/common/ wink-examples/ext/DynamicResource/src/main/java/org/apache/wink/example/dynamicresource/ wink-server/src/main/java/org/apache/wink/server/internal/registr...

Author: elman
Date: Sun Aug  9 07:50:27 2009
New Revision: 802500

URL: http://svn.apache.org/viewvc?rev=802500&view=rev
Log:
refactor DynamicResource. See [WINK-134]

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/AbstractDynamicResource.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/DynamicResource.java
    incubator/wink/trunk/wink-examples/ext/DynamicResource/src/main/java/org/apache/wink/example/dynamicresource/MyApplication.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceBeanTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithDuplicateWorkspaceTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithEmptyPathTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/ExtensionResourceBeanTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/ResourceRecordFactoryTest.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/AbstractDynamicResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/AbstractDynamicResource.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/AbstractDynamicResource.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/AbstractDynamicResource.java Sun Aug  9 07:50:27 2009
@@ -23,14 +23,17 @@
 /**
  * Provides a basic implementation of the
  * org.apache.wink.common.DynamicResource.
+ * <p>
+ * In general it's recommended to extend from this class, instead of
+ * implementing the DynamicResource.
  */
 public abstract class AbstractDynamicResource implements DynamicResource {
 
-    private String[] dispatchedPath;
-    private Object[] parents;
-    private String   workspaceTitle;
-    private String   collectionTitle;
-    private String   beanName;
+    private String path;
+    private Object parent;
+    private String workspaceTitle;
+    private String collectionTitle;
+    private String beanName;
 
     public String getBeanName() {
         return beanName;
@@ -40,22 +43,6 @@
         this.beanName = beanName;
     }
 
-    public void setDispatchedPath(String[] dispatchedPath) {
-        this.dispatchedPath = dispatchedPath;
-    }
-
-    public String[] getDispatchedPath() {
-        return dispatchedPath;
-    }
-
-    public void setParents(Object[] parents) {
-        this.parents = parents;
-    }
-
-    public Object[] getParents() {
-        return parents;
-    }
-
     public void setWorkspaceTitle(String workspaceTitle) {
         this.workspaceTitle = workspaceTitle;
     }
@@ -72,4 +59,20 @@
         return collectionTitle;
     }
 
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setParent(Object parent) {
+        this.parent = parent;
+    }
+
+    public Object getParent() {
+        return parent;
+    }
+
 }

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/DynamicResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/DynamicResource.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/DynamicResource.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/DynamicResource.java Sun Aug  9 07:50:27 2009
@@ -20,18 +20,24 @@
 
 package org.apache.wink.common;
 
+import org.apache.wink.common.annotations.Parent;
+
 /**
- * This interface replaces DispatchedPath annotation to declare a resource. It's
- * impossible to declare resource using both DynamicResource interface and
- * DispatchedPath annotation.
+ * This interface replaces Path annotation to declare a resource. It's
+ * impossible to declare resource using both DynamicResource interface and Path
+ * annotation.
+ * <p>
+ * In general it's recommended to extend from AbstractDynamicResource, instead
+ * of implementing the DynamicResource.
  * 
  * @see org.apache.wink.common.AbstractDynamicResource
+ * @see javax.ws.rs.Path
  */
 public interface DynamicResource {
 
     /**
      * returns the name of the bean The bean name must be unique and usually
-     * should come from Spring If your bean is not generated by Spring, return
+     * should come from Spring. If your bean is not generated by Spring, return
      * null and the unique bean name will be generated. If method bean name was
      * set using the setBeanName method, the method must return the same name
      * that was set.
@@ -49,40 +55,35 @@
     void setBeanName(String beanName);
 
     /**
-     * Returns array of URI templates. Like value() of javax.ws.rs.Path
-     * annotation.
+     * Returns path. Similar to value() of javax.ws.rs.Path
      * 
-     * @return array of URI templates
+     * @return path of the resource
      */
-    String[] getDispatchedPath();
+    String getPath();
 
     /**
      * <p>
-     * A parent of this dispatched URI so the resulting dispatched URI is a
-     * composition of the parent dispatched URI and this one. There can be more
-     * than one parent.
-     * <p>
-     * Note that in comparison to the DispatchedPath annotation, the parent here
-     * must be reference to the resource and not class.
-     * <p>
-     * In case there are no parents, return empty list.
+     * A parent of this resource, so the resulting path is a composition of the
+     * parent's path and this one.
      * <p>
-     * If returns null, the default parent (RootResource) is used.
+     * Note that in comparison to the Parent annotation, the parent here must be
+     * reference to the resource and not class.
      * <p>
      * If method setParent was invoked, this method must return the same parent
      * that was set.
      * 
      * @return Resource instance of the parent dispatched URIs
+     * @see Parent
      */
-    Object[] getParents();
+    Object getParent();
 
     /**
      * <p>
-     * Sets parents. See getParents() for full description.
+     * Sets parents. See getParent() for full description.
      * 
      * @param parents
      */
-    void setParents(Object[] parents);
+    void setParent(Object parents);
 
     /**
      * Returns the workspace title. If the title was already defined using

Modified: incubator/wink/trunk/wink-examples/ext/DynamicResource/src/main/java/org/apache/wink/example/dynamicresource/MyApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-examples/ext/DynamicResource/src/main/java/org/apache/wink/example/dynamicresource/MyApplication.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-examples/ext/DynamicResource/src/main/java/org/apache/wink/example/dynamicresource/MyApplication.java (original)
+++ incubator/wink/trunk/wink-examples/ext/DynamicResource/src/main/java/org/apache/wink/example/dynamicresource/MyApplication.java Sun Aug  9 07:50:27 2009
@@ -32,7 +32,7 @@
         BookmarksResource br = new BookmarksResource();
         br.setWorkspaceTitle("Demo Bookmarks Service");
         br.setCollectionTitle("My Bookmarks");
-        br.setDispatchedPath(new String[] {"/bookmarks"});
+        br.setPath("/bookmarks");
         hs.add(br);
         return hs;
     }

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java (original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java Sun Aug  9 07:50:27 2009
@@ -20,15 +20,12 @@
 
 package org.apache.wink.server.internal.registry;
 
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.wink.common.DynamicResource;
 import org.apache.wink.common.internal.lifecycle.LifecycleManagersRegistry;
 import org.apache.wink.common.internal.lifecycle.ObjectFactory;
@@ -36,6 +33,8 @@
 import org.apache.wink.common.internal.registry.metadata.ResourceMetadataCollector;
 import org.apache.wink.common.internal.runtime.RuntimeContext;
 import org.apache.wink.common.internal.uritemplate.UriTemplateProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ResourceRecordFactory {
 
@@ -237,20 +236,19 @@
      */
     private ClassMetadata fixInstanceMetadata(ClassMetadata classMetadata,
                                               DynamicResource dynamicResource) {
-        String[] dispatchedPath = dynamicResource.getDispatchedPath();
-        if (dispatchedPath != null) {
-            classMetadata.addPaths(Arrays.asList(dispatchedPath));
+        String path = dynamicResource.getPath();
+        if (path != null) {
+            classMetadata.addPath(path);
             if (logger.isDebugEnabled()) {
-                logger.debug("Adding dispatched path from instance: {}", Arrays
-                    .toString(dispatchedPath));
+                logger.debug("Adding dispatched path from instance: {}", path);
             }
         }
 
-        Object[] parents = dynamicResource.getParents();
-        if (parents != null) {
-            classMetadata.getParentInstances().addAll(Arrays.asList(parents));
+        Object parent = dynamicResource.getParent();
+        if (parent != null) {
+            classMetadata.getParentInstances().add(parent);
             if (logger.isDebugEnabled()) {
-                logger.debug("Adding parent beans from instance: {}", Arrays.toString(parents));
+                logger.debug("Adding parent beans from instance: {}", parent);
             }
         }
 

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceBeanTest.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceBeanTest.java (original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceBeanTest.java Sun Aug  9 07:50:27 2009
@@ -46,46 +46,34 @@
         public Set<Object> getInstances() {
             AbstractTestCollectionResource servicesCollection =
                 new AbstractTestCollectionResource();
-            servicesCollection.setDispatchedPath(new String[] {"/services"});
+            servicesCollection.setPath("/services");
 
             AbstractTestCollectionResource servicesCollectionWithWorkspaceAndTitle =
                 new AbstractTestCollectionResource();
-            servicesCollectionWithWorkspaceAndTitle
-                .setDispatchedPath(new String[] {"/services/workspaceAndTitle"});
+            servicesCollectionWithWorkspaceAndTitle.setPath("/services/workspaceAndTitle");
             servicesCollectionWithWorkspaceAndTitle.setWorkspaceTitle("Services Workspace Title");
             servicesCollectionWithWorkspaceAndTitle.setCollectionTitle("Services Collection Title");
 
             AbstractTestSingleResource singleService = new AbstractTestSingleResource();
-            singleService.setDispatchedPath(new String[] {"/services/{id}"});
+            singleService.setPath("/services/{id}");
 
-            // TODO: do we support multiple paths?
             AbstractTestSingleResource singleServiceDifferentURIs =
                 new AbstractTestSingleResource();
-            singleServiceDifferentURIs.setDispatchedPath(new String[] {"/services1/{id}"/*
-                                                                                         * ,
-                                                                                         * "/services2/{id}"
-                                                                                         */});
+            singleServiceDifferentURIs.setPath("/services1/{id}");
 
             AbstractTestSingleParentResource singleServiceParent =
                 new AbstractTestSingleParentResource();
-            singleServiceParent.setDispatchedPath(new String[] {"parent"});
-            singleServiceParent.setParents(new Object[] {singleService});
+            singleServiceParent.setPath("parent");
+            singleServiceParent.setParent(singleService);
 
-            // TODO: do we support multiple paths and multiple parents?
             AbstractTestSingleParentResource singleServiceMultipleParents =
                 new AbstractTestSingleParentResource();
-            singleServiceMultipleParents.setDispatchedPath(new String[] {"parent1"/*
-                                                                                   * ,
-                                                                                   * "parent2"
-                                                                                   */});
-            singleServiceMultipleParents.setParents(new Object[] {singleService /*
-                                                                                 * ,
-                                                                                 * singleServiceDifferentURIs
-                                                                                 */});
+            singleServiceMultipleParents.setPath("parent1");
+            singleServiceMultipleParents.setParent(singleService);
 
             AbstractTestReferencingBeanResource beanReferencingaAnotherBean =
                 new AbstractTestReferencingBeanResource();
-            beanReferencingaAnotherBean.setDispatchedPath(new String[] {"/referenceBean/{id}"});
+            beanReferencingaAnotherBean.setPath("/referenceBean/{id}");
             beanReferencingaAnotherBean.setRefdBean(singleService);
 
             AbstractTestWithAnnotationsResource resourceWithAnnotations =
@@ -93,13 +81,13 @@
 
             AbstractTestReferencingBeanResource beanReferencingClass =
                 new AbstractTestReferencingBeanResource();
-            beanReferencingClass.setDispatchedPath(new String[] {"/referenceClass/{id}"});
+            beanReferencingClass.setPath("/referenceClass/{id}");
             beanReferencingClass.setRefdBean(resourceWithAnnotations);
 
             AbstractTestSingleParentResource singleServiceParentIsClass =
                 new AbstractTestSingleParentResource();
-            singleServiceParentIsClass.setDispatchedPath(new String[] {"parent"});
-            singleServiceParentIsClass.setParents(new Object[] {resourceWithAnnotations});
+            singleServiceParentIsClass.setPath("parent");
+            singleServiceParentIsClass.setParent(resourceWithAnnotations);
 
             Set<Object> set = new HashSet<Object>();
             set.add(servicesCollection);

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithDuplicateWorkspaceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithDuplicateWorkspaceTest.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithDuplicateWorkspaceTest.java (original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithDuplicateWorkspaceTest.java Sun Aug  9 07:50:27 2009
@@ -47,14 +47,14 @@
             AbstractTestWithWorkspaceResource servicesCollectionWithWorskapce =
                 new AbstractTestWithWorkspaceResource();
             servicesCollectionWithWorskapce
-                .setDispatchedPath(new String[] {"/services/withWorkspace"});
+                .setPath("/services/withWorkspace");
             servicesCollectionWithWorskapce.setCollectionTitle("Spring Collection");
             servicesCollectionWithWorskapce.setWorkspaceTitle("Spring Workspace");
 
             AbstractTestWithWorkspaceResource servicesCollectionWithoutWorskapce =
                 new AbstractTestWithWorkspaceResource();
             servicesCollectionWithoutWorskapce
-                .setDispatchedPath(new String[] {"/services/withoutWorkspace"});
+                .setPath("/services/withoutWorkspace");
 
             set.add(servicesCollectionWithWorskapce);
             set.add(servicesCollectionWithoutWorskapce);

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithEmptyPathTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithEmptyPathTest.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithEmptyPathTest.java (original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/AbstractResourceWithEmptyPathTest.java Sun Aug  9 07:50:27 2009
@@ -41,11 +41,10 @@
         @Override
         public Set<Object> getInstances() {
             AbstractTestCollectionResource emptyPath = new AbstractTestCollectionResource();
-            emptyPath.setDispatchedPath(new String[] {"/a"});
+            emptyPath.setPath("/a");
 
             AbstractTestCollectionResource2 emptyParent = new AbstractTestCollectionResource2();
-            emptyParent.setDispatchedPath(new String[] {"/emptyParent"});
-            emptyParent.setParents(new Object[0]);
+            emptyParent.setPath("/emptyParent");
             Set<Object> set = new HashSet<Object>();
             set.add(emptyPath);
             set.add(emptyParent);

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/ExtensionResourceBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/ExtensionResourceBeanTest.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/ExtensionResourceBeanTest.java (original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/ExtensionResourceBeanTest.java Sun Aug  9 07:50:27 2009
@@ -38,23 +38,21 @@
     @Override
     protected Object[] getSingletons() {
         BasicBeanResource basicResourceResource = new BasicBeanResource();
-        basicResourceResource.setDispatchedPath(new String[] {"/basicBeanUrl",
-            "/basicBeanUrlNoParent"});
+        basicResourceResource.setPath("/basicBeanUrl");
 
         BasicResource basit = new BasicResource();
 
         ExtendedBasicBeanResource extendedBasicBeanResource = new ExtendedBasicBeanResource();
-        extendedBasicBeanResource.setDispatchedPath(new String[] {""});
-        extendedBasicBeanResource.setParents(new Object[] {basicResourceResource});
+        extendedBasicBeanResource.setPath("");
+        extendedBasicBeanResource.setParent(basicResourceResource);
 
         ExtendedBasicBeanWithNoParentResource extendedBasicBeanWithNoParentResource =
             new ExtendedBasicBeanWithNoParentResource();
-        extendedBasicBeanWithNoParentResource.setDispatchedPath(new String[] {"/basicBeanUrl",
-            "/basicBeanUrlNoParent"});
+        extendedBasicBeanWithNoParentResource.setPath("/basicBeanUrl");
 
         ExtendedBasicResource extendedBasicResource = new ExtendedBasicResource();
-        extendedBasicResource.setDispatchedPath(new String[] {""});
-        extendedBasicResource.setParents(new Object[] {basicResourceResource});
+        extendedBasicResource.setPath("");
+        extendedBasicResource.setParent(basicResourceResource);
 
         Set<Object> set = new HashSet<Object>();
         set.add(basicResourceResource);

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/ResourceRecordFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/ResourceRecordFactoryTest.java?rev=802500&r1=802499&r2=802500&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/ResourceRecordFactoryTest.java (original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/ResourceRecordFactoryTest.java Sun Aug  9 07:50:27 2009
@@ -90,7 +90,7 @@
     public void testDynamicResource() {
         ResourceRecordFactory factory = new ResourceRecordFactory(new LifecycleManagersRegistry());
         Dynamic dynamic = new Dynamic();
-        dynamic.setDispatchedPath(new String[] {"/pathDyna"});
+        dynamic.setPath("/pathDyna");
 
         ResourceRecord dynamicRecord = factory.getResourceRecord(dynamic);
         assertEquals("/pathDyna", dynamicRecord.getMetadata().getPath());
@@ -99,7 +99,7 @@
         assertTrue(o == dynamic);
 
         Dynamic dynamic2 = new Dynamic();
-        dynamic2.setDispatchedPath(new String[] {"/pathDyna2"});
+        dynamic2.setPath("/pathDyna2");
         ResourceRecord dynamicRecord2 = factory.getResourceRecord(dynamic2);
         assertEquals("/pathDyna2", dynamicRecord2.getMetadata().getPath());
         Object o2 = dynamicRecord2.getObjectFactory().getInstance(null);