Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 88661 invoked from network); 24 Jul 2009 15:00:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Jul 2009 15:00:40 -0000 Received: (qmail 69864 invoked by uid 500); 24 Jul 2009 15:01:45 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 69829 invoked by uid 500); 24 Jul 2009 15:01:45 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 69819 invoked by uid 99); 24 Jul 2009 15:01:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2009 15:01:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2009 15:01:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 28327238889B; Fri, 24 Jul 2009 15:01:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: chemistry-commits@incubator.apache.org From: fguillaume@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090724150118.28327238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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. + *

+ * Basic repository information is available through {@link RepositoryEntry}. + *

+ * 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. - *

- * If typeId is provided, only the specific type and its descendants are - * returned, otherwise all types are returned. - *

- * 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 getTypes(String typeId, boolean returnPropertyDefinitions); - - /** - * Gets the type definitions of the repository. - *

- * If typeId is provided, only the specific type and its descendants are - * returned, otherwise all types are returned. - *

- * If returnPropertyDefinitions is {@code false}, then the - * {@link PropertyDefinition}s will not be returned in each {@link Type}. - *

- * 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 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. + *

+ * 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. + *

+ * 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 getTypes(String typeId); + + /** + * Gets the types. + *

+ * If typeId is provided, only the specific type and its descendants are + * returned, otherwise all types are returned. + *

+ * The depth parameter controls the number of levels of the type hierarchy + * to return: + *

    + *
  • -1: all descendants at all depths,
  • + *
  • 1: only children of the type,
  • + *
  • more than 1: grand-children up to that depth,
  • + *
+ * 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 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 typeRegistry; + protected TypeManager typeManager; protected Map collections = new HashMap(); @@ -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 getTypes(String typeId, - boolean returnPropertyDefinitions, int maxItems, int skipCount, - boolean[] hasMoreItems) { - loadTypes(); - throw new UnsupportedOperationException("Not yet Implemented"); + public Collection getTypes(String typeId) { + return typeManager.getTypes(typeId); } - public Collection getTypes(String typeId, + public Collection 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 map; protected BaseType baseType; - protected String parentId; + protected String parentId = UNDEFINED; protected Map 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, APPType> { +public class TypeFeedReader extends AbstractFeedReader { public static final TypeFeedReader INSTANCE = new TypeFeedReader(); @@ -40,13 +38,13 @@ } @Override - protected void addEntry(Map feed, APPType entry) { - feed.put(entry.getId(), entry); + protected void addEntry(TypeManager typeManager, APPType type) { + typeManager.addType(type); } @Override - protected Map createFeed(StaxReader reader) { - return new HashMap(); + 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> getTypeFeedReader() { + public FeedReader 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 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> getObjectFeedReader(); - FeedReader> getTypeFeedReader(); + FeedReader getTypeFeedReader(); XmlObjectWriter 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 getObjectFeed(ReadContext ctx) throws ContentManagerException; - Map 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 implements FeedReader { 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 { 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 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 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. emptyList()); - protected final Map types = new HashMap(); - 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 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 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 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 t = getTypes(typeId, returnPropertyDefinitions); - if (t == null) { - hasMoreItems[0] = false; - return Collections.emptyList(); - } - List all = new ArrayList(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 getTypes(String typeId) { + return typeManager.getTypes(typeId); + } + + public Collection 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 types = new HashMap(); + + protected final Map> typesChildren = new HashMap>(); + + 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()); + 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 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 getTypes(String typeId) { + return getTypes(typeId, -1, true); + } + + /* + * This implementation returns subtypes depth-first. + */ + public Collection 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 list = new LinkedList(); + collectSubTypes(typeId, depth, returnPropertyDefinitions, list, + new HashSet()); + return list; + } + + protected void collectSubTypes(String typeId, int depth, + boolean returnPropertyDefinitions, List list, Set 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 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 types = repo.getTypes(null, true); - assertEquals(5 + 2, types.size()); // default types have been added + public void testTypes() { + Collection 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 getTypes(String typeId, - boolean returnPropertyDefinitions) { - boolean[] hasMoreItems = new boolean[1]; - return getTypes(typeId, returnPropertyDefinitions, 0, 0, hasMoreItems); + public Collection getTypes(String typeId) { + return getTypes(typeId, -1, true); } - public List getTypes(String typeId, - boolean returnPropertyDefinitions, int maxItems, - int skipCount, boolean[] hasMoreItems) { + public List getTypes(String typeId, int depth, + boolean returnPropertyDefinitions) { // TODO dynamically discover and return types. + // TODO depth, returnPropertyDefinitions try { // TODO pass credentials as parameters