abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r613765 [2/4] - in /incubator/abdera/java/branches/server_refactor/src: main/java/org/ main/java/org/apache/ main/java/org/apache/abdera/ main/java/org/apache/abdera/protocol/ main/java/org/apache/abdera/protocol/server/ main/java/org/apach...
Date Mon, 21 Jan 2008 05:33:58 GMT
Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManagerProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManagerProvider.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManagerProvider.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManagerProvider.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,50 @@
+/*
+* 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 org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceManager;
+
+public abstract class AbstractWorkspaceManagerProvider 
+  extends AbstractProvider
+  implements WorkspaceManager {
+  
+  @Override 
+  protected WorkspaceManager getWorkspaceManager(
+    RequestContext request) {
+      return this;
+  }
+  
+  public boolean checkTarget(
+    RequestContext request) {
+      return request.getTarget() != null;
+  }
+  
+  public String[] getMethods(RequestContext request) {
+    return ProviderHelper.getDefaultMethods(request);
+  }
+  
+  public boolean checkMethod(
+    RequestContext request) {
+      return ProviderHelper.defaultCheckMethod(
+        request, 
+        getMethods(request));
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,131 @@
+/*
+* 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.abdera.writer.Writer;
+
+public class BaseResponseContext<T extends Base>
+  extends AbstractResponseContext {
+
+  private final T base;
+  private final boolean chunked;
+  
+  public BaseResponseContext(T base) {
+    this(base, true);
+  }
+  
+  public BaseResponseContext(T base, boolean chunked) {
+    this.base = base;
+    setStatus(200);
+    setStatusText("OK");
+    this.chunked = chunked;
+    try {
+      MimeType type = getContentType();
+      String charset = type.getParameter("charset");
+      if (charset == null) charset = getCharsetFromBase(base);
+      if (charset == null) charset = "UTF-8";
+      type.setParameter("charset", charset);
+      setContentType(type.toString());
+    } catch (Exception e) {}
+  }
+  
+  @SuppressWarnings("unchecked") private String getCharsetFromBase(Base base) {
+    if (base == null) return null;
+    if (base instanceof Document) {
+      return ((Document)base).getCharset();
+    } else if (base instanceof Element) {
+      return getCharsetFromBase(((Element)base).getDocument());
+    }
+    return null;
+  }
+  
+  public T getBase() {
+    return base;
+  }
+  
+  public boolean hasEntity() {
+    return (base != null);
+  }
+
+  public void writeTo(java.io.Writer javaWriter) throws IOException {
+    if (hasEntity()) {
+      if (writer == null) base.writeTo(javaWriter);
+      else writeTo(javaWriter,writer);
+    }
+  }
+  
+  public void writeTo(OutputStream out) throws IOException {
+    if (hasEntity()) {
+      if (writer == null) base.writeTo(out);
+      else writeTo(out,writer);
+    }
+  }
+
+  @Override
+  public MimeType getContentType() {
+    try {
+      MimeType t = super.getContentType();
+      if (t == null) {
+        String type = MimeTypeHelper.getMimeType(base);
+        if (type != null) t = new MimeType(type);
+      }
+      return t;
+    } catch (javax.activation.MimeTypeParseException e) {
+      throw new org.apache.abdera.util.MimeTypeParseException(e);
+    }
+  }
+
+  @Override
+  public long getContentLength() {
+    long len = super.getContentLength();
+    if (hasEntity() && len == -1 && !chunked) {
+      try {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        base.writeTo(out);
+        len = out.size();
+        super.setContentLength(len);
+      } catch (Exception e) {}
+    }
+    return len;
+  }
+  
+  public void writeTo(
+    OutputStream out, 
+    Writer writer) 
+      throws IOException {
+    writer.writeTo(base, out);
+  }
+    
+  public void writeTo(
+    java.io.Writer javaWriter, 
+    Writer abderaWriter) 
+      throws IOException {
+    abderaWriter.writeTo(base, javaWriter);
+  }
+    
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,101 @@
+/*
+* 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 javax.security.auth.Subject;
+
+import org.apache.abdera.i18n.text.Localizer;
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.ServiceManager;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.util.ServiceUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class DefaultServiceContext 
+  extends AbstractServiceContext {
+
+  private static final Log logger = LogFactory.getLog(DefaultServiceContext.class);
+  
+  protected String defaultsubjectresolver = SimpleSubjectResolver.class.getName();
+  protected String defaulttargetresolver = RegexTargetResolver.class.getName();
+  protected String defaultprovidermanager = null;
+  
+  public DefaultServiceContext() {}
+  
+  private Object instance(String id, String _default) {
+    String instance = getProperty(id);
+    Object obj =  ServiceUtil.newInstance( id, (instance!=null)?instance:_default, abdera);
+    logger.debug(Localizer.sprintf("RETURNING.INSTANCE", obj, id));
+    return obj;
+  }
+  
+  @SuppressWarnings("unchecked")
+  public synchronized ItemManager<Provider> getProviderManager() {
+    if (providerManager == null) {
+      providerManager = (ItemManager<Provider>) instance(
+        ServiceManager.PROVIDER_MANAGER, getDefaultProviderManager());
+    }
+    return providerManager;
+  }
+  
+  protected String getDefaultProviderManager() {
+    return defaultprovidermanager;
+  }
+
+  @SuppressWarnings("unchecked")
+  public Resolver<Subject> getSubjectResolver() {
+    if (subjectResolver == null) {
+      subjectResolver = (Resolver<Subject>) instance(
+        ServiceManager.SUBJECT_RESOLVER, getDefaultSubjectResolver());
+    }
+    return subjectResolver;
+  }
+  
+  protected String getDefaultSubjectResolver() {
+    return defaultsubjectresolver;
+  }
+
+  @SuppressWarnings("unchecked")
+  public Resolver<Target> getTargetResolver(String contextPath) {
+    if (targetResolver == null) {
+      targetResolver = (Resolver<Target>) instance(
+        ServiceManager.TARGET_RESOLVER, getDefaultTargetResolver());
+    }
+    return targetResolver;
+  }
+  
+  protected String getDefaultTargetResolver() {
+    return defaulttargetresolver;
+  }
+
+  public void setDefaultProviderManager(String defaultprovidermanager) {
+    this.defaultprovidermanager = defaultprovidermanager;
+  }
+
+  public void setDefaultSubjectResolver(String defaultsubjectresolver) {
+    this.defaultsubjectresolver = defaultsubjectresolver;
+  }
+
+  public void setDefaultTargetResolver(String defaulttargetresolver) {
+    this.defaulttargetresolver = defaulttargetresolver;
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,49 @@
+/*
+* 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.OutputStream;
+
+import org.apache.abdera.writer.Writer;
+
+public final class EmptyResponseContext 
+  extends AbstractResponseContext {
+
+  public EmptyResponseContext(int status) {
+    setStatus(status);
+  }
+  
+  public EmptyResponseContext(int status, String text) {
+    setStatusText(text);
+  }
+  
+  public boolean hasEntity() {
+    return false;
+  }
+
+  public void writeTo(OutputStream out) 
+    throws IOException {}
+
+  public void writeTo(OutputStream out, Writer writer) throws IOException {}
+
+  public void writeTo(java.io.Writer javaWriter, Writer abderaWriter) throws IOException {}
+
+  public void writeTo(java.io.Writer javaWriter) throws IOException {}
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EntityProviderResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EntityProviderResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EntityProviderResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EntityProviderResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,74 @@
+/*
+* 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 org.apache.abdera.Abdera;
+import org.apache.abdera.protocol.EntityProvider;
+import org.apache.abdera.writer.StreamWriter;
+
+/**
+ * StreamWriterResponseContext implementation based on the EntityProvider interface
+ */
+public class EntityProviderResponseContext 
+  extends StreamWriterResponseContext {
+  
+  private final EntityProvider provider;
+  
+  public EntityProviderResponseContext(
+    EntityProvider provider,
+    Abdera abdera, 
+    String encoding, 
+    String sw) {
+      super(abdera, encoding, sw);
+      this.provider = provider;
+      init();
+  }
+
+  public EntityProviderResponseContext(
+    EntityProvider provider,
+    Abdera abdera, 
+    String encoding) {
+      super(abdera, encoding);
+      this.provider = provider;
+      init();
+  }
+
+  public EntityProviderResponseContext(
+    EntityProvider provider,
+    Abdera abdera) {
+      super(abdera);
+      this.provider = provider;
+      init();
+  }
+
+  private void init() {
+    setContentType(provider.getContentType());
+    setEntityTag(provider.getEntityTag());
+    setLastModified(provider.getLastModified());
+  }
+  
+  @Override 
+  protected void writeTo(
+    StreamWriter sw) 
+      throws IOException {
+    provider.writeTo(sw);
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,151 @@
+/*
+* 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.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.util.Date;
+
+import org.apache.abdera.util.EntityTag;
+
+
+/**
+ * ResponseContext implementation for arbitrary media resources
+ */
+public class MediaResponseContext
+  extends AbstractResponseContext {
+
+  private InputStream in;
+
+  public MediaResponseContext(
+    InputStream in, 
+    EntityTag etag, 
+    int status) {
+      this.in = in;
+      this.status = status;
+      setEntityTag(etag);
+  }
+  
+  public MediaResponseContext(
+    InputStream in,  
+    int status) {
+      this.in = in;
+      this.status = status;
+  }
+  
+  public MediaResponseContext(
+    InputStream in, 
+    Date lastmodified, 
+    int status) {
+      this.in = in;
+      this.status = status;
+      setLastModified(lastmodified);
+  }
+
+  public MediaResponseContext(
+    byte[] bytes,
+    int status) {
+      this(new ByteArrayInputStream(bytes),status);
+  }
+  
+  public MediaResponseContext(
+    byte[] bytes,
+    Date lastmodified,
+    int status) {
+      this(new ByteArrayInputStream(bytes),lastmodified,status);
+  }
+
+  public MediaResponseContext(
+    byte[] bytes,
+    EntityTag etag,
+    int status) {
+      this(new ByteArrayInputStream(bytes),etag,status);
+  }
+
+  public MediaResponseContext(
+    ReadableByteChannel channel,
+    int status) {
+      this(Channels.newInputStream(channel),status);
+  }
+  
+  public MediaResponseContext(
+    ReadableByteChannel channel,
+    Date lastmodified,
+    int status) {
+      this(Channels.newInputStream(channel),lastmodified,status);
+  }
+
+  public MediaResponseContext(
+    ReadableByteChannel channel,
+    EntityTag etag,
+    int status) {
+      this(Channels.newInputStream(channel),etag,status);
+  }
+  
+  public boolean hasEntity() {
+    return in != null;
+  }
+
+  public void writeTo(
+    OutputStream out) 
+      throws IOException {
+    if (in != null) {
+      byte[] buf = new byte[500];
+      int r = -1;
+      while ((r = in.read(buf)) != -1) {
+        out.write(buf,0,r);
+        buf = new byte[100];
+      }
+    }
+  } 
+
+  public void writeTo(
+    Writer out) 
+      throws IOException {
+    if (in != null) {
+      InputStreamReader rdr = new InputStreamReader(in);
+      char[] buf = new char[500];
+      int r = -1;
+      while ((r = rdr.read(buf)) != -1) {
+        out.write(buf,0,r);
+        buf = new char[100];
+      }
+    }
+  }
+
+  public void writeTo(
+    OutputStream out, 
+    org.apache.abdera.writer.Writer writer) 
+      throws IOException {
+    throw new UnsupportedOperationException();
+  }
+
+  public void writeTo(
+    Writer javaWriter, 
+    org.apache.abdera.writer.Writer abderaWriter) 
+      throws IOException {
+    throw new UnsupportedOperationException();
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,184 @@
+/*
+* 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.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
+
+/**
+ * <p>Provides a utility class helpful for determining which type of resource
+ * the client is requesting.  Each resource type (e.g. service doc, collection,
+ * entry, edit uri, media resource, etc) is assigned a regex pattern.  Given
+ * the request URI (path and querystring), this will determine which resource
+ * was selected and return an appropriate TargetMatcher.  TargetMatcher is 
+ * essentially just a simplified version of the java.util.regex.Matcher that
+ * also specifies the Resource Type.</p>
+ * 
+ * <pre>
+ *  RequestContext request = ...
+ *  RegexTargetResolver tr = new RegexTargetResolver();
+ *  tr.setPattern("/atom",ResourceType.INTROSPECTION)
+ *    .setPattern("/atom/([^/#?]+)",ResourceType.COLLECTION)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)",ResourceType.ENTRY)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)\\?edit",ResourceType.ENTRY_EDIT)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)\\?media",ResourceType.MEDIA)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)\\?edit-media",ResourceType.MEDIA_EDIT);
+ *  
+ *  Target target = tr.resolve(request);
+ *  System.out.println(target.getType());
+ *  System.out.println(targer.getParameter("foo"));
+ * </pre>
+ *  
+ */
+public class RegexTargetResolver 
+  implements Resolver<Target> {
+
+  private final Map<Pattern, TargetType> patterns;
+  
+  public RegexTargetResolver() {
+    this.patterns = new HashMap<Pattern, TargetType>();
+  }
+  
+  public RegexTargetResolver(Map<String, TargetType> patterns) {
+    this.patterns = new HashMap<Pattern, TargetType>();
+    for (String p : patterns.keySet()) {
+      TargetType type = patterns.get(p);
+      setPattern(p,type);
+    }
+  }
+  
+  public synchronized RegexTargetResolver setPattern(String pattern, TargetType type) {
+    Pattern p = Pattern.compile(pattern);
+    this.patterns.put(p,type);
+    return this;
+  }
+  
+  public Target resolve(Request request) {
+    RequestContext context = (RequestContext) request;
+    String uri = context.getTargetPath();
+    for (Pattern pattern : patterns.keySet()) {
+      Matcher matcher = pattern.matcher(uri);
+      if (matcher.matches()) {
+        TargetType type = patterns.get(pattern);
+        return getTarget(type, context, matcher);
+      }
+    }
+    return null;
+  }
+  
+  protected Target getTarget(
+    TargetType type, 
+    RequestContext request, 
+    Matcher matcher) {
+      return new RegexTarget(type, request, matcher);
+  }
+  
+  public static class RegexTarget
+    extends AbstractTarget
+    implements Target {
+    
+    private static final long serialVersionUID = 165211244926064449L;
+    protected transient Matcher matcher;
+    
+    protected RegexTarget(
+      TargetType type, 
+      RequestContext context, 
+      Matcher matcher) {
+        super(type, context);
+        this.matcher = matcher;
+    }
+    
+    @Override
+    public int hashCode() {
+      final int PRIME = 31;
+      int result = 1;
+      String m = matcher.group(0);
+      String p = matcher.pattern().pattern();
+      result = PRIME * result + super.hashCode();
+      result = PRIME * result + ((m == null) ? 0 : m.hashCode());
+      result = PRIME * result + ((p == null) ? 0 : p.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 RegexTarget other = (RegexTarget) obj;
+      String m = matcher.group(0);
+      String p = matcher.pattern().pattern();
+      String m2 = other.matcher.group(0);
+      String p2 = other.matcher.pattern().pattern();
+      if (!super.equals(obj)) return false;
+      if (m == null) {
+        if (m2 != null)
+          return false;
+      } else if (!m.equals(m2))
+        return false;
+      if (p == null) {
+        if (p2 != null)
+          return false;
+      } else if (!p.equals(p2))
+        return false;
+      if (type == null) {
+        if (other.type != null)
+          return false;
+      } else if (!type.equals(other.type))
+        return false;
+      return true;
+    }
+    
+    public String toString() {
+      String m = matcher.group(0);
+      String p = matcher.pattern().pattern();
+      StringBuilder buf = new StringBuilder();
+      buf.append("RegexTarget[")
+         .append(p)
+         .append(" ==> ")
+         .append(m)
+         .append("] = ")
+         .append(type.toString())
+         .append("\n");
+      String[] params = getParameterNames();
+      for (String param : params) {
+        buf.append("    ")
+           .append(param)
+           .append(" = ")
+           .append(getParameter(param))
+           .append("\n");
+      }
+      return buf.toString();
+    }
+
+    public String getIdentity() {
+      return context.getUri().toString();
+    }
+    
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,57 @@
+/*
+* 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;
+
+
+public class ResponseContextException extends Exception {
+  private static final long serialVersionUID = 3733396309311202018L;
+  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();
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,88 @@
+/*
+* 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.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+/**
+ * A simple base implementation of AbstractResponseContext that makes it a bit 
+ * easier to create custom ResponseContext implementations
+ * 
+ * e.g. new SimpleResponseContext() {
+ *        public boolean hasEntity() { return true; }
+ *        public void writeEntity(Writer writer) { ... }
+ *      }
+ */
+public abstract class SimpleResponseContext 
+  extends AbstractResponseContext {
+  
+  protected String encoding = "UTF-8";
+  
+  protected SimpleResponseContext() {
+    this(null);
+  }
+  
+  protected SimpleResponseContext(String encoding) {
+    this.encoding = encoding != null ? encoding : "UTF-8";
+  }
+  
+  protected SimpleResponseContext setEncoding(String encoding) {
+    this.encoding = encoding;
+    return this;
+  }
+  
+  protected String getEncoding() {
+    return this.encoding;
+  }
+  
+  public void writeTo(
+    OutputStream out) 
+      throws IOException {
+    if (hasEntity())
+      writeTo(new OutputStreamWriter(out,encoding));
+  }
+  
+  public void writeTo(
+    Writer writer) 
+      throws IOException {
+    if (hasEntity())
+      writeEntity(writer);
+  }
+  
+  protected abstract void writeEntity(
+    Writer writer) 
+      throws IOException;
+  
+  public void writeTo(
+    OutputStream out, 
+    org.apache.abdera.writer.Writer writer)
+      throws IOException {
+    throw new UnsupportedOperationException();
+  }
+  
+  public void writeTo(
+    Writer javaWriter,
+    org.apache.abdera.writer.Writer abderaWriter) 
+      throws IOException {
+    throw new UnsupportedOperationException();
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,108 @@
+/*
+* 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.Serializable;
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.RequestContext;
+
+public class SimpleSubjectResolver 
+  implements Resolver<Subject> {
+
+  public static final Principal ANONYMOUS = new AnonymousPrincipal();
+  
+  public Subject resolve(Request request) {
+    RequestContext context = (RequestContext) request;
+    return resolve(context.getPrincipal());
+  }
+  
+  public Subject resolve(Principal principal) {
+    Subject subject = new Subject();
+    subject.getPrincipals().add((principal != null) ? principal : ANONYMOUS);
+    return subject;
+  }
+
+  public Subject resolve(String userid) {
+    if (userid == null) return resolve(ANONYMOUS);
+    return resolve(new SimplePrincipal(userid));
+  }
+
+  static class SimplePrincipal 
+    implements Principal, 
+               Serializable {
+    private static final long serialVersionUID = 7161420960293729670L;
+    final String name;
+    SimplePrincipal(String name) {
+      this.name = name;
+    }
+    public String getName() {
+      return name;
+    }
+    public String toString() {
+      return name;
+    }
+    @Override
+    public int hashCode() {
+      final int PRIME = 31;
+      int result = 1;
+      result = PRIME * result + ((name == null) ? 0 : name.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 SimplePrincipal other = (SimplePrincipal) obj;
+      if (name == null) {
+        if (other.name != null) return false;
+      } else if (!name.equals(other.name))
+        return false;
+      return true;
+    }
+    
+  }
+  
+  public static final class AnonymousPrincipal 
+    implements Principal, 
+               Serializable {
+    private static final long serialVersionUID = -5050930075733261944L;
+    final String name = "Anonymous";
+    public String getName() {
+      return name;
+    }
+    public String toString() {
+      return name;
+    }
+    public boolean equals(Object other) {
+      if (other == null) return false;
+      return this == other;
+    }
+    public int hashCode() {
+      final int PRIME = 31;
+      int result = 1;
+      result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+      return result;
+    }
+  }
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SingletonProviderManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SingletonProviderManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SingletonProviderManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SingletonProviderManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,33 @@
+/*
+* 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 org.apache.abdera.protocol.server.Provider;
+
+public class SingletonProviderManager 
+  extends AbstractSingletonProviderManager {
+
+  @Override
+  protected Provider initProvider() {
+    return provider;
+  }
+
+  public void setProvider(Provider provider) {
+    this.provider = provider;
+  }
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,125 @@
+/*
+ * 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.Writer;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.writer.StreamWriter;
+
+/**
+ * Abstract base class for creating ResponseContext implementations that use
+ * the StreamWriter interface.  Using the StreamWriter to write out documents
+ * is significantly faster than using the object model but requires developers
+ * to know more about proper Atom syntax.
+ */
+public abstract class StreamWriterResponseContext 
+  extends SimpleResponseContext {
+  
+  private final Abdera abdera;
+  private final String sw;
+  private boolean autoindent;
+  
+  /**
+   * Create a new StreamWriterResponseContext
+   * @param abdera The Abdera instance
+   */
+  protected StreamWriterResponseContext(
+    Abdera abdera) {
+      this(abdera,null,null);
+  }
+
+  /**
+   * Create a new StreamWriterResponseContext
+   * @param abdera The Abdera instance
+   * @param encoding The charset encoding
+   */
+  protected StreamWriterResponseContext(
+      Abdera abdera,
+      String encoding) {
+        this(abdera,encoding,null);
+  }
+  
+  /**
+   * Create a new StreamWriterResponseContext
+   * @param abdera The Abdera instance
+   * @param encoding The charset encoding
+   * @param sw The name of the Named StreamWriter to use
+   */
+  protected StreamWriterResponseContext(
+    Abdera abdera,
+    String encoding,
+    String sw) {
+      super(encoding);
+      this.abdera = abdera;
+      this.sw = sw;
+  }
+  
+  /**
+   * Get the Abdera instance
+   */
+  protected final Abdera getAbdera() {
+    return abdera;
+  }
+  
+  /**
+   * Create a new StreamWriter instance.  If the sw property was set,
+   * the specified Named StreamWriter will be returned
+   */
+  protected StreamWriter newStreamWriter() {
+    return sw == null ? 
+      abdera.newStreamWriter() : 
+      abdera.getWriterFactory().newStreamWriter(sw);
+  }
+  
+  protected void writeEntity(
+    Writer writer) 
+      throws IOException {
+    writeTo(
+      newStreamWriter()
+        .setWriter(writer)
+        .setAutoIndent(autoindent));
+  }
+  
+  /**
+   * Write to the specified StreamWriter.  Subclasses of this class must
+   * implement this method.
+   */
+  protected abstract void writeTo(StreamWriter sw) throws IOException;
+  
+  /**
+   * True to enable automatic indenting on the StreamWriter
+   */
+  public StreamWriterResponseContext setAutoIndent(boolean autoindent) {
+    this.autoindent = autoindent;
+    return this;
+  }
+  
+  /**
+   * True if automatic indenting is enabled on the StreamWriter
+   */
+  public boolean getAutoIndent() {
+    return this.autoindent;
+  }
+
+  public boolean hasEntity() {
+    return true;
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/AbstractBasicAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/AbstractBasicAdapter.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/AbstractBasicAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/AbstractBasicAdapter.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,149 @@
+/*
+* 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 java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+
+public abstract class AbstractBasicAdapter implements BasicAdapter {
+  public static Logger logger =
+    Logger.getLogger(AbstractBasicAdapter.class.getName());
+
+  protected Properties feedProperties;
+  protected final String feedId;
+  protected final Abdera abdera;
+
+  public static final String GBASE_NS = "http://base.google.com/ns/1.0";
+  public static final String GBASE_NS_PREFIX = "g";
+
+  protected static final String PROP_NAME_FEED_URI = "feedUri";
+  protected static final String PROP_NAME_TITLE = "title";
+  protected static final String PROP_NAME_AUTHOR = "author";
+
+  public static final String ENTRY_ELEM_NAME_ID = "id";
+  public static final String ENTRY_ELEM_NAME_TITLE = "title";
+  public static final String ENTRY_ELEM_NAME_AUTHOR = "author";
+  public static final String ENTRY_ELEM_NAME_UPDATED = "updated";
+
+  protected AbstractBasicAdapter(Abdera abdera, Properties feedProperties,
+      String feedId) {
+    this.abdera = abdera;
+    this.feedProperties = feedProperties;
+    this.feedId = feedId;
+  }
+
+  public String getProperty(String key) throws Exception {
+    String val = feedProperties.getProperty(key);
+    if (val == null) {
+      logger.warning("Cannot find property " + key +
+          "in Adapter properties file for feed " + feedId);
+      throw new RuntimeException();
+    }
+    return val;
+  }
+
+  protected Feed createFeed() throws Exception {
+    Feed feed = abdera.newFeed();
+    feed.setId(getProperty(PROP_NAME_FEED_URI));
+    feed.setTitle(getProperty(PROP_NAME_TITLE));
+    feed.setUpdated(new Date());
+    feed.addAuthor(getProperty(PROP_NAME_AUTHOR));
+    return feed;
+  }
+
+  protected void addEditLinkToEntry(Entry entry) throws Exception {
+    if (getEditUriFromEntry(entry) == null) {
+      entry.addLink(entry.getId().toString(), "edit");
+    }
+  }
+
+  //TODO: this should be moved to a Util class
+  public static String getEditUriFromEntry(Entry entry) throws Exception {
+    String editUri = null;
+    List<Link> editLinks = entry.getLinks("edit");
+    for (Link link : editLinks) {
+      // if there is more than one edit link, we should not automatically
+      // assume that it's always going to point to an Atom document
+      // representation.
+      if (link.getMimeType() != null) {
+        if (link.getMimeType().match("application/atom+xml")) {
+          editUri = link.getResolvedHref().toString();
+          break;
+        }
+      } else {
+        // edit link with no type attribute is the right one to use
+        editUri = link.getResolvedHref().toString();
+        break;
+      }
+    }
+   return editUri;
+  }
+
+  protected void setEntryIdIfNull(Entry entry) throws Exception{
+    // if there is no id in Entry, assign one.
+    if (entry.getId() != null) {
+      return;
+    }
+    String uuidUri = abdera.getFactory().newUuidUri();
+    String[] segments = uuidUri.split(":");
+    String entryId = segments[segments.length - 1];
+    entry.setId(createEntryIdUri(entryId));
+  }
+
+  protected String createEntryIdUri(String entryId) throws Exception{
+    return getProperty(PROP_NAME_FEED_URI) + "/" + entryId;
+  }
+
+  protected Map<String, Object> collectColumns(Entry entry) {
+    Map<String, Object> columns = new HashMap<String, Object>();
+
+    if (entry.getId() != null) {
+      columns.put(ENTRY_ELEM_NAME_ID, entry.getId().toString());
+    }
+    if (entry.getAuthor() != null) {
+      columns.put(ENTRY_ELEM_NAME_AUTHOR, entry.getAuthor().getText());
+    }
+    if (entry.getTitle() != null) {
+      columns.put(ENTRY_ELEM_NAME_TITLE, entry.getTitle());
+    }
+    if (entry.getUpdated() != null) {
+      columns.put(ENTRY_ELEM_NAME_UPDATED, entry.getUpdated());
+    }
+
+    // get all our namespace extension elements
+    List<Element> extElements = entry.getExtensions(GBASE_NS);
+    if (extElements != null) {
+      for (Element element : extElements) {
+        String name = element.getQName().getLocalPart();
+        String value = element.getText();
+        columns.put(name, value);
+      }
+    }
+    return columns;
+  }
+}
\ No newline at end of file

Added: 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=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,44 @@
+/*
+* 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.model.Entry;
+import org.apache.abdera.model.Feed;
+
+public interface BasicAdapter {
+
+  public Feed getFeed() 
+    throws Exception;
+
+  public Entry getEntry(
+    Object entryId) 
+      throws Exception;
+
+  public Entry createEntry(
+    Entry entry) 
+      throws Exception;
+
+  public Entry updateEntry(
+    Object entryId, 
+    Entry entry) 
+      throws Exception;
+
+  public boolean deleteEntry(
+    Object entryId) 
+      throws Exception;
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapterManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapterManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapterManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapterManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,114 @@
+/*
+* 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 java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.apache.abdera.Abdera;
+
+public class BasicAdapterManager {
+  public static Logger logger =
+    Logger.getLogger(BasicAdapterManager.class.getName());
+
+  protected static final String PROP_NAME_ADAPTER_CLASS = "adapterClassName";
+  protected static final String PROPERTIES_PATH = "/abdera/adapter/";
+  protected static final String PROPERTIES_FILE_SUFFIX = ".properties";
+
+  protected static BasicAdapterManager basicAdapterManager = null;
+
+  // maps a feed id to an adapter instance
+  protected Map<String, BasicAdapter> adapterInstanceMap =
+      new HashMap<String, BasicAdapter>();
+
+  protected Abdera abdera;
+
+  public BasicAdapterManager(Abdera abdera) {
+    this.abdera = abdera;
+  }
+  
+  public BasicAdapter getAdapter(String feedId) throws Exception {
+    BasicAdapter basicAdapter = adapterInstanceMap.get(feedId);
+    if (basicAdapter != null) {
+      return basicAdapter;
+    }
+
+    // load the feed properties file
+    Properties properties = loadFeedInfo(feedId);
+    String className = properties.getProperty(PROP_NAME_ADAPTER_CLASS);
+    if (className == null) {
+      logger.warning("property '" + PROP_NAME_ADAPTER_CLASS +
+          "' not found for feed '" + feedId + "'");
+      throw new RuntimeException();
+    }
+
+    return createAdapterInstance(feedId, className, properties);
+   }
+
+  protected Properties loadFeedInfo(String feedId)
+    throws Exception {
+    String fileName = PROPERTIES_PATH + feedId + PROPERTIES_FILE_SUFFIX;
+    InputStream in = this.getClass().getResourceAsStream(fileName);
+    if (in == null) {
+      throw new FileNotFoundException();
+    }
+    Properties props = new Properties();
+    props.load(in);
+    in.close();
+    return props;
+  }
+
+  protected synchronized BasicAdapter createAdapterInstance(
+    String feedId,
+    String className, 
+    Properties properties) 
+      throws Exception {
+    BasicAdapter basicAdapter = adapterInstanceMap.get(feedId);
+    if (basicAdapter != null) {
+      return basicAdapter;
+    }
+    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+    Class<?> adapterClass = cl.loadClass(className);
+    Constructor<?>[] ctors = adapterClass.getConstructors();
+    for (Constructor<?> element : ctors) {
+      logger.finest("Public constructor found: " +
+        element.toString());
+    }
+    Constructor<?> c = 
+      adapterClass.getConstructor(
+        new Class[] {
+          Abdera.class,
+          Properties.class, 
+          String.class});
+    c.setAccessible(true);
+    BasicAdapter adapterInstance = 
+      (BasicAdapter) c.newInstance(
+        abdera, 
+        properties,
+        feedId);
+
+    // put this adapter instance in adapterInstanceMap
+    adapterInstanceMap.put(feedId, adapterInstance);
+    return adapterInstance;
+  }
+}
\ No newline at end of file

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=613765&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 Sun Jan 20 21:33:46 2008
@@ -0,0 +1,182 @@
+/*
+* 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 java.util.logging.Logger;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.server.CollectionAdapter;
+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.Target;
+import org.apache.abdera.protocol.server.impl.AbstractWorkspaceManagerProvider;
+import org.apache.abdera.protocol.server.impl.EmptyResponseContext;
+import org.apache.abdera.util.MimeTypeHelper;
+
+@SuppressWarnings("unchecked")
+public class BasicProvider 
+  extends AbstractWorkspaceManagerProvider
+  implements CollectionAdapter {
+    
+  public CollectionAdapter getCollectionAdapter(
+    RequestContext request) {
+      return this;
+  }
+
+  public static final String PARAM_ENTRY = "entry";
+  public static final String PARAM_FEED = "feed";
+
+  private static final boolean CREATE_FLAG = true;
+  private static final boolean UPDATE_FLAG = false;
+
+  public static Logger logger = Logger.getLogger(
+      BasicProvider.class.getName());
+
+  public static BasicAdapterManager basicAdapterManager;
+
+  private ResponseContext createOrUpdateEntry(RequestContext request,
+      boolean createFlag) {
+    try {
+      MimeType mimeType = request.getContentType();
+      String contentType = mimeType == null ? null : mimeType.toString();
+      if (contentType != null && !MimeTypeHelper.isAtom(contentType) &&
+          !MimeTypeHelper.isXml(contentType)) {
+        // unsupported media type
+        return new EmptyResponseContext(415);
+      }
+
+      Abdera abdera = request.getServiceContext().getAbdera();
+      Parser parser = abdera.getParser();
+      Entry inputEntry = (Entry) request.getDocument(parser).getRoot();
+
+      Target target = request.getTarget();
+      String feedId = target.getParameter(PARAM_FEED);
+      String entryId = createFlag == UPDATE_FLAG
+          ? target.getParameter(PARAM_ENTRY) : null;
+
+      BasicAdapter basicAdapter = getAdapterManagerInstance(request).getAdapter(feedId);
+      Entry newEntry = createFlag == CREATE_FLAG
+          ? basicAdapter.createEntry(inputEntry)
+          : basicAdapter.updateEntry(entryId, inputEntry);
+      if (newEntry != null) {
+        Document<Entry> newEntryDoc = newEntry.getDocument();
+        ResponseContext response =
+          new BasicResponseContext<Document<Entry>>(newEntryDoc, createFlag ? 201 : 200);
+        String loc = newEntry.getEditLinkResolvedHref().toString();
+        response.setLocation(loc);
+        return response;
+      } else {
+        return new EmptyResponseContext(404);
+      }
+    } catch (Exception e) {
+      EmptyResponseContext response = new EmptyResponseContext(500);
+      response.setStatusText(e.getMessage());
+      return response;
+    }
+  }
+
+  private BasicAdapterManager getAdapterManagerInstance(RequestContext request) {
+    if (basicAdapterManager == null) {
+      basicAdapterManager =
+        new BasicAdapterManager(request.getServiceContext().getAbdera());
+    }
+    return basicAdapterManager;
+  }
+
+  public ResponseContext postEntry(RequestContext request) {
+    return createOrUpdateEntry(request, CREATE_FLAG);
+  }
+  
+  public ResponseContext deleteEntry(RequestContext request) {
+    Target target = request.getTarget();
+    String feedId = target.getParameter(PARAM_FEED);
+    String entryId = target.getParameter(PARAM_ENTRY);
+
+    try {
+      BasicAdapter basicAdapter = getAdapterManagerInstance(request).getAdapter(feedId);
+      if (basicAdapter.deleteEntry(entryId)) {
+        return new EmptyResponseContext(200);
+      } else { // entry not found
+        return new EmptyResponseContext(404);
+      }
+    } catch (Exception e) {
+      EmptyResponseContext response = new EmptyResponseContext(500);
+      response.setStatusText(e.getMessage());
+      return response;
+    }
+  }
+
+  public ResponseContext putEntry(RequestContext request) {
+    return createOrUpdateEntry(request, UPDATE_FLAG);
+  }
+
+  public ResponseContext getEntry(RequestContext request) {
+    Target target = request.getTarget();
+    String feedId = target.getParameter(PARAM_FEED);
+    String entryId = target.getParameter(PARAM_ENTRY);
+
+    try {
+      BasicAdapter basicAdapter = getAdapterManagerInstance(request).getAdapter(feedId);
+      Entry entry = basicAdapter.getEntry(entryId);
+      if (entry != null) {
+        Document<Entry> entryDoc = entry.getDocument();
+        return new BasicResponseContext<Document<Entry>>(entryDoc,200);
+      } else {
+        return new EmptyResponseContext(404);
+      }
+    } catch (Exception e) {
+      EmptyResponseContext response = new EmptyResponseContext(500);
+      response.setStatusText(e.getMessage());
+      return response;
+    }
+  }
+
+  public ResponseContext getFeed(RequestContext request) {
+    Target target = request.getTarget();
+    String feedId = target.getParameter(PARAM_FEED);
+    try {
+      BasicAdapter basicAdapter = getAdapterManagerInstance(request).getAdapter(feedId);
+      Feed feed = basicAdapter.getFeed();
+      if (feed != null) {
+        Document<Feed> feedDoc = feed.getDocument();
+        return new BasicResponseContext<Document<Feed>>(feedDoc, 200);
+      } else {
+        return new EmptyResponseContext(404);
+      }
+    } catch (Exception e) {
+      EmptyResponseContext response = new EmptyResponseContext(500);
+      response.setStatusText(e.getMessage());
+      return response;
+    }
+  }
+
+  public ResponseContext extensionRequest(RequestContext request) {
+    return ProviderHelper.notallowed(
+      request, 
+      "Method Not Allowed", 
+      this.getMethods(request));
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProviderManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProviderManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProviderManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProviderManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,31 @@
+/*
+* 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.Provider;
+import org.apache.abdera.protocol.server.impl.AbstractSingletonProviderManager;
+
+public class BasicProviderManager 
+  extends AbstractSingletonProviderManager {
+
+  @Override
+  protected Provider initProvider() {
+    return new BasicProvider();
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,47 @@
+/*
+* 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 java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.abdera.model.Base;
+import org.apache.abdera.protocol.server.impl.BaseResponseContext;
+
+public class BasicResponseContext<T extends Base>
+  extends BaseResponseContext<T> {
+
+  protected T base;
+
+  public BasicResponseContext(T t, int status) {
+    super(t);
+    base = t;
+    setStatus(status);
+  }
+
+  @Override
+  public void writeTo(OutputStream out) throws IOException {
+    if (hasEntity()) {
+      if (writer == null) {
+        base.writeTo(out);  // TODO: JSON here
+      } else {
+        writeTo(out, writer);  // TODO: JSON here
+      }
+    }
+  }
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicServiceContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicServiceContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicServiceContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,30 @@
+/*
+* 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.impl.DefaultServiceContext;
+
+public class BasicServiceContext 
+  extends DefaultServiceContext {
+
+  public BasicServiceContext() {
+    this.defaultprovidermanager = BasicProviderManager.class.getName();
+    this.defaulttargetresolver = BasicTargetResolver.class.getName();
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicTargetResolver.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicTargetResolver.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicTargetResolver.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,93 @@
+/*
+* 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+
+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.impl.RegexTargetResolver;
+
+public class BasicTargetResolver 
+  extends RegexTargetResolver {
+
+  public BasicTargetResolver() {
+    setPattern("/" + "([^/#?]+)", TargetType.TYPE_COLLECTION);
+    setPattern("/" + "([^/#?]+)/([^/#?]+)", TargetType.TYPE_ENTRY);
+  }
+
+  @Override
+  protected Target getTarget(
+    TargetType type,
+    RequestContext request,
+    Matcher matcher) {
+      return new FeedServerTarget(type, request, matcher);
+  }
+
+  private static final class FeedServerTarget extends RegexTarget {
+
+    protected FeedServerTarget(
+      TargetType type,
+      RequestContext context,
+      Matcher matcher) {
+        super(type, context, matcher);
+    }
+
+    @Override
+    public String getParameter(String name) {
+      TargetType type = getType();
+
+      if (type.equals(TargetType.TYPE_COLLECTION) ||
+          type.equals(TargetType.TYPE_ENTRY)) {
+        if (name.equalsIgnoreCase(BasicProvider.PARAM_FEED)) {
+          return matcher.group(1);
+        }
+      }
+
+      if (type.equals(TargetType.TYPE_ENTRY)) {
+        if (name.equalsIgnoreCase(BasicProvider.PARAM_ENTRY)) {
+          return matcher.group(2);
+        }
+      }
+
+      return super.getParameter(name);
+    }
+
+    @Override
+    public String[] getParameterNames() {
+      List<String> paramNames = new ArrayList<String>();
+      paramNames.addAll(Arrays.asList(super.getParameterNames()));
+      TargetType type = getType();
+      if (type.equals(TargetType.TYPE_COLLECTION) ||
+          type.equals(TargetType.TYPE_ENTRY)) {
+        paramNames.add(BasicProvider.PARAM_FEED);
+      }
+
+      if (type.equals(TargetType.TYPE_ENTRY)) {
+        paramNames.add(BasicProvider.PARAM_ENTRY);
+      }
+
+      return paramNames.toArray(new String[0]);
+    }
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/SampleBasicAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/SampleBasicAdapter.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/SampleBasicAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/SampleBasicAdapter.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,138 @@
+/*
+* 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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+
+public class SampleBasicAdapter extends AbstractBasicAdapter implements BasicAdapter {
+  private static final String ERROR_DUP_ENTRY = "Entry Already Exists";
+  private static final String ERROR_INVALID_ENTRY = "No Such Entry in the Feed";
+
+  public static Logger logger = Logger.getLogger(SampleBasicAdapter.class.getName());
+  protected HashMap<String, byte[]> entries = new HashMap<String, byte[]>();
+
+  public SampleBasicAdapter(Abdera abdera, Properties feedProperties,
+    String feedId) {
+    super(abdera, feedProperties, feedId);
+  }
+
+  public Feed getFeed() throws Exception {
+    Feed feed = createFeed();
+
+    // get all keys in the feed - with keys in descending order of
+    // lastUpdatedDate
+    Set<String> keys = entries.keySet();
+    for (String s : keys) {
+      Entry entry = getEntry(s);
+      // TODO: why clone this? Abdera seems to mess up the object
+      // if we pass the reference to this object
+      feed.addEntry((Entry) entry.clone());
+    }
+    return feed;
+  }
+
+  public Entry getEntry(Object entryId)  throws Exception {
+    return retrieveEntry((String) entryId);
+  }
+
+  public Entry createEntry(Entry entry) throws Exception {
+    // entryId may be null. if it is, assign one
+    setEntryIdIfNull(entry);
+    logger.info("assigning id to Entry: " + entry.getId().toString());
+    String entryId = getEntryIdFromUri(entry.getId().toString());
+
+    if (entries.containsKey(entryId)) {
+      throw new Exception(ERROR_DUP_ENTRY);
+    }
+    // add an "updated" element if one was not provided
+    if (entry.getUpdated() == null) {
+      entry.setUpdated(new Date());
+    }
+    addEditLinkToEntry(entry);
+    storeEntry(entryId, entry);
+    logger.finest("returning this entry from sampleadapter.createEntry: " +
+        entry.toString());
+    return entry;
+  }
+
+  public Entry updateEntry(Object entryId, Entry entry) throws Exception {
+    if (!entries.containsKey(entryId)) {
+      throw new Exception(ERROR_INVALID_ENTRY);
+    }
+    entries.remove(entryId);
+    // add an "updated" element if one was not provided
+    if (entry.getUpdated() == null) {
+      entry.setUpdated(new Date());
+    }
+    addEditLinkToEntry(entry);
+    storeEntry((String) entryId, entry);
+    logger.finest("returning this entry from sampleadapter.updateEntry: " +
+        entry.toString());
+    return entry;
+  }
+
+  public boolean deleteEntry(Object entryId) throws Exception {
+    if (!entries.containsKey(entryId)) {
+      return false;
+    }
+    entries.remove(entryId);
+    return true;
+  }
+
+  protected String getEntryIdFromUri(String uri) {
+    String[] segments = uri.split("/");
+    return segments[segments.length - 1];
+  }
+
+  protected void storeEntry(String entryId, Entry entry) throws Exception {
+    Document<Element> entryDoc = entry.getDocument();
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    entryDoc.writeTo(bos);
+
+    // Get the bytes of the serialized object and store in hashmap
+    byte[] buf = bos.toByteArray();
+    bos.close();
+    entries.put(entryId, buf);
+  }
+
+  protected Entry retrieveEntry(String entryId) throws Exception {
+    // Deserialize from a byte array
+    byte[] bytes = entries.get(entryId);
+    if (bytes == null) {
+      // entry not found
+      return null;
+    }
+    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+    Document<Entry> entryDoc = abdera.getParser().parse(in);
+    Entry entry = entryDoc.getRoot();
+    return entry;
+  }
+}
+



Mime
View raw message