abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r614267 - 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/abder...
Date Tue, 22 Jan 2008 17:26:32 GMT
Author: jmsnell
Date: Tue Jan 22 09:26:26 2008
New Revision: 614267

URL: http://svn.apache.org/viewvc?rev=614267&view=rev
Log:
Additional simplifications and changes as suggested by Dan.

ServiceContext has been eliminated and collapsed into Provider.  The AbderaServlet would create
a single Provider instance and use that for all requests.  The Provider now provides the Subject
and Target resolvers.

Transactional methods now take RequestContext as input

Added:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProvider.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestProvider.java
Removed:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/AbstractServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/DefaultServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleServiceContext.java
Modified:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.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/context/AbstractRequestContext.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/CollectionInfo.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/SimpleCollection.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/provider/basic/BasicAdapter.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/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.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/DefaultTest.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

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java
Tue Jan 22 09:26:26 2008
@@ -17,9 +17,27 @@
 */
 package org.apache.abdera.protocol.server;
 
+import java.util.Map;
+
+import javax.security.auth.Subject;
+
+import org.apache.abdera.Abdera;
+
 
 public interface Provider {
+  
+  void init(Abdera abdera, Map<String,String> properties);
 
+  Abdera getAbdera();
+  
+  String getProperty(String name);
+  
+  String[] getPropertyNames();
+  
+  Subject resolveSubject(RequestContext request);
+  
+  Target resolveTarget(RequestContext request);
+  
   ResponseContext process(RequestContext request);
   
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
Tue Jan 22 09:26:26 2008
@@ -48,7 +48,7 @@
   
   Abdera getAbdera();
     
-  ServiceContext getServiceContext();
+  Provider getProvider();
     
   Target getTarget();
     

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java
Tue Jan 22 09:26:26 2008
@@ -21,7 +21,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.text.Localizer;
-import org.apache.abdera.protocol.server.context.DefaultServiceContext;
+import org.apache.abdera.protocol.server.impl.DefaultProvider;
 import org.apache.abdera.util.ServiceUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -31,15 +31,6 @@
   public static final String PROVIDER =
     "org.apache.abdera.protocol.server.Provider";
   
-  public static final String SUBJECT_RESOLVER = 
-    "org.apache.abdera.protocol.server.SubjectResolver";
-  
-  public static final String TARGET_RESOLVER = 
-    "org.apache.abdera.protocol.server.TargetResolver";
-  
-  public static final String SERVICE_CONTEXT =
-    "org.apache.abdera.protocol.server.ServiceContext";
-  
   private final static Log log = LogFactory.getLog(ServiceManager.class);
   
   private static ServiceManager INSTANCE = null;
@@ -63,21 +54,20 @@
     return abdera;
   }
   
-  public ServiceContext newServiceContext(
+  public Provider newProvider (
     Map<String,String> properties) {
     Abdera abdera = getAbdera();
-    String instance = properties.get(SERVICE_CONTEXT);
-    log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","ServiceContext"));
-    ServiceContext context = 
-      (ServiceContext) ServiceUtil.newInstance(
-        SERVICE_CONTEXT, 
+    String instance = properties.get(PROVIDER);
+    log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","Provider"));
+    Provider provider = 
+      (Provider) ServiceUtil.newInstance(
+        PROVIDER, 
         (instance != null) ? 
           instance : 
-          DefaultServiceContext.class.getName(),
+          DefaultProvider.class.getName(),
         abdera);
-    log.debug(Localizer.sprintf("INITIALIZING.INSTANCE", "ServiceContext"));
-    context.init(abdera, properties);
-    return context;
+    log.debug(Localizer.sprintf("INITIALIZING.INSTANCE", "Provider"));
+    provider.init(abdera, properties);
+    return provider;
   }
-  
 }

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=614267&r1=614266&r2=614267&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
Tue Jan 22 09:26:26 2008
@@ -19,10 +19,10 @@
 
 public interface Transactional {
 
-  void start();
+  void start(RequestContext request);
   
-  void end();
+  void end(RequestContext request);
   
-  void compensate(Throwable t);
+  void compensate(RequestContext request, Throwable t);
   
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/AbstractRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/AbstractRequestContext.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/AbstractRequestContext.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/context/AbstractRequestContext.java
Tue Jan 22 09:26:26 2008
@@ -30,8 +30,8 @@
 import org.apache.abdera.parser.ParseException;
 import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
-import org.apache.abdera.protocol.server.ServiceContext;
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.util.AbstractRequest;
 import org.apache.commons.logging.Log;
@@ -43,7 +43,7 @@
 
   private final static Log log = LogFactory.getLog(AbstractRequestContext.class);
   
-  protected final ServiceContext context;
+  protected final Provider provider;
   protected Subject subject;
   protected Principal principal;
   protected Target target;
@@ -53,18 +53,18 @@
   protected Document<?> document;
   
   protected AbstractRequestContext(
-    ServiceContext context,
+    Provider provider,
     String method, 
     IRI requestUri,
     IRI baseUri) {
-      this.context = context;
+      this.provider = provider;
       this.method = method;
       this.baseUri = baseUri;
       this.requestUri = requestUri;
   }
   
   public Abdera getAbdera() {
-    return context.getAbdera();
+    return provider.getAbdera();
   }
     
   @SuppressWarnings("unchecked")
@@ -143,8 +143,8 @@
     return target;
   }
   
-  public ServiceContext getServiceContext() {
-    return context;
+  public Provider getProvider() {
+    return provider;
   }
 
   public String getTargetPath() {

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=614267&r1=614266&r2=614267&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
Tue Jan 22 09:26:26 2008
@@ -17,6 +17,12 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
+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.CollectionAdapter;
 import org.apache.abdera.protocol.server.MediaCollectionAdapter;
 import org.apache.abdera.protocol.server.Provider;
@@ -31,6 +37,47 @@
 public abstract class AbstractProvider 
   implements Provider {
   
+  protected Abdera abdera;
+  protected Map<String,String> properties;
+  
+  public void init(
+    Abdera abdera, 
+    Map<String, String> properties) {
+      this.abdera = abdera;
+      this.properties = properties;
+  }
+  
+  public String getProperty(String name) {
+    return properties.get(name);
+  }
+  
+  public String[] getPropertyNames() {
+    return properties.keySet().toArray(new String[properties.size()]);
+  }
+  
+  public Abdera getAbdera() {
+    return abdera;
+  }
+
+  public Subject resolveSubject(RequestContext request) {
+    Resolver<Subject> subjectResolver = getSubjectResolver(request);
+    return subjectResolver != null ? 
+       subjectResolver.resolve(request) : null;
+  }
+
+  public Target resolveTarget(RequestContext request) {
+    Resolver<Target> targetResolver = 
+      getTargetResolver(request);
+    return targetResolver != null ? 
+      targetResolver.resolve(request) : null;
+  }
+
+  protected Resolver<Subject> getSubjectResolver(RequestContext request) {
+    return new SimpleSubjectResolver();
+  }
+    
+  protected abstract Resolver<Target> getTargetResolver(RequestContext request);
+
   public ResponseContext process(
     RequestContext request) {    
       Target target = request.getTarget();
@@ -56,7 +103,7 @@
         adapter instanceof Transactional ? 
           (Transactional)adapter : null;
       try {
-        if (transaction != null) transaction.start();
+        if (transaction != null) transaction.start(request);
         if (type == TargetType.TYPE_CATEGORIES) {
           if (method.equalsIgnoreCase("GET"))
             return adapter.getCategories(request);
@@ -94,11 +141,11 @@
         return adapter.extensionRequest(request);
       } catch (Throwable e) {
         if (transaction != null) 
-          transaction.compensate(e);
+          transaction.compensate(request,e);
         return ProviderHelper.servererror(request, e);
       } finally {
         if (transaction != null) 
-          transaction.end();
+          transaction.end(request);
       }
   }
    

Modified: 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/impl/CollectionInfo.java?rev=614267&r1=614266&r2=614267&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/impl/CollectionInfo.java
Tue Jan 22 09:26:26 2008
@@ -20,15 +20,15 @@
 import org.apache.abdera.protocol.server.CollectionAdapter;
 import org.apache.abdera.protocol.server.RequestContext;
 
-public interface CollectionInfo 
-  extends CollectionAdapter {
+public interface CollectionInfo {
 
-  public String getHref(RequestContext request);
+  String getHref(RequestContext request);
   
-  public String getTitle(RequestContext request);
+  String getTitle(RequestContext request);
   
-  public String[] getAccepts(RequestContext request);
+  String[] getAccepts(RequestContext request);
   
-  public boolean isAdapterFor(RequestContext request);
+  boolean isAdapterFor(RequestContext request);
   
+  CollectionAdapter getCollectionAdapter(RequestContext request);
 }

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=614267&r1=614266&r2=614267&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
Tue Jan 22 09:26:26 2008
@@ -21,8 +21,12 @@
 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.WorkspaceManager;
 import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
 import org.apache.abdera.util.Constants;
@@ -32,12 +36,28 @@
   extends AbstractProvider {
   
   private List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
-  
-  public DefaultProvider() {}
+  private Resolver<Target> targetResolver;
+  private Resolver<Subject> subjectResolver;
   
   public DefaultProvider(WorkspaceInfo... workspaces) {
     for (WorkspaceInfo wi : workspaces)
       addWorkspace(wi);
+  }
+  
+  protected Resolver<Target> getTargetResolver(RequestContext request) {
+    return targetResolver;
+  }
+  
+  public void setTargetResolver(Resolver<Target> targetResolver) {
+    this.targetResolver = targetResolver;
+  }
+
+  protected Resolver<Subject> getSubjectResolver(RequestContext request) {
+    return subjectResolver;
+  }
+  
+  public void setSubjectResolver(Resolver<Subject> subjectResolver) {
+    this.subjectResolver = subjectResolver;
   }
   
   public void addWorkspace(WorkspaceInfo wi) {

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=614267&r1=614266&r2=614267&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
Tue Jan 22 09:26:26 2008
@@ -19,12 +19,11 @@
 
 import org.apache.abdera.protocol.server.CollectionAdapter;
 import org.apache.abdera.protocol.server.RequestContext;
-import org.apache.abdera.protocol.server.ResponseContext;
 
 public class SimpleCollection 
   implements CollectionInfo {
   
-  private final CollectionAdapter internal;
+  private final CollectionAdapter adapter;
   private final String id;
   private final String title;
   private final String href;
@@ -36,7 +35,7 @@
     String title,
     String href,
     String... accepts) {
-      this.internal = adapter;
+      this.adapter = adapter;
       this.id = id;
       this.title = title;
       this.accepts = accepts;
@@ -58,33 +57,8 @@
   public boolean isAdapterFor(RequestContext request) {
     return request.getTarget().getParameter("collection").equals(this.id);
   }
-  
-  public ResponseContext deleteEntry(RequestContext request) {
-    return internal.deleteEntry(request);
-  }
-  
-  public ResponseContext extensionRequest(RequestContext request) {
-    return internal.extensionRequest(request);
-  }
-  
-  public ResponseContext getEntry(RequestContext request) {
-    return internal.getEntry(request);
-  }
-  
-  public ResponseContext getFeed(RequestContext request) {
-    return internal.getFeed(request);
-  }
-  
-  public ResponseContext postEntry(RequestContext request) {
-    return internal.postEntry(request);
-  }
-  
-  public ResponseContext putEntry(RequestContext request) {
-    return internal.putEntry(request);
-  }
 
-  public ResponseContext getCategories(RequestContext request) {
-    return internal.getCategories(request);
+  public CollectionAdapter getCollectionAdapter(RequestContext request) {
+    return adapter;
   }
-  
 }

Modified: 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/SimpleWorkspace.java?rev=614267&r1=614266&r2=614267&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/SimpleWorkspace.java
Tue Jan 22 09:26:26 2008
@@ -54,7 +54,8 @@
   public CollectionAdapter getCollectionAdapter(
     RequestContext request) {
       for (CollectionInfo ci : getCollections(request)) {
-        if (ci.isAdapterFor(request)) return ci;
+        if (ci.isAdapterFor(request)) 
+          return ci.getCollectionAdapter(request);
       }
       return null;
   }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
Tue Jan 22 09:26:26 2008
@@ -120,7 +120,7 @@
         String entryId = 
           !createFlag ? 
             target.getParameter(
-              BasicServiceContext.PARAM_ENTRY) : null;
+              BasicProvider.PARAM_ENTRY) : null;
         Entry newEntry = createFlag
             ? createEntry(inputEntry)
             : updateEntry(entryId, inputEntry);
@@ -148,7 +148,7 @@
   public ResponseContext deleteEntry(
     RequestContext request) {
       Target target = request.getTarget();
-      String entryId = target.getParameter(BasicServiceContext.PARAM_ENTRY);
+      String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
       try {
         return deleteEntry(entryId) ?
           ProviderHelper.nocontent() :
@@ -166,7 +166,7 @@
   public ResponseContext getEntry(
     RequestContext request) {
       Target target = request.getTarget();
-      String entryId = target.getParameter(BasicServiceContext.PARAM_ENTRY);
+      String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
       try {
         Entry entry = getEntry(entryId);
         return entry != null ?

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProvider.java?rev=614267&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProvider.java
(added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProvider.java
Tue Jan 22 09:26:26 2008
@@ -0,0 +1,40 @@
+/*
+* 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.provider.basic;
+
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.impl.DefaultProvider;
+import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
+
+public class BasicProvider 
+  extends DefaultProvider {
+
+  public static final String PARAM_FEED = "feed";
+  public static final String PARAM_ENTRY = "entry";
+  
+  public BasicProvider() {
+    setTargetResolver(
+      new RegexTargetResolver()
+        .setPattern("/", TargetType.TYPE_SERVICE)
+        .setPattern("/" + "([^/#?]+)", TargetType.TYPE_COLLECTION, PARAM_FEED)
+        .setPattern("/" + "([^/#?]+)/([^/#?]+)", TargetType.TYPE_ENTRY, PARAM_FEED, PARAM_ENTRY)
+    );
+    addWorkspace(new BasicWorkspace());
+  }
+  
+}

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=614267&r1=614266&r2=614267&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
Tue Jan 22 09:26:26 2008
@@ -66,7 +66,7 @@
         .getAdapter(
           request.getTarget()
             .getParameter(
-              BasicServiceContext.PARAM_FEED));
+                BasicProvider.PARAM_FEED));
     } catch (Exception e) {
       return null;
     }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
Tue Jan 22 09:26:26 2008
@@ -35,7 +35,6 @@
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
-import org.apache.abdera.protocol.server.ServiceContext;
 import org.apache.abdera.protocol.server.ServiceManager;
 import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
@@ -53,48 +52,38 @@
   private final static Log log = LogFactory.getLog(AbderaServlet.class);
   
   protected ServiceManager manager;
-  protected ServiceContext context;
+  protected Provider provider;
   
   public void init() throws ServletException {
     log.debug("Initialing Abdera Servlet");
     manager = createServiceManager();
-    context = createServiceContext();
-    if (context == null) {
-      log.debug("Cannot create service context");
-      throw new ServletException("Cannot create service context");
-    }
+    provider = createProvider();
+    log.debug("Using provider - " + provider);
   }
 
   public Abdera getAbdera() {
      return ServiceManager.getAbdera();
   }
   
-  public ServiceContext getServiceContext() {
-    return context;
-  }
-
   public ServiceManager getServiceManager() {
     return manager;
   }
 
-  protected ServiceContext createServiceContext() {
-    return manager.newServiceContext(
-        getProperties(
-          getServletConfig()));
-  }
-
   protected ServiceManager createServiceManager() {
     return ServiceManager.getInstance();
   }
+
+  protected Provider createProvider() {
+    return manager.newProvider(getProperties(getServletConfig()));
+  }
   
   @Override
   protected void service(
     HttpServletRequest request, 
     HttpServletResponse response) 
       throws ServletException, IOException {
-    RequestContext reqcontext = new ServletRequestContext(context, request);
-    Provider provider = context.getProvider(reqcontext);
-    log.debug("Provider - " + provider);
+    RequestContext reqcontext = 
+      new ServletRequestContext(provider, request);
     try {
       output(
         request,

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
Tue Jan 22 09:26:26 2008
@@ -26,17 +26,14 @@
 import java.util.List;
 import java.util.Locale;
 
-import javax.security.auth.Subject;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.text.Localizer;
-import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
-import org.apache.abdera.protocol.server.ServiceContext;
-import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.context.AbstractRequestContext;
 
 public class ServletRequestContext 
@@ -47,25 +44,18 @@
   private HttpSession session;
   
   public ServletRequestContext(
-    ServiceContext context,
+    Provider provider,
     HttpServletRequest request) {
       super(
-        context, 
+        provider, 
         request.getMethod(), 
         initRequestUri(request),
-        initBaseUri(context,request));
+        initBaseUri(provider,request));
       this.request = request;
       this.session = request.getSession(false);
-      
-      Resolver<Subject> subjectResolver = context.getSubjectResolver();
-      principal = request.getUserPrincipal();
-      subject = (subjectResolver != null)? 
-        subjectResolver.resolve(this) : null;
-      
-      Resolver<Target> targetResolver = 
-        context.getTargetResolver();
-      target = (targetResolver != null) ? 
-        targetResolver.resolve(this) : null;
+      this.principal = request.getUserPrincipal();
+      this.subject = provider.resolveSubject(this);
+      this.target = provider.resolveTarget(this);
   }
   
   public Object getProperty(Property property) {
@@ -183,9 +173,9 @@
   }
   
   private static String getHost(
-    ServiceContext context, 
+    Provider provider, 
     HttpServletRequest request) {
-      Abdera abdera = context.getAbdera();
+      Abdera abdera = provider.getAbdera();
       String host = abdera.getConfiguration().getConfigurationOption(
         "org.apache.abdera.protocol.server.Host");
       return (host != null) ? 
@@ -194,9 +184,9 @@
   }
   
   private static int getPort(
-    ServiceContext context, 
+    Provider provider, 
     HttpServletRequest request) {
-    Abdera abdera = context.getAbdera();
+    Abdera abdera = provider.getAbdera();
       String port = abdera.getConfiguration().getConfigurationOption(
         "org.apache.abdera.protocol.server.Port");
       return (port != null) ? 
@@ -205,15 +195,15 @@
   }
   
   private static IRI initBaseUri(
-    ServiceContext context, 
+    Provider provider, 
     HttpServletRequest request) {
       StringBuilder buffer = 
         new StringBuilder(
           (request.isSecure())?
             "https":"http");
       buffer.append("://");
-      buffer.append(getHost(context,request));
-      int port = getPort(context,request);
+      buffer.append(getHost(provider,request));
+      int port = getPort(provider,request);
       if (port != 80) {
         buffer.append(":");
         buffer.append(port);

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/JettyServer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/JettyServer.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/JettyServer.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/JettyServer.java
Tue Jan 22 09:26:26 2008
@@ -17,9 +17,8 @@
 */
 package org.apache.abdera.protocol.server.test;
 
-import org.apache.abdera.protocol.server.ServiceContext;
+import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.ServiceManager;
-import org.apache.abdera.protocol.server.provider.basic.BasicServiceContext;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.Context;
@@ -40,11 +39,11 @@
     this.port = port;
   }
   
-  public void start(Class<? extends ServiceContext> _class) throws Exception {
+  public void start(Class<? extends Provider> _class) throws Exception {
     server = new Server(port);
     Context context = new Context(server, "/", Context.SESSIONS);
     ServletHolder servletHolder = new ServletHolder(new AbderaServlet());
-    servletHolder.setInitParameter(ServiceManager.SERVICE_CONTEXT, _class.getName());
+    servletHolder.setInitParameter(ServiceManager.PROVIDER, _class.getName());
     context.addServlet(servletHolder, "/*");
     server.start();
   }
@@ -53,9 +52,4 @@
     server.stop();
   }
   
-  public static void main(String... args) throws Exception {
-    JettyServer js = new JettyServer();
-    js.start(BasicServiceContext.class);
-    js.stop();
-  }
 }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
Tue Jan 22 09:26:26 2008
@@ -33,7 +33,7 @@
 import org.apache.abdera.protocol.client.AbderaClient;
 import org.apache.abdera.protocol.client.ClientResponse;
 import org.apache.abdera.protocol.client.RequestOptions;
-import org.apache.abdera.protocol.server.provider.basic.BasicServiceContext;
+import org.apache.abdera.protocol.server.provider.basic.BasicProvider;
 import org.apache.abdera.protocol.server.test.JettyServer;
 import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.MimeTypeHelper;
@@ -49,7 +49,7 @@
     try {
       if (server == null) {
         server = new JettyServer();
-        server.start(BasicServiceContext.class);
+        server.start(BasicProvider.class);
       }
     } catch (Exception e) {}
   }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
Tue Jan 22 09:26:26 2008
@@ -49,7 +49,7 @@
     try {
       if (server == null) {
         server = new JettyServer();
-        server.start(TestServiceContext.class);
+        server.start(TestProvider.class);
       }
     } catch (Exception e) {}
   }

Added: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestProvider.java?rev=614267&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestProvider.java
(added)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestProvider.java
Tue Jan 22 09:26:26 2008
@@ -0,0 +1,61 @@
+/*
+* 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.test.impl;
+
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.impl.DefaultProvider;
+import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
+import org.apache.abdera.protocol.server.impl.SimpleCollection;
+import org.apache.abdera.protocol.server.impl.SimpleWorkspace;
+import org.apache.abdera.protocol.server.test.simple.SimpleAdapter;
+
+public class TestProvider 
+  extends DefaultProvider {
+
+  public TestProvider() {
+    setTargetResolver(
+      new RegexTargetResolver()
+        .setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE)
+        .setPattern("/atom/([^/#?]+);categories", TargetType.TYPE_CATEGORIES, "collection")
+        .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
+        .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection",
"entry")
+    );        
+    SimpleWorkspace workspace = new SimpleWorkspace();
+    workspace.setTitle("My Blog");
+    workspace.addCollection(
+      new SimpleCollection(
+        new SimpleAdapter(),
+        "feed1", 
+        "entries1", 
+        "/atom/feed1", 
+        "application/atom+xml;type=entry"
+      )
+    );
+    workspace.addCollection(
+      new SimpleCollection(
+        new SimpleAdapter(),
+        "feed2", 
+        "entries2", 
+        "/atom/feed2", 
+        "application/atom+xml;type=entry"
+      )
+    );        
+    addWorkspace(workspace);
+  }
+  
+}

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
Tue Jan 22 09:26:26 2008
@@ -19,11 +19,15 @@
 
 import java.io.IOException;
 
+import org.apache.abdera.protocol.Resolver;
 import org.apache.abdera.protocol.server.CollectionAdapter;
 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.context.StreamWriterResponseContext;
 import org.apache.abdera.protocol.server.impl.AbstractWorkspaceProvider;
+import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
 import org.apache.abdera.util.Constants;
 import org.apache.abdera.writer.StreamWriter;
 
@@ -34,13 +38,10 @@
   private final String name;
   private final String href;
   
-  public SimpleProvider(
-    CollectionAdapter adapter, 
-    String name, 
-    String href) {
-      this.adapter = adapter;
-      this.name = name;
-      this.href = href;
+  public SimpleProvider() {
+      this.adapter = new SimpleAdapter();
+      this.name = "Simple";
+      this.href = "/atom/feed";
   }
   
   public CollectionAdapter getCollectionAdapter(
@@ -72,5 +73,13 @@
         }
         .setStatus(200)
         .setContentType(Constants.APP_MEDIA_TYPE);
+  }
+ 
+  protected Resolver<Target> getTargetResolver(RequestContext request) {
+    return new RegexTargetResolver()
+      .setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE)
+      .setPattern("/atom/([^/#?]+);categories", TargetType.TYPE_CATEGORIES, "collection")
+      .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
+      .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection","entry");
   }
 }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java?rev=614267&r1=614266&r2=614267&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
Tue Jan 22 09:26:26 2008
@@ -49,7 +49,7 @@
     try {
       if (server == null) {
         server = new JettyServer();
-        server.start(SimpleServiceContext.class);
+        server.start(SimpleProvider.class);
       }
     } catch (Exception e) {}
   }



Mime
View raw message