You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/02/23 17:20:42 UTC

svn commit: r915409 [1/2] - in /incubator/chemistry/trunk/chemistry: chemistry-api/src/main/java/org/apache/chemistry/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-client/src/main/java/org/apache/chemist...

Author: fguillaume
Date: Tue Feb 23 16:20:40 2010
New Revision: 915409

URL: http://svn.apache.org/viewvc?rev=915409&view=rev
Log:
CMIS-127: Better way to register Repository instances and look them up

Added:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPContext.java
      - copied, changed from r912590, incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepositoryService.java   (with props)
Removed:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryFactory.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPContentManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Repository.java
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryService.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPServiceDocumentReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPType.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeEntryReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractEntryReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractFeedReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/EntryReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/FeedReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ServiceDocumentReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectEntryReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedTreeReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestServiceDocumentReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestTypeFeedReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCheckedOutCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISParentsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/servlet/CMISServlet.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubAbderaServlet.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Repository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Repository.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Repository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Repository.java Tue Feb 23 16:20:40 2010
@@ -28,21 +28,29 @@
  */
 public interface Repository extends RepositoryEntry, TypeManager {
 
+    /** The connection parameter key for the user name. */
+    public static final String PARAM_USERNAME = "username";
+
+    /** The connection parameter key for the user password. */
+    public static final String PARAM_PASSWORD = "password";
+
     /**
      * Gets a new connection to this repository.
      *
+     * @param params the connection parameters
      * @return the connection
      */
-    Connection getConnection(Map<String, Serializable> parameters);
+    Connection getConnection(Map<String, Serializable> params);
 
     /**
      * Gets a new connection using the SPI for this repository.
      * <p>
      * The SPI is a connection providing access to lower-level features.
      *
+     * @param params the connection parameters
      * @return the SPI connection
      */
-    SPI getSPI();
+    SPI getSPI(Map<String, Serializable> params);
 
     /**
      * Gets an extension service on this repository.

Added: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java?rev=915409&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java Tue Feb 23 16:20:40 2010
@@ -0,0 +1,90 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * Entry point for Java code wishing to get to registered CMIS repositories, or
+ * to register new ones for the current JVM.
+ */
+public class RepositoryManager implements RepositoryService {
+
+    protected static RepositoryManager instance;
+
+    protected List<RepositoryService> services = new CopyOnWriteArrayList<RepositoryService>();
+
+    public static RepositoryManager getInstance() {
+        if (instance == null) {
+            synchronized (RepositoryManager.class) {
+                if (instance == null) {
+                    instance = new RepositoryManager();
+                }
+            }
+        }
+        return instance;
+    }
+
+    public synchronized void registerService(RepositoryService service) {
+        if (service == this) {
+            // avoid stupid errors
+            throw new IllegalArgumentException();
+        }
+        if (services.contains(service)) {
+            throw new IllegalArgumentException();
+        }
+        services.add(service);
+    }
+
+    public synchronized void unregisterService(RepositoryService service) {
+        if (!services.remove(service)) {
+            throw new IllegalArgumentException();
+        }
+    }
+
+    public Repository getDefaultRepository() {
+        for (RepositoryService service : services) {
+            Repository repository = service.getDefaultRepository();
+            if (repository != null) {
+                return repository;
+            }
+        }
+        return null;
+    }
+
+    public Collection<RepositoryEntry> getRepositories() {
+        List<RepositoryEntry> entries = new ArrayList<RepositoryEntry>(1);
+        for (RepositoryService service : services) {
+            entries.addAll(service.getRepositories());
+        }
+        return entries;
+    }
+
+    public Repository getRepository(String repositoryId) {
+        for (RepositoryService service : services) {
+            Repository repository = service.getRepository(repositoryId);
+            if (repository != null) {
+                return repository;
+            }
+        }
+        return null;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryService.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryService.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/RepositoryService.java Tue Feb 23 16:20:40 2010
@@ -20,6 +20,11 @@
 
 /**
  * CMIS Repository Service.
+ * <p>
+ * An instance of this class is retrieved through the global
+ * {@link RepositoryManager}.
+ *
+ * @see RepositoryManager
  */
 public interface RepositoryService {
 
@@ -43,6 +48,7 @@
      * Gets a repository identified by its ID.
      *
      * @param repositoryId the repository ID
+     * @return the repository, or {@code null} if not found
      */
     Repository getRepository(String repositoryId);
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java Tue Feb 23 16:20:40 2010
@@ -61,7 +61,6 @@
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.URITemplate;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.XmlProperty;
 import org.apache.chemistry.impl.simple.SimpleListPage;
 import org.apache.chemistry.impl.simple.SimpleObjectId;
@@ -79,10 +78,11 @@
 
     protected APPFolder root;
 
-    public APPConnection(APPRepository repository) {
+    public APPConnection(APPRepository repository,
+            Map<String, Serializable> params) {
         this.repository = repository;
-        connector = new Connector(repository.getContentManager().getClient(),
-                new ReadContext(this));
+        connector = new Connector(repository.getClient(params),
+                new APPContext(this));
     }
 
     public Connection getConnection() {
@@ -102,10 +102,6 @@
         return repository;
     }
 
-    public Connector getConnector() {
-        return connector;
-    }
-
     public Folder getRootFolder() {
         if (root == null) {
             root = (APPFolder) getObject(repository.info.getRootFolderId());
@@ -113,10 +109,6 @@
         return root;
     }
 
-    public String getBaseUrl() {
-        return repository.cm.getBaseUrl();
-    }
-
     /*
      * ----- Factories -----
      */

Copied: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPContext.java (from r912590, incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java)
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPContext.java?p2=incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPContext.java&p1=incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java&r1=912590&r2=915409&rev=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPContext.java Tue Feb 23 16:20:40 2010
@@ -15,34 +15,39 @@
  *     Bogdan Stefanescu, Nuxeo
  *     Florent Guillaume, Nuxeo
  */
-package org.apache.chemistry.atompub.client.stax;
+package org.apache.chemistry.atompub.client;
 
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.Repository;
-import org.apache.chemistry.atompub.client.ContentManager;
 
 /**
- *
+ * A context for the current AtomPub operations.
+ * <p>
+ * Used to construct new objects.
  */
-public class ReadContext {
+public class APPContext {
 
-    protected Repository repository;
+    protected APPRepositoryService repositoryService;
 
-    protected Connection connection;
+    protected APPRepository repository;
 
-    protected ContentManager contentManager;
+    protected APPConnection connection;
 
-    public ReadContext(Connection connection) {
+    public APPContext(APPConnection connection) {
         this.connection = connection;
-        this.repository = connection.getRepository();
+        this.repository = (APPRepository) connection.getRepository();
     }
 
-    public ReadContext(Repository repository) {
+    public APPContext(APPRepository repository) {
         this.repository = repository;
     }
 
-    public ReadContext(ContentManager contentManager) {
-        this.contentManager = contentManager;
+    public APPContext(APPRepositoryService repositoryService) {
+        this.repositoryService = repositoryService;
+    }
+
+    public APPRepositoryService getRepositoryService() {
+        return repositoryService;
     }
 
     public Repository getRepository() {
@@ -53,8 +58,4 @@
         return connection;
     }
 
-    public ContentManager getContentManager() {
-        return contentManager;
-    }
-
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java Tue Feb 23 16:20:40 2010
@@ -29,7 +29,6 @@
 import org.apache.chemistry.Tree;
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.client.stax.AbstractObjectReader;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.XmlProperty;
 import org.apache.chemistry.xml.stax.StaxReader;
 
@@ -39,7 +38,7 @@
 public class APPObjectEntryReader extends AbstractObjectReader<APPObjectEntry> {
 
     @Override
-    protected APPObjectEntry createObject(ReadContext ctx) {
+    protected APPObjectEntry createObject(APPContext ctx) {
         APPConnection connection = (APPConnection) ctx.getConnection();
         return new APPObjectEntry(connection,
                 new HashMap<String, XmlProperty>(), null);
@@ -68,7 +67,7 @@
     }
 
     @Override
-    protected void readAtomElement(ReadContext ctx, StaxReader reader,
+    protected void readAtomElement(APPContext ctx, StaxReader reader,
             APPObjectEntry object) throws XMLStreamException {
         QName name = reader.getName();
         if (AtomPub.ATOM_CONTENT.equals(name)) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java Tue Feb 23 16:20:40 2010
@@ -36,7 +36,6 @@
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.URITemplate;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.impl.simple.SimpleTypeManager;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.logging.Log;
@@ -49,9 +48,9 @@
 
     private static final Log log = LogFactory.getLog(APPRepository.class);
 
-    protected final APPContentManager cm;
+    protected final APPRepositoryService rs;
 
-    protected final Connector connector;
+    protected final Connector typesConnector;
 
     protected RepositoryInfo info;
 
@@ -63,13 +62,14 @@
 
     protected final Map<String, URITemplate> uriTemplates = new HashMap<String, URITemplate>();
 
-    public APPRepository(APPContentManager cm) {
-        this(cm, null);
+    public APPRepository(APPRepositoryService rs) {
+        this(rs, null);
     }
 
-    public APPRepository(APPContentManager cm, RepositoryInfo info) {
-        this.cm = cm;
-        connector = new Connector(cm.getClient(), new ReadContext(this));
+    public APPRepository(APPRepositoryService rs, RepositoryInfo info) {
+        this.rs = rs;
+        typesConnector = new Connector(rs.getDefaultClient(), new APPContext(
+                this));
         this.info = info;
     }
 
@@ -77,12 +77,8 @@
         this.info = info;
     }
 
-    public APPContentManager getContentManager() {
-        return cm;
-    }
-
-    public HttpClient client() {
-        return cm.getClient();
+    public HttpClient getClient(Map<String, Serializable> params) {
+        return rs.getClient(params);
     }
 
     public String getId() {
@@ -100,14 +96,21 @@
         return info.getThinClientURI();
     }
 
-    public SPI getSPI() {
+    public SPI getSPI(Map<String, Serializable> params) {
         loadTypes();
-        return new APPConnection(this);
+        return new APPConnection(this, params);
     }
 
-    public Connection getConnection(Map<String, Serializable> parameters) {
+    /**
+     * {@inheritDoc}
+     * <p>
+     * The connection parameters should use
+     * {@link APPRepositoryService#PARAM_USERNAME} and
+     * {@link APPRepositoryService#PARAM_PASSWORD} as parameter keys.
+     */
+    public Connection getConnection(Map<String, Serializable> params) {
         loadTypes();
-        return new APPConnection(this);
+        return new APPConnection(this, params);
     }
 
     public void addCollection(String type, String href) {
@@ -216,7 +219,7 @@
 
     protected TypeManager readTypes(String href) throws Exception {
         href = includePropertyDefinitionsInURI(href);
-        return connector.getTypeFeed(href, true);
+        return typesConnector.getTypeFeed(href, true);
     }
 
     protected static String includePropertyDefinitionsInURI(String href) {

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java?rev=915409&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java Tue Feb 23 16:20:40 2010
@@ -0,0 +1,171 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ *     Bogdan Stefanescu, Nuxeo
+ *     Florent Guillaume, Nuxeo
+ *     Chris Hubick
+ */
+package org.apache.chemistry.atompub.client;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryEntry;
+import org.apache.chemistry.RepositoryService;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScheme;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.auth.CredentialsProvider;
+
+/**
+ * A {@link RepositoryService} providing the repositories found through an
+ * AtomPub Service Document, configured through a URL.
+ */
+public class APPRepositoryService implements RepositoryService {
+
+    protected final String url;
+
+    protected final Map<String, Serializable> urlParams;
+
+    protected final List<HttpClient> clients = new ArrayList<HttpClient>(2);
+
+    protected final List<Map<String, Serializable>> clientParams = new ArrayList<Map<String, Serializable>>(
+            2);
+
+    protected List<APPRepository> repos;
+
+    /**
+     * Constructs an AtomPub RepositoryService given a URL
+     * <p>
+     * The optional parameters are used to fetch the initial AtomPub Service
+     * Document, but will not be used for subsequent connections.
+     *
+     * @param url the AtomPub Service Document URL
+     * @param params the parameters
+     */
+    public APPRepositoryService(String url, Map<String, Serializable> params) {
+        this.url = url;
+        this.urlParams = params;
+    }
+
+    public Collection<RepositoryEntry> getRepositories() {
+        loadRepositories();
+        List<RepositoryEntry> res = new ArrayList<RepositoryEntry>(repos.size());
+        res.addAll(repos);
+        return res;
+    }
+
+    protected void loadRepositories() {
+        if (repos != null) {
+            return;
+        }
+        Connector connector = new Connector(getDefaultClient(), new APPContext(
+                this));
+        repos = connector.getServiceDocument(url);
+    }
+
+    public Repository getDefaultRepository() throws ContentManagerException {
+        loadRepositories();
+        return repos.size() == 0 ? null : repos.get(0);
+    }
+
+    public Repository getRepository(String id) throws ContentManagerException {
+        loadRepositories();
+        for (Repository repository : repos) {
+            if (repository.getId().equals(id)) {
+                return repository;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Gets a {@link HttpClient} for the given connection parameters.
+     *
+     * @param params the connection parameters
+     * @return the client, which may be multi-threaded and retrieved from a
+     *         cache
+     */
+    public synchronized HttpClient getClient(Map<String, Serializable> params) {
+        int i = 0;
+        for (Map<String, Serializable> p : clientParams) {
+            if ((params == null && p == null)
+                    || (params != null && params.equals(p))) {
+                return clients.get(i);
+            }
+            i++;
+        }
+        // create a new client
+        HttpClient client = newClient(params);
+        clients.add(client);
+        clientParams.add(params);
+        return client;
+    }
+
+    // used to load types
+    protected HttpClient getDefaultClient() {
+        return getClient(urlParams);
+    }
+
+    protected HttpClient newClient(Map<String, Serializable> params) {
+        HttpClient client = new HttpClient();
+        client.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
+        Credentials credentials = getCredentials(params);
+        if (credentials != null) {
+            CredentialsProvider cp = new FixedCredentialsProvider(credentials);
+            client.getState().setCredentials(AuthScope.ANY, credentials);
+            client.getParams().setParameter(CredentialsProvider.PROVIDER, cp);
+            client.getParams().setAuthenticationPreemptive(true);
+        }
+        return client;
+    }
+
+    protected Credentials getCredentials(Map<String, Serializable> params) {
+        if (params == null) {
+            return null;
+        }
+        String username = (String) params.get(Repository.PARAM_USERNAME);
+        if (username == null) {
+            return null;
+        }
+        String password = (String) params.get(Repository.PARAM_PASSWORD);
+        return new UsernamePasswordCredentials(username, password);
+    }
+
+    /**
+     * Simple credentials provider using fixed credentials. Other
+     * implementations could query the user through a GUI.
+     */
+    public static class FixedCredentialsProvider implements CredentialsProvider {
+
+        protected final Credentials credentials;
+
+        public FixedCredentialsProvider(Credentials credentials) {
+            this.credentials = credentials;
+        }
+
+        public Credentials getCredentials(AuthScheme scheme, String host,
+                int port, boolean proxy) {
+            return credentials;
+        }
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPServiceDocumentReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPServiceDocumentReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPServiceDocumentReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPServiceDocumentReader.java Tue Feb 23 16:20:40 2010
@@ -18,7 +18,6 @@
 
 import org.apache.chemistry.RepositoryInfo;
 import org.apache.chemistry.atompub.URITemplate;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.ServiceDocumentReader;
 
 /**
@@ -38,8 +37,8 @@
     }
 
     @Override
-    protected APPRepository createRepository(ReadContext ctx) {
-        return new APPRepository((APPContentManager) ctx.getContentManager());
+    protected APPRepository createRepository(APPContext ctx) {
+        return new APPRepository(ctx.getRepositoryService());
     }
 
     @Override

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPType.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPType.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPType.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPType.java Tue Feb 23 16:20:40 2010
@@ -175,7 +175,8 @@
     protected void loadPropertyDef() {
         if (propertyDefs == null) {
             String href = APPRepository.includePropertyDefinitionsInURI(getEditLink());
-            APPType typeDef = repository.connector.getType(href, true, getId());
+            APPType typeDef = repository.typesConnector.getType(href, true,
+                    getId());
             propertyDefs = typeDef.propertyDefs == null ? new HashMap<String, PropertyDefinition>()
                     : typeDef.propertyDefs;
         }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java Tue Feb 23 16:20:40 2010
@@ -35,20 +35,9 @@
 import org.apache.chemistry.Tree;
 import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.atompub.AtomPub;
-import org.apache.chemistry.atompub.client.APPObjectEntry;
-import org.apache.chemistry.atompub.client.APPObjectEntryReader;
-import org.apache.chemistry.atompub.client.APPObjectEntryWriter;
-import org.apache.chemistry.atompub.client.APPObjectFeedReader;
-import org.apache.chemistry.atompub.client.APPRepository;
-import org.apache.chemistry.atompub.client.APPServiceDocumentReader;
-import org.apache.chemistry.atompub.client.APPType;
-import org.apache.chemistry.atompub.client.ContentManagerException;
-import org.apache.chemistry.atompub.client.TypeEntryReader;
-import org.apache.chemistry.atompub.client.TypeFeedReader;
 import org.apache.chemistry.atompub.client.stax.EntryReader;
 import org.apache.chemistry.atompub.client.stax.FeedReader;
 import org.apache.chemistry.atompub.client.stax.QueryWriter;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.XmlObjectWriter;
 import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.impl.simple.SimpleTree;
@@ -64,21 +53,24 @@
 import org.apache.commons.httpclient.methods.RequestEntity;
 
 /**
- * A Connector abstracts the HTTP or AtomPub operations.
+ * Abstracts the HTTP or AtomPub operations.
+ * <p>
+ * A {@link Connector} is tied to a {@link HttpClient} that itself holds
+ * potential connection authentication parameters.
  */
 public class Connector {
 
     protected final HttpClient client;
 
-    protected final ReadContext ctx;
+    protected final APPContext ctx;
 
-    public Connector(HttpClient client, ReadContext ctx) {
+    public Connector(HttpClient client, APPContext ctx) {
         this.client = client;
         this.ctx = ctx;
     }
 
-    public APPRepository[] getServiceDocument(String href) {
-        GetMethod method = new GetMethod(href);
+    public List<APPRepository> getServiceDocument(String uri) {
+        GetMethod method = new GetMethod(uri);
         try {
             client.executeMethod(method);
             int status = method.getStatusCode();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeEntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeEntryReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeEntryReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeEntryReader.java Tue Feb 23 16:20:40 2010
@@ -30,7 +30,6 @@
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.client.stax.AbstractEntryReader;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.xml.stax.ChildrenNavigator;
 import org.apache.chemistry.xml.stax.StaxReader;
 import org.apache.commons.logging.Log;
@@ -50,13 +49,13 @@
     }
 
     @Override
-    protected APPType createObject(ReadContext ctx) {
+    protected APPType createObject(APPContext ctx) {
         APPType type = new APPType((APPRepository) ctx.getRepository());
         return type;
     }
 
     @Override
-    protected void readAtomElement(ReadContext ctx, StaxReader reader,
+    protected void readAtomElement(APPContext ctx, StaxReader reader,
             APPType object) throws XMLStreamException {
         if (AtomPub.ATOM_LINK.equals(reader.getName())) {
             String rel = reader.getAttributeValue(AtomPub.ATOM_NS, "rel");
@@ -67,7 +66,7 @@
     }
 
     @Override
-    protected void readCmisElement(ReadContext context, StaxReader reader,
+    protected void readCmisElement(APPContext ctx, StaxReader reader,
             APPType entry) throws XMLStreamException {
         if (AtomPubCMIS.TYPE.equals(reader.getName())) {
             ChildrenNavigator children = reader.getChildren();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractEntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractEntryReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractEntryReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractEntryReader.java Tue Feb 23 16:20:40 2010
@@ -24,6 +24,7 @@
 import org.apache.chemistry.CMIS;
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
+import org.apache.chemistry.atompub.client.APPContext;
 import org.apache.chemistry.xml.stax.ChildrenNavigator;
 import org.apache.chemistry.xml.stax.StaxReader;
 
@@ -32,18 +33,18 @@
  */
 public abstract class AbstractEntryReader<T> implements EntryReader<T> {
 
-    protected abstract T createObject(ReadContext ctx);
+    protected abstract T createObject(APPContext ctx);
 
-    public T read(ReadContext ctx, InputStream in) throws XMLStreamException {
+    public T read(APPContext ctx, InputStream in) throws XMLStreamException {
         return read(ctx, StaxReader.newReader(in));
     }
 
-    public T read(ReadContext ctx, XMLStreamReader reader)
+    public T read(APPContext ctx, XMLStreamReader reader)
             throws XMLStreamException {
         return read(ctx, StaxReader.newReader(reader));
     }
 
-    public T read(ReadContext ctx, StaxReader reader) throws XMLStreamException {
+    public T read(APPContext ctx, StaxReader reader) throws XMLStreamException {
         if (!reader.getFirstTag(AtomPub.ATOM_ENTRY)) {
             return null;
         }
@@ -61,12 +62,12 @@
         return object;
     }
 
-    protected void readCmisElement(ReadContext ctx, StaxReader reader, T object)
+    protected void readCmisElement(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         // do nothing
     }
 
-    protected void readEntryElement(ReadContext ctx, StaxReader reader, T object)
+    protected void readEntryElement(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         if (reader.getNamespaceURI().equals(AtomPub.ATOM_NS)) {
             readAtomElement(ctx, reader, object);
@@ -75,12 +76,12 @@
         }
     }
 
-    protected void readAtomElement(ReadContext ctx, StaxReader reader, T object)
+    protected void readAtomElement(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         // do nothing
     }
 
-    protected void readExtensionElement(ReadContext ctx, StaxReader reader,
+    protected void readExtensionElement(APPContext ctx, StaxReader reader,
             T object) throws XMLStreamException {
         // do nothing
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractFeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractFeedReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractFeedReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractFeedReader.java Tue Feb 23 16:20:40 2010
@@ -27,6 +27,7 @@
 
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
+import org.apache.chemistry.atompub.client.APPContext;
 import org.apache.chemistry.xml.stax.ChildrenNavigator;
 import org.apache.chemistry.xml.stax.StaxReader;
 
@@ -49,7 +50,7 @@
         this.entryBuilder = entryBuilder;
     }
 
-    public T read(ReadContext ctx, File file) throws XMLStreamException,
+    public T read(APPContext ctx, File file) throws XMLStreamException,
             IOException {
         InputStream in = new FileInputStream(file);
         try {
@@ -59,7 +60,7 @@
         }
     }
 
-    public T read(ReadContext ctx, URL url) throws XMLStreamException,
+    public T read(APPContext ctx, URL url) throws XMLStreamException,
             IOException {
         InputStream in = url.openStream();
         try {
@@ -69,7 +70,7 @@
         }
     }
 
-    public T read(ReadContext ctx, InputStream in) throws XMLStreamException {
+    public T read(APPContext ctx, InputStream in) throws XMLStreamException {
         StaxReader xr = StaxReader.newReader(in);
         try {
             return read(ctx, xr);
@@ -78,7 +79,7 @@
         }
     }
 
-    public T read(ReadContext ctx, Reader reader) throws XMLStreamException {
+    public T read(APPContext ctx, Reader reader) throws XMLStreamException {
         StaxReader xr = StaxReader.newReader(reader);
         try {
             return read(ctx, xr);
@@ -87,7 +88,7 @@
         }
     }
 
-    public T read(ReadContext ctx, StaxReader reader) throws XMLStreamException {
+    public T read(APPContext ctx, StaxReader reader) throws XMLStreamException {
         if (!reader.getFirstTag(AtomPub.ATOM_FEED)) {
             throw new XMLStreamException("Parse error: Not an atom feed");
         }
@@ -116,12 +117,12 @@
         return feed;
     }
 
-    protected boolean isDone(ReadContext ctx, StaxReader reader)
+    protected boolean isDone(APPContext ctx, StaxReader reader)
             throws XMLStreamException {
         return false;
     }
 
-    protected void readAtomElement(ReadContext ctx, StaxReader reader,
+    protected void readAtomElement(APPContext ctx, StaxReader reader,
             String nsUri, T feed) throws XMLStreamException {
         if (AtomPub.ATOM_LINK.equals(reader.getName())) {
             String rel = reader.getAttributeValue(AtomPub.ATOM_NS, "rel");
@@ -131,7 +132,7 @@
         }
     }
 
-    protected void readExtensionElement(ReadContext ctx, StaxReader reader,
+    protected void readExtensionElement(APPContext ctx, StaxReader reader,
             String nsUri, T feed) throws XMLStreamException {
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java Tue Feb 23 16:20:40 2010
@@ -30,6 +30,7 @@
 import org.apache.chemistry.PropertyDefinition;
 import org.apache.chemistry.Tree;
 import org.apache.chemistry.atompub.AtomPubCMIS;
+import org.apache.chemistry.atompub.client.APPContext;
 import org.apache.chemistry.atompub.client.APPObjectFeedTreeReader;
 import org.apache.chemistry.xml.stax.ChildrenNavigator;
 import org.apache.chemistry.xml.stax.ParseException;
@@ -51,7 +52,7 @@
     protected abstract void setChildren(T object, List<Tree<ObjectEntry>> tree);
 
     @Override
-    protected void readCmisElement(ReadContext ctx, StaxReader reader, T object)
+    protected void readCmisElement(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         QName name = reader.getName();
         if (AtomPubCMIS.OBJECT.equals(name)) {
@@ -66,7 +67,7 @@
         }
     }
 
-    protected void readCmisObject(ReadContext ctx, StaxReader reader, T object)
+    protected void readCmisObject(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         ChildrenNavigator children = reader.getChildren();
         while (children.next()) {
@@ -74,7 +75,7 @@
         }
     }
 
-    protected void readObjectChildElement(ReadContext ctx, StaxReader reader,
+    protected void readObjectChildElement(APPContext ctx, StaxReader reader,
             T object) throws XMLStreamException {
         if (reader.getNamespaceURI().equals(CMIS.CMIS_NS)) {
             QName name = reader.getName();
@@ -92,7 +93,7 @@
         }
     }
 
-    protected void readProperties(ReadContext ctx, StaxReader reader, T object)
+    protected void readProperties(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         for (PropertyIterator it = new PropertyIterator(reader); it.hasNext();) {
             XmlProperty p = it.next();
@@ -100,7 +101,7 @@
         }
     }
 
-    protected void readPropertyWithType(ReadContext ctx, StaxReader reader,
+    protected void readPropertyWithType(APPContext ctx, StaxReader reader,
             T object, XmlProperty p) {
         String id = p.getId();
         PropertyDefinition def = ctx.getRepository().getPropertyDefinition(id);
@@ -111,7 +112,7 @@
         setProperty(object, p);
     }
 
-    protected void readAllowableActions(ReadContext ctx, StaxReader reader,
+    protected void readAllowableActions(APPContext ctx, StaxReader reader,
             T object) throws XMLStreamException {
         Map<QName, Boolean> allowableActions = new HashMap<QName, Boolean>();
         ChildrenNavigator children = reader.getChildren();
@@ -123,22 +124,22 @@
         setAllowableActions(object, allowableActions);
     }
 
-    protected void readChangeEventInfo(ReadContext ctx, StaxReader reader,
+    protected void readChangeEventInfo(APPContext ctx, StaxReader reader,
             T object) throws XMLStreamException {
         // TODO not yet implemented
     }
 
-    protected void readOtherCmisElement(ReadContext ctx, StaxReader reader,
+    protected void readOtherCmisElement(APPContext ctx, StaxReader reader,
             T object) throws XMLStreamException {
         // do nothing
     }
 
-    protected void readPathSegment(ReadContext ctx, StaxReader reader, T object)
+    protected void readPathSegment(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         setPathSegment(object, reader.getElementText());
     }
 
-    protected void readChildren(ReadContext ctx, StaxReader reader, T object)
+    protected void readChildren(APPContext ctx, StaxReader reader, T object)
             throws XMLStreamException {
         // TODO better use of generics
         List<Tree<ObjectEntry>> list = new APPObjectFeedTreeReader().read(ctx, reader);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/EntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/EntryReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/EntryReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/EntryReader.java Tue Feb 23 16:20:40 2010
@@ -21,6 +21,7 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.chemistry.atompub.client.APPContext;
 import org.apache.chemistry.xml.stax.StaxReader;
 
 /**
@@ -28,10 +29,10 @@
  */
 public interface EntryReader<T> {
 
-    T read(ReadContext ctx, InputStream in) throws XMLStreamException;
+    T read(APPContext ctx, InputStream in) throws XMLStreamException;
 
-    T read(ReadContext ctx, XMLStreamReader xr) throws XMLStreamException;
+    T read(APPContext ctx, XMLStreamReader xr) throws XMLStreamException;
 
-    T read(ReadContext ctx, StaxReader sr) throws XMLStreamException;
+    T read(APPContext ctx, StaxReader sr) throws XMLStreamException;
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/FeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/FeedReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/FeedReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/FeedReader.java Tue Feb 23 16:20:40 2010
@@ -21,6 +21,7 @@
 
 import javax.xml.stream.XMLStreamException;
 
+import org.apache.chemistry.atompub.client.APPContext;
 import org.apache.chemistry.xml.stax.StaxReader;
 
 /**
@@ -28,10 +29,10 @@
  */
 public interface FeedReader<T> {
 
-    T read(ReadContext ctx, InputStream in) throws XMLStreamException;
+    T read(APPContext ctx, InputStream in) throws XMLStreamException;
 
-    T read(ReadContext ctx, Reader reader) throws XMLStreamException;
+    T read(APPContext ctx, Reader reader) throws XMLStreamException;
 
-    T read(ReadContext ctx, StaxReader reader) throws XMLStreamException;
+    T read(APPContext ctx, StaxReader reader) throws XMLStreamException;
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ServiceDocumentReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ServiceDocumentReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ServiceDocumentReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ServiceDocumentReader.java Tue Feb 23 16:20:40 2010
@@ -29,9 +29,9 @@
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
-import org.apache.chemistry.CapabilityACL;
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMIS;
+import org.apache.chemistry.CapabilityACL;
 import org.apache.chemistry.CapabilityChange;
 import org.apache.chemistry.CapabilityJoin;
 import org.apache.chemistry.CapabilityQuery;
@@ -41,7 +41,7 @@
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.URITemplate;
-import org.apache.chemistry.atompub.client.APPRepository;
+import org.apache.chemistry.atompub.client.APPContext;
 import org.apache.chemistry.atompub.client.APPRepositoryCapabilities;
 import org.apache.chemistry.atompub.client.APPRepositoryInfo;
 import org.apache.chemistry.xml.stax.ChildrenNavigator;
@@ -52,7 +52,7 @@
  */
 public abstract class ServiceDocumentReader<T extends Repository> {
 
-    protected abstract T createRepository(ReadContext ctx);
+    protected abstract T createRepository(APPContext ctx);
 
     protected abstract void addCollection(T repo, String href, String type);
 
@@ -60,17 +60,16 @@
 
     protected abstract void setInfo(T repo, RepositoryInfo info);
 
-    @SuppressWarnings("unchecked")
-    public T[] read(ReadContext context, InputStream in) throws IOException {
+    public List<T> read(APPContext ctx, InputStream in) throws IOException {
         try {
             StaxReader reader = StaxReader.newReader(in);
             if (!reader.fwdTag("service")) {
                 throw new IOException("Invalid APP service document");
             }
-            List<Repository> repos = new ArrayList<Repository>();
+            List<T> repos = new ArrayList<T>(1);
             ChildrenNavigator workspaces = reader.getChildren("workspace");
             while (workspaces.next()) {
-                T repo = createRepository(context);
+                T repo = createRepository(ctx);
                 ChildrenNavigator children = reader.getChildren();
                 while (children.next()) {
                     QName name = reader.getName();
@@ -86,18 +85,16 @@
                         }
                         addCollection(repo, href, type);
                     } else if (AtomPubCMIS.REPOSITORY_INFO.equals(name)) {
-                        RepositoryInfo info = readRepositoryInfo(context,
-                                reader);
+                        RepositoryInfo info = readRepositoryInfo(ctx, reader);
                         setInfo(repo, info);
                     } else if (AtomPubCMIS.URI_TEMPLATE.equals(name)) {
-                        URITemplate uriTemplate = readURITemplate(context,
-                                reader);
+                        URITemplate uriTemplate = readURITemplate(ctx, reader);
                         addURITemplate(repo, uriTemplate);
                     }
                 }
                 repos.add(repo);
             }
-            return (T[]) repos.toArray(new APPRepository[repos.size()]);
+            return repos;
         } catch (XMLStreamException e) {
             IOException ioe = new IOException();
             ioe.initCause(e);
@@ -105,7 +102,7 @@
         }
     }
 
-    protected RepositoryInfo readRepositoryInfo(ReadContext context,
+    protected RepositoryInfo readRepositoryInfo(APPContext ctx,
             StaxReader reader) throws XMLStreamException {
         APPRepositoryCapabilities caps = null;
         Map<String, Object> map = new HashMap<String, Object>();
@@ -155,7 +152,7 @@
                     }
                 }
             } else if (CMIS.REPOSITORY_SPECIFIC_INFORMATION.equals(name)) {
-                readRepositorySpecificInformation(context, reader);
+                readRepositorySpecificInformation(ctx, reader);
             } else if (CMIS.CHANGES_ON_TYPE.equals(name)) {
                 changeLogBaseTypes.add(BaseType.get(reader.getElementText()));
             } else {
@@ -172,7 +169,7 @@
         return new APPRepositoryInfo(caps, map, changeLogBaseTypes);
     }
 
-    protected URITemplate readURITemplate(ReadContext context, StaxReader reader)
+    protected URITemplate readURITemplate(APPContext ctx, StaxReader reader)
             throws XMLStreamException {
         String type = null;
         String mediaType = null;
@@ -191,7 +188,7 @@
         return new URITemplate(type, mediaType, template);
     }
 
-    protected void readRepositorySpecificInformation(ReadContext context,
+    protected void readRepositorySpecificInformation(APPContext ctx,
             StaxReader reader) {
         // do nothing
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectEntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectEntryReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectEntryReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectEntryReader.java Tue Feb 23 16:20:40 2010
@@ -30,21 +30,21 @@
 import org.apache.chemistry.PropertyType;
 import org.apache.chemistry.Updatability;
 import org.apache.chemistry.atompub.client.APPObjectEntry.Link;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
 import org.apache.chemistry.impl.simple.SimpleType;
 import org.apache.chemistry.impl.simple.SimpleTypeManager;
 
 public class TestAPPObjectEntryReader extends TestCase {
 
-    protected ReadContext getReadContext() {
+    protected APPContext getAPPContext() {
         Set<BaseType> changeLogBaseTypes = new HashSet<BaseType>();
         changeLogBaseTypes.add(BaseType.DOCUMENT);
         changeLogBaseTypes.add(BaseType.FOLDER);
         APPRepositoryInfo ri = new APPRepositoryInfo(
                 new APPRepositoryCapabilities(), new HashMap<String, Object>(),
                 changeLogBaseTypes);
-        APPRepository repo = new APPRepository(new APPContentManager(null), ri);
+        APPRepository repo = new APPRepository(new APPRepositoryService(null,
+                null), ri);
 
         SimpleTypeManager tm = new SimpleTypeManager();
         PropertyDefinition psn = new SimplePropertyDefinition("string_null",
@@ -75,13 +75,13 @@
         tm.addType(t);
         repo.typeManager = tm;
 
-        return new ReadContext(new APPConnection(repo));
+        return new APPContext(new APPConnection(repo, null));
     }
 
     public void testReadObjectEntry() throws Exception {
         InputStream is = getClass().getResourceAsStream("/entry.xml");
-        APPObjectEntry entry = new APPObjectEntryReader().read(
-                getReadContext(), is);
+        APPObjectEntry entry = new APPObjectEntryReader().read(getAPPContext(),
+                is);
         Link[] links = entry.getLinks();
         assertEquals(2, links.length);
         Link link = links[0];

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedReader.java Tue Feb 23 16:20:40 2010
@@ -32,21 +32,21 @@
 import org.apache.chemistry.PropertyDefinition;
 import org.apache.chemistry.PropertyType;
 import org.apache.chemistry.Updatability;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
 import org.apache.chemistry.impl.simple.SimpleType;
 import org.apache.chemistry.impl.simple.SimpleTypeManager;
 
 public class TestAPPObjectFeedReader extends TestCase {
 
-    protected ReadContext getReadContext() {
+    protected APPContext getAPPContext() {
         Set<BaseType> changeLogBaseTypes = new HashSet<BaseType>();
         changeLogBaseTypes.add(BaseType.DOCUMENT);
         changeLogBaseTypes.add(BaseType.FOLDER);
         APPRepositoryInfo ri = new APPRepositoryInfo(
                 new APPRepositoryCapabilities(), new HashMap<String, Object>(),
                 changeLogBaseTypes);
-        APPRepository repo = new APPRepository(new APPContentManager(null), ri);
+        APPRepository repo = new APPRepository(new APPRepositoryService(null,
+                null), ri);
 
         SimpleTypeManager tm = new SimpleTypeManager();
         PropertyDefinition ps = new SimplePropertyDefinition("string",
@@ -60,13 +60,13 @@
         tm.addType(t);
         repo.typeManager = tm;
 
-        return new ReadContext(new APPConnection(repo));
+        return new APPContext(new APPConnection(repo, null));
     }
 
     public void testReadAPPObjectFeed() throws Exception {
         InputStream is = getClass().getResourceAsStream("/feed.xml");
         ListPage<ObjectEntry> list = new APPObjectFeedReader().read(
-                getReadContext(), is);
+                getAPPContext(), is);
         assertEquals(2, list.size());
         assertEquals("string1", list.get(0).getValue("string"));
         assertEquals("string2", list.get(1).getValue("string"));

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedTreeReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedTreeReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedTreeReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestAPPObjectFeedTreeReader.java Tue Feb 23 16:20:40 2010
@@ -33,21 +33,21 @@
 import org.apache.chemistry.PropertyType;
 import org.apache.chemistry.Tree;
 import org.apache.chemistry.Updatability;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
 import org.apache.chemistry.impl.simple.SimpleType;
 import org.apache.chemistry.impl.simple.SimpleTypeManager;
 
 public class TestAPPObjectFeedTreeReader extends TestCase {
 
-    protected ReadContext getReadContext() {
+    protected APPContext getAPPContext() {
         Set<BaseType> changeLogBaseTypes = new HashSet<BaseType>();
         changeLogBaseTypes.add(BaseType.DOCUMENT);
         changeLogBaseTypes.add(BaseType.FOLDER);
         APPRepositoryInfo ri = new APPRepositoryInfo(
                 new APPRepositoryCapabilities(), new HashMap<String, Object>(),
                 changeLogBaseTypes);
-        APPRepository repo = new APPRepository(new APPContentManager(null), ri);
+        APPRepository repo = new APPRepository(new APPRepositoryService(null,
+                null), ri);
 
         SimpleTypeManager tm = new SimpleTypeManager();
         PropertyDefinition ps = new SimplePropertyDefinition("string",
@@ -61,13 +61,13 @@
         tm.addType(t);
         repo.typeManager = tm;
 
-        return new ReadContext(new APPConnection(repo));
+        return new APPContext(new APPConnection(repo, null));
     }
 
     public void testReadAPPObjectFeed() throws Exception {
         InputStream is = getClass().getResourceAsStream("/feed-nested.xml");
         List<Tree<ObjectEntry>> list = new APPObjectFeedTreeReader().read(
-                getReadContext(), is);
+                getAPPContext(), is);
         assertEquals(2, list.size());
         Tree<ObjectEntry> tree = list.get(0);
         assertEquals(3, tree.size());

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestServiceDocumentReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestServiceDocumentReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestServiceDocumentReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestServiceDocumentReader.java Tue Feb 23 16:20:40 2010
@@ -19,6 +19,7 @@
 import java.io.InputStream;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import junit.framework.TestCase;
@@ -32,7 +33,6 @@
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.RepositoryCapabilities;
 import org.apache.chemistry.RepositoryInfo;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.ServiceDocumentReader;
 import org.apache.chemistry.impl.simple.SimpleObjectId;
 
@@ -41,10 +41,10 @@
     public void testReadServiceDocument() throws Exception {
         InputStream is = getClass().getResourceAsStream("/service-document.xml");
         ServiceDocumentReader<APPRepository> reader = new APPServiceDocumentReader();
-        ReadContext ctx = new ReadContext(new APPContentManager(""));
-        Repository[] repos = reader.read(ctx, is);
-        assertEquals(1, repos.length);
-        Repository repo = repos[0];
+        APPContext ctx = new APPContext(new APPRepositoryService("", null));
+        List<APPRepository> repos = reader.read(ctx, is);
+        assertEquals(1, repos.size());
+        Repository repo = repos.get(0);
         assertEquals("test", repo.getId());
         assertEquals("testname", repo.getName());
         RepositoryInfo info = repo.getInfo();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestTypeFeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestTypeFeedReader.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestTypeFeedReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TestTypeFeedReader.java Tue Feb 23 16:20:40 2010
@@ -21,16 +21,14 @@
 
 import junit.framework.TestCase;
 
-import org.apache.chemistry.Repository;
 import org.apache.chemistry.TypeManager;
-import org.apache.chemistry.atompub.client.stax.ReadContext;
 
 public class TestTypeFeedReader extends TestCase {
 
     public void testReadTypesFeed() throws Exception {
         InputStream is = getClass().getResourceAsStream("/types-feed.xml");
         TypeManager typeManager = new TypeFeedReader(true).read(
-                new ReadContext((Repository) null), is);
+                new APPContext((APPRepository) null), is);
         assertEquals(5, typeManager.getTypes().size());
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCheckedOutCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCheckedOutCollection.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCheckedOutCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCheckedOutCollection.java Tue Feb 23 16:20:40 2010
@@ -67,7 +67,7 @@
     @Override
     public Iterable<ObjectEntry> getEntries(RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             Target target = request.getTarget();
             String folderIdString = target.getParameter(AtomPubCMIS.PARAM_FOLDER_ID);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java Tue Feb 23 16:20:40 2010
@@ -74,7 +74,7 @@
 
     @Override
     public ResponseContext getFeed(RequestContext request) {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             Feed feed;
             if (COLTYPE_DESCENDANTS.equals(getType())
@@ -199,7 +199,7 @@
                 }
             }
 
-            if (isMediaEntry(entryObj)) {
+            if (isMediaEntry(entryObj, spi)) {
                 addMediaContent(feedIri, e, entryObj, request);
             } else {
                 addContent(e, entryObj, request);
@@ -283,7 +283,7 @@
     public void putMedia(ObjectEntry entry, MimeType contentType, String slug,
             InputStream in, RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             ContentStream cs = new SimpleContentStream(in,
                     contentType.toString(), slug);
@@ -311,7 +311,7 @@
     @Override
     public void deleteMedia(String resourceName, RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             String id = getResourceName(request);
             spi.deleteContentStream(new SimpleObjectId(id));

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java Tue Feb 23 16:20:40 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.chemistry.atompub.server;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -27,6 +28,7 @@
 import org.apache.abdera.protocol.server.context.ResponseContextException;
 import org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter;
 import org.apache.chemistry.Repository;
+import org.apache.chemistry.SPI;
 import org.apache.chemistry.atompub.AtomPub;
 
 /**
@@ -59,6 +61,15 @@
      * ----- Helpers -----
      */
 
+    public SPI getSPI(RequestContext request) {
+        return repository.getSPI(getConnectionParams(request));
+    }
+
+    protected Map<String, Serializable> getConnectionParams(
+            RequestContext request) {
+        return null; // TODO username, password
+    }
+
     public static int getParameter(RequestContext request, String name, int def) {
         String value = request.getTarget().getParameter(name);
         return value == null ? def : Integer.parseInt(value);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java Tue Feb 23 16:20:40 2010
@@ -489,7 +489,7 @@
     @Override
     public ResponseContext postEntry(RequestContext request) {
         // TODO parameter versioningState
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             PropertiesAndStream posted = extractCMISProperties(request, null);
             ObjectId folderId = spi.newObjectId(id);
@@ -540,7 +540,7 @@
             Entry entry = request.getAbdera().getFactory().newEntry();
             ObjectEntry object = spi.getProperties(objectId, null);
             addEntryDetails(request, entry, null, object);
-            if (isMediaEntry(object)) {
+            if (isMediaEntry(object, spi)) {
                 addMediaContent(null, entry, object, request);
             } else {
                 addContent(entry, object, request);
@@ -570,7 +570,7 @@
 
     @Override
     public ResponseContext putEntry(RequestContext request) {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             // existing object
             String id = getResourceName(request);
@@ -601,7 +601,7 @@
             // refetch full object
             object = spi.getProperties(object, null);
             addEntryDetails(request, entry, null, object);
-            if (isMediaEntry(object)) {
+            if (isMediaEntry(object, spi)) {
                 addMediaContent(null, entry, object, request);
             } else {
                 addContent(entry, object, request);
@@ -631,7 +631,7 @@
     public void deleteEntry(String resourceName, RequestContext request)
             throws ResponseContextException {
         ObjectId object;
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             String oid = resourceName;
             object = spi.newObjectId(oid);
@@ -681,7 +681,7 @@
 
     @Override
     public ResponseContext getMedia(RequestContext request) {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             String id = getResourceName(request);
             ObjectEntry object = getEntry(id, request, spi);
@@ -717,17 +717,6 @@
         }
     }
 
-    @Override
-    public boolean isMediaEntry(ObjectEntry object)
-            throws ResponseContextException {
-        SPI spi = repository.getSPI();
-        try {
-            return isMediaEntry(object, spi);
-        } finally {
-            spi.close();
-        }
-    }
-
     public boolean isMediaEntry(ObjectEntry object, SPI spi)
             throws ResponseContextException {
         return getContentType(object) != null && getContentSize(object) != -1
@@ -773,7 +762,7 @@
 
     @Override
     public ResponseContext getEntry(RequestContext request) {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             String id = getResourceName(request);
             ObjectEntry object = getEntry(id, request, spi);
@@ -799,7 +788,7 @@
     @Override
     public ObjectEntry getEntry(String resourceName, RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             return getEntry(resourceName, request, spi);
         } finally {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISParentsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISParentsCollection.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISParentsCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISParentsCollection.java Tue Feb 23 16:20:40 2010
@@ -54,7 +54,7 @@
     @Override
     public Iterable<ObjectEntry> getEntries(RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             ObjectId objectId = spi.newObjectId(id);
             Collection<ObjectEntry> parents = spi.getObjectParents(objectId,

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java Tue Feb 23 16:20:40 2010
@@ -151,7 +151,7 @@
     @Override
     public Iterable<ObjectEntry> getEntries(RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getSPI();
+        SPI spi = getSPI(request);
         try {
             Paging paging = new Paging(maxItems, skipCount);
             Inclusion inclusion = new Inclusion(null, renditions,

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java Tue Feb 23 16:20:40 2010
@@ -42,6 +42,7 @@
 import org.apache.abdera.protocol.server.ServiceManager;
 import org.apache.abdera.protocol.server.servlet.ServletRequestContext;
 import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryManager;
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.server.CMISChildrenCollection;
@@ -67,9 +68,6 @@
     @Context
     protected UriInfo ui;
 
-    // TODO inject repository somehow
-    public static Repository repository;
-
     // TODO configure somehow
     public static PathMunger pathMunger;
 
@@ -86,6 +84,7 @@
 
     public AbderaResource() throws Exception {
         try {
+            Repository repository = RepositoryManager.getInstance().getDefaultRepository();
             provider = new CMISProvider(repository);
             provider.init(ServiceManager.getAbdera(),
                     new HashMap<String, String>());

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/servlet/CMISServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/servlet/CMISServlet.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/servlet/CMISServlet.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/servlet/CMISServlet.java Tue Feb 23 16:20:40 2010
@@ -27,7 +27,6 @@
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
 import org.apache.chemistry.Repository;
-import org.apache.chemistry.RepositoryFactory;
 import org.apache.chemistry.atompub.server.CMISProvider;
 
 public class CMISServlet extends AbderaServlet {
@@ -63,29 +62,13 @@
 
     private Repository createRepository(ServletContext context,
             Map<String, String> params) throws ServletException {
-
         String className = params.get("class");
         if (className == null) {
             String msg = "Repository factory expected in 'class' parameter.";
             throw new ServletException(msg);
         }
-        RepositoryFactory factory = null;
-
-        try {
-            Class<?> c = Class.forName(className);
-            factory = (RepositoryFactory) c.newInstance();
-        } catch (Exception e) {
-            String msg = "Unable to create repository factory class: "
-                    + className;
-            throw new ServletException(msg, e);
-        }
-
-        try {
-            return factory.create(context, params);
-        } catch (Exception e) {
-            String msg = "Unable to create repository.";
-            throw new ServletException(msg, e);
-        }
+        // TODO create repository from factory
+        throw new UnsupportedOperationException();
     }
 
     @Override

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java Tue Feb 23 16:20:40 2010
@@ -49,12 +49,15 @@
 import org.apache.chemistry.PropertyType;
 import org.apache.chemistry.RelationshipDirection;
 import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryManager;
+import org.apache.chemistry.RepositoryService;
 import org.apache.chemistry.Updatability;
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
 import org.apache.chemistry.impl.simple.SimpleRepository;
+import org.apache.chemistry.impl.simple.SimpleRepositoryService;
 import org.apache.chemistry.impl.simple.SimpleType;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
@@ -80,9 +83,9 @@
 
     protected static String doc3id;
 
-    public Server server;
+    protected RepositoryService repositoryService;
 
-    public Repository repository;
+    public Server server;
 
     public String base;
 
@@ -100,7 +103,8 @@
 
     @Override
     public void setUp() throws Exception {
-        repository = makeRepository(null);
+        repositoryService = new SimpleRepositoryService(makeRepository(null));
+        RepositoryManager.getInstance().registerService(repositoryService);
         startServer();
         base = "http://localhost:" + PORT + CONTEXT_PATH + SERVLET_PATH
                 + getResourcePath();
@@ -109,6 +113,8 @@
     @Override
     public void tearDown() throws Exception {
         stopServer();
+        RepositoryManager.getInstance().unregisterService(repositoryService);
+        repositoryService = null;
     }
 
     public abstract void startServer() throws Exception;

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubAbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubAbderaServlet.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubAbderaServlet.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubAbderaServlet.java Tue Feb 23 16:20:40 2010
@@ -18,6 +18,8 @@
 
 import javax.servlet.Servlet;
 
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryManager;
 import org.apache.chemistry.atompub.server.servlet.CMISServlet;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.Context;
@@ -31,6 +33,7 @@
     @Override
     public void startServer() throws Exception {
         server = new Server(PORT);
+        Repository repository = RepositoryManager.getInstance().getDefaultRepository();
         Servlet servlet = new CMISServlet(repository);
         ServletHolder servletHolder = new ServletHolder(servlet);
         Context context = new Context(server, CONTEXT_PATH, Context.SESSIONS);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java Tue Feb 23 16:20:40 2010
@@ -52,7 +52,6 @@
 
     @Override
     public void startServer() throws Exception {
-        AbderaResource.repository = repository; // TODO inject differently
         AbderaResource.pathMunger = null; // TODO
         server = new Server(PORT);
         server.setHandler(new WebAppContext(server, makeWar(), CONTEXT_PATH));