chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r773069 [2/6] - in /incubator/chemistry/trunk/chemistry: ./ chemistry-api/src/main/java/org/apache/chemistry/ chemistry-api/src/main/java/org/apache/chemistry/property/ chemistry-api/src/main/java/org/apache/chemistry/repository/ chemistry-...
Date Fri, 08 May 2009 19:52:44 GMT
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForChildren.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForChildren.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForChildren.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForChildren.java Fri May  8 19:52:42 2009
@@ -39,14 +39,16 @@
 import org.apache.abdera.protocol.server.context.AbstractResponseContext;
 import org.apache.abdera.protocol.server.context.BaseResponseContext;
 import org.apache.abdera.protocol.server.context.ResponseContextException;
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.Repository;
 import org.apache.chemistry.ReturnVersion;
 import org.apache.chemistry.SPI;
+import org.apache.chemistry.Type;
 import org.apache.chemistry.atompub.CMIS;
-import org.apache.chemistry.atompub.ObjectElement;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.type.BaseType;
+import org.apache.chemistry.atompub.abdera.ObjectElement;
 
 /**
  * CMIS Collection for the children of a Folder.
@@ -110,6 +112,7 @@
     /*
      * ----- AbstractEntityCollectionAdapter -----
      */
+
     @Override
     protected String addEntryDetails(RequestContext request, Entry entry,
             IRI feedIri, ObjectEntry object) throws ResponseContextException {
@@ -139,17 +142,13 @@
         // CMIS links
         entry.addLink(getRepositoryLink(request), CMIS.LINK_REPOSITORY);
         entry.addLink(getTypeLink(object.getTypeId(), request), CMIS.LINK_TYPE);
-        if (object.getType().getBaseType() == BaseType.FOLDER) {
+        Type objectType = repository.getType(object.getTypeId());
+        if (objectType.getBaseType() == BaseType.FOLDER) {
             String oid = object.getId();
             entry.addLink(getChildrenLink(oid, request), CMIS.LINK_CHILDREN);
             entry.addLink(getDescendantsLink(oid, request),
                     CMIS.LINK_DESCENDANTS);
             entry.addLink(getParentsLink(oid, request), CMIS.LINK_PARENTS);
-            String pid = object.getId(Property.PARENT_ID);
-            if (pid != null) {
-                // TODO unclear in spec (parent vs parents)
-                entry.addLink(getObjectLink(pid, request), CMIS.LINK_PARENT);
-            }
         }
         // entry.addLink("XXX", CMIS.LINK_ALLOWABLE_ACTIONS);
         // entry.addLink("XXX", CMIS.LINK_RELATIONSHIPS);
@@ -157,7 +156,8 @@
         // ContentStreamUri needs to know the media link
         String mediaLink = isMediaEntry(object) ? getMediaLink(object.getId(),
                 request) : null;
-        entry.addExtension(new ObjectElement(factory, object, mediaLink));
+        entry.addExtension(new ObjectElement(factory, object, objectType,
+                mediaLink));
 
         return link;
     }
@@ -169,10 +169,11 @@
     @Override
     public Iterable<ObjectEntry> getEntries(RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getConnection(null).getSPI();
+        SPI spi = repository.getSPI(); // TODO XXX connection leak
         boolean[] hasMoreItems = new boolean[1];
-        List<ObjectEntry> children = spi.getChildren(id, null, null, false,
-                false, 0, 0, null, hasMoreItems);
+        ObjectId objectId = spi.newObjectId(id);
+        List<ObjectEntry> children = spi.getChildren(objectId, null, null,
+                false, false, 0, 0, null, hasMoreItems);
         return children;
     }
 
@@ -200,7 +201,7 @@
     public List<Person> getAuthors(ObjectEntry object, RequestContext request) {
         String author = null;
         try {
-            author = object.getString(Property.CREATED_BY);
+            author = (String) object.getValue(Property.CREATED_BY);
         } catch (Exception e) {
             // no such property or bad type
         }
@@ -215,7 +216,8 @@
     @Override
     public boolean isMediaEntry(ObjectEntry object)
             throws ResponseContextException {
-        return object.hasContentStream();
+        SPI spi = repository.getSPI(); // TODO XXX connection leak
+        return spi.hasContentStream(object);
     }
 
     @Override
@@ -225,7 +227,7 @@
         String mediaLink = getMediaLink(object.getId(), request);
         entry.setContent(new IRI(mediaLink), getContentType(object));
         entry.addLink(mediaLink, "edit-media");
-        entry.addLink(mediaLink, "cmis-stream");
+        entry.addLink(mediaLink, CMIS.LINK_STREAM);
         return mediaLink;
     }
 
@@ -238,14 +240,15 @@
 
     @Override
     public String getContentType(ObjectEntry object) {
-        return object.getString(Property.CONTENT_STREAM_MIME_TYPE);
+        return (String) object.getValue(Property.CONTENT_STREAM_MIME_TYPE);
     }
 
     @Override
     public ObjectEntry getEntry(String id, RequestContext request)
             throws ResponseContextException {
-        SPI spi = repository.getConnection(null).getSPI();
-        return spi.getProperties(id, ReturnVersion.THIS, null, false, false);
+        SPI spi = repository.getSPI(); // TODO XXX connection leak
+        return spi.getProperties(spi.newObjectId(id), ReturnVersion.THIS, null,
+                false, false);
     }
 
     @Override
@@ -263,9 +266,9 @@
     public InputStream getMediaStream(ObjectEntry object)
             throws ResponseContextException {
         // TODO entry was fetched for mostly nothing...
-        SPI spi = repository.getConnection(null).getSPI();
+        SPI spi = repository.getSPI(); // TODO XXX connection leak
         try {
-            return spi.getContentStream(object.getId(), 0, -1);
+            return spi.getContentStream(object, 0, -1);
         } catch (IOException e) {
             throw new ResponseContextException(500, e);
         }
@@ -285,12 +288,12 @@
     public String getTitle(ObjectEntry object) {
         String title = null;
         try {
-            title = object.getString("title"); // TODO improve
+            title = (String) object.getValue("title"); // TODO improve
         } catch (Exception e) {
             // no such property or bad type
         }
         if (title == null) {
-            title = object.getName();
+            title = (String) object.getValue(Property.NAME);
         }
         return title;
     }
@@ -299,7 +302,7 @@
     public Date getUpdated(ObjectEntry object) {
         Date date = null;
         try {
-            Calendar calendar = object.getDateTime(Property.LAST_MODIFICATION_DATE);
+            Calendar calendar = (Calendar) object.getValue(Property.LAST_MODIFICATION_DATE);
             if (calendar != null) {
                 date = calendar.getTime();
             }
@@ -316,7 +319,7 @@
     public Text getSummary(ObjectEntry object, RequestContext request) {
         String summary = null;
         try {
-            summary = object.getString("description"); // TODO improve
+            summary = (String) object.getValue("description"); // TODO improve
         } catch (Exception e) {
             // no such property or bad type
         }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForOther.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForOther.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForOther.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForOther.java Fri May  8 19:52:42 2009
@@ -27,7 +27,7 @@
 import org.apache.abdera.model.Person;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.context.ResponseContextException;
-import org.apache.chemistry.repository.Repository;
+import org.apache.chemistry.Repository;
 
 /**
  * CMIS Collection for the XXX.

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForTypes.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForTypes.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForTypes.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollectionForTypes.java Fri May  8 19:52:42 2009
@@ -21,6 +21,8 @@
 import java.util.Date;
 import java.util.List;
 
+import javax.xml.namespace.QName;
+
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Content;
@@ -30,9 +32,11 @@
 import org.apache.abdera.model.Person;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.context.ResponseContextException;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.Type;
 import org.apache.chemistry.atompub.CMIS;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.type.Type;
 
 /**
  * CMIS Collection for the Types.
@@ -133,7 +137,97 @@
         el.setText(bool(type.isControllable()));
         el = factory.newElement(CMIS.VERSIONABLE, dt);
         el.setText(bool(type.isVersionable()));
-
+        el = factory.newElement(CMIS.INCLUDED_IN_SUPERTYPE_QUERY, dt);
+        el.setText(bool(type.isIncludedInSuperTypeQuery()));
+        if ("true".equals(request.getParameter("includePropertyDefinitions"))) {
+            for (PropertyDefinition pd : type.getPropertyDefinitions()) {
+                QName qname;
+                switch (pd.getType().ordinal()) {
+                case PropertyType.STRING_ORD:
+                    qname = CMIS.PROPERTY_STRING_DEFINITION;
+                    break;
+                case PropertyType.DECIMAL_ORD:
+                    qname = CMIS.PROPERTY_DECIMAL_DEFINITION;
+                    break;
+                case PropertyType.INTEGER_ORD:
+                    qname = CMIS.PROPERTY_INTEGER_DEFINITION;
+                    break;
+                case PropertyType.BOOLEAN_ORD:
+                    qname = CMIS.PROPERTY_BOOLEAN_DEFINITION;
+                    break;
+                case PropertyType.DATETIME_ORD:
+                    qname = CMIS.PROPERTY_DATETIME_DEFINITION;
+                    break;
+                case PropertyType.URI_ORD:
+                    qname = CMIS.PROPERTY_URI_DEFINITION;
+                    break;
+                case PropertyType.ID_ORD:
+                    qname = CMIS.PROPERTY_ID_DEFINITION;
+                    break;
+                case PropertyType.XML_ORD:
+                    qname = CMIS.PROPERTY_XML_DEFINITION;
+                    break;
+                case PropertyType.HTML_ORD:
+                    qname = CMIS.PROPERTY_HTML_DEFINITION;
+                    break;
+                default:
+                    throw new AssertionError(pd.getType().name());
+                }
+                Element def = factory.newElement(qname, dt);
+                el = factory.newElement(CMIS.NAME, def);
+                el.setText(pd.getName());
+                el = factory.newElement(CMIS.ID, def);
+                el.setText(pd.getId());
+                el = factory.newElement(CMIS.PACKAGE, def);
+                el.setText("system"); // TODO package
+                el = factory.newElement(CMIS.DISPLAY_NAME, def);
+                el.setText(pd.getDisplayName());
+                el = factory.newElement(CMIS.DESCRIPTION, def);
+                el.setText(pd.getDescription());
+                el = factory.newElement(CMIS.PROPERTY_TYPE, def);
+                el.setText(pd.getType().name());
+                el = factory.newElement(CMIS.CARDINALITY, def);
+                el.setText(pd.isMultiValued() ? "multi" : "single");
+                el = factory.newElement(CMIS.UPDATABILITY, def);
+                el.setText(pd.getUpdatability().toString());
+                el = factory.newElement(CMIS.INHERITED, def);
+                el.setText(pd.isInherited() ? "true" : "false");
+                el = factory.newElement(CMIS.REQUIRED, def);
+                el.setText(pd.isRequired() ? "true" : "false");
+                el = factory.newElement(CMIS.QUERYABLE, def);
+                el.setText(pd.isQueryable() ? "true" : "false");
+                el = factory.newElement(CMIS.ORDERABLE, def);
+                el.setText(pd.isOrderable() ? "true" : "false");
+                // TODO choices
+                // TODO defaultValue
+                switch (pd.getType().ordinal()) {
+                case PropertyType.STRING_ORD:
+                    // TODO maxLength
+                    break;
+                case PropertyType.DECIMAL_ORD:
+                    // TODO precision
+                    break;
+                case PropertyType.INTEGER_ORD:
+                    // TODO minValue/maxValue
+                    break;
+                case PropertyType.BOOLEAN_ORD:
+                    break;
+                case PropertyType.DATETIME_ORD:
+                    break;
+                case PropertyType.URI_ORD:
+                    break;
+                case PropertyType.ID_ORD:
+                    break;
+                case PropertyType.XML_ORD:
+                    // TODO schemaURI
+                    break;
+                case PropertyType.HTML_ORD:
+                    break;
+                default:
+                    throw new AssertionError(pd.getType().name());
+                }
+            }
+        }
         return link;
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java Fri May  8 19:52:42 2009
@@ -32,8 +32,8 @@
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
 import org.apache.abdera.protocol.server.impl.TemplateTargetBuilder;
 import org.apache.abdera.util.Constants;
+import org.apache.chemistry.Repository;
 import org.apache.chemistry.atompub.CMIS;
-import org.apache.chemistry.repository.Repository;
 
 /**
  * Abdera provider for the CMIS bindings used by Chemistry.
@@ -59,7 +59,8 @@
         // service
         targetBuilder.setTemplate(TargetType.TYPE_SERVICE,
                 "{target_base}/repository");
-        targetResolver.setPattern("/repository", TargetType.TYPE_SERVICE);
+        targetResolver.setPattern("/repository(\\?.*)?",
+                TargetType.TYPE_SERVICE);
 
         // entry
         targetBuilder.setTemplate(TargetType.TYPE_ENTRY,
@@ -85,7 +86,7 @@
         targetResolver.setPattern("/unfiled", TargetType.TYPE_COLLECTION);
         targetResolver.setPattern("/query", //
                 TargetType.TYPE_COLLECTION);
-        targetResolver.setPattern("/types", //
+        targetResolver.setPattern("/types(\\?.*)?", //
                 TargetType.TYPE_COLLECTION);
         // per-object collections
         targetResolver.setPattern("/parents/([^/?]+)",
@@ -111,12 +112,12 @@
         CollectionInfo ci;
 
         workspaceInfo.addCollection(new CMISCollectionForChildren(
-                CMIS.COL_ROOT_CHILDREN, repository.getInfo().getRootFolderId(),
-                repository));
+                CMIS.COL_ROOT_CHILDREN,
+                repository.getInfo().getRootFolderId().getId(), repository));
 
         workspaceInfo.addCollection(new CMISCollectionForOther(
                 CMIS.COL_ROOT_DESCENDANTS, "descendants",
-                repository.getInfo().getRootFolderId(), repository));
+                repository.getInfo().getRootFolderId().getId(), repository));
 
         workspaceInfo.addCollection(new CMISCollectionForOther(
                 CMIS.COL_UNFILED, "unfiled", null, repository));

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java Fri May  8 19:52:42 2009
@@ -28,11 +28,10 @@
 import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
 import org.apache.abdera.writer.StreamWriter;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryCapabilities;
+import org.apache.chemistry.RepositoryInfo;
 import org.apache.chemistry.atompub.CMIS;
-import org.apache.chemistry.repository.QueryCapability;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.repository.RepositoryCapabilities;
-import org.apache.chemistry.repository.RepositoryInfo;
 import org.w3c.dom.Document;
 
 /**
@@ -43,6 +42,8 @@
  */
 public class CMISServiceResponse extends StreamWriterResponseContext {
 
+    public static final String ATOMPUB_VERSION_SUPPORTED = "0.61";
+
     protected final CMISProvider provider;
 
     protected final RequestContext request;
@@ -107,7 +108,7 @@
             write(CMIS.VENDOR_NAME, info.getVendorName());
             write(CMIS.PRODUCT_NAME, info.getProductName());
             write(CMIS.PRODUCT_VERSION, info.getProductVersion());
-            write(CMIS.ROOT_FOLDER_ID, info.getRootFolderId());
+            write(CMIS.ROOT_FOLDER_ID, info.getRootFolderId().getId());
 
             sw.startElement(CMIS.CAPABILITIES);
             write(CMIS.CAPABILITY_MULTIFILING, cap.hasMultifiling());
@@ -118,39 +119,11 @@
             write(CMIS.CAPABILITY_PWC_SEARCHABLE, cap.isPWCSearchable());
             write(CMIS.CAPABILITY_ALL_VERSIONS_SEARCHABLE,
                     cap.isAllVersionsSearchable());
-            QueryCapability qc = cap.getQueryCapability();
-            // CMIS 0.50 query/fulltext
-            String fts;
-            String qcs;
-            switch (qc) {
-            case NONE:
-            case METADATA_ONLY:
-                qcs = qc.toString();
-                fts = "none";
-                break;
-            case FULL_TEXT_ONLY:
-                qcs = qc.toString();
-                fts = "fulltextonly";
-                break;
-            case BOTH_COMBINED:
-                qcs = "both";
-                fts = "fulltext";
-                break;
-            case BOTH_SEPARATE:
-                qcs = "both";
-                fts = "fulltextonly";
-                break;
-            default:
-                throw new UnsupportedOperationException();
-            }
-            write(CMIS.CAPABILITY_QUERY, qcs); // CMIS 0.50
+            write(CMIS.CAPABILITY_QUERY, cap.getQueryCapability().toString());
             write(CMIS.CAPABILITY_JOIN, cap.getJoinCapability().toString());
-            write(CMIS.CAPABILITY_FULL_TEXT, fts); // CMIS 0.50
             sw.endElement();
 
-            // String version = info.getVersionSupported();
-            String version = "0.5";
-            write(CMIS.VERSIONS_SUPPORTED, version);
+            write(CMIS.VERSION_SUPPORTED, ATOMPUB_VERSION_SUPPORTED);
             write(CMIS.REPOSITORY_SPECIFIC_INFORMATION,
                     info.getRepositorySpecificInformation());
             sw.endElement();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java Fri May  8 19:52:42 2009
@@ -18,74 +18,25 @@
  */
 package org.apache.chemistry.atompub.server;
 
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.repository.RepositoryFactory;
+import org.apache.chemistry.Repository;
 
 public class CMISServlet extends AbderaServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private Repository repository;
-
-    public CMISServlet() {}
+    private final Repository repository;
 
     public CMISServlet(Repository repository) {
         this.repository = repository;
     }
 
     @Override
-    public void init() throws ServletException {
-        if (repository == null) {
-            Map<String, String> params = new HashMap<String, String>();
-            @SuppressWarnings("unchecked")
-            Enumeration<String> names = getInitParameterNames();
-            while (names.hasMoreElements()) {
-                String name = names.nextElement();
-                params.put(name, getInitParameter(name));
-            }
-            repository = createRepository(getServletContext(), params);
-        }
-        super.init();
-    }
-
-    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);
-        }
-    }
-
-    @Override
     protected Provider createProvider() {
         Provider provider = new CMISProvider(repository);
         Abdera abdera = new Abdera();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java Fri May  8 19:52:42 2009
@@ -21,6 +21,7 @@
 import org.apache.abdera.protocol.server.CollectionAdapter;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.impl.AbstractWorkspaceManager;
+import org.apache.chemistry.Repository;
 
 /**
  * Workspace manager that correctly finds the appropriate collection adapter by
@@ -37,27 +38,24 @@
     }
 
     public CollectionAdapter getCollectionAdapter(RequestContext request) {
+        Repository repository = provider.getRepository();
         String path = request.getTargetPath();
         String paths = path + '/';
-        if (paths.startsWith("/types/")) {
-            return new CMISCollectionForTypes(null, provider.getRepository());
+        if (paths.startsWith("/types/") || paths.startsWith("/types?")) {
+            return new CMISCollectionForTypes(null, repository);
         }
         if (paths.startsWith("/children/")) {
-            return new CMISCollectionForChildren(null,
-                    request.getTarget().getParameter("objectid"),
-                    provider.getRepository());
+            String id = request.getTarget().getParameter("objectid");
+            return new CMISCollectionForChildren(null, id, repository);
         }
         if (paths.startsWith("/object/")) {
-            return new CMISCollectionForChildren(null, null,
-                    provider.getRepository());
+            return new CMISCollectionForChildren(null, null, repository);
         }
         if (paths.startsWith("/file/")) {
-            return new CMISCollectionForChildren(null, null,
-                    provider.getRepository());
+            return new CMISCollectionForChildren(null, null, repository);
         }
         if (paths.startsWith("/unfiled/")) {
-            return new CMISCollectionForOther(null, "unfiled", null,
-                    provider.getRepository());
+            return new CMISCollectionForOther(null, "unfiled", null, repository);
         }
         return null;
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubServer.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubServer.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubServer.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubServer.java Fri May  8 19:52:42 2009
@@ -30,20 +30,21 @@
 import org.apache.abdera.model.Workspace;
 import org.apache.abdera.protocol.client.AbderaClient;
 import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.ContentStream;
+import org.apache.chemistry.ContentStreamPresence;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.Updatability;
 import org.apache.chemistry.atompub.CMIS;
 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.SimpleType;
-import org.apache.chemistry.property.PropertyType;
-import org.apache.chemistry.property.Updatability;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.ContentStreamPresence;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpStatus;
@@ -72,7 +73,7 @@
 
     @Override
     public void setUp() throws Exception {
-        repository = makeRepository();
+        repository = makeRepository(null);
         startServer();
     }
 
@@ -94,17 +95,17 @@
         server.stop();
     }
 
-    public static Repository makeRepository() throws IOException {
-        SimplePropertyDefinition p1 = new SimplePropertyDefinition("title",
+    public static Repository makeRepository(String rootId) throws IOException {
+        PropertyDefinition p1 = new SimplePropertyDefinition("title",
                 "def:title", "Title", "", false, PropertyType.STRING, false,
                 null, false, false, "", Updatability.READ_WRITE, true, true, 0,
                 null, null, -1, null, null);
-        SimplePropertyDefinition p2 = new SimplePropertyDefinition(
-                "description", "def:description", "Description", "", false,
+        PropertyDefinition p2 = new SimplePropertyDefinition("description",
+                "def:description", "Description", "", false,
                 PropertyType.STRING, false, null, false, false, "",
                 Updatability.READ_WRITE, true, true, 0, null, null, -1, null,
                 null);
-        SimplePropertyDefinition p3 = new SimplePropertyDefinition("date",
+        PropertyDefinition p3 = new SimplePropertyDefinition("date",
                 "def:date", "Date", "", false, PropertyType.DATETIME, false,
                 null, false, false, null, Updatability.READ_WRITE, true, true,
                 0, null, null, -1, null, null);
@@ -117,7 +118,7 @@
                 false, false, ContentStreamPresence.NOT_ALLOWED, null, null,
                 Arrays.asList(p1, p2));
         SimpleRepository repo = new SimpleRepository("test", Arrays.asList(dt,
-                ft));
+                ft), rootId);
         Connection conn = repo.getConnection(null);
         Folder root = conn.getRootFolder();
 
@@ -173,7 +174,7 @@
         assertNotNull(el);
 
         resp = client.get(base + "/children/"
-                + repository.getInfo().getRootFolderId());
+                + repository.getInfo().getRootFolderId().getId());
         assertEquals(200, resp.getStatus());
         Element ch = resp.getDocument().getRoot();
         assertNotNull(ch);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java Fri May  8 19:52:42 2009
@@ -31,14 +31,14 @@
     private CMIS() {
     }
 
-    public static QName CMISName(String localPart) {
-        return new QName(CMIS_NS, localPart, CMIS_PREFIX);
-    }
-
     public static final String CMIS_NS = "http://docs.oasis-open.org/ns/cmis/core/200901";
 
     public static final String CMIS_PREFIX = "cmis";
 
+    public static QName CMISName(String localPart) {
+        return new QName(CMIS_NS, localPart, CMIS_PREFIX);
+    }
+
     /*
      * ----- XML Qualified Names -----
      */
@@ -79,9 +79,7 @@
 
     public static final QName CAPABILITY_JOIN = CMISName("capabilityJoin");
 
-    public static final QName CAPABILITY_FULL_TEXT = CMISName("capabilityFullText");
-
-    public static final QName VERSIONS_SUPPORTED = CMISName("cmisVersionsSupported");
+    public static final QName VERSION_SUPPORTED = CMISName("cmisVersionSupported");
 
     public static final QName REPOSITORY_SPECIFIC_INFORMATION = CMISName("repositorySpecificInformation");
 
@@ -113,6 +111,46 @@
 
     public static final QName VERSIONABLE = CMISName("versionable");
 
+    public static final QName INCLUDED_IN_SUPERTYPE_QUERY = CMISName("includedInSupertypeQuery");
+
+    public static final QName PROPERTY_STRING_DEFINITION = CMISName("propertyStringDefinition");
+
+    public static final QName PROPERTY_DECIMAL_DEFINITION = CMISName("propertyDecimalDefinition");
+
+    public static final QName PROPERTY_INTEGER_DEFINITION = CMISName("propertyIntegerDefinition");
+
+    public static final QName PROPERTY_BOOLEAN_DEFINITION = CMISName("propertyBooleanDefinition");
+
+    public static final QName PROPERTY_DATETIME_DEFINITION = CMISName("propertyDateTimeDefinition");
+
+    public static final QName PROPERTY_URI_DEFINITION = CMISName("propertyUriDefinition");
+
+    public static final QName PROPERTY_ID_DEFINITION = CMISName("propertyIdDefinition");
+
+    public static final QName PROPERTY_XML_DEFINITION = CMISName("propertyXmlDefinition");
+
+    public static final QName PROPERTY_HTML_DEFINITION = CMISName("propertyHtmlDefinition");
+
+    public static final QName NAME = CMISName("name");
+
+    public static final QName ID = CMISName("id");
+
+    public static final QName PACKAGE = CMISName("package");
+
+    public static final QName PROPERTY_TYPE = CMISName("propertyType");
+
+    public static final QName CARDINALITY = CMISName("cardinality");
+
+    public static final QName UPDATABILITY = CMISName("updatability");
+
+    public static final QName INHERITED = CMISName("inherited");
+
+    public static final QName REQUIRED = CMISName("required");
+
+    public static final QName ORDERABLE = CMISName("orderable");
+
+    public static final QName DEFAULT_VALUE = CMISName("defaultValue");
+
     public static final QName OBJECT = CMISName("object");
 
     public static final QName PROPERTIES = CMISName("properties");
@@ -135,8 +173,6 @@
 
     public static final QName PROPERTY_HTML = CMISName("propertyHtml");
 
-    public static final QName NAME = CMISName("name");
-
     public static final QName VALUE = CMISName("value");
 
     public static final QName ALLOWABLE_ACTIONS = CMISName("allowableActions");
@@ -167,8 +203,6 @@
 
     public static final String LINK_LATEST_VERSION = "latestversion";
 
-    public static final String LINK_PARENT = "parent";
-
     public static final String LINK_SOURCE = "source";
 
     public static final String LINK_TARGET = "target";
@@ -187,6 +221,8 @@
 
     public static final String LINK_ALL_VERSIONS = "allversions";
 
+    public static final String LINK_PWC = "pwc";
+
     public static final String LINK_RELATIONSHIPS = "relationships";
 
     public static final String LINK_POLICIES = "policies";

Copied: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/AllowableActionsElement.java (from r773055, incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AllowableActionsElement.java)
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/AllowableActionsElement.java?p2=incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/AllowableActionsElement.java&p1=incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AllowableActionsElement.java&r1=773055&r2=773069&rev=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AllowableActionsElement.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/AllowableActionsElement.java Fri May  8 19:52:42 2009
@@ -16,10 +16,11 @@
  * Authors:
  *     Florent Guillaume
  */
-package org.apache.chemistry.atompub;
+package org.apache.chemistry.atompub.abdera;
 
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.ExtensibleElementWrapper;
+import org.apache.chemistry.atompub.CMIS;
 
 /**
  * Abdera ElementWrapper for an AtomPub cmis:allowableActions element.

Copied: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/ObjectElement.java (from r773055, incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/ObjectElement.java)
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/ObjectElement.java?p2=incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/ObjectElement.java&p1=incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/ObjectElement.java&r1=773055&r2=773069&rev=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/ObjectElement.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/ObjectElement.java Fri May  8 19:52:42 2009
@@ -16,14 +16,16 @@
  * Authors:
  *     Florent Guillaume
  */
-package org.apache.chemistry.atompub;
+package org.apache.chemistry.atompub.abdera;
 
+import java.io.Serializable;
 import java.util.Map;
 
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.ExtensibleElementWrapper;
 import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.property.Property;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.atompub.CMIS;
 
 /**
  * Abdera ElementWrapper for an AtomPub cmis:object element.
@@ -32,18 +34,18 @@
  */
 public class ObjectElement extends ExtensibleElementWrapper {
 
-    public ObjectElement(Factory factory, ObjectEntry object,
+    public ObjectElement(Factory factory, ObjectEntry object, Type type,
             String contentStreamURI) {
         super(factory, CMIS.OBJECT);
-        setProperties(object.getProperties(), contentStreamURI);
+        setProperties(object.getValues(), type, contentStreamURI);
     }
 
-    public void setProperties(Map<String, Property> properties,
+    public void setProperties(Map<String, Serializable> values, Type type,
             String contentStreamURI) {
         PropertiesElement el = new PropertiesElement(getFactory(),
                 contentStreamURI);
         addExtension(el);
-        el.setProperties(properties);
+        el.setProperties(values, type);
     }
 
     // TODO allowable actions

Copied: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java (from r773055, incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/PropertiesElement.java)
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java?p2=incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java&p1=incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/PropertiesElement.java&r1=773055&r2=773069&rev=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/PropertiesElement.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java Fri May  8 19:52:42 2009
@@ -16,7 +16,7 @@
  * Authors:
  *     Florent Guillaume
  */
-package org.apache.chemistry.atompub;
+package org.apache.chemistry.atompub.abdera;
 
 import java.io.Serializable;
 import java.lang.reflect.Array;
@@ -33,9 +33,11 @@
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.ExtensibleElement;
 import org.apache.abdera.model.ExtensibleElementWrapper;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.property.PropertyType;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.atompub.CMIS;
 
 /**
  * Abdera ElementWrapper for an AtomPub cmis:properties element.
@@ -66,26 +68,26 @@
         }
     }
 
-    public void setProperties(Map<String, Property> properties) {
-        for (String name : properties.keySet()) {
-            if (Property.CONTENT_STREAM_URI.equals(name)) {
+    public void setProperties(Map<String, Serializable> values, Type type) {
+        for (PropertyDefinition propertyDefinition : type.getPropertyDefinitions()) {
+            String name = propertyDefinition.getName();
+            if (name.equals(Property.CONTENT_STREAM_URI)) {
                 // special-cased in constructor
                 continue;
             }
-            setProperty(properties.get(name));
+            setProperty(values.get(name), propertyDefinition);
         }
     }
 
     @SuppressWarnings("null")
-    public void setProperty(Property property) {
-        Serializable value = property.getValue();
+    public void setProperty(Serializable value,
+            PropertyDefinition propertyDefinition) {
         if (value == null) {
             // TODO assumes this isn't called several times
             return;
         }
-        PropertyDefinition def = property.getDefinition();
-        QName qname = propertyQName(def);
-        boolean multi = def.isMultiValued();
+        QName qname = propertyQName(propertyDefinition);
+        boolean multi = propertyDefinition.isMultiValued();
         List<String> values = null;
         if (multi) {
             if (value.getClass().isArray()) {
@@ -94,10 +96,10 @@
                 return;
             }
         }
-        PropertyType type = def.getType();
-        switch (type) {
-        case STRING:
-        case ID:
+        PropertyType type = propertyDefinition.getType();
+        switch (type.ordinal()) {
+        case PropertyType.STRING_ORD:
+        case PropertyType.ID_ORD:
             if (multi) {
                 for (String v : (String[]) value) {
                     values.add(v);
@@ -106,7 +108,7 @@
                 values = Collections.singletonList((String) value);
             }
             break;
-        case DECIMAL:
+        case PropertyType.DECIMAL_ORD:
             if (multi) {
                 for (BigDecimal v : (BigDecimal[]) value) {
                     values.add(v.toString());
@@ -115,7 +117,7 @@
                 values = Collections.singletonList(((BigDecimal) value).toString());
             }
             break;
-        case INTEGER:
+        case PropertyType.INTEGER_ORD:
             if (multi) {
                 for (Number v : (Number[]) value) {
                     values.add(v.toString());
@@ -124,7 +126,7 @@
                 values = Collections.singletonList(((Number) value).toString());
             }
             break;
-        case BOOLEAN:
+        case PropertyType.BOOLEAN_ORD:
             if (multi) {
                 for (Boolean v : (Boolean[]) value) {
                     values.add(v.toString());
@@ -133,7 +135,7 @@
                 values = Collections.singletonList(((Boolean) value).toString());
             }
             break;
-        case DATETIME:
+        case PropertyType.DATETIME_ORD:
             if (multi) {
                 for (Calendar v : (Calendar[]) value) {
                     values.add(calendarString(v));
@@ -142,17 +144,17 @@
                 values = Collections.singletonList(calendarString((Calendar) value));
             }
             break;
-        case URI:
+        case PropertyType.URI_ORD:
             throw new UnsupportedOperationException(type.toString());
-        case XML:
+        case PropertyType.XML_ORD:
             throw new UnsupportedOperationException(type.toString());
-        case HTML:
+        case PropertyType.HTML_ORD:
             throw new UnsupportedOperationException(type.toString());
         default:
             throw new UnsupportedOperationException(type.toString());
         }
         ExtensibleElement el = addExtension(qname);
-        el.setAttributeValue(CMIS.NAME, def.getName());
+        el.setAttributeValue(CMIS.NAME, propertyDefinition.getName());
         for (String s : values) {
             Element val = el.addExtension(CMIS.VALUE);
             // don't merge these two lines as JDK 5 has problems compiling it
@@ -161,24 +163,24 @@
     }
 
     protected static QName propertyQName(PropertyDefinition def) {
-        switch (def.getType()) {
-        case STRING:
+        switch (def.getType().ordinal()) {
+        case PropertyType.STRING_ORD:
             return CMIS.PROPERTY_STRING;
-        case DECIMAL:
+        case PropertyType.DECIMAL_ORD:
             return CMIS.PROPERTY_DECIMAL;
-        case INTEGER:
+        case PropertyType.INTEGER_ORD:
             return CMIS.PROPERTY_INTEGER;
-        case BOOLEAN:
+        case PropertyType.BOOLEAN_ORD:
             return CMIS.PROPERTY_BOOLEAN;
-        case DATETIME:
+        case PropertyType.DATETIME_ORD:
             return CMIS.PROPERTY_DATETIME;
-        case ID:
+        case PropertyType.ID_ORD:
             return CMIS.PROPERTY_ID;
-        case URI:
+        case PropertyType.URI_ORD:
             return CMIS.PROPERTY_URI;
-        case XML:
+        case PropertyType.XML_ORD:
             return CMIS.PROPERTY_XML;
-        case HTML:
+        case PropertyType.HTML_ORD:
             return CMIS.PROPERTY_HTML;
         default:
             throw new UnsupportedOperationException(def.getType().toString());
@@ -204,5 +206,5 @@
                 cal.get(Calendar.SECOND), //
                 sign, offset / 60, offset % 60);
     }
-    
+
 }

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseObject.java?rev=773069&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseObject.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseObject.java Fri May  8 19:52:42 2009
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2009 Nuxeo SA <http://nuxeo.com>
+ *
+ * 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
+ */
+package org.apache.chemistry.impl.base;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+
+/**
+ * Base implementation of a {@link CMISObject}. The implemented methods are
+ * completely generic.
+ *
+ * @author Florent Guillaume
+ */
+public abstract class BaseObject implements CMISObject {
+
+    public Map<String, Property> getProperties() {
+        Map<String, Property> properties = new HashMap<String, Property>();
+        for (PropertyDefinition pd : getType().getPropertyDefinitions()) {
+            String name = pd.getName();
+            properties.put(name, getProperty(name));
+        }
+        return properties;
+    }
+
+    public void setValue(String name, Serializable value) {
+        getProperty(name).setValue(value);
+    }
+
+    public void setValues(Map<String, Serializable> values) {
+        for (Entry<String, Serializable> entry : values.entrySet()) {
+            setValue(entry.getKey(), entry.getValue());
+        }
+    }
+
+    /*
+     * ----- Convenience methods -----
+     */
+
+    public String getString(String name) {
+        return (String) getValue(name);
+    }
+
+    public String[] getStrings(String name) {
+        return (String[]) getValue(name);
+    }
+
+    public BigDecimal getDecimal(String name) {
+        return (BigDecimal) getValue(name);
+    }
+
+    public BigDecimal[] getDecimals(String name) {
+        return (BigDecimal[]) getValue(name);
+    }
+
+    public Integer getInteger(String name) {
+        return (Integer) getValue(name);
+    }
+
+    public Integer[] getIntegers(String name) {
+        return (Integer[]) getValue(name);
+    }
+
+    public Boolean getBoolean(String name) {
+        return (Boolean) getValue(name);
+    }
+
+    public Boolean[] getBooleans(String name) {
+        return (Boolean[]) getValue(name);
+    }
+
+    public Calendar getDateTime(String name) {
+        return (Calendar) getValue(name);
+    }
+
+    public Calendar[] getDateTimes(String name) {
+        return (Calendar[]) getValue(name);
+    }
+
+    public URI getURI(String name) {
+        return (URI) getValue(name);
+    }
+
+    public URI[] getURIs(String name) {
+        return (URI[]) getValue(name);
+    }
+
+    public String getId(String name) {
+        return (String) getValue(name);
+    }
+
+    public String[] getIds(String name) {
+        return (String[]) getValue(name);
+    }
+
+    public String getXML(String name) {
+        return (String) getValue(name);
+    }
+
+    public String[] getXMLs(String name) {
+        return (String[]) getValue(name);
+    }
+
+    public String getHTML(String name) {
+        return (String) getValue(name);
+    }
+
+    public String[] getHTMLs(String name) {
+        return (String[]) getValue(name);
+    }
+
+    /*
+     * ----- Convenience methods for specific properties -----
+     */
+
+    public String getId() {
+        return getString(Property.ID);
+    }
+
+    public URI getURI() {
+        return getURI(Property.URI);
+    }
+
+    public String getTypeId() {
+        return getId(Property.TYPE_ID);
+    }
+
+    public String getCreatedBy() {
+        return getString(Property.CREATED_BY);
+    }
+
+    public Calendar getCreationDate() {
+        return getDateTime(Property.CREATION_DATE);
+    }
+
+    public String getLastModifiedBy() {
+        return getString(Property.LAST_MODIFIED_BY);
+    }
+
+    public Calendar getLastModificationDate() {
+        return getDateTime(Property.LAST_MODIFICATION_DATE);
+    }
+
+    public String getChangeToken() {
+        return getString(Property.CHANGE_TOKEN);
+    }
+
+    public String getName() {
+        return getString(Property.NAME);
+    }
+
+    public boolean isImmutable() {
+        Boolean b = getBoolean(Property.IS_IMMUTABLE);
+        return b == null ? false : b.booleanValue();
+    }
+
+    public boolean isLatestVersion() {
+        Boolean b = getBoolean(Property.IS_LATEST_VERSION);
+        return b == null ? false : b.booleanValue();
+    }
+
+    public boolean isMajorVersion() {
+        Boolean b = getBoolean(Property.IS_MAJOR_VERSION);
+        return b == null ? false : b.booleanValue();
+    }
+
+    public boolean isLatestMajorVersion() {
+        Boolean b = getBoolean(Property.IS_LATEST_MAJOR_VERSION);
+        return b == null ? false : b.booleanValue();
+    }
+
+    public String getVersionLabel() {
+        return getString(Property.VERSION_LABEL);
+    }
+
+    public String getVersionSeriesId() {
+        return getId(Property.VERSION_SERIES_ID);
+    }
+
+    public boolean isVersionSeriesCheckedOut() {
+        Boolean b = getBoolean(Property.IS_VERSION_SERIES_CHECKED_OUT);
+        return b == null ? false : b.booleanValue();
+    }
+
+    public String getVersionSeriesCheckedOutBy() {
+        return getString(Property.VERSION_SERIES_CHECKED_OUT_BY);
+    }
+
+    public String getVersionSeriesCheckedOutId() {
+        return getId(Property.VERSION_SERIES_CHECKED_OUT_ID);
+    }
+
+    public String getCheckinComment() {
+        return getString(Property.CHECKIN_COMMENT);
+    }
+
+    public void setName(String name) {
+        setValue(Property.NAME, name);
+    }
+
+}

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

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

Added: 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=773069&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java Fri May  8 19:52:42 2009
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2009 Nuxeo SA <http://nuxeo.com>
+ *
+ * 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
+ */
+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;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryCapabilities;
+import org.apache.chemistry.RepositoryEntry;
+import org.apache.chemistry.RepositoryInfo;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.impl.simple.SimpleProperty;
+import org.apache.chemistry.impl.simple.SimpleType;
+
+/**
+ * Base implementation of a {@link Repository}. The implemented methods are
+ * completely generic and base on {@link SimpleType} and {@link SimpleProperty}.
+ *
+ * @author Florent Guillaume
+ */
+public abstract class BaseRepository implements Repository, RepositoryInfo,
+        RepositoryCapabilities {
+
+    // from the spec
+    public static final String ROOT_FOLDER_NAME = "CMIS_Root_Folder";
+
+    public static final String ROOT_TYPE_ID = "Root";
+
+    public static final String DOCUMENT_TYPE_ID = "document";
+
+    public static final String FOLDER_TYPE_ID = "folder";
+
+    public static final String RELATIONSHIP_TYPE_ID = "relationship";
+
+    public static final String POLICY_TYPE_ID = "policy";
+
+    public static SimpleType ROOT_TYPE = new SimpleType(ROOT_TYPE_ID,
+            FOLDER_TYPE_ID, "Root", "Root Folder Type", BaseType.FOLDER, "",
+            false, false, false, false, false, false,
+            ContentStreamPresence.NOT_ALLOWED, null, null,
+            Collections.<PropertyDefinition> emptyList());
+
+    public static SimpleType DOCUMENT_TYPE = new SimpleType(DOCUMENT_TYPE_ID,
+            null, "Document", "Document Type", BaseType.DOCUMENT, "", true,
+            true, true, true, true, true, ContentStreamPresence.ALLOWED, null,
+            null, Collections.<PropertyDefinition> emptyList());
+
+    public static SimpleType FOLDER_TYPE = new SimpleType(FOLDER_TYPE_ID, null,
+            "Folder", "Folder Type", BaseType.FOLDER, "", true, true, false,
+            true, true, false, ContentStreamPresence.NOT_ALLOWED, null, null,
+            Collections.<PropertyDefinition> emptyList());
+
+    public static SimpleType RELATIONSHIP_TYPE = new SimpleType(
+            RELATIONSHIP_TYPE_ID, null, "Relationship", "Relationship Type",
+            BaseType.RELATIONSHIP, "", true, true, false, true, false, false,
+            ContentStreamPresence.NOT_ALLOWED, null, null,
+            Collections.<PropertyDefinition> emptyList());
+
+    protected static SimpleType POLICY_TYPE = new SimpleType(POLICY_TYPE_ID,
+            null, "Policy", "Policy Type", BaseType.POLICY, "", true, true,
+            false, true, false, false, ContentStreamPresence.NOT_ALLOWED, null,
+            null, Collections.<PropertyDefinition> emptyList());
+
+    protected final Map<String, Type> types = new HashMap<String, Type>();
+
+    protected final String name;
+
+    protected BaseRepository(String name) {
+        this.name = name;
+    }
+
+    protected static Collection<SimpleType> getDefaultTypes() {
+        return Arrays.asList(DOCUMENT_TYPE, FOLDER_TYPE, RELATIONSHIP_TYPE,
+                POLICY_TYPE, ROOT_TYPE);
+    }
+
+    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);
+        }
+    }
+
+    /*
+     * ----- RepositoryEntry -----
+     */
+
+    public String getId() {
+        return name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    /*
+     * ----- Repository -----
+     */
+
+    public RepositoryInfo getInfo() {
+        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 -----
+     */
+
+    public String getVendorName() {
+        return "Apache";
+    }
+
+    public String getProductVersion() {
+        // TODO update this when releasing
+        return "0.1-SNAPSHOT";
+    }
+
+    public String getVersionSupported() {
+        return "0.61";
+    }
+
+    public org.w3c.dom.Document getRepositorySpecificInformation() {
+        return null;
+    }
+
+    public RepositoryCapabilities getCapabilities() {
+        return this;
+    }
+
+    public Collection<RepositoryEntry> getRelatedRepositories() {
+        return Collections.emptySet();
+    }
+
+}

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

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

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java Fri May  8 19:52:42 2009
@@ -26,29 +26,31 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.ContentStream;
+import org.apache.chemistry.ContentStreamPresence;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.Policy;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
 import org.apache.chemistry.Relationship;
 import org.apache.chemistry.RelationshipDirection;
+import org.apache.chemistry.Repository;
 import org.apache.chemistry.ReturnVersion;
 import org.apache.chemistry.SPI;
+import org.apache.chemistry.Type;
 import org.apache.chemistry.Unfiling;
 import org.apache.chemistry.VersioningState;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.ContentStreamPresence;
-import org.apache.chemistry.type.Type;
 
 public class SimpleConnection implements Connection, SPI {
 
@@ -82,41 +84,40 @@
         return rootFolder;
     }
 
-    public ObjectEntry getRootEntry() {
-        return rootFolder;
-    }
-
-    public List<ObjectEntry> getChildren(ObjectEntry folder) {
-        return getChildren(folder.getId(), null, null, false, false,
-                Integer.MAX_VALUE, 0, null, new boolean[1]);
-    }
-
     /*
      * ----- Factories -----
      */
 
-    public Document newDocument(String typeId, ObjectEntry folder) {
+    public ObjectId newObjectId(String id) {
+        return new SimpleObjectId(id);
+    }
+
+    public SimpleObjectEntry newObjectEntry(String typeId) {
+        return new SimpleObjectEntry(new SimpleData(typeId), this);
+    }
+
+    public Document newDocument(String typeId, Folder folder) {
         Type type = repository.getType(typeId);
         if (type == null || type.getBaseType() != BaseType.DOCUMENT) {
             throw new IllegalArgumentException(typeId);
         }
-        SimpleData data = new SimpleData(typeId);
+        SimpleObjectEntry entry = newObjectEntry(typeId);
         if (folder != null) {
-            data.put(Property.PARENT_ID, folder.getId());
+            entry.setValue(Property.PARENT_ID, folder.getId());
         }
-        return new SimpleDocument(data, this);
+        return new SimpleDocument(entry);
     }
 
-    public Folder newFolder(String typeId, ObjectEntry folder) {
+    public Folder newFolder(String typeId, Folder folder) {
         Type type = repository.getType(typeId);
         if (type == null || type.getBaseType() != BaseType.FOLDER) {
             throw new IllegalArgumentException(typeId);
         }
-        SimpleData data = new SimpleData(typeId);
+        SimpleObjectEntry entry = newObjectEntry(typeId);
         if (folder != null) {
-            data.put(Property.PARENT_ID, folder.getId());
+            entry.setValue(Property.PARENT_ID, folder.getId());
         }
-        return new SimpleFolder(data, this);
+        return new SimpleFolder(entry);
     }
 
     public Relationship newRelationship(String typeId) {
@@ -124,27 +125,26 @@
         if (type == null || type.getBaseType() != BaseType.RELATIONSHIP) {
             throw new IllegalArgumentException(typeId);
         }
-        SimpleData data = new SimpleData(typeId);
-        return new SimpleRelationship(data, this);
+        return new SimpleRelationship(newObjectEntry(typeId));
     }
 
-    public Policy newPolicy(String typeId, ObjectEntry folder) {
+    public Policy newPolicy(String typeId, Folder folder) {
         Type type = repository.getType(typeId);
         if (type == null || type.getBaseType() != BaseType.POLICY) {
             throw new IllegalArgumentException(typeId);
         }
-        SimpleData data = new SimpleData(typeId);
+        SimpleObjectEntry entry = newObjectEntry(typeId);
         if (folder != null) {
-            data.put(Property.PARENT_ID, folder.getId());
+            entry.setValue(Property.PARENT_ID, folder.getId());
         }
-        return new SimplePolicy(data, this);
+        return new SimplePolicy(entry);
     }
 
     /*
      * Called by save() for new objects.
      */
     protected void saveObject(SimpleObject object) {
-        SimpleData data = object.data;
+        SimpleData data = object.entry.data;
         Map<String, Serializable> update = new HashMap<String, Serializable>();
 
         // generate an ID
@@ -171,8 +171,6 @@
                 } else if (Property.LAST_MODIFICATION_DATE.equals(name)) {
                     update.put(Property.LAST_MODIFICATION_DATE,
                             Calendar.getInstance());
-                } else if (Property.CONTENT_STREAM_ALLOWED.equals(name)) {
-                    update.put(Property.CONTENT_STREAM_ALLOWED, "allowed");
                 } else if (Property.IS_LATEST_VERSION.equals(name)) {
                     update.put(Property.IS_LATEST_VERSION, Boolean.TRUE);
                 } else if (Property.IS_LATEST_MAJOR_VERSION.equals(name)) {
@@ -190,29 +188,28 @@
             }
         }
 
-        byte[] contentBytes = (byte[]) data.get(SimpleDocument.CONTENT_BYTES_KEY);
+        // content stream
+        byte[] bytes = (byte[]) data.get(SimpleProperty.CONTENT_BYTES_KEY);
         if (type.getContentStreamAllowed() == ContentStreamPresence.REQUIRED
-                && contentBytes == null) {
+                && bytes == null) {
             throw new RuntimeException("Content stream required"); // TODO
         }
+        update.put(Property.CONTENT_STREAM_LENGTH, bytes == null ? null
+                : Integer.valueOf(bytes.length)); // TODO Long
 
-        // content stream
-        if (contentBytes != null) {
-            update.put(Property.CONTENT_STREAM_LENGTH,
-                    Integer.valueOf(contentBytes.length));
-        }
         // update data once we know there's no error
-        data.putAll(update);
+        for (String key : update.keySet()) {
+            Serializable value = update.get(key);
+            if (value == null) {
+                data.remove(key);
+            } else {
+                data.put(key, value);
+            }
+        }
 
         // properties
         repository.datas.put(id, data); // TODO clone data?
 
-        if (contentBytes == null) {
-            repository.contentBytes.remove(id);
-        } else {
-            repository.contentBytes.put(id, contentBytes);
-        }
-
         // parents/children
         String parentId = (String) data.get(Property.PARENT_ID);
         if (type.getBaseType() == BaseType.FOLDER) {
@@ -237,20 +234,21 @@
      * ----- Navigation Services -----
      */
 
-    public List<ObjectEntry> getDescendants(String folderId, BaseType type,
+    public List<ObjectEntry> getDescendants(ObjectId folder, BaseType type,
             int depth, String filter, boolean includeAllowableActions,
             boolean includeRelationships, String orderBy) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public List<ObjectEntry> getChildren(String folderId, BaseType type,
+    public List<ObjectEntry> getChildren(ObjectId folder, BaseType type,
             String filter, boolean includeAllowableActions,
             boolean includeRelationships, int maxItems, int skipCount,
             String orderBy, boolean[] hasMoreItems) {
         // TODO type and orderBy
-        Set<String> ids = repository.children.get(folderId);
-        List<ObjectEntry> all = new ArrayList<ObjectEntry>(ids.size());
+        Set<String> ids = repository.children.get(folder.getId());
+        int total = ids.size();
+        List<ObjectEntry> all = new ArrayList<ObjectEntry>(total);
         for (String id : ids) {
             SimpleData data = repository.datas.get(id);
             // could build a full Object, but some implementations won't
@@ -258,36 +256,40 @@
         }
 
         int fromIndex = skipCount;
-        if (fromIndex < 0 || fromIndex > all.size()) {
+        if (fromIndex < 0 || fromIndex > total) {
             hasMoreItems[0] = false;
             return Collections.emptyList();
         }
         if (maxItems == 0) {
-            maxItems = all.size();
+            maxItems = total;
         }
         int toIndex = skipCount + maxItems;
-        if (toIndex > all.size()) {
-            toIndex = all.size();
+        if (toIndex > total) {
+            toIndex = total;
+        }
+        hasMoreItems[0] = toIndex < total;
+        if (fromIndex == 0 && toIndex == total) {
+            return all;
+        } else {
+            return all.subList(fromIndex, toIndex);
         }
-        hasMoreItems[0] = toIndex < all.size();
-        return all.subList(fromIndex, toIndex);
     }
 
-    public List<ObjectEntry> getFolderParent(String folderId, String filter,
+    public List<ObjectEntry> getFolderParent(ObjectId folder, String filter,
             boolean includeAllowableActions, boolean includeRelationships,
             boolean returnToRoot) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public Collection<ObjectEntry> getObjectParents(String objectId,
+    public Collection<ObjectEntry> getObjectParents(ObjectId object,
             String filter, boolean includeAllowableActions,
             boolean includeRelationships) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public Collection<ObjectEntry> getCheckedoutDocuments(String folderId,
+    public Collection<ObjectEntry> getCheckedoutDocuments(ObjectId folder,
             String filter, boolean includeAllowableActions,
             boolean includeRelationships, int maxItems, int skipCount,
             boolean[] hasMoreItems) {
@@ -299,70 +301,78 @@
      * ----- Object Services -----
      */
 
-    public String createDocument(String typeId,
-            Map<String, Serializable> properties, String folderId,
+    public ObjectId createDocument(String typeId,
+            Map<String, Serializable> properties, ObjectId folder,
             ContentStream contentStream, VersioningState versioningState) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public String createFolder(String typeId,
-            Map<String, Serializable> properties, String folderId) {
+    public ObjectId createFolder(String typeId,
+            Map<String, Serializable> properties, ObjectId folder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public String createRelationship(String typeId,
-            Map<String, Serializable> properties, String sourceId,
-            String targetId) {
+    public ObjectId createRelationship(String typeId,
+            Map<String, Serializable> properties, ObjectId source,
+            ObjectId target) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public String createPolicy(String typeId,
-            Map<String, Serializable> properties, String folderId) {
+    public ObjectId createPolicy(String typeId,
+            Map<String, Serializable> properties, ObjectId folder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public Collection<String> getAllowableActions(String objectId, String asUser) {
+    public Collection<String> getAllowableActions(ObjectId object, String asUser) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public ObjectEntry getProperties(String objectId,
+    public ObjectEntry getProperties(ObjectId object,
             ReturnVersion returnVersion, String filter,
             boolean includeAllowableActions, boolean includeRelationships) {
-        SimpleData data = repository.datas.get(objectId);
+        SimpleData data = repository.datas.get(object.getId());
         if (data == null) {
-            throw new RuntimeException("Not found: " + objectId); // TODO
+            return null;
         }
         return new SimpleObjectEntry(data, this);
     }
 
-    public CMISObject getObject(String objectId, ReturnVersion returnVersion) {
+    public CMISObject getObject(ObjectId object, ReturnVersion returnVersion) {
         // TODO returnVersion
-        SimpleData data = repository.datas.get(objectId);
+        SimpleData data = repository.datas.get(object.getId());
         if (data == null) {
-            throw new RuntimeException("Not found: " + objectId); // TODO
+            return null;
         }
         String typeId = (String) data.get(Property.TYPE_ID);
         switch (repository.getType(typeId).getBaseType()) {
         case DOCUMENT:
-            return new SimpleDocument(data, this);
+            return new SimpleDocument(new SimpleObjectEntry(data, this));
         case FOLDER:
-            return new SimpleFolder(data, this);
+            return new SimpleFolder(new SimpleObjectEntry(data, this));
         case RELATIONSHIP:
-            return new SimpleRelationship(data, this);
+            return new SimpleRelationship(new SimpleObjectEntry(data, this));
         case POLICY:
-            return new SimplePolicy(data, this);
+            return new SimplePolicy(new SimpleObjectEntry(data, this));
+        default:
+            throw new AssertionError(typeId);
         }
-        throw new RuntimeException();
     }
 
-    public InputStream getContentStream(String documentId, int offset,
+    public boolean hasContentStream(ObjectId document) {
+        SimpleData data = repository.datas.get(document.getId());
+        byte[] bytes = (byte[]) data.get(SimpleProperty.CONTENT_BYTES_KEY);
+        return bytes != null;
+    }
+
+    public InputStream getContentStream(ObjectId document, int offset,
             int length) {
-        byte[] bytes = repository.contentBytes.get(documentId);
+        SimpleData data = repository.datas.get(document.getId());
+        byte[] bytes = (byte[]) data.get(SimpleProperty.CONTENT_BYTES_KEY);
         if (bytes == null) {
             return null;
         }
@@ -372,73 +382,124 @@
         return new ByteArrayInputStream(bytes, offset, length);
     }
 
-    public void setContentStream(String documentId, boolean overwrite,
+    public ObjectId setContentStream(ObjectId document, boolean overwrite,
             ContentStream contentStream) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void deleteContentStream(String documentId) {
+    public void deleteContentStream(ObjectId document) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public String updateProperties(String objectId, String changeToken,
+    public ObjectId updateProperties(ObjectId object, String changeToken,
             Map<String, Serializable> properties) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void moveObject(String objectId, String targetFolderId,
-            String sourceFolderId) {
+    public void moveObject(ObjectId object, ObjectId targetFolder,
+            ObjectId sourceFolder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void moveObject(ObjectEntry object, ObjectEntry targetFolder,
-            ObjectEntry sourceFolder) {
+    public void moveObject(CMISObject object, Folder targetFolder,
+            Folder sourceFolder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void deleteObject(String objectId) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+    public void deleteObject(ObjectId object) {
+        String id = object.getId();
+        if (repository.rootId.equals(id)) {
+            throw new RuntimeException("Cannot delete root"); // TODO
+        }
+        SimpleData data = repository.datas.get(id);
+        if (data == null) {
+            throw new RuntimeException("Not found: " + object); // TODO
+        }
+        // delete children info
+        Set<String> children = repository.children.get(id);
+        if (children != null) {
+            if (children.size() > 0) {
+                throw new RuntimeException(
+                        "Cannot delete, folder has children: " + object); // TODO
+            }
+            // remove only if empty
+            repository.children.remove(id);
+        }
+        // delete parents info
+        // TODO unfiling, remove from all parents for now
+        Set<String> parents = repository.parents.remove(id);
+        if (parents != null) {
+            for (String pid : parents) {
+                // remove as child of parent
+                repository.children.get(pid).remove(id);
+            }
+        }
+        repository.datas.remove(id);
     }
 
-    public void deleteObject(ObjectEntry object) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+    public void deleteObject(CMISObject object) {
+        deleteObject((ObjectId) object);
     }
 
-    public Collection<String> deleteTree(String folderId, Unfiling unfiling,
+    public Collection<String> deleteTree(ObjectId folder, Unfiling unfiling,
             boolean continueOnFailure) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        // TODO unfiling
+        // TODO continueOnFailure
+        String id = folder.getId();
+        if (repository.rootId.equals(id)) {
+            throw new RuntimeException("Cannot delete root"); // TODO
+        }
+        SimpleData data = repository.datas.get(id);
+        if (data == null) {
+            throw new RuntimeException("Not found: " + folder); // TODO
+        }
+        String typeId = (String) data.get(Property.TYPE_ID);
+        if (repository.getType(typeId).getBaseType() != BaseType.FOLDER) {
+            throw new RuntimeException("Not a folder: " + folder); // TODO
+        }
+        Set<String> deletedIds = new HashSet<String>();
+        for (String childId : repository.children.get(id)) {
+            SimpleData childData = repository.datas.get(childId);
+            String childTypeId = (String) childData.get(Property.TYPE_ID);
+            if (repository.getType(childTypeId).getBaseType() == BaseType.FOLDER) {
+                deletedIds.addAll(deleteTree(new SimpleObjectId(childId),
+                        unfiling, continueOnFailure));
+            } else {
+                deleteObject(new SimpleObjectId(childId));
+                deletedIds.add(childId);
+            }
+        }
+        deleteObject(folder);
+        deletedIds.add(id);
+        return deletedIds;
     }
 
-    public Collection<String> deleteTree(ObjectEntry folder, Unfiling unfiling,
+    public Collection<String> deleteTree(Folder folder, Unfiling unfiling,
             boolean continueOnFailure) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        return deleteTree((ObjectId) folder, unfiling, continueOnFailure);
     }
 
-    public void addObjectToFolder(String objectId, String folderId) {
+    public void addObjectToFolder(ObjectId object, ObjectId folder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void addObjectToFolder(ObjectEntry object, ObjectEntry folder) {
+    public void addObjectToFolder(CMISObject object, Folder folder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void removeObjectFromFolder(String objectId, String folderId) {
+    public void removeObjectFromFolder(ObjectId object, ObjectId folder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void removeObjectFromFolder(ObjectEntry object, ObjectEntry folder) {
+    public void removeObjectFromFolder(CMISObject object, Folder folder) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
@@ -455,7 +516,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public Collection<ObjectEntry> query(String statement,
+    public Collection<CMISObject> query(String statement,
             boolean searchAllVersions) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
@@ -465,35 +526,34 @@
      * ----- Versioning Services -----
      */
 
-    public String checkOut(String documentId, boolean[] contentCopied) {
+    public ObjectId checkOut(ObjectId document, boolean[] contentCopied) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public CMISObject checkOut(ObjectEntry document) {
+    public Document checkOut(Document document) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void cancelCheckOut(String documentId) {
+    public void cancelCheckOut(ObjectId document) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void cancelCheckOut(ObjectEntry document) {
+    public void cancelCheckOut(Document document) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public String checkIn(String documentId, boolean major,
+    public ObjectId checkIn(ObjectId document, boolean major,
             Map<String, Serializable> properties, ContentStream contentStream,
             String comment) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public CMISObject checkIn(ObjectEntry document, boolean major,
-            String comment) {
+    public Document checkIn(Document document, boolean major, String comment) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
@@ -504,7 +564,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public CMISObject getLatestVersion(ObjectEntry document, boolean major) {
+    public Document getLatestVersion(Document document, boolean major) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
@@ -515,8 +575,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public Collection<ObjectEntry> getAllVersions(ObjectEntry document,
-            String filter) {
+    public Collection<Document> getAllVersions(Document document, String filter) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
@@ -526,7 +585,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public void deleteAllVersions(ObjectEntry document) {
+    public void deleteAllVersions(Document document) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
@@ -535,7 +594,7 @@
      * ----- Relationship Services -----
      */
 
-    public List<ObjectEntry> getRelationships(String objectId,
+    public List<ObjectEntry> getRelationships(ObjectId object,
             RelationshipDirection direction, String typeId,
             boolean includeSubRelationshipTypes, String filter,
             String includeAllowableActions, int maxItems, int skipCount,
@@ -544,7 +603,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public List<ObjectEntry> getRelationships(ObjectEntry object,
+    public List<Relationship> getRelationships(CMISObject object,
             RelationshipDirection direction, String typeId,
             boolean includeSubRelationshipTypes) {
         // TODO Auto-generated method stub
@@ -555,33 +614,33 @@
      * ----- Policy Services -----
      */
 
-    public void applyPolicy(String policyId, String objectId) {
+    public void applyPolicy(ObjectId policy, ObjectId object) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void applyPolicy(Policy policy, ObjectEntry object) {
+    public void applyPolicy(Policy policy, CMISObject object) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void removePolicy(String policyId, String objectId) {
+    public void removePolicy(ObjectId policy, ObjectId object) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public void removePolicy(Policy policy, ObjectEntry object) {
+    public void removePolicy(Policy policy, CMISObject object) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public Collection<ObjectEntry> getAppliedPolicies(String policyId,
+    public Collection<ObjectEntry> getAppliedPolicies(ObjectId policy,
             String filter) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public Collection<Policy> getAppliedPolicies(ObjectEntry object) {
+    public Collection<Policy> getAppliedPolicies(CMISObject object) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }



Mime
View raw message