abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r603739 - in /incubator/abdera/java/trunk: client/src/test/java/org/apache/abdera/test/client/ client/src/test/java/org/apache/abdera/test/client/app/ jcr/src/test/java/org/apache/abdera/jcr/ server/src/main/java/org/apache/abdera/protocol/...
Date Wed, 12 Dec 2007 21:00:02 GMT
Author: dandiep
Date: Wed Dec 12 13:00:00 2007
New Revision: 603739

URL: http://svn.apache.org/viewvc?rev=603739&view=rev
Log:
Rename WorkspaceProvider to ServiceProvider because really what it does is back
a services document.

Make ServiceProvider implement Target<Resolver> so I never have to screw with
regexs. This has a wonderful side affect of cleaning up some of the
CollectionProvider lookup code too.

Rename AbstractTarget to DefaultTarget so I can use it in the ServiceProvider.

Rename the tests to have CollectionProvider in the name instead of ContentProvider
which was the old name.

Make the tests use a port that is not 8080 because 8080 is used on a lot of machines.


Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
      - copied, changed from r599148, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
      - copied, changed from r599147, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ServiceProvider.java
      - copied, changed from r599147, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceProvider.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
      - copied, changed from r599147, incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/ContentProviderTest.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java
      - copied, changed from r599147, incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java
Removed:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceProvider.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/ContentProviderTest.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java
Modified:
    incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/JettyUtil.java
    incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
    incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java

Modified: incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/JettyUtil.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/JettyUtil.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/JettyUtil.java
(original)
+++ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/JettyUtil.java
Wed Dec 12 13:00:00 2007
@@ -26,7 +26,7 @@
 
   private static final String PORT_PROP = "abdera.test.client.port";
   
-  private static int PORT = 8080;
+  private static int PORT = 9002;
   private static Server server = null;
   private static ServletHandler handler = null;
   

Modified: incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
(original)
+++ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
Wed Dec 12 13:00:00 2007
@@ -45,6 +45,7 @@
 import org.apache.abdera.protocol.client.RequestOptions;
 import org.apache.abdera.protocol.client.ClientResponse;
 import org.apache.abdera.test.client.JettyTest;
+import org.apache.abdera.test.client.JettyUtil;
 import org.apache.abdera.util.EntityTag;
 import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.writer.WriterOptions;
@@ -400,7 +401,8 @@
     options.setUseExpectContinue(false);
 
     // do the introspection step
-    ClientResponse response = abderaClient.get("http://localhost:8080/service",
+    ClientResponse response = abderaClient.get("http://localhost:" +
+    		JettyUtil.getPort() + "/service",
                                          options);
     String col_uri;
 

Modified: incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
(original)
+++ incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
Wed Dec 12 13:00:00 2007
@@ -26,13 +26,11 @@
 import org.apache.abdera.protocol.client.RequestOptions;
 import org.apache.abdera.protocol.server.CollectionProvider;
 import org.apache.abdera.protocol.server.ServiceContext;
-import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.impl.DefaultServiceContext;
-import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
+import org.apache.abdera.protocol.server.impl.ServiceProvider;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
 import org.apache.abdera.protocol.server.impl.SingletonProviderManager;
-import org.apache.abdera.protocol.server.impl.WorkspaceProvider;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
 import org.apache.abdera.writer.Writer;
 import org.apache.jackrabbit.core.TransientRepository;
@@ -54,19 +52,12 @@
 
     abderaServiceContext = new DefaultServiceContext();
 
-    RegexTargetResolver resolver = new RegexTargetResolver();
-    resolver.setPattern("/acme(\\?[^#]*)?", TargetType.TYPE_SERVICE);
-    resolver.setPattern("/acme/feed(\\?[^#]*)?", TargetType.TYPE_COLLECTION);
-    resolver.setPattern("/acme/feed/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY);
-    abderaServiceContext.setTargetResolver(resolver);
-
     SingletonProviderManager pm = new SingletonProviderManager();
     abderaServiceContext.setProviderManager(pm);
 
-    WorkspaceProvider wp = new WorkspaceProvider();
+    ServiceProvider sp = new ServiceProvider();
 
     SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
-    wi.setId("acme");
 
     repository = new TransientRepository();
     
@@ -79,15 +70,15 @@
     cp.initialize();
 
     Map<String, CollectionProvider> contentProviders = new HashMap<String, CollectionProvider>();
-    contentProviders.put("feed", cp);
+    contentProviders.put("acme/feed", cp);
 
     wi.setCollectionProviders(contentProviders);
 
     List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
     workspaces.add(wi);
-    wp.setWorkspaces(workspaces);
-    pm.setProvider(wp);
-
+    sp.setWorkspaces(workspaces);
+    pm.setProvider(sp);
+    abderaServiceContext.setTargetResolver(sp);
     initializeJetty();
   }
 

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java
Wed Dec 12 13:00:00 2007
@@ -23,12 +23,16 @@
 
 public interface WorkspaceInfo {
 
-  String getId();
-
   String getName();
 
+  /**
+   * A map of CollectionProviders keyed by URI (in relation to the services document) - i.e.
+   * if the services document was at "/services" and the collection at "/services/workspace/feed",
+   * then the key would be "workspace/feed".
+   * @return
+   */
   Map<String, CollectionProvider> getCollectionProviders();
 
-  CollectionProvider getCollectionProvider(String id) throws ResponseContextException;
+  CollectionProvider getCollectionProvider(String href);
 
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
Wed Dec 12 13:00:00 2007
@@ -229,6 +229,8 @@
       return new EmptyResponseContext(415);
     } catch (ClassCastException cce) {
       return new EmptyResponseContext(415);
+    } catch (ResponseContextException e) {
+      return e.getResponseContext();
     } catch (Exception e) {
       log.warn(e.getMessage(), e);
       return new EmptyResponseContext(400);
@@ -505,7 +507,11 @@
   }
 
   protected String getEntryID(RequestContext request) {
-    String path = request.getUri().toString();
+    String path = request.getTargetPath();
+    int q = path.indexOf("?");
+    if (q != -1) {
+      path = path.substring(0, q);
+    }
     String[] segments = path.split("/");
     String id = segments[segments.length - 1];
     return Escaping.decode(id);

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
(from r599148, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java&r1=599148&r2=603739&rev=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
Wed Dec 12 13:00:00 2007
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.Map;
 import java.util.Set;
@@ -30,28 +31,110 @@
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Service;
 import org.apache.abdera.model.Workspace;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
 import org.apache.abdera.protocol.server.CollectionProvider;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.WorkspaceInfo;
-import org.apache.abdera.protocol.util.EncodingUtil;
+import org.apache.abdera.protocol.server.RequestContext.Scope;
 import org.apache.abdera.util.EntityTag;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public abstract class AbstractWorkspaceProvider extends AbstractProvider {
-  private final static Log log = LogFactory.getLog(AbstractWorkspaceProvider.class);
+/**
+ * Represents an Atom service which is backed by various workspaces and CollectionProviders.
+ * This class can be extended to provide a dynamic list of workspaces or ServiceProvider
can
+ * be used to use a static list.
+ * 
+ */
+public abstract class AbstractServiceProvider extends AbstractProvider implements Resolver<Target>
{
+  private static final Log log = LogFactory.getLog(AbstractServiceProvider.class);
+  public static final String COLLECTION_PROVIDER_ATTRIBUTE = "collectionProvider";
   
     private EntityTag service_etag = new EntityTag("simple");
+    private String servicesPath = "/";
     
-    protected AbstractWorkspaceProvider(int count) {
+    protected AbstractServiceProvider(int count) {
       super(count);
     }
 
+    public Target resolve(Request request) {
+      RequestContext context = (RequestContext) request;
+      String uri = context.getTargetPath();
+      
+      if (servicesPath == null) {
+        throw new RuntimeException("You must set the servicesPath property on the ServiceProvider.");
+      }
+      
+      TargetType tt = null;
+      if (uri.equals(servicesPath)) {
+        tt = TargetType.TYPE_SERVICE;
+      } else if (uri.startsWith(servicesPath)) {
+        String path = uri.substring(servicesPath.length());
+        int q = path.indexOf("?");
+        if (q != -1) {
+          path = path.substring(0, q);
+        }
+        
+        path = Escaping.decode(path);
+
+        CollectionProvider provider = null;
+        String providerHref = null;
+        for (WorkspaceInfo wi : getWorkspaces()) {
+          for (Map.Entry<String, CollectionProvider> e : wi.getCollectionProviders().entrySet())
{
+            if (path.startsWith(e.getKey())) {
+              provider = e.getValue();
+              providerHref = e.getKey();
+              break;
+            }
+          }
+        }
+        
+        if (provider != null) {
+          context.setAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE, provider);
+          
+          if (providerHref.equals(path)) {
+            tt = TargetType.TYPE_COLLECTION;
+          } else {
+            tt = getOtherTargetType(context, path, providerHref, provider);
+          }
+        }
+      } 
+      
+      if (tt == null) {
+        tt = TargetType.TYPE_UNKNOWN;
+      }
+      
+      return new DefaultTarget(tt, context);
+    }
+
+    private TargetType getOtherTargetType(RequestContext context, 
+                                          String path, 
+                                          String providerHref, 
+                                          CollectionProvider provider) {
+      String baseMedia = null;
+      if (provider instanceof AbstractCollectionProvider) {
+        baseMedia = ((AbstractCollectionProvider) provider).getBaseMediaIri();
+      }
+      
+      if (providerHref.startsWith("/")) {
+        providerHref = providerHref.substring(1);
+      }
+      
+      if (providerHref.startsWith(baseMedia)) {
+        return TargetType.TYPE_MEDIA;
+      } else {
+        return TargetType.TYPE_ENTRY;
+      }
+    }
+
     public ResponseContext getService(RequestContext request) {
       Abdera abdera = request.getAbdera();
-      Document<Service> service = getServicesDocument(abdera, getEncoding(request));
-      AbstractResponseContext rc = new BaseResponseContext<Document<Service>>(service);
+      AbstractResponseContext rc = getServicesDocument(abdera, getEncoding(request));
       rc.setEntityTag(service_etag);
       return rc;
     }
@@ -59,46 +142,58 @@
     private String getEncoding(RequestContext request) {
       return "utf-8";
     }
-    
-    @SuppressWarnings("unchecked")
-    private Document<Service> getServicesDocument(Abdera abdera, String enc) {    
     
-      if (enc == null) {
-        enc = "utf-8";
-      }
-      
-      Factory factory = abdera.getFactory();
-      Service service = factory.newService();
-      for (WorkspaceInfo wp : getWorkspaces()) {
-        Workspace workspace = service.addWorkspace(wp.getName());
-        Set<Map.Entry<String, CollectionProvider>> entrySet = 
-          (Set<Map.Entry<String, CollectionProvider>>) (wp.getCollectionProviders().entrySet());
-        for (Map.Entry<String, CollectionProvider> entry : entrySet) {
-          CollectionProvider cp = entry.getValue();
-
-          String id;
-          String workspaceKey;
-          try {
-            id = Escaping.encode(wp.getId(), enc, Profile.PATH);
-            workspaceKey = Escaping.encode(entry.getKey(), enc, Profile.PATH);
-          } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-          }
-          Collection collection = workspace.addCollection(cp.getTitle(), 
-                                                          id + "/" + workspaceKey);
-          collection.setAccept("entry");
-          // collection.addCategories().setFixed(false);
+
+    private AbstractResponseContext getServicesDocument(
+      final Abdera abdera, 
+      final String enc) {
+      return new StreamWriterResponseContext(abdera) { 
+        @SuppressWarnings({"serial","unchecked"}) 
+        protected void writeTo(
+          StreamWriter sw) 
+            throws IOException {
+          
+          sw.startDocument()
+            .startService();          
+          
+          for (WorkspaceInfo wp : getWorkspaces()) {
+            sw.startWorkspace().writeTitle(wp.getName());
+            Set<Map.Entry<String, CollectionProvider>> entrySet = 
+              (Set<Map.Entry<String, CollectionProvider>>) (wp.getCollectionProviders().entrySet());
+            
+            for (Map.Entry<String, CollectionProvider> entry : entrySet) {
+              CollectionProvider cp = entry.getValue();
+
+              String href;
+              try {
+                href = Escaping.encode(entry.getKey(), enc, Profile.PATH);
+              } catch (UnsupportedEncodingException e) {
+                throw new RuntimeException(e);
+              }
+
+              try {
+                sw.startCollection(href)
+                  .writeTitle(cp.getTitle())
+                  .writeAcceptsEntry() 
+                  .endCollection();
+              } catch (RuntimeException e) {}
+            }
+            
+            sw.endWorkspace();    
+          }          
+          sw.endService()
+            .endDocument();
+          
         }
-      }
-      return service.getDocument();
+      };
     }
-
+    
     public abstract java.util.Collection<WorkspaceInfo> getWorkspaces();
 
     public ResponseContext getFeed(RequestContext request) {
       CollectionProvider provider = null;
       ResponseContext res = null;
       try {
-        provider = getCollectionProvider(resolveBase(request), request);
+        provider = getCollectionProvider(request);
         
         provider.begin(request);
         
@@ -113,36 +208,8 @@
     }
 
     @SuppressWarnings("unchecked")
-    private CollectionProvider getCollectionProvider(IRI resolveBase, 
-                                                     RequestContext request) throws ResponseContextException
{
-      String path = resolveBase.getPath();
-      String[] paths = path.split("/");
-      String id = null;
-      WorkspaceInfo wp = null;
-      if (paths.length < 1) {
-        // TODO:
-        throw new ResponseContextException(404);
-      } else if (paths.length == 1) {
-        wp = getWorkspaceInfo("");
-        if (wp == null) {
-          // TODO: 404
-          throw new ResponseContextException(404);
-        }
-        id = paths[0];
-      } else {
-        String workspaceId = paths[paths.length - 2];
-        workspaceId = Escaping.decode(workspaceId);
-        wp = getWorkspaceInfo(workspaceId);
-        if (wp == null) {
-          // TODO: 404
-          throw new ResponseContextException(404);
-        }
-        id = paths[paths.length - 1];
-      }
-      
-      id = Escaping.decode(id);
-      
-      return wp.getCollectionProvider(id);
+    private CollectionProvider getCollectionProvider(RequestContext request) {
+      return (CollectionProvider) request.getAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE);
     }
 
     /**
@@ -161,13 +228,12 @@
       
       return e.getResponseContext();
     }
-    protected abstract WorkspaceInfo getWorkspaceInfo(String string);
 
     public ResponseContext createEntry(RequestContext request) {
       CollectionProvider provider = null;
       ResponseContext response = null;
       try {
-        provider = getCollectionProvider(request.getUri(), request);
+        provider = getCollectionProvider(request);
         provider.begin(request);
         
         return provider.createEntry(request);
@@ -194,8 +260,7 @@
       CollectionProvider provider = null;
       ResponseContext response = null;
       try {
-        IRI entryBaseIri = resolveBase(request).resolve("../");
-        provider = getCollectionProvider(entryBaseIri, request);
+        provider = getCollectionProvider(request);
         provider.begin(request);
         
         return provider.getMedia(request);
@@ -218,12 +283,9 @@
       CollectionProvider provider = null;
       ResponseContext response = null;
       try {
-        provider = getCollectionProvider(resolveBase(request).resolve("./"), request);
+        provider = getCollectionProvider(request);
       
         return provider.deleteEntry(request);
-      } catch (ResponseContextException e) {
-        response = createErrorResponse(e);
-        return response;
       } finally {
         end(provider, request, response);
       }
@@ -235,7 +297,7 @@
       ResponseContext response = null;
       try {
         IRI entryBaseIri = resolveBase(request).resolve("./");
-        provider = getCollectionProvider(entryBaseIri, request);
+        provider = getCollectionProvider(request);
         provider.begin(request);
         
         return provider.getEntry(request, entryBaseIri);
@@ -253,7 +315,7 @@
       ResponseContext response = null;
       try {
         IRI entryBaseIri = resolveBase(request).resolve("./");
-        provider = getCollectionProvider(entryBaseIri, request);
+        provider = getCollectionProvider(request);
         provider.begin(request);
         
         return provider.updateEntry(request, entryBaseIri);
@@ -265,5 +327,12 @@
       }
     }
 
+    public String getServicesPath() {
+      return servicesPath;
+    }
+
+    public void setServicesPath(String servicesPath) {
+      this.servicesPath = servicesPath;
+    }
 
 }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
(from r599147, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java&r1=599147&r2=603739&rev=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
Wed Dec 12 13:00:00 2007
@@ -17,23 +17,25 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
+import java.util.Iterator;
+
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.TargetType;
 
-public abstract class AbstractTarget 
+public class DefaultTarget 
   implements Target {
 
   protected final TargetType type;
   protected final RequestContext context;
   
-  protected AbstractTarget(
+  public DefaultTarget(
     TargetType type, 
     RequestContext context) {
       this.type = type;
       this.context = context;
   }
-  
+
   public String getIdentity() {
     return context.getUri().toString();
   }
@@ -47,6 +49,10 @@
     return (pn != null) ? pn : new String[0];
   }
 
+  public Iterator<String> iterator() {
+    return java.util.Arrays.asList(getParameterNames()).iterator();
+  }
+
   public TargetType getType() {
     return type;
   }
@@ -76,7 +82,7 @@
       return false;
     if (getClass() != obj.getClass())
       return false;
-    final AbstractTarget other = (AbstractTarget) obj;
+    final DefaultTarget other = (DefaultTarget) obj;
     if (context == null) {
       if (other.context != null)
         return false;

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
Wed Dec 12 13:00:00 2007
@@ -97,7 +97,7 @@
   }
   
   public static class RegexTarget
-    extends AbstractTarget
+    extends DefaultTarget
     implements Target {
     
     private static final long serialVersionUID = 165211244926064449L;

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ServiceProvider.java
(from r599147, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceProvider.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ServiceProvider.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ServiceProvider.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceProvider.java&r1=599147&r2=603739&rev=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ServiceProvider.java
Wed Dec 12 13:00:00 2007
@@ -21,21 +21,17 @@
 
 import org.apache.abdera.protocol.server.WorkspaceInfo;
 
-public class WorkspaceProvider extends AbstractWorkspaceProvider {
+/**
+ *  Represents an Atom service which is backed by a static list of WorkspaceInfos.
+ *  
+ *  @see AbstractServiceProvider
+ */
+public class ServiceProvider extends AbstractServiceProvider {
 
   private Collection<WorkspaceInfo> workspaces;
   
-  public WorkspaceProvider() {
+  public ServiceProvider() {
     super(10);
-  }
-  
-  public WorkspaceInfo getWorkspaceInfo(String id) {
-    for (WorkspaceInfo wp : workspaces) {
-      if (wp.getId().equals(id)) {
-        return wp;
-      }
-    }
-    return null;
   }
 
   public Collection<WorkspaceInfo> getWorkspaces() {

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java?rev=603739&r1=603738&r2=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java
Wed Dec 12 13:00:00 2007
@@ -26,18 +26,7 @@
 public class SimpleWorkspaceInfo implements WorkspaceInfo {
     private Map<String, CollectionProvider> collectionProviders;
     private String name;
-    private String id;
-    
-    /* (non-Javadoc)
-     * @see org.apache.abdera.protocol.server.content.WorkspaceInfo#getId()
-     */
-    public String getId() {
-        return id;
-    }
 
-    public void setId(String id) {
-        this.id = id;
-    }
     public String getName() {
         return name;
     }

Copied: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
(from r599147, incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/ContentProviderTest.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java?p2=incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java&p1=incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/ContentProviderTest.java&r1=599147&r2=603739&rev=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/ContentProviderTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
Wed Dec 12 13:00:00 2007
@@ -27,7 +27,7 @@
 import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
 import org.apache.abdera.protocol.server.impl.SingletonProviderManager;
-import org.apache.abdera.protocol.server.impl.WorkspaceProvider;
+import org.apache.abdera.protocol.server.impl.ServiceProvider;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterFactory;
@@ -35,7 +35,7 @@
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
 
-public class ContentProviderTest extends TestCase {
+public class CollectionProviderTest extends TestCase {
 
   private Server server;
   private DefaultServiceContext abderaServiceContext;
@@ -46,30 +46,26 @@
     
     abderaServiceContext = new DefaultServiceContext();
 
-    RegexTargetResolver resolver = new RegexTargetResolver();
-    resolver.setPattern("/acme(\\?[^#]*)?", TargetType.TYPE_SERVICE);
-    resolver.setPattern("/acme/customers(\\?[^#]*)?", TargetType.TYPE_COLLECTION);
-    resolver.setPattern("/acme/customers/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY);
-    abderaServiceContext.setTargetResolver(resolver);
     
     SingletonProviderManager pm = new SingletonProviderManager();
     abderaServiceContext.setProviderManager(pm);
 
-    WorkspaceProvider wp = new WorkspaceProvider();
-
+    ServiceProvider sp = new ServiceProvider();
+    
     SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
-    wi.setId("acme");
-    CustomerContentProvider cp = new CustomerContentProvider();
+    CustomerCollectionProvider cp = new CustomerCollectionProvider();
     Map<String, CollectionProvider> contentProviders = new HashMap<String, CollectionProvider>();
-    contentProviders.put("customers", cp);
+    contentProviders.put("acme/customers", cp);
     
     wi.setCollectionProviders(contentProviders);
 
     List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
     workspaces.add(wi);
-    wp.setWorkspaces(workspaces);
-    pm.setProvider(wp);
-
+    sp.setWorkspaces(workspaces);
+    
+    pm.setProvider(sp);
+    abderaServiceContext.setTargetResolver(sp);
+    
     initializeJetty();
   }
 

Copied: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java
(from r599147, incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java?p2=incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java&p1=incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java&r1=599147&r2=603739&rev=603739&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java
Wed Dec 12 13:00:00 2007
@@ -18,7 +18,7 @@
 import org.apache.abdera.protocol.server.impl.AbstractCollectionProvider;
 import org.apache.abdera.protocol.server.impl.ResponseContextException;
 
-public class CustomerContentProvider extends AbstractCollectionProvider<Customer> {
+public class CustomerCollectionProvider extends AbstractCollectionProvider<Customer>
{
   private static final String ID_PREFIX = "urn:acme:customer:";
   
   private final static AtomicInteger nextId = new AtomicInteger(1000);



Mime
View raw message