abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r614618 [1/2] - in /incubator/abdera/java/branches/server_refactor/src: main/java/org/apache/abdera/protocol/server/ main/java/org/apache/abdera/protocol/server/context/ main/java/org/apache/abdera/protocol/server/impl/ main/java/org/apache...
Date Wed, 23 Jan 2008 18:49:32 GMT
Author: dandiep
Date: Wed Jan 23 10:49:24 2008
New Revision: 614618

URL: http://svn.apache.org/viewvc?rev=614618&view=rev
Log:
I'll follow up with an email on outstanding issues, but:

- As all things, this is a work in progress. But its a significant step forward as it reenables a bunch of missing functionality. The only piece that I've not reenabled is the BasicAdapter stuff at the moment. I figure its better to commit though in the meantime.
- Simplify the steps needed to build Providers even more. DefaultProvider now comes configured for the default use case out of the box. "Convention over configuration". It uses the StructuredResolver/DefaultWorkspaceManager by default, but this can be overridden quite easily.
- Simplify the class hierarchy by making CollectionInfo not extend CollectionAdapter as you may just want to describe a collection sometimes and not load the whole thing.
- Simplify the WorkspaceManager/WorkspaceInfo classes. The Provider doesn't need to know about what methods are supported. The CollectionAdapter can just return the appropriate response if it isn't supported. See AbstractCollectionAdapter.extensionRequest or postMedia for example.
- Move some interfaces from impl to top level server package
- Support Transactional semantics needed for JCR adapter
- Readd ResponseContextException
- Readd AbstractCollectionAdapter
- Readd AbstractEntityCollectionAdapter
- Readd CustomerAdapterTest
- Use Junit4 annotations for the SimpleTest

Added:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoriesInfo.java
      - copied, changed from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoryInfo.java
      - copied, changed from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionInfo.java
      - copied, changed from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java
      - copied, changed from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java
      - copied, changed from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspace.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/CustomerAdapter.java   (with props)
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/CustomerAdapterTest.java   (with props)
Removed:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspace.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceInfo.java
Modified:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicWorkspace.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/JettyServer.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestProvider.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleAdapter.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java

Copied: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoriesInfo.java (from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoriesInfo.java?p2=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoriesInfo.java&p1=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java&r1=614365&r2=614618&rev=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoriesInfo.java Wed Jan 23 10:49:24 2008
@@ -15,11 +15,10 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.impl;
+package org.apache.abdera.protocol.server;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Categories;
-import org.apache.abdera.protocol.server.RequestContext;
 
 public interface CategoriesInfo 
   extends Iterable<CategoryInfo> {

Copied: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoryInfo.java (from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoryInfo.java?p2=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoryInfo.java&p1=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java&r1=614365&r2=614618&rev=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CategoryInfo.java Wed Jan 23 10:49:24 2008
@@ -15,11 +15,10 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.impl;
+package org.apache.abdera.protocol.server;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Category;
-import org.apache.abdera.protocol.server.RequestContext;
 
 public interface CategoryInfo {
 

Copied: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionInfo.java (from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionInfo.java?p2=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionInfo.java&p1=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java&r1=614365&r2=614618&rev=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionInfo.java Wed Jan 23 10:49:24 2008
@@ -15,10 +15,8 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.impl;
+package org.apache.abdera.protocol.server;
 
-import org.apache.abdera.protocol.server.CollectionAdapter;
-import org.apache.abdera.protocol.server.RequestContext;
 
 public interface CollectionInfo {
 
@@ -28,9 +26,6 @@
   
   String[] getAccepts(RequestContext request);
   
-  boolean isAdapterFor(RequestContext request);
-  
   CategoriesInfo[] getCategoriesInfo(RequestContext request);
-  
-  CollectionAdapter getCollectionAdapter(RequestContext request);
+
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java Wed Jan 23 10:49:24 2008
@@ -27,5 +27,5 @@
   ResponseContext getMedia(RequestContext request);
   
   ResponseContext putMedia(RequestContext request);
-    
+
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java Wed Jan 23 10:49:24 2008
@@ -115,7 +115,7 @@
     RequestContext request,
     String reason,
     Throwable t) {
-      log.debug(Localizer.get("SERVER_ERROR"));
+      log.info(Localizer.get("SERVER_ERROR"), t);
       return createErrorResponse(request.getAbdera(),500,reason,t);
   }
 

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java Wed Jan 23 10:49:24 2008
@@ -17,11 +17,13 @@
 */
 package org.apache.abdera.protocol.server;
 
+import org.apache.abdera.protocol.server.context.ResponseContextException;
+
 public interface Transactional {
 
-  void start(RequestContext request);
+  void start(RequestContext request) throws ResponseContextException;
   
-  void end(RequestContext request);
+  void end(RequestContext request, ResponseContext response);
   
   void compensate(RequestContext request, Throwable t);
   

Copied: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java (from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceInfo.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java?p2=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java&p1=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceInfo.java&r1=614365&r2=614618&rev=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/WorkspaceInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceInfo.java Wed Jan 23 10:49:24 2008
@@ -15,17 +15,14 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.impl;
+package org.apache.abdera.protocol.server;
 
-import org.apache.abdera.protocol.server.RequestContext;
-import org.apache.abdera.protocol.server.WorkspaceManager;
+import java.util.Collection;
 
-public interface WorkspaceInfo 
-  extends WorkspaceManager {
+public interface WorkspaceInfo {
 
-  String getTitle(RequestContext request);
+  String getTitle(RequestContext requsest);
   
-  CollectionInfo[] getCollections(RequestContext request);
+  Collection<CollectionInfo> getCollections(RequestContext request);
   
-  boolean isWorkspaceFor(RequestContext request);
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java Wed Jan 23 10:49:24 2008
@@ -17,14 +17,13 @@
 */
 package org.apache.abdera.protocol.server;
 
+import java.util.Collection;
+
+
 public interface WorkspaceManager {
     
   CollectionAdapter getCollectionAdapter(RequestContext request);
   
-  boolean checkTarget(RequestContext request);
-  
-  boolean checkMethod(RequestContext request);
-  
-  String[] getMethods(RequestContext request);
+  Collection<WorkspaceInfo> getWorkspaces(RequestContext request);
   
 }

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,56 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.context;
+
+
+public class ResponseContextException extends Exception {
+  private AbstractResponseContext responseContext;
+
+  public ResponseContextException(AbstractResponseContext responseContext, Throwable t) {
+    super(t);
+    this.responseContext = responseContext;
+  }
+
+  public ResponseContextException(AbstractResponseContext responseContext) {
+    super();
+    this.responseContext = responseContext;
+  }
+
+  public ResponseContextException(int responseCode) {
+    this(new EmptyResponseContext(responseCode));
+  }
+
+  public ResponseContextException(int responseCode, Throwable t) {
+    this(new EmptyResponseContext(responseCode), t);
+  }
+
+  public ResponseContextException(String msg, int responseCode) {
+    this.responseContext = new EmptyResponseContext(responseCode);
+    this.responseContext.setStatusText(msg);
+  }
+
+  public AbstractResponseContext getResponseContext() {
+    return responseContext;
+  }
+
+  @Override
+  public String getMessage() {
+    return responseContext.getStatusText();
+  }
+  
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,185 @@
+package org.apache.abdera.protocol.server.impl;
+
+import static org.apache.abdera.protocol.server.ProviderHelper.calculateEntityTag;
+
+import java.io.IOException;
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.text.UrlEncoding;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.ParseException;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.server.CategoriesInfo;
+import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
+import org.apache.abdera.protocol.server.MediaCollectionAdapter;
+import org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.Transactional;
+import org.apache.abdera.protocol.server.context.AbstractResponseContext;
+import org.apache.abdera.protocol.server.context.BaseResponseContext;
+import org.apache.abdera.protocol.server.context.EmptyResponseContext;
+import org.apache.abdera.protocol.server.context.ResponseContextException;
+import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class AbstractCollectionAdapter implements CollectionAdapter, MediaCollectionAdapter,
+  Transactional, CollectionInfo {
+
+  private final static Log log = LogFactory.getLog(AbstractEntityCollectionAdapter.class);
+
+  public void compensate(RequestContext request, Throwable t) {
+  }
+
+  public void end(RequestContext request, ResponseContext response) {
+  }
+
+  public void start(RequestContext request) throws ResponseContextException {
+  }
+
+  public boolean isCollectionFor(RequestContext request) {
+    String href = getHref(request);
+    IRI base = ProviderHelper.resolveBase(request);
+    
+    if (base.getPath().equals(href)) { 
+      return true;
+    }
+    
+    return false;
+  }
+
+  public String[] getAccepts(RequestContext request) {
+    return new String[] { "application/atom+xml;type=entry" };
+  }
+
+  public CategoriesInfo[] getCategoriesInfo(RequestContext request) {
+    return null;
+  }
+
+  public ResponseContext deleteMedia(RequestContext request) {
+    return ProviderHelper.notallowed(request);
+  }
+
+  public ResponseContext getMedia(RequestContext request) {
+    return ProviderHelper.notallowed(request);
+  }
+
+  public ResponseContext putMedia(RequestContext request) {
+    return ProviderHelper.notallowed(request);
+  }
+
+  public ResponseContext postMedia(RequestContext request) {
+    return ProviderHelper.notallowed(request);
+  }
+
+  public abstract String getAuthor() throws ResponseContextException;
+
+  public abstract String getId(RequestContext request);
+  
+  protected ResponseContext buildCreateEntryResponse(IRI entryIri, Entry entry) {
+    BaseResponseContext<Entry> rc = new BaseResponseContext<Entry>(entry);
+    rc.setLocation(entryIri.resolve(entry.getEditLinkResolvedHref()).toString());
+    rc.setContentLocation(rc.getLocation().toString());
+    rc.setEntityTag(calculateEntityTag(entry));
+    rc.setStatus(201);
+    return rc;
+  }
+
+  protected ResponseContext buildCreateMediaEntryResponse(IRI entryIri, Entry entry) {
+    return buildCreateEntryResponse(entryIri, entry);
+  }
+
+  protected ResponseContext buildGetEntryResponse(RequestContext request, Entry entry) throws ResponseContextException {
+    Feed feed = createFeedBase(request);
+    entry.setSource(feed.getAsSource());
+    Document<Entry> entry_doc = entry.getDocument();
+    AbstractResponseContext rc = new BaseResponseContext<Document<Entry>>(entry_doc);
+    rc.setEntityTag(calculateEntityTag(entry));
+    return rc;
+  }
+
+  protected ResponseContext buildGetFeedResponse(Feed feed) {
+    Document<Feed> document = feed.getDocument();
+    AbstractResponseContext rc = new BaseResponseContext<Document<Feed>>(document);
+    rc.setEntityTag(calculateEntityTag(document.getRoot()));
+    return rc;
+  }
+
+  /**
+   * Create a ResponseContext (or take it from the Exception) for an exception
+   * that occurred in the application.
+   * 
+   * @param e
+   * @return
+   */
+  protected ResponseContext createErrorResponse(ResponseContextException e) {
+    if (log.isInfoEnabled()) {
+      log.info("A ResponseException was thrown.", e);
+    } else if (e.getResponseContext() instanceof EmptyResponseContext
+               && ((EmptyResponseContext)e.getResponseContext()).getStatus() >= 500) {
+      log.warn("A ResponseException was thrown.", e);
+    }
+
+    return e.getResponseContext();
+  }
+
+  protected Feed createFeedBase(RequestContext request) throws ResponseContextException {
+    Factory factory = request.getAbdera().getFactory();
+    Feed feed = factory.newFeed();
+    feed.setId(getId(request));
+    feed.setTitle(getTitle(request));
+    feed.addLink("");
+    feed.addLink("", "self");
+    feed.addAuthor(getAuthor());
+    feed.setUpdated(new Date());
+    return feed;
+  }
+  
+  @SuppressWarnings("unchecked")
+  protected Entry getEntryFromRequest(RequestContext request) throws ResponseContextException {
+    Abdera abdera = request.getAbdera();
+    Parser parser = abdera.getParser();
+
+    Document<Entry> entry_doc;
+    try {
+      entry_doc = (Document<Entry>)request.getDocument(parser).clone();
+    } catch (ParseException e) {
+      throw new ResponseContextException(500, e);
+    } catch (IOException e) {
+      throw new ResponseContextException(500, e);
+    }
+    if (entry_doc == null) {
+      return null;
+    }
+    return entry_doc.getRoot();
+  }
+
+  protected String getEntryID(RequestContext request) {
+    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 UrlEncoding.decode(id);
+  }
+
+  public ResponseContext extensionRequest(RequestContext request) {
+    return ProviderHelper.notallowed(request, getMethods(request));
+  }
+
+  private String[] getMethods(RequestContext request) {
+    return ProviderHelper.getDefaultMethods(request);
+  }
+
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,455 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Person;
+import org.apache.abdera.model.Text;
+import org.apache.abdera.parser.ParseException;
+import org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.context.EmptyResponseContext;
+import org.apache.abdera.protocol.server.context.MediaResponseContext;
+import org.apache.abdera.protocol.server.context.ResponseContextException;
+import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * By extending this class it becomes easy to build Collections which are
+ * backed by a set of entities - such as a database row, domain objects, or
+ * files.
+ * @param <T> The entity that this is backed by.
+ */
+public abstract class AbstractEntityCollectionAdapter<T> 
+  extends AbstractCollectionAdapter {
+  private final static Log log = LogFactory.getLog(AbstractEntityCollectionAdapter.class);
+  private String href;
+  
+  public String getHref() {
+    return href;
+  }
+
+  public void setHref(String href) {
+    this.href = href;
+  }
+
+  public String getHref(RequestContext request) {
+    return getHref();
+  }
+
+  public abstract T postEntry(String title, IRI id, String summary, Date updated, List<Person> authors, Content content, RequestContext request) throws ResponseContextException;
+  
+  @Override
+  public ResponseContext postMedia(RequestContext request) {
+    try {
+      T doc = postMediaEntry(request.getContentType(), request.getSlug(), 
+                             request.getInputStream(), request);
+
+      IRI baseIri = ProviderHelper.resolveBase(request);
+      IRI entryIri = getEntryBaseFromFeedIRI(baseIri);
+
+      Entry entry = request.getAbdera().getFactory().newEntry();
+
+      addEntryDetails(request, entry, entryIri, doc);
+
+      addMediaContent(entryIri, entry, doc);
+
+      return buildCreateMediaEntryResponse(entryIri, entry);
+    } catch (IOException e) {
+      return new EmptyResponseContext(500);
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    }
+  }
+
+  public ResponseContext postEntry(RequestContext request) {
+    try {
+      Entry entry = getEntryFromRequest(request);
+      if (entry != null) {
+        if (!ProviderHelper.isValidEntry(entry))
+          return new EmptyResponseContext(400);
+  
+        entry.setUpdated(new Date());
+        
+        
+          T entryObj = postEntry(entry.getTitle(),
+                                 entry.getId(),
+                                 entry.getSummary(),
+                                 entry.getUpdated(),
+                                 entry.getAuthors(),
+                                 entry.getContentElement(), request);
+          entry.getIdElement().setValue(getId(entryObj));
+        
+          IRI entryBaseUri = getEntryBaseFromFeedIRI(ProviderHelper.resolveBase(request));
+          
+          IRI entryIri = entryBaseUri.resolve(getName(entryObj));
+          entry.addLink(entryIri.toString(), "edit");
+    
+          return buildCreateEntryResponse(entryIri, entry);
+      } else {
+        return new EmptyResponseContext(400);
+      }
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    }
+  }
+
+  public T postMediaEntry(MimeType mimeType, String slug, InputStream inputStream, RequestContext request) throws ResponseContextException {
+    throw new UnsupportedOperationException();
+  }
+
+  public ResponseContext deleteEntry(RequestContext request) {
+    String id = getEntryID(request);
+    if (id != null) {
+  
+      try {
+        deleteEntry(id, request);
+      } catch (ResponseContextException e) {
+        return createErrorResponse(e);
+      }
+      
+      return new EmptyResponseContext(204);
+    } else {
+      // TODO: is this right?
+      return new EmptyResponseContext(404);
+    }
+  }
+
+  public abstract void deleteEntry(String resourceName, RequestContext request) throws ResponseContextException;
+
+  public List<Person> getAuthors(T entry, RequestContext request) throws ResponseContextException {
+    return null;
+  }
+  
+  public abstract Object getContent(T entry, RequestContext request) throws ResponseContextException;
+  
+  // GET, POST, PUT, DELETE
+  
+  public String getContentType(T entry) {
+    throw new UnsupportedOperationException();
+  }
+  
+  public abstract Iterable<T> getEntries(RequestContext request) throws ResponseContextException;
+
+  public ResponseContext getEntry(RequestContext request) {
+    try {
+      Entry entry = getEntryFromCollectionProvider(getFeedIRI(request),
+                                                   request);
+      if (entry != null) {
+        return buildGetEntryResponse(request, entry);
+      } else {
+        return new EmptyResponseContext(404);
+      }
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    }
+  }
+
+  private IRI getFeedIRI(RequestContext request) {
+    return ProviderHelper.resolveBase(request).resolve("../..");
+  }
+
+  public abstract T getEntry(String resourceName, RequestContext request) throws ResponseContextException;
+
+  public ResponseContext getFeed(RequestContext request) {
+    try {
+      Feed feed = createFeedBase(request);
+    
+      addFeedDetails(feed, request);
+      
+      return buildGetFeedResponse(feed);
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    }
+  }
+
+  protected void addFeedDetails(Feed feed, RequestContext request) throws ResponseContextException {
+    feed.setUpdated(new Date());
+
+    IRI baseIri = ProviderHelper.resolveBase(request);
+    IRI entryIri = getEntryBaseFromFeedIRI(baseIri);
+    
+    Iterable<T> entries = getEntries(request);
+    if (entries != null) {
+      for (T entryObj : entries) {
+        Entry e = feed.addEntry();
+  
+        addEntryDetails(request, e, entryIri, entryObj);
+
+        if (isMediaEntry(entryObj)) {
+          addMediaContent(entryIri, e, entryObj);
+        } else {
+          addContent(e, entryObj, request);
+        }
+      }
+    }
+  }
+  /**
+   * Gets the UUID for the specified entry.
+   * @param entry
+   * @return
+   */
+  public abstract String getId(T entry) throws ResponseContextException;
+
+  public ResponseContext getMedia(RequestContext request) {
+    try {
+      String id = getEntryID(request);
+      T entryObj = getEntry(id, request);
+
+      if (entryObj == null) {
+        return new EmptyResponseContext(404);
+      }
+
+      return buildGetMediaResponse(entryObj);
+    } catch (ParseException pe) {
+      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);
+    }
+  }
+
+  protected ResponseContext buildGetMediaResponse(T entryObj) throws ResponseContextException {
+    MediaResponseContext ctx = new MediaResponseContext(getMediaStream(entryObj), 
+                                                        getUpdated(entryObj), 
+                                                        200);
+    ctx.setContentType(getContentType(entryObj));
+
+    return ctx;
+  }
+  public String getMediaName(T entry) throws ResponseContextException {
+    throw new UnsupportedOperationException();
+  }
+
+  public InputStream getMediaStream(T entry) throws ResponseContextException {
+    throw new UnsupportedOperationException();
+  }
+  
+  public abstract String getName(T entry) throws ResponseContextException;
+
+  public abstract String getTitle(T entry) throws ResponseContextException;
+
+  public abstract Date getUpdated(T entry) throws ResponseContextException;
+
+  public boolean isMediaEntry(T entry) throws ResponseContextException {
+    return false;
+  }
+  
+  public ResponseContext putEntry(RequestContext request) {
+    try {
+      String id = getEntryID(request);
+      T entryObj = getEntry(id, request);
+      
+      if (entryObj == null) {
+        return new EmptyResponseContext(404);
+      }
+      
+      Entry orig_entry = getEntryFromCollectionProvider(entryObj, getFeedIRI(request), request);
+      if (orig_entry != null) {
+
+        MimeType contentType = request.getContentType();
+        if (contentType != null && !MimeTypeHelper.isAtom(contentType.toString()))
+          return new EmptyResponseContext(415);
+
+        Entry entry = getEntryFromRequest(request);
+        if (entry != null) {
+          if (!entry.getId().equals(orig_entry.getId()))
+            return new EmptyResponseContext(409);
+
+          if (!ProviderHelper.isValidEntry(entry))
+            return new EmptyResponseContext(400);
+
+          putEntry(entryObj, entry.getTitle(), new Date(), entry.getAuthors(), 
+                      entry.getSummary(), entry.getContentElement(), request);
+          return new EmptyResponseContext(204);
+        } else {
+          return new EmptyResponseContext(400);
+        }
+      } else {
+        return new EmptyResponseContext(404);
+      }
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    } catch (ParseException pe) {
+      return new EmptyResponseContext(415);
+    } catch (ClassCastException cce) {
+      return new EmptyResponseContext(415);
+    } catch (Exception e) {
+      log.warn(e.getMessage(), e);
+      return new EmptyResponseContext(400);
+    }
+    
+  }
+
+  public abstract void putEntry(T entry, String title, Date updated, 
+                                List<Person> authors, String summary, 
+                                Content content, RequestContext request) throws ResponseContextException;
+
+  protected void addContent(Entry e, T doc, RequestContext request) throws ResponseContextException {
+    Object content = getContent(doc, request);
+
+    if (content instanceof Content) {
+      e.setContentElement((Content)content);
+    } else if (content instanceof String) {
+      e.setContent((String)content);
+    }
+  }
+
+  protected void addEntryDetails(RequestContext request, Entry e, 
+                               IRI entryBaseIri, T entryObj) throws ResponseContextException {
+    IRI entryIri = entryBaseIri.resolve(getName(entryObj));
+    e.addLink(entryIri.toString(), "edit");
+    e.setId(getId(entryObj));
+    e.setTitle(getTitle(entryObj));
+    e.setUpdated(getUpdated(entryObj));
+    
+    List<Person> authors = getAuthors(entryObj, request);
+    if (authors != null) {
+      for (Person a : authors) {
+        e.addAuthor(a);
+      }
+    }
+    
+    Text t = getSummary(entryObj, request);
+    if (t != null) {
+      e.setSummaryElement(t);
+    }
+  }
+
+  public Text getSummary(T entry, RequestContext request) throws ResponseContextException {
+    return null;
+  }
+
+  protected void addMediaContent(IRI entryBaseIri, Entry entry, T doc) throws ResponseContextException {
+    String name = getMediaName(doc);
+    IRI mediaIri = entryBaseIri.resolve(name);
+
+    entry.setContent(mediaIri, getContentType(doc));
+    entry.addLink(mediaIri.toString(), "edit-media");
+  }
+
+  protected ResponseContext createMediaEntry(RequestContext request) {
+    try {
+      T doc = postMediaEntry(request.getContentType(), request.getSlug(), 
+                               request.getInputStream(), request);
+
+      IRI baseIri = ProviderHelper.resolveBase(request);
+      IRI entryIri = getEntryBaseFromFeedIRI(baseIri);
+
+      Entry entry = request.getAbdera().getFactory().newEntry();
+
+      addEntryDetails(request, entry, entryIri, doc);
+
+      addMediaContent(entryIri, entry, doc);
+
+      return buildCreateMediaEntryResponse(entryIri, entry);
+    } catch (IOException e) {
+      return new EmptyResponseContext(500);
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    }
+  }
+
+  protected ResponseContext createNonMediaEntry(RequestContext request) throws IOException {
+    try {
+      Entry entry = getEntryFromRequest(request);
+      if (entry != null) {
+        if (!ProviderHelper.isValidEntry(entry))
+          return new EmptyResponseContext(400);
+
+        entry.setUpdated(new Date());
+
+        T entryObj = postEntry(entry.getTitle(), 
+                               entry.getId(), 
+                               entry.getSummary(), 
+                               entry.getUpdated(), 
+                               entry.getAuthors(), 
+                               entry.getContentElement(), 
+                               request);
+        
+        entry.getIdElement().setValue(getId(entryObj));
+
+        IRI entryBaseUri = getEntryBaseFromFeedIRI(ProviderHelper.resolveBase(request));
+
+        IRI entryIri = entryBaseUri.resolve(getName(entryObj));
+        entry.addLink(entryIri.toString(), "edit");
+
+        return buildCreateEntryResponse(entryIri, entry);
+      } else {
+        return new EmptyResponseContext(400);
+      }
+    } catch (ResponseContextException e) {
+      return createErrorResponse(e);
+    }
+  }
+
+  protected IRI getEntryBaseFromFeedIRI(IRI baseIri) {
+    return new IRI(baseIri.toString() + "/");
+  }
+
+  protected Entry getEntryFromCollectionProvider(IRI feedIri, RequestContext request) throws ResponseContextException {
+    String id = getEntryID(request);
+    T entryObj = getEntry(id, request);
+
+    if (entryObj == null) {
+      return null;
+    }
+
+    return getEntryFromCollectionProvider(entryObj, feedIri, request);
+  }
+
+  Entry getEntryFromCollectionProvider(T entryObj, IRI feedIri, RequestContext request)
+    throws ResponseContextException {
+    Abdera abdera = request.getAbdera();
+    Factory factory = abdera.getFactory();
+    Entry entry = factory.newEntry();
+
+    return buildEntry(entryObj, entry, feedIri, request);
+  }
+
+  private Entry buildEntry(T entryObj, Entry entry, IRI feedIri, RequestContext request)
+    throws ResponseContextException {
+    addEntryDetails(request, entry, feedIri, entryObj);
+
+    if (isMediaEntry(entryObj)) {
+      addMediaContent(feedIri, entry, entryObj);
+    } else {
+      addContent(entry, entryObj, request);
+    }
+
+    return entry;
+  }
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java Wed Jan 23 10:49:24 2008
@@ -17,13 +17,17 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
+import java.io.IOException;
 import java.util.Map;
 
 import javax.security.auth.Subject;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.CategoriesInfo;
+import org.apache.abdera.protocol.server.CategoryInfo;
 import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
 import org.apache.abdera.protocol.server.MediaCollectionAdapter;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.ProviderHelper;
@@ -32,7 +36,11 @@
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.Transactional;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.WorkspaceManager;
+import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
+import org.apache.abdera.util.Constants;
+import org.apache.abdera.writer.StreamWriter;
 
 public abstract class AbstractProvider 
   implements Provider {
@@ -88,30 +96,28 @@
           return getServiceDocument(request);
       }
       WorkspaceManager wm = getWorkspaceManager(request);
-      if (!wm.checkTarget(request)) {
+      
+      CollectionAdapter adapter = 
+        wm.getCollectionAdapter(request);
+      if (adapter == null) {
         return ProviderHelper.notfound(
           request);
       }
-      if (!wm.checkMethod(request)) {
-        return ProviderHelper.notallowed(
-          request,  
-          wm.getMethods(request));
-      }      
-      CollectionAdapter adapter = 
-        wm.getCollectionAdapter(request);
+      
       Transactional transaction = 
         adapter instanceof Transactional ? 
           (Transactional)adapter : null;
+      ResponseContext response = null;
       try {
         if (transaction != null) transaction.start(request);
         if (type == TargetType.TYPE_CATEGORIES) {
           if (method.equalsIgnoreCase("GET"))
-            return adapter.getCategories(request);
+            response = adapter.getCategories(request);
         } else if (type == TargetType.TYPE_COLLECTION) {
           if (method.equalsIgnoreCase("GET")) 
-            return adapter.getFeed(request);
+            response = adapter.getFeed(request);
           else if (method.equalsIgnoreCase("POST")) {
-            return ProviderHelper.isAtom(request) ?
+            response = ProviderHelper.isAtom(request) ?
               adapter.postEntry(request) :
               adapter instanceof MediaCollectionAdapter ?
                 ((MediaCollectionAdapter)adapter).postMedia(request) :
@@ -119,42 +125,91 @@
           }
         } else if (type == TargetType.TYPE_ENTRY) {
           if (method.equalsIgnoreCase("GET")) 
-            return adapter.getEntry(request);
+            response = adapter.getEntry(request);
           else if (method.equalsIgnoreCase("PUT")) 
-            return adapter.putEntry(request);
+            response = adapter.putEntry(request);
           else if (method.equalsIgnoreCase("DELETE")) 
-            return adapter.deleteEntry(request);
+            response = adapter.deleteEntry(request);
         } else if (type == TargetType.TYPE_MEDIA) {
           if (adapter instanceof MediaCollectionAdapter) {
             MediaCollectionAdapter mcadapter = 
               (MediaCollectionAdapter) adapter;
             if (method.equalsIgnoreCase("GET")) 
-              return mcadapter.getMedia(request);
+              response = mcadapter.getMedia(request);
             else if (method.equalsIgnoreCase("PUT")) 
-              return mcadapter.putMedia(request);
+              response = mcadapter.putMedia(request);
             else if (method.equalsIgnoreCase("DELETE")) 
-              return mcadapter.deleteMedia(request);        
+              response = mcadapter.deleteMedia(request);        
           } else {
-            return ProviderHelper.notsupported(request);
+            response = ProviderHelper.notsupported(request);
           }
+        } else {
+          response = adapter.extensionRequest(request);
         }
-        return adapter.extensionRequest(request);
+        return response;
       } catch (Throwable e) {
         if (transaction != null) 
           transaction.compensate(request,e);
         return ProviderHelper.servererror(request, e);
       } finally {
         if (transaction != null) 
-          transaction.end(request);
+          transaction.end(request, response);
       }
   }
    
   protected abstract WorkspaceManager getWorkspaceManager(
     RequestContext request);
   
+
   protected ResponseContext getServiceDocument(
-    RequestContext request) {
-      return ProviderHelper.notfound(request);
+    final RequestContext request) {
+      return 
+        new StreamWriterResponseContext(request.getAbdera()) {
+          protected void writeTo(
+            StreamWriter sw) 
+              throws IOException {
+            sw.startDocument()
+              .startService();
+            for (WorkspaceInfo wi : getWorkspaceManager(request).getWorkspaces(request)) {
+              sw.startWorkspace()
+                .writeTitle(wi.getTitle(request));
+              for (CollectionInfo ci : wi.getCollections(request)) {
+                sw.startCollection(ci.getHref(request))
+                  .writeTitle(ci.getTitle(request))
+                  .writeAccepts(ci.getAccepts(request));
+                CategoriesInfo[] catinfos = ci.getCategoriesInfo(request);
+                if (catinfos != null) {
+                  for (CategoriesInfo catinfo : catinfos) {
+                    String href = catinfo.getHref(request);
+                    if (href != null) {
+                      sw.startCategories()
+                        .writeAttribute("href", href)
+                        .endCategories();
+                    } else {
+                      sw.startCategories(
+                        catinfo.isFixed(request), 
+                        catinfo.getScheme(request));
+                      for (CategoryInfo cat : catinfo) {
+                        sw.writeCategory(
+                          cat.getTerm(request), 
+                          cat.getScheme(request), 
+                          cat.getLabel(request));
+                      }
+                      sw.endCategories();
+                    }
+                  }
+                }
+                sw.endCollection();
+              }
+              sw.endWorkspace();
+            }
+            sw.endService()
+              .endDocument();
+          }
+        }
+        .setStatus(200)
+        .setContentType(Constants.APP_MEDIA_TYPE);
   }
+
   
 }

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.protocol.server.impl;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+import org.apache.abdera.protocol.server.WorkspaceManager;
+
+public abstract class AbstractWorkspaceManager implements WorkspaceManager {
+  protected Collection<WorkspaceInfo> workspaces;
+
+  public Collection<WorkspaceInfo> getWorkspaces(RequestContext request) {
+    return workspaces;
+  }
+
+  public void addWorkspace(WorkspaceInfo workspace) {
+    if (workspaces == null) {
+      workspaces = new HashSet<WorkspaceInfo>();
+    }
+    workspaces.add(workspace);
+  }
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java Wed Jan 23 10:49:24 2008
@@ -17,31 +17,29 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 import javax.security.auth.Subject;
 
 import org.apache.abdera.protocol.Resolver;
 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.WorkspaceInfo;
 import org.apache.abdera.protocol.server.WorkspaceManager;
-import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.writer.StreamWriter;
 
 public class DefaultProvider 
   extends AbstractProvider {
   
-  private List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
+  private WorkspaceManager workspaceManager;
   private Resolver<Target> targetResolver;
   private Resolver<Subject> subjectResolver;
   
-  public DefaultProvider(WorkspaceInfo... workspaces) {
-    for (WorkspaceInfo wi : workspaces)
-      addWorkspace(wi);
+  public DefaultProvider() {
+    workspaceManager = new DefaultWorkspaceManager();
+    targetResolver = new StructuredTargetResolver(workspaceManager);
+  }
+  
+  public DefaultProvider(String base) {
+    workspaceManager = new DefaultWorkspaceManager();
+    targetResolver = new StructuredTargetResolver(workspaceManager, base);
   }
   
   protected Resolver<Target> getTargetResolver(RequestContext request) {
@@ -60,78 +58,20 @@
     this.subjectResolver = subjectResolver;
   }
   
-  public void addWorkspace(WorkspaceInfo wi) {
-    if (!workspaces.contains(wi))
-      workspaces.add(wi);
-  }
-   
-  protected WorkspaceInfo getWorkspace(
-    RequestContext request) {
-      for (WorkspaceInfo wi : getWorkspaces(request)) {
-        if (wi.isWorkspaceFor(request))
-          return wi;
-      }
-      return null;
-  }
- 
-  protected WorkspaceInfo[] getWorkspaces(
-    RequestContext request) {
-      return workspaces.toArray(new WorkspaceInfo[workspaces.size()]);
-  }
-  
   protected WorkspaceManager getWorkspaceManager(
     RequestContext request) {
-      return getWorkspace(request);
+      return getWorkspaceManager();
   }
   
-  protected ResponseContext getServiceDocument(
-    final RequestContext request) {
-      return 
-        new StreamWriterResponseContext(request.getAbdera()) {
-          protected void writeTo(
-            StreamWriter sw) 
-              throws IOException {
-            sw.startDocument()
-              .startService();
-            for (WorkspaceInfo wi : getWorkspaces(request)) {
-              sw.startWorkspace()
-                .writeTitle(wi.getTitle(request));
-              for (CollectionInfo ci : wi.getCollections(request)) {
-                sw.startCollection(ci.getHref(request))
-                  .writeTitle(ci.getTitle(request))
-                  .writeAccepts(ci.getAccepts(request));
-                CategoriesInfo[] catinfos = ci.getCategoriesInfo(request);
-                if (catinfos != null) {
-                  for (CategoriesInfo catinfo : catinfos) {
-                    String href = catinfo.getHref(request);
-                    if (href != null) {
-                      sw.startCategories()
-                        .writeAttribute("href", href)
-                        .endCategories();
-                    } else {
-                      sw.startCategories(
-                        catinfo.isFixed(request), 
-                        catinfo.getScheme(request));
-                      for (CategoryInfo cat : catinfo) {
-                        sw.writeCategory(
-                          cat.getTerm(request), 
-                          cat.getScheme(request), 
-                          cat.getLabel(request));
-                      }
-                      sw.endCategories();
-                    }
-                  }
-                }
-                sw.endCollection();
-              }
-              sw.endWorkspace();
-            }
-            sw.endService()
-              .endDocument();
-          }
-        }
-        .setStatus(200)
-        .setContentType(Constants.APP_MEDIA_TYPE);
+  public WorkspaceManager getWorkspaceManager() {
+    return workspaceManager;
+  }
+
+  public void setWorkspaceManager(WorkspaceManager workspaceManager) {
+    this.workspaceManager = workspaceManager;
   }
   
+  public void addWorkspace(WorkspaceInfo workspace) {
+    ((DefaultWorkspaceManager) getWorkspaceManager()).addWorkspace(workspace);
+  }
 }

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,99 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+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 class DefaultTarget 
+  implements Target {
+
+  protected final TargetType type;
+  protected final RequestContext context;
+  
+  public DefaultTarget(
+    TargetType type, 
+    RequestContext context) {
+      this.type = type;
+      this.context = context;
+  }
+
+  public String getIdentity() {
+    return context.getUri().toString();
+  }
+
+  public String getParameter(String name) {
+    return context.getParameter(name);
+  }
+
+  public String[] getParameterNames() {
+    String[] pn = context.getParameterNames();
+    return (pn != null) ? pn : new String[0];
+  }
+
+  public Iterator<String> iterator() {
+    return java.util.Arrays.asList(getParameterNames()).iterator();
+  }
+
+  public TargetType getType() {
+    return type;
+  }
+ 
+  public RequestContext getRequestContext() {
+    return context;
+  }
+  
+  public String toString() {
+    return getType() + " - " + getIdentity();
+  }
+
+  @Override
+  public int hashCode() {
+    final int PRIME = 31;
+    int result = 1;
+    result = PRIME * result + ((context == null) ? 0 : context.hashCode());
+    result = PRIME * result + ((type == null) ? 0 : type.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    final DefaultTarget other = (DefaultTarget) obj;
+    if (context == null) {
+      if (other.context != null)
+        return false;
+    } else if (!context.equals(other.context))
+      return false;
+    if (type == null) {
+      if (other.type != null)
+        return false;
+    } else if (!type.equals(other.type))
+      return false;
+    return true;
+  }
+
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultTarget.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,16 @@
+package org.apache.abdera.protocol.server.impl;
+
+import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+import org.apache.abdera.protocol.server.RequestContext.Scope;
+
+
+public class DefaultWorkspaceManager extends AbstractWorkspaceManager {
+
+  public CollectionAdapter getCollectionAdapter(RequestContext request) {
+    return (CollectionAdapter) request.getAttribute(Scope.REQUEST, StructuredTargetResolver.COLLECTION_PROVIDER_ATTRIBUTE);
+  }
+
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java Wed Jan 23 10:49:24 2008
@@ -24,6 +24,8 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Categories;
+import org.apache.abdera.protocol.server.CategoriesInfo;
+import org.apache.abdera.protocol.server.CategoryInfo;
 import org.apache.abdera.protocol.server.RequestContext;
 
 public class SimpleCategoriesInfo 

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java Wed Jan 23 10:49:24 2008
@@ -21,6 +21,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Category;
+import org.apache.abdera.protocol.server.CategoryInfo;
 import org.apache.abdera.protocol.server.RequestContext;
 
 public class SimpleCategoryInfo 

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java Wed Jan 23 10:49:24 2008
@@ -21,7 +21,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.abdera.protocol.server.CategoriesInfo;
 import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
 import org.apache.abdera.protocol.server.RequestContext;
 
 public class SimpleCollection 
@@ -50,6 +52,11 @@
       this.href = href;
   }
   
+  public boolean isCollectionFor(RequestContext request) {
+    // TODO Auto-generated method stub
+    return false;
+  }
+
   public String[] getAccepts(RequestContext request) {
     return accepts;
   }

Copied: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java (from r614365, incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspace.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java?p2=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java&p1=incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspace.java&r1=614365&r2=614618&rev=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspace.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleWorkspaceInfo.java Wed Jan 23 10:49:24 2008
@@ -1,39 +1,39 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 package org.apache.abdera.protocol.server.impl;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
-import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
 import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
 
-public class SimpleWorkspace
-  extends AbstractWorkspaceInfo
-  implements WorkspaceInfo {
+public class SimpleWorkspaceInfo implements WorkspaceInfo {
 
   protected String title;
-  protected List<CollectionInfo> collections = new ArrayList<CollectionInfo>();
-  
+  protected Set<CollectionInfo> collections;
+
   public String getTitle() {
     return title;
   }
-  
+
   public void setTitle(String title) {
     this.title = title;
   }
@@ -43,28 +43,22 @@
   }
 
   public void addCollection(CollectionInfo ci) {
-    if (!this.collections.contains(ci))
-      this.collections.add(ci);
+    getCollections().add(ci);
+  }
+
+  public Collection<CollectionInfo> getCollections(RequestContext request) {
+    return collections;
   }
-  
-  public CollectionInfo[] getCollections(RequestContext request) {
-    return collections.toArray(new CollectionInfo[collections.size()]);
-  }
-
-  public CollectionAdapter getCollectionAdapter(
-    RequestContext request) {
-      for (CollectionInfo ci : getCollections(request)) {
-        if (ci.isAdapterFor(request)) 
-          return ci.getCollectionAdapter(request);
-      }
-      return null;
-  }
-
-  public boolean isWorkspaceFor(RequestContext request) {
-    for (CollectionInfo ci : getCollections(request)) {
-      if (ci.isAdapterFor(request)) return true;
+
+  public Set<CollectionInfo> getCollections() {
+    if (collections == null) {
+      collections = new HashSet<CollectionInfo>();
     }
-    return false;
+
+    return collections;
   }
 
+  public void setCollections(Set<CollectionInfo> collections) {
+    this.collections = collections;
+  }
 }

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,135 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.abdera.i18n.text.UrlEncoding;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.CollectionInfo;
+import org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.protocol.server.RequestContext;
+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.server.WorkspaceManager;
+import org.apache.abdera.protocol.server.RequestContext.Scope;
+
+/**
+ * Resolves targets based on a simple assumed URI structure. 
+ */
+public class StructuredTargetResolver implements Resolver<Target> {
+
+  public static final String COLLECTION_PROVIDER_ATTRIBUTE = "collectionProvider";
+  public static final String URI_PARAMETER_ATTRIBUTE_PREFIX = "uriParameter";
+
+  private Pattern servicesPattern = Pattern.compile("^/");
+
+  private WorkspaceManager workspaceManager;
+  
+  public StructuredTargetResolver(WorkspaceManager workspaceManager) {
+    this.workspaceManager = workspaceManager;
+  }
+
+  public StructuredTargetResolver(WorkspaceManager workspaceManager, String servicesPattern) {
+    this.workspaceManager = workspaceManager;
+    this.servicesPattern = Pattern.compile(servicesPattern);
+  }
+
+  public Target resolve(Request request) {
+    RequestContext context = (RequestContext)request;
+    String uri = context.getTargetPath();
+
+    System.out.println("Target " + uri);
+    System.out.println("Request " + context.getResolvedUri());
+    
+    if (servicesPattern == null) {
+      throw new RuntimeException("You must set the servicesPattern property on the ServiceProvider.");
+    }
+
+    Matcher uriMatcher = servicesPattern.matcher(uri);
+    TargetType tt = null;
+    if (uriMatcher.matches()) {
+      tt = TargetType.TYPE_SERVICE;
+    } else {
+      uriMatcher.reset();
+      if (uriMatcher.find()) {
+        String path = uri.substring(uriMatcher.start());
+        if (path.startsWith("/")) {
+          path = path.substring(1);
+        }
+        int q = path.indexOf("?");
+        if (q != -1) {
+          path = path.substring(0, q);
+        }
+
+        path = UrlEncoding.decode(path);
+
+        CollectionInfo collection = null;
+        String href = null;
+        for (WorkspaceInfo wi : workspaceManager.getWorkspaces(context)) {
+          for (CollectionInfo c : wi.getCollections(context)) {
+            href = c.getHref(context);
+            if (path.startsWith(href)) {
+              collection = c;
+              break;
+            }
+          }
+        }
+
+        if (collection != null) {
+          context.setAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE, collection);
+
+          if (href.equals(path)) {
+            tt = TargetType.TYPE_COLLECTION;
+          } else {
+            tt = getOtherTargetType(context, path, href, collection);
+          }
+        }
+      }
+    }
+
+    if (tt == null) {
+      tt = TargetType.TYPE_UNKNOWN;
+    } else {
+      for (int i = 1; i <= uriMatcher.groupCount(); i++) {
+        if (uriMatcher.group(i) != null) {
+          context.setAttribute(Scope.REQUEST, URI_PARAMETER_ATTRIBUTE_PREFIX + Integer.toString(i),
+                               uriMatcher.group(i));
+        }
+      }
+    }
+
+    return new DefaultTarget(tt, context);
+  }
+
+  @SuppressWarnings("unchecked")
+  protected TargetType getOtherTargetType(RequestContext context, 
+                                          String path, String providerHref,
+                                          CollectionInfo collection) {
+    if (path.endsWith(";categories")) {
+      return TargetType.TYPE_CATEGORIES;
+    } else if (context.getContentType() != null && !ProviderHelper.isAtom(context)) {
+      return TargetType.TYPE_MEDIA;
+    } else {
+      return TargetType.TYPE_ENTRY;
+    }
+  }
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicWorkspace.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicWorkspace.java?rev=614618&r1=614617&r2=614618&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicWorkspace.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicWorkspace.java Wed Jan 23 10:49:24 2008
@@ -18,19 +18,19 @@
 package org.apache.abdera.protocol.server.provider.basic;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
 import org.apache.abdera.protocol.server.RequestContext;
-import org.apache.abdera.protocol.server.impl.AbstractWorkspaceInfo;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.impl.CollectionAdapterManager;
-import org.apache.abdera.protocol.server.impl.CollectionInfo;
 import org.apache.abdera.protocol.server.impl.SimpleCollection;
 
-public class BasicWorkspace
-  extends AbstractWorkspaceInfo {
+public class BasicWorkspace implements WorkspaceInfo {
 
   protected CollectionAdapterManager cam;
   
@@ -42,7 +42,7 @@
     return cam;
   }
   
-  public CollectionInfo[] getCollections(RequestContext request) {
+  public Collection<CollectionInfo> getCollections(RequestContext request) {
     CollectionAdapterManager cam = getCollectionAdapterManager(request);
     List<CollectionInfo> collections = new ArrayList<CollectionInfo>();
     try {
@@ -57,7 +57,7 @@
         collections.add(col);
       }
     } catch (Exception e) {}
-    return collections.toArray(new CollectionInfo[collections.size()]);
+    return collections;
   }
 
   public CollectionAdapter getCollectionAdapter(RequestContext request) {

Added: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java?rev=614618&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java Wed Jan 23 10:49:24 2008
@@ -0,0 +1,22 @@
+package org.apache.abdera.protocol.server.customer;
+
+import java.util.Date;
+
+public class Customer {
+  private int id;
+  private String name;
+  
+  public int getId() {
+    return id;
+  }
+  public void setId(int id) {
+    this.id = id;
+  }
+  public String getName() {
+    return name;
+  }
+  public void setName(String name) {
+    this.name = name;
+  }
+  
+}

Propchange: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/customer/Customer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message