chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r797514 - 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/chemistry/ato...
Date Fri, 24 Jul 2009 15:01:17 GMT
Author: fguillaume
Date: Fri Jul 24 15:01:16 2009
New Revision: 797514

URL: http://svn.apache.org/viewvc?rev=797514&view=rev
Log:
CMIS-44: cleaned up types children/descendants, factored out common implementation

Added:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
  (with props)
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
  (with props)
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Repository.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/APPType.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeFeedReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/IOProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.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/FeedReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TypeFeedReaderTest.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.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=797514&r1=797513&r2=797514&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
Fri Jul 24 15:01:16 2009
@@ -17,14 +17,16 @@
 package org.apache.chemistry;
 
 import java.io.Serializable;
-import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 
 /**
  * A CMIS Repository.
+ * <p>
+ * Basic repository information is available through {@link RepositoryEntry}.
+ * <p>
+ * Types are managed through {@link TypeManager}.
  */
-public interface Repository extends RepositoryEntry {
+public interface Repository extends RepositoryEntry, TypeManager {
 
     /**
      * Gets a new connection to this repository.
@@ -66,50 +68,4 @@
      */
     RepositoryInfo getInfo();
 
-    /**
-     * Gets the type definitions of the repository.
-     * <p>
-     * If typeId is provided, only the specific type and its descendants are
-     * returned, otherwise all types are returned.
-     * <p>
-     * If returnPropertyDefinitions is {@code false}, then the
-     * {@link PropertyDefinition}s will not be returned in each {@link Type}.
-     *
-     * @param typeId the base type ID, or {@code null}
-     * @return the repository's types
-     */
-    Collection<Type> getTypes(String typeId, boolean returnPropertyDefinitions);
-
-    /**
-     * Gets the type definitions of the repository.
-     * <p>
-     * If typeId is provided, only the specific type and its descendants are
-     * returned, otherwise all types are returned.
-     * <p>
-     * If returnPropertyDefinitions is {@code false}, then the
-     * {@link PropertyDefinition}s will not be returned in each {@link Type}.
-     * <p>
-     * If maxItems is {@code 0} then a repository-specific maximum will be used.
-     *
-     * @param typeId the base type ID, or {@code null}
-     * @param returnPropertyDefinitions {@code false} to skip property
-     *            definitions
-     * @param maxItems the maximum number of items, or {@code 0}
-     * @param skipCount the number of results to skip in the list
-     * @param hasMoreItems a 1-value boolean array to return a flag stating if
-     *            there are more items
-     * @return the repository's types, or a subset of them
-     */
-    // this API is present to mirror the wire protocol
-    List<Type> getTypes(String typeId, boolean returnPropertyDefinitions,
-            int maxItems, int skipCount, boolean[] hasMoreItems);
-
-    /**
-     * Gets the definition for the specified type.
-     *
-     * @param typeId the type ID
-     * @return the type definition
-     */
-    Type getType(String typeId);
-
 }

Added: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java?rev=797514&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
Fri Jul 24 15:01:16 2009
@@ -0,0 +1,81 @@
+/*
+ * 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.Collection;
+
+/**
+ * A manager of types.
+ */
+public interface TypeManager {
+
+    /**
+     * Adds a new type to the type manager.
+     * <p>
+     * In most cases, this method will throw
+     * {@link UnsupportedOperationException}.
+     *
+     * @param type the new type.
+     */
+    void addType(Type type);
+
+    /**
+     * Gets the specified type.
+     *
+     * @param typeId the type ID
+     * @return the type, or {@code null} if not found
+     */
+    Type getType(String typeId);
+
+    /**
+     * Gets the types.
+     * <p>
+     * If typeId is provided, only the specific type and its descendants are
+     * returned, otherwise all types are returned.
+     *
+     * @param typeId the base type ID, or {@code null}
+     * @return the types, or a subset of them
+     */
+    Collection<Type> getTypes(String typeId);
+
+    /**
+     * Gets the types.
+     * <p>
+     * If typeId is provided, only the specific type and its descendants are
+     * returned, otherwise all types are returned.
+     * <p>
+     * The depth parameter controls the number of levels of the type hierarchy
+     * to return:
+     * <ul>
+     * <li>-1: all descendants at all depths,</li>
+     * <li>1: only children of the type,</li>
+     * <li>more than 1: grand-children up to that depth,</li>
+     * </ul>
+     * If returnPropertyDefinitions is {@code false}, then the
+     * {@link PropertyDefinition}s will not be returned in each {@link Type}.
+     *
+     * @param typeId the base type ID, or {@code null}
+     * @param depth the number of levels of depth in the type hierarchy from
+     *            which to return results
+     * @param returnPropertyDefinitions {@code false} to skip property
+     *            definitions
+     * @return the types, or a subset of them
+     */
+    Collection<Type> getTypes(String typeId, int depth,
+            boolean returnPropertyDefinitions);
+
+}

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

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

Propchange: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=797514&r1=797513&r2=797514&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
Fri Jul 24 15:01:16 2009
@@ -13,6 +13,7 @@
  *
  * Authors:
  *     Bogdan Stefanescu, Nuxeo
+ *     Florent Guillaume, Nuxeo
  */
 package org.apache.chemistry.atompub.client;
 
@@ -22,9 +23,9 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.List;
 import java.util.Map;
 
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.RepositoryInfo;
@@ -47,7 +48,7 @@
 
     protected String id;
 
-    protected Map<String, Type> typeRegistry;
+    protected TypeManager typeManager;
 
     protected Map<String, String> collections = new HashMap<String, String>();
 
@@ -103,22 +104,23 @@
         return info;
     }
 
+    public void addType(Type type) {
+        throw new UnsupportedOperationException("Cannot add types");
+    }
+
     public Type getType(String typeId) {
         loadTypes();
-        return typeRegistry.get(typeId);
+        return typeManager.getType(typeId);
     }
 
-    public List<Type> getTypes(String typeId,
-            boolean returnPropertyDefinitions, int maxItems, int skipCount,
-            boolean[] hasMoreItems) {
-        loadTypes();
-        throw new UnsupportedOperationException("Not yet Implemented");
+    public Collection<Type> getTypes(String typeId) {
+        return typeManager.getTypes(typeId);
     }
 
-    public Collection<Type> getTypes(String typeId,
+    public Collection<Type> getTypes(String typeId, int depth,
             boolean returnPropertyDefinitions) {
         loadTypes();
-        throw new UnsupportedOperationException("Not yet Implemented");
+        return typeManager.getTypes(typeId, depth, returnPropertyDefinitions);
     }
 
     public String getRelationshipName() {
@@ -132,36 +134,37 @@
     /** type API */
 
     public void addType(APPType type) {
-        typeRegistry.put(type.getId(), type);
+        typeManager.addType(type);
     }
 
     protected void loadTypes() {
-        if (typeRegistry == null) {
+        if (typeManager != null) {
+            return;
+        }
+        try {
+            String href = getCollectionHref(CMIS.COL_TYPES_CHILDREN);
+            if (href == null) {
+                throw new IllegalArgumentException(
+                        "Invalid CMIS repository. No types children collection defined");
+            }
+            // TODO lazy load property definition
+            Request req = new Request(href + "?includePropertyDefinitions=true");
+            Response resp = cm.getConnector().get(req);
+            if (!resp.isOk()) {
+                throw new ContentManagerException(
+                        "Remote server returned error code: "
+                                + resp.getStatusCode());
+            }
+            InputStream in = resp.getStream();
             try {
-                String href = getCollectionHref(CMIS.COL_TYPES_CHILDREN);
-                if (href == null) {
-                    throw new IllegalArgumentException(
-                            "Invalid CMIS repository. No types children collection defined");
-                }
-                // TODO lazy load property definition
-                Request req = new Request(href + "?includePropertyDefinitions=true");
-                Response resp = cm.getConnector().get(req);
-                if (!resp.isOk()) {
-                    throw new ContentManagerException(
-                            "Remote server returned error code: "
-                                    + resp.getStatusCode());
-                }
-                InputStream in = resp.getStream();
-                try {
-                    typeRegistry = TypeFeedReader.INSTANCE.read(
-                            new ReadContext(this), in);
-                } finally {
-                    in.close();
-                }
-            } catch (Exception e) { // TODO how to handle exceptions?
-                throw new RuntimeException(
-                        "Failed to load repository types for " + getName(), e);
+                typeManager = TypeFeedReader.INSTANCE.read(
+                        new ReadContext(this), in);
+            } finally {
+                in.close();
             }
+        } catch (Exception e) { // TODO how to handle exceptions?
+            throw new RuntimeException("Failed to load repository types for "
+                    + getName(), e);
         }
     }
 

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=797514&r1=797513&r2=797514&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
Fri Jul 24 15:01:16 2009
@@ -35,11 +35,13 @@
  */
 public class APPType extends APPObjectEntry implements Type {
 
+    private static final String UNDEFINED = "\0\0\0";
+
     protected Map<String, String> map;
 
     protected BaseType baseType;
 
-    protected String parentId;
+    protected String parentId = UNDEFINED;
 
     protected Map<String, PropertyDefinition> propertyDefs;
 
@@ -88,8 +90,11 @@
     }
 
     public String getParentId() {
-        if (parentId == null) {
+        if (parentId == UNDEFINED) {
             parentId = map.get(CMIS.PARENT_ID.getLocalPart());
+            if ("".equals(parentId)) {
+                parentId = null;
+            }
         }
         return parentId;
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeFeedReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeFeedReader.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeFeedReader.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/TypeFeedReader.java
Fri Jul 24 15:01:16 2009
@@ -13,21 +13,19 @@
  *
  * Authors:
  *     Bogdan Stefanescu, Nuxeo
+ *     Florent Guillaume, Nuxeo
  */
 package org.apache.chemistry.atompub.client;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.chemistry.Type;
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.atompub.client.stax.AbstractFeedReader;
+import org.apache.chemistry.impl.simple.SimpleTypeManager;
 import org.apache.chemistry.xml.stax.StaxReader;
 
 /**
- *
+ * Reader for a feed of types.
  */
-public class TypeFeedReader extends
-        AbstractFeedReader<Map<String, Type>, APPType> {
+public class TypeFeedReader extends AbstractFeedReader<TypeManager, APPType> {
 
     public static final TypeFeedReader INSTANCE = new TypeFeedReader();
 
@@ -40,13 +38,13 @@
     }
 
     @Override
-    protected void addEntry(Map<String, Type> feed, APPType entry) {
-        feed.put(entry.getId(), entry);
+    protected void addEntry(TypeManager typeManager, APPType type) {
+        typeManager.addType(type);
     }
 
     @Override
-    protected Map<String, Type> createFeed(StaxReader reader) {
-        return new HashMap<String, Type>();
+    protected TypeManager createFeed(StaxReader reader) {
+        return new SimpleTypeManager();
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
Fri Jul 24 15:01:16 2009
@@ -19,8 +19,8 @@
 package org.apache.chemistry.atompub.client.connector;
 
 import java.util.List;
-import java.util.Map;
 
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Type;
 import org.apache.chemistry.atompub.client.APPObjectEntryReader;
@@ -29,9 +29,9 @@
 import org.apache.chemistry.atompub.client.APPServiceDocumentReader;
 import org.apache.chemistry.atompub.client.TypeEntryReader;
 import org.apache.chemistry.atompub.client.TypeFeedReader;
-import org.apache.chemistry.atompub.client.stax.QueryWriter;
 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.ServiceDocumentReader;
 import org.apache.chemistry.atompub.client.stax.XmlObjectWriter;
 
@@ -65,7 +65,7 @@
         return serviceDocumentReader;
     }
 
-    public FeedReader<Map<String, Type>> getTypeFeedReader() {
+    public FeedReader<TypeManager> getTypeFeedReader() {
         return typeFeedReader;
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
Fri Jul 24 15:01:16 2009
@@ -20,10 +20,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
-import java.util.Map;
 
 import javax.xml.stream.XMLStreamException;
 
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.Type;
@@ -136,7 +136,7 @@
         }
     }
 
-    public Map<String, Type> getTypeFeed(ReadContext ctx)
+    public TypeManager getTypeFeed(ReadContext ctx)
             throws ContentManagerException {
         try {
             return io.getTypeFeedReader().read(ctx, getStream());

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/IOProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/IOProvider.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/IOProvider.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/IOProvider.java
Fri Jul 24 15:01:16 2009
@@ -18,8 +18,8 @@
 package org.apache.chemistry.atompub.client.connector;
 
 import java.util.List;
-import java.util.Map;
 
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Type;
 import org.apache.chemistry.atompub.client.stax.EntryReader;
@@ -41,7 +41,7 @@
 
     FeedReader<List<ObjectEntry>> getObjectFeedReader();
 
-    FeedReader<Map<String, Type>> getTypeFeedReader();
+    FeedReader<TypeManager> getTypeFeedReader();
 
     XmlObjectWriter<ObjectEntry> getObjectEntryWriter();
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java
Fri Jul 24 15:01:16 2009
@@ -18,8 +18,8 @@
 
 import java.io.InputStream;
 import java.util.List;
-import java.util.Map;
 
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.Type;
@@ -51,8 +51,7 @@
     List<ObjectEntry> getObjectFeed(ReadContext ctx)
             throws ContentManagerException;
 
-    Map<String, Type> getTypeFeed(ReadContext ctx)
-            throws ContentManagerException;
+    TypeManager getTypeFeed(ReadContext ctx) throws ContentManagerException;
 
     ObjectEntry getObject(ReadContext ctx) throws ContentManagerException;
 

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=797514&r1=797513&r2=797514&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
Fri Jul 24 15:01:16 2009
@@ -30,7 +30,7 @@
 import org.apache.chemistry.xml.stax.StaxReader;
 
 /**
- *
+ * Feed reader that returns a generic type T built of entries of generic type E.
  */
 public abstract class AbstractFeedReader<T, E> implements FeedReader<T> {
 

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=797514&r1=797513&r2=797514&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
Fri Jul 24 15:01:16 2009
@@ -24,7 +24,7 @@
 import org.apache.chemistry.xml.stax.StaxReader;
 
 /**
- *
+ * Feed reader that returns a generic type T.
  */
 public interface FeedReader<T> {
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TypeFeedReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TypeFeedReaderTest.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TypeFeedReaderTest.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/java/org/apache/chemistry/atompub/client/TypeFeedReaderTest.java
Fri Jul 24 15:01:16 2009
@@ -18,21 +18,20 @@
 package org.apache.chemistry.atompub.client;
 
 import java.io.InputStream;
-import java.util.Map;
 
 import junit.framework.TestCase;
 
 import org.apache.chemistry.Repository;
-import org.apache.chemistry.Type;
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.atompub.client.stax.ReadContext;
 
 public class TypeFeedReaderTest extends TestCase {
 
     public void testReadTypesFeed() throws Exception {
         InputStream is = getClass().getResourceAsStream("/feed-types.xml");
-        Map<String, Type> typeRegistry = TypeFeedReader.INSTANCE.read(
-                new ReadContext((Repository) null), is);
-        assertEquals(5, typeRegistry.size());
+        TypeManager typeManager = TypeFeedReader.INSTANCE.read(new ReadContext(
+                (Repository) null), is);
+        assertEquals(5, typeManager.getTypes(null).size());
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
Fri Jul 24 15:01:16 2009
@@ -263,7 +263,7 @@
     @Override
     public Iterable<Type> getEntries(RequestContext request)
             throws ResponseContextException {
-        return repository.getTypes(null, true);
+        return repository.getTypes(null);
     }
 
     @Override

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java
Fri Jul 24 15:01:16 2009
@@ -16,13 +16,9 @@
  */
 package org.apache.chemistry.impl.base;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.ContentStreamPresence;
@@ -32,8 +28,10 @@
 import org.apache.chemistry.RepositoryEntry;
 import org.apache.chemistry.RepositoryInfo;
 import org.apache.chemistry.Type;
+import org.apache.chemistry.TypeManager;
 import org.apache.chemistry.impl.simple.SimpleProperty;
 import org.apache.chemistry.impl.simple.SimpleType;
+import org.apache.chemistry.impl.simple.SimpleTypeManager;
 
 /**
  * Base implementation of a {@link Repository}. The implemented methods are
@@ -77,10 +75,10 @@
             ContentStreamPresence.NOT_ALLOWED, null, null,
             Collections.<PropertyDefinition> emptyList());
 
-    protected final Map<String, Type> types = new HashMap<String, Type>();
-
     protected final String name;
 
+    protected final TypeManager typeManager = new SimpleTypeManager();
+
     protected BaseRepository(String name) {
         this.name = name;
     }
@@ -92,11 +90,7 @@
 
     protected void addTypes(Collection<SimpleType> types) {
         for (Type type : types) {
-            String typeId = type.getId();
-            if (this.types.containsKey(typeId)) {
-                throw new RuntimeException("Type already defined: " + typeId);
-            }
-            this.types.put(typeId, type);
+            typeManager.addType(type);
         }
     }
 
@@ -120,59 +114,6 @@
         return this;
     }
 
-    public Type getType(String typeId) {
-        return types.get(typeId);
-    }
-
-    public Collection<Type> getTypes(String typeId,
-            boolean returnPropertyDefinitions) {
-        // TODO always returns property definitions for now
-        if (typeId == null) {
-            return Collections.unmodifiableCollection(types.values());
-        }
-        if (!types.containsKey(typeId)) {
-            return null; // TODO
-        }
-        // TODO return all descendants as well
-        return Collections.singleton(types.get(typeId));
-    }
-
-    public List<Type> getTypes(String typeId,
-            boolean returnPropertyDefinitions, int maxItems, int skipCount,
-            boolean[] hasMoreItems) {
-        if (maxItems < 0) {
-            throw new IllegalArgumentException(String.valueOf(maxItems));
-        }
-        if (skipCount < 0) {
-            throw new IllegalArgumentException(String.valueOf(skipCount));
-        }
-        if (hasMoreItems.length < 1) {
-            throw new IllegalArgumentException(
-                    "hasMoreItems parameter too small");
-        }
-
-        Collection<Type> t = getTypes(typeId, returnPropertyDefinitions);
-        if (t == null) {
-            hasMoreItems[0] = false;
-            return Collections.emptyList();
-        }
-        List<Type> all = new ArrayList<Type>(t);
-        int fromIndex = skipCount;
-        if (fromIndex < 0 || fromIndex > all.size()) {
-            hasMoreItems[0] = false;
-            return Collections.emptyList();
-        }
-        if (maxItems == 0) {
-            maxItems = all.size();
-        }
-        int toIndex = skipCount + maxItems;
-        if (toIndex > all.size()) {
-            toIndex = all.size();
-        }
-        hasMoreItems[0] = toIndex < all.size();
-        return all.subList(fromIndex, toIndex);
-    }
-
     /*
      * ----- RepositoryInfo -----
      */
@@ -202,4 +143,24 @@
         return Collections.emptySet();
     }
 
+    /*
+     * ----- TypeManager -----
+     */
+    public void addType(Type type) {
+        throw new UnsupportedOperationException("Cannot add types");
+    }
+
+    public Type getType(String typeId) {
+        return typeManager.getType(typeId);
+    }
+
+    public Collection<Type> getTypes(String typeId) {
+        return typeManager.getTypes(typeId);
+    }
+
+    public Collection<Type> getTypes(String typeId, int depth,
+            boolean returnPropertyDefinitions) {
+        return typeManager.getTypes(typeId, depth, returnPropertyDefinitions);
+    }
+
 }

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java?rev=797514&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
Fri Jul 24 15:01:16 2009
@@ -0,0 +1,113 @@
+/*
+ * 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.impl.simple;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.chemistry.BaseType;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.TypeManager;
+
+public class SimpleTypeManager implements TypeManager {
+
+    protected final Map<String, Type> types = new HashMap<String, Type>();
+
+    protected final Map<String, Collection<Type>> typesChildren = new HashMap<String,
Collection<Type>>();
+
+    public void addType(Type type) {
+        String typeId = type.getId();
+        if (types.containsKey(typeId)) {
+            throw new RuntimeException("Type already defined: " + typeId);
+        }
+        types.put(typeId, type);
+        typesChildren.put(typeId, new LinkedList<Type>());
+        String parentId = type.getParentId();
+        if (parentId == null) {
+            // check it's a base type
+            try {
+                BaseType.get(typeId);
+            } catch (IllegalArgumentException e) {
+                throw new IllegalArgumentException("Type: " + typeId
+                        + " must have a parent type");
+            }
+        } else {
+            Collection<Type> siblings = typesChildren.get(parentId);
+            if (siblings == null) {
+                throw new IllegalArgumentException("Type: " + typeId
+                        + " refers to unknown parent: " + parentId);
+            }
+            siblings.add(type);
+            // TODO check no cycle
+        }
+    }
+
+    public Type getType(String typeId) {
+        return types.get(typeId);
+    }
+
+    public Collection<Type> getTypes(String typeId) {
+        return getTypes(typeId, -1, true);
+    }
+
+    /*
+     * This implementation returns subtypes depth-first.
+     */
+    public Collection<Type> getTypes(String typeId, int depth,
+            boolean returnPropertyDefinitions) {
+        if (typeId == null) {
+            // ignore depth
+            // TODO returnPropertyDefinitions
+            return Collections.unmodifiableCollection(types.values());
+        }
+        if (!types.containsKey(typeId)) {
+            throw new IllegalArgumentException("No such type: " + typeId);
+        }
+        // TODO spec unclear on depth 0
+        List<Type> list = new LinkedList<Type>();
+        collectSubTypes(typeId, depth, returnPropertyDefinitions, list,
+                new HashSet<String>());
+        return list;
+    }
+
+    protected void collectSubTypes(String typeId, int depth,
+            boolean returnPropertyDefinitions, List<Type> list, Set<String> done)
{
+        if (done.contains(typeId)) {
+            // TODO move cycles check to addType
+            throw new IllegalStateException("Types contain a cycle involving: "
+                    + typeId);
+        }
+        // TODO returnPropertyDefinitions
+        list.add(types.get(typeId));
+        done.add(typeId);
+        if (depth == 0) {
+            return;
+        }
+        Collection<Type> children = typesChildren.get(typeId);
+        for (Type type : children) {
+            collectSubTypes(type.getId(), depth - 1, returnPropertyDefinitions,
+                    list, done);
+        }
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
Fri Jul 24 15:01:16 2009
@@ -69,7 +69,11 @@
                 "Fold", "My Folder Type", BaseType.FOLDER, "", true, true,
                 true, true, false, false, ContentStreamPresence.NOT_ALLOWED,
                 null, null, Arrays.asList(d1, d2));
-        repo = new SimpleRepository("test", Arrays.asList(mt1, mt2), null);
+        SimpleType mt3 = new SimpleType("subdoc", "doc", "SubDoc",
+                "My SubDoc Type", BaseType.DOCUMENT, "", true, true, true,
+                true, true, true, ContentStreamPresence.ALLOWED, null, null,
+                Arrays.asList(d1, d2, d3));
+        repo = new SimpleRepository("test", Arrays.asList(mt1, mt2, mt3), null);
 
     }
 
@@ -95,9 +99,30 @@
         assertEquals(JoinCapability.NONE, capabilities.getJoinCapability());
         assertEquals(QueryCapability.BOTH_COMBINED,
                 capabilities.getQueryCapability());
+    }
 
-        Collection<Type> types = repo.getTypes(null, true);
-        assertEquals(5 + 2, types.size()); // default types have been added
+    public void testTypes() {
+        Collection<Type> types = repo.getTypes(null);
+        assertEquals(5 + 3, types.size()); // default types have been added
+        assertNotNull(repo.getType("doc"));
+        assertNotNull(repo.getType("subdoc"));
+        assertNotNull(repo.getType("fold"));
+        assertNull(repo.getType("no-such-type"));
+        assertEquals(3,
+                repo.getTypes(BaseType.DOCUMENT.getId(), -1, false).size());
+        assertEquals(1, // TODO spec unclear on depth 0
+                repo.getTypes(BaseType.DOCUMENT.getId(), 0, false).size());
+        assertEquals(2,
+                repo.getTypes(BaseType.DOCUMENT.getId(), 1, false).size());
+        assertEquals(3,
+                repo.getTypes(BaseType.DOCUMENT.getId(), 2, false).size());
+        assertEquals(3,
+                repo.getTypes(BaseType.DOCUMENT.getId(), 3, false).size());
+        assertEquals(2, repo.getTypes("doc", -1, false).size());
+        assertEquals(1, repo.getTypes("doc", 0, false).size());
+        assertEquals(2, repo.getTypes("doc", 1, false).size());
+        assertEquals(2, repo.getTypes("doc", 2, false).size());
+        assertEquals(2, repo.getTypes("doc", 3, false).size());
     }
 
     public void testRoot() throws Exception {

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java?rev=797514&r1=797513&r2=797514&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
Fri Jul 24 15:01:16 2009
@@ -89,6 +89,10 @@
         return this;
     }
 
+    public void addType(Type type) {
+        throw new UnsupportedOperationException("Cannot add types");
+    }
+
     public Type getType(String typeId) {
         try {
             // TODO pass credentials as parameters
@@ -113,17 +117,15 @@
         return null;
     }
 
-    public Collection<Type> getTypes(String typeId,
-                                     boolean returnPropertyDefinitions) {
-        boolean[] hasMoreItems = new boolean[1];
-        return getTypes(typeId, returnPropertyDefinitions, 0, 0, hasMoreItems);
+    public Collection<Type> getTypes(String typeId) {
+        return getTypes(typeId, -1, true);
     }
 
-    public List<Type> getTypes(String typeId,
-                               boolean returnPropertyDefinitions, int maxItems,
-                               int skipCount, boolean[] hasMoreItems) {
+    public List<Type> getTypes(String typeId, int depth,
+            boolean returnPropertyDefinitions) {
 
         // TODO dynamically discover and return types.
+        // TODO depth, returnPropertyDefinitions
 
         try {
             // TODO pass credentials as parameters



Mime
View raw message