You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2009/05/08 21:52:44 UTC

svn commit: r773069 [3/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-...

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java Fri May  8 19:52:42 2009
@@ -21,7 +21,7 @@
 import java.io.Serializable;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.chemistry.property.Property;
+import org.apache.chemistry.Property;
 
 /**
  * The data held in the repository for one object.

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java Fri May  8 19:52:42 2009
@@ -24,24 +24,22 @@
 import java.net.URI;
 
 import org.apache.chemistry.ContentStream;
+import org.apache.chemistry.ContentStreamPresence;
 import org.apache.chemistry.Document;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.type.ContentStreamPresence;
+import org.apache.chemistry.Property;
 
 public class SimpleDocument extends SimpleObject implements Document {
 
-    public SimpleDocument(SimpleData data, SimpleConnection connection) {
-        super(data, connection);
+    public SimpleDocument(SimpleObjectEntry entry) {
+        super(entry);
     }
 
-    protected static final String CONTENT_BYTES_KEY = "__content__";
-
     protected byte[] getContentBytes() {
-        return (byte[]) data.get(CONTENT_BYTES_KEY);
+        return (byte[]) entry.data.get(SimpleProperty.CONTENT_BYTES_KEY);
     }
-    
+
     public InputStream getStream() {
-    	byte[] contentBytes = getContentBytes();
+        byte[] contentBytes = getContentBytes();
         if (contentBytes == null) {
             return null;
         }
@@ -49,7 +47,7 @@
     }
 
     public ContentStream getContentStream() {
-    	byte[] contentBytes = getContentBytes();
+        byte[] contentBytes = getContentBytes();
         if (contentBytes == null) {
             return null;
         }
@@ -76,20 +74,20 @@
             throw new RuntimeException("Content stream required"); // TODO
         }
         if (contentStream == null) {
-            _setValue(Property.CONTENT_STREAM_LENGTH, null);
-            _setValue(Property.CONTENT_STREAM_MIME_TYPE, null);
-            _setValue(Property.CONTENT_STREAM_FILENAME, null);
-            _setValue(Property.CONTENT_STREAM_URI, null);
-            data.remove(CONTENT_BYTES_KEY);
+            entry.setValue(Property.CONTENT_STREAM_LENGTH, null);
+            entry.setValue(Property.CONTENT_STREAM_MIME_TYPE, null);
+            entry.setValue(Property.CONTENT_STREAM_FILENAME, null);
+            entry.setValue(Property.CONTENT_STREAM_URI, null);
+            entry.setValue(SimpleProperty.CONTENT_BYTES_KEY, null);
         } else {
-            _setValue(Property.CONTENT_STREAM_LENGTH,
+            entry.setValue(Property.CONTENT_STREAM_LENGTH,
                     Integer.valueOf((int) contentStream.getLength())); // cast?
-            _setValue(Property.CONTENT_STREAM_MIME_TYPE,
+            entry.setValue(Property.CONTENT_STREAM_MIME_TYPE,
                     contentStream.getMimeType());
-            _setValue(Property.CONTENT_STREAM_FILENAME,
+            entry.setValue(Property.CONTENT_STREAM_FILENAME,
                     contentStream.getFilename());
-            _setValue(Property.CONTENT_STREAM_URI, contentStream.getURI());
-            data.put(CONTENT_BYTES_KEY,
+            entry.setValue(Property.CONTENT_STREAM_URI, contentStream.getURI());
+            entry.setValue(SimpleProperty.CONTENT_BYTES_KEY,
                     SimpleContentStream.getBytes(contentStream.getStream()));
         }
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java Fri May  8 19:52:42 2009
@@ -22,35 +22,35 @@
 import java.util.List;
 import java.util.Set;
 
+import org.apache.chemistry.BaseType;
+import org.apache.chemistry.CMISObject;
 import org.apache.chemistry.Document;
-import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Folder;
-import org.apache.chemistry.type.BaseType;
 
 public class SimpleFolder extends SimpleObject implements Folder {
 
-    public SimpleFolder(SimpleData data, SimpleConnection connection) {
-        super(data, connection);
+    public SimpleFolder(SimpleObjectEntry entry) {
+        super(entry);
     }
 
-    public List<ObjectEntry> getChildren(BaseType type, String orderBy) {
+    public List<CMISObject> getChildren(BaseType type, String orderBy) {
         // TODO type and orderBy
-        Set<String> ids = connection.repository.children.get(getId());
-        List<ObjectEntry> children = new ArrayList<ObjectEntry>(ids.size());
+        Set<String> ids = entry.connection.repository.children.get(getId());
+        List<CMISObject> children = new ArrayList<CMISObject>(ids.size());
         for (String id : ids) {
-            SimpleData d = connection.repository.datas.get(id);
-            // could build a full Object, but some implementations won't
-            children.add(new SimpleObjectEntry(d, connection));
+            SimpleData d = entry.connection.repository.datas.get(id);
+            children.add(SimpleObject.construct(new SimpleObjectEntry(d,
+                    entry.connection)));
         }
         return children;
     }
 
     public Document newDocument(String typeId) {
-        return connection.newDocument(typeId, this);
+        return entry.connection.newDocument(typeId, this);
     }
 
     public Folder newFolder(String typeId) {
-        return connection.newFolder(typeId, this);
+        return entry.connection.newFolder(typeId, this);
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java Fri May  8 19:52:42 2009
@@ -19,61 +19,55 @@
 package org.apache.chemistry.impl.simple;
 
 import java.io.Serializable;
-import java.util.Map;
 import java.util.Set;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
-import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
-import org.apache.chemistry.Policy;
-import org.apache.chemistry.Relationship;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.type.BaseType;
-
-public class SimpleObject extends SimpleObjectEntry implements CMISObject {
-
-    protected SimpleObject(SimpleData data, SimpleConnection connection) {
-        super(data, connection);
-    }
-
-    @Override
-    public Document getDocument() {
-        if (getType().getBaseType() != BaseType.DOCUMENT) {
-            throw new RuntimeException("Not a document: " + getId());
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.impl.base.BaseObject;
+
+/**
+ * Simple implementation of a {@link CMISObject}.
+ *
+ * @author Florent Guillaume
+ */
+public class SimpleObject extends BaseObject {
+
+    protected final SimpleObjectEntry entry;
+
+    private final Type type;
+
+    protected SimpleObject(SimpleObjectEntry entry) {
+        this.entry = entry;
+        type = entry.connection.repository.getType(entry.getTypeId());
+    }
+
+    protected static SimpleObject construct(SimpleObjectEntry entry) {
+        BaseType baseType = entry.connection.repository.getType(
+                entry.getTypeId()).getBaseType();
+        switch (baseType) {
+        case DOCUMENT:
+            return new SimpleDocument(entry);
+        case FOLDER:
+            return new SimpleFolder(entry);
+        case POLICY:
+            return new SimplePolicy(entry);
+        case RELATIONSHIP:
+            return new SimpleRelationship(entry);
+        default:
+            throw new AssertionError();
         }
-        return (Document) this;
     }
 
-    @Override
-    public Folder getFolder() {
-        if (getType().getBaseType() != BaseType.FOLDER) {
-            throw new RuntimeException("Not a folder: " + getId());
-        }
-        return (Folder) this;
-    }
-
-    @Override
-    public Relationship getRelationship() {
-        if (getType().getBaseType() != BaseType.RELATIONSHIP) {
-            throw new RuntimeException("Not a relationship: " + getId());
-        }
-        return (Relationship) this;
-    }
-
-    @Override
-    public Policy getPolicy() {
-        if (getType().getBaseType() != BaseType.POLICY) {
-            throw new RuntimeException("Not a policy: " + getId());
-        }
-        return (Policy) this;
+    public Type getType() {
+        return type;
     }
 
-    /*
-     * ----- CMISObject -----
-     */
-
     public Folder getParent() {
-        Set<String> parents = connection.repository.parents.get(getId());
+        Set<String> parents = entry.connection.repository.parents.get(getId());
         if (parents == SimpleRepository.NO_PARENT) {
             return null;
         }
@@ -81,51 +75,32 @@
             throw new RuntimeException("Several parents for: " + getId()); // TODO
         }
         String pid = parents.iterator().next();
-        SimpleData data = connection.repository.datas.get(pid);
-        return new SimpleFolder(data, connection);
+        SimpleData data = entry.connection.repository.datas.get(pid);
+        return new SimpleFolder(new SimpleObjectEntry(data, entry.connection));
     }
 
-    public void setValue(String name, Serializable value) {
-        SimplePropertyDefinition pd = (SimplePropertyDefinition) getType().getPropertyDefinition(
+    public Serializable getValue(String name) {
+        PropertyDefinition propertyDefinition = getType().getPropertyDefinition(
                 name);
-        if (pd == null) {
+        if (propertyDefinition == null) {
             throw new IllegalArgumentException(name);
         }
-        String error = pd.validationError(value);
-        if (error != null) {
-            throw new RuntimeException("Property " + name + ": " + error); // TODO
-        }
-
-        _setValue(name, value);
-    }
-
-    protected void _setValue(String name, Serializable value) {
-        if (value == null) {
-            data.remove(name);
-        } else {
-            data.put(name, value);
-        }
+        return entry.data.get(name);
     }
 
-    public void setValues(Map<String, Serializable> values) {
-        // don't use putAll as we want to do type checks
-        for (String name : values.keySet()) {
-            setValue(name, values.get(name));
+    public Property getProperty(String name) {
+        PropertyDefinition propertyDefinition = getType().getPropertyDefinition(
+                name);
+        if (propertyDefinition == null) {
+            throw new IllegalArgumentException(name);
         }
+        return new SimpleProperty(entry, name, propertyDefinition);
     }
 
     public void save() {
         if (getId() == null) {
-            connection.saveObject(this);
+            entry.connection.saveObject(this);
         }
     }
 
-    /*
-     * ----- convenience methods for specific properties -----
-     */
-
-    public void setName(String name) {
-        setValue(Property.NAME, name);
-    }
-
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java Fri May  8 19:52:42 2009
@@ -19,23 +19,20 @@
 package org.apache.chemistry.impl.simple;
 
 import java.io.Serializable;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.chemistry.Document;
 import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.Folder;
-import org.apache.chemistry.Policy;
-import org.apache.chemistry.Relationship;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.Type;
+import org.apache.chemistry.Property;
 
+/**
+ * Simple implementation of an {@link ObjectEntry}.
+ * <p>
+ * This implementation doesn't do type validation when values are set.
+ *
+ * @author Florent Guillaume
+ */
 public class SimpleObjectEntry implements ObjectEntry {
 
     protected final SimpleData data;
@@ -47,276 +44,45 @@
         this.connection = connection;
     }
 
-    public Type getType() {
-        String typeId = (String) data.get(Property.TYPE_ID);
-        return connection.repository.getType(typeId);
+    public String getId() {
+        return (String) data.get(Property.ID);
     }
 
-    public Property getProperty(String name) {
-        return new SimpleProperty(this, name);
+    public String getTypeId() {
+        return (String) data.get(Property.TYPE_ID);
     }
 
-    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 Map<String, Serializable> getValues() {
+        return new HashMap<String, Serializable>(data);
     }
 
     public Serializable getValue(String name) {
-        PropertyDefinition propertyDefinition = getType().getPropertyDefinition(
-                name);
-        if (propertyDefinition == null) {
-            throw new IllegalArgumentException(name);
-        }
         return data.get(name);
     }
 
-    public Collection<String> getAllowableActions() {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<ObjectEntry> getRelationships() {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
-    }
-
-    /*
-     * ----- link to Document/Folder/etc classes -----
-     */
-
-    public Document getDocument() {
-        if (getType().getBaseType() != BaseType.DOCUMENT) {
-            throw new RuntimeException("Not a document: " + getId());
+    public void setValue(String name, Serializable value) {
+        if (value == null) {
+            data.remove(name);
+        } else {
+            data.put(name, value);
         }
-        return new SimpleDocument(data, connection);
     }
 
-    public Folder getFolder() {
-        if (getType().getBaseType() != BaseType.FOLDER) {
-            throw new RuntimeException("Not a folder: " + getId());
+    public void setValues(Map<String, Serializable> values) {
+        // don't use putAll as we want to check for nulls
+        for (String name : values.keySet()) {
+            setValue(name, values.get(name));
         }
-        return new SimpleFolder(data, connection);
-    }
-
-    public Relationship getRelationship() {
-        if (getType().getBaseType() != BaseType.RELATIONSHIP) {
-            throw new RuntimeException("Not a relationship: " + getId());
-        }
-        return new SimpleRelationship(data, connection);
-    }
-
-    public Policy getPolicy() {
-        if (getType().getBaseType() != BaseType.POLICY) {
-            throw new RuntimeException("Not a policy: " + getId());
-        }
-        return new SimplePolicy(data, connection);
-    }
-
-    /*
-     * ----- 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 boolean hasContentStream() {
-        // spec says this is present iff content stream is present
-        String name = Property.CONTENT_STREAM_MIME_TYPE;
-        PropertyDefinition propertyDefinition = getType().getPropertyDefinition(
-                name);
-        if (propertyDefinition == null) {
-            return false;
-        }
-        return data.containsKey(name);
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((data == null) ? 0 : data.hashCode());
-        return result;
+    public Collection<String> getAllowableActions() {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException();
     }
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        SimpleObjectEntry other = (SimpleObjectEntry) obj;
-        if (data == null) {
-            if (other.data != null) {
-                return false;
-            }
-        } else if (!data.equals(other.data)) {
-            return false;
-        }
-        return true;
+    public Collection<ObjectEntry> getRelationships() {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException();
     }
 
-    
 }

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectId.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectId.java?rev=773069&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectId.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectId.java Fri May  8 19:52:42 2009
@@ -0,0 +1,69 @@
+/*
+ * 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.simple;
+
+import org.apache.chemistry.ObjectId;
+
+/**
+ * A wrapper for an object ID.
+ *
+ * @author Florent Guillaume
+ */
+public class SimpleObjectId implements ObjectId {
+
+    private final String id;
+
+    public SimpleObjectId(String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    @Override
+    public String toString() {
+        return this.getClass().getSimpleName() + '(' + id + ')';
+    }
+
+    @Override
+    public int hashCode() {
+        return id == null ? 31 : id.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (obj instanceof SimpleObjectId) {
+            return equals((SimpleObjectId) obj);
+        }
+        return false;
+    }
+
+    private boolean equals(SimpleObjectId other) {
+        if (id == null) {
+            return other.id == null;
+        } else {
+            return id.equals(other.id);
+        }
+    }
+
+}

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

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

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePolicy.java Fri May  8 19:52:42 2009
@@ -22,8 +22,8 @@
 
 public class SimplePolicy extends SimpleObject implements Policy {
 
-    public SimplePolicy(SimpleData data, SimpleConnection connection) {
-        super(data, connection);
+    public SimplePolicy(SimpleObjectEntry entry) {
+        super(entry);
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleProperty.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleProperty.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleProperty.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleProperty.java Fri May  8 19:52:42 2009
@@ -21,8 +21,9 @@
 import java.io.Serializable;
 
 import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.Updatability;
 
 /**
  * A live property of an object.
@@ -31,17 +32,23 @@
  */
 public class SimpleProperty implements Property {
 
+    protected static final String CONTENT_BYTES_KEY = "__content__";
+
     protected final ObjectEntry entry;
 
     protected final String name;
 
-    public SimpleProperty(ObjectEntry entry, String name) {
+    private final PropertyDefinition propertyDefinition;
+
+    public SimpleProperty(ObjectEntry entry, String name,
+            PropertyDefinition propertyDefinition) {
         this.entry = entry;
         this.name = name;
+        this.propertyDefinition = propertyDefinition;
     }
 
     public PropertyDefinition getDefinition() {
-        return entry.getType().getPropertyDefinition(name);
+        return propertyDefinition;
     }
 
     public Serializable getValue() {
@@ -49,8 +56,10 @@
     }
 
     public void setValue(Serializable value) {
-        // TODO XXX
-        throw new UnsupportedOperationException();
+        if (propertyDefinition.getUpdatability() == Updatability.READ_ONLY) {
+            throw new RuntimeException("Read-only property: " + name);
+        }
+        entry.setValue(name, value);
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePropertyDefinition.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePropertyDefinition.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePropertyDefinition.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimplePropertyDefinition.java Fri May  8 19:52:42 2009
@@ -26,10 +26,10 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.chemistry.property.Choice;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.property.PropertyType;
-import org.apache.chemistry.property.Updatability;
+import org.apache.chemistry.Choice;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.Updatability;
 
 public class SimplePropertyDefinition implements PropertyDefinition {
 
@@ -81,9 +81,10 @@
             int precision, Integer minValue, Integer maxValue, int maxLength,
             URI schemaURI, String encoding) {
         super();
-    	if (name.equals(SimpleDocument.CONTENT_BYTES_KEY)) {
-    		throw new IllegalArgumentException(SimpleDocument.CONTENT_BYTES_KEY + " is a reserved name");
-    	}
+        if (name.equals(SimpleProperty.CONTENT_BYTES_KEY)) {
+            throw new IllegalArgumentException(SimpleProperty.CONTENT_BYTES_KEY
+                    + " is a reserved name");
+        }
         this.name = name;
         this.id = id;
         this.displayName = displayName;
@@ -208,30 +209,30 @@
                     : "Property is single-valued";
         }
         Class<?> klass;
-        switch (type) {
-        case STRING:
-        case ID:
+        switch (type.ordinal()) {
+        case PropertyType.STRING_ORD:
+        case PropertyType.ID_ORD:
             klass = String.class;
             break;
-        case DECIMAL:
+        case PropertyType.DECIMAL_ORD:
             klass = BigDecimal.class;
             break;
-        case INTEGER:
+        case PropertyType.INTEGER_ORD:
             klass = Integer.class; // TODO Long
             break;
-        case BOOLEAN:
+        case PropertyType.BOOLEAN_ORD:
             klass = Boolean.class;
             break;
-        case DATETIME:
+        case PropertyType.DATETIME_ORD:
             klass = Calendar.class;
             break;
-        case URI:
+        case PropertyType.URI_ORD:
             klass = URI.class;
             break;
-        case XML:
+        case PropertyType.XML_ORD:
             klass = String.class; // TODO
             break;
-        case HTML:
+        case PropertyType.HTML_ORD:
             klass = String.class; // TODO
             break;
         default:

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRelationship.java Fri May  8 19:52:42 2009
@@ -22,8 +22,8 @@
 
 public class SimpleRelationship extends SimpleObject implements Relationship {
 
-    public SimpleRelationship(SimpleData data, SimpleConnection connection) {
-        super(data, connection);
+    public SimpleRelationship(SimpleObjectEntry entry) {
+        super(entry);
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java Fri May  8 19:52:42 2009
@@ -20,124 +20,64 @@
 
 import java.io.Serializable;
 import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
 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 java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.chemistry.Connection;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.repository.JoinCapability;
-import org.apache.chemistry.repository.QueryCapability;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.repository.RepositoryCapabilities;
-import org.apache.chemistry.repository.RepositoryEntry;
-import org.apache.chemistry.repository.RepositoryInfo;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.ContentStreamPresence;
-import org.apache.chemistry.type.Type;
-
-public class SimpleRepository 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";
-
-    protected 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.<SimplePropertyDefinition> emptyList());
-
-    protected 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.<SimplePropertyDefinition> emptyList());
-
-    protected 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.<SimplePropertyDefinition> emptyList());
-
-    protected 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.<SimplePropertyDefinition> 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.<SimplePropertyDefinition> emptyList());
+import org.apache.chemistry.JoinCapability;
+import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.QueryCapability;
+import org.apache.chemistry.SPI;
+import org.apache.chemistry.impl.base.BaseRepository;
 
-    public static final String USERNAME = "USERNAME";
-
-    public static final String PASSWORD = "PASSWORD";
+public class SimpleRepository extends BaseRepository {
 
     protected static final Set<String> NO_PARENT = Collections.unmodifiableSet(new HashSet<String>());
 
-    private final String name;
-
-    private final String rootFolderId;
+    protected final String rootId;
 
-    private final Map<String, Type> types;
+    private final ObjectId rootFolderId;
 
     /** Map of id -> data */
     protected final Map<String, SimpleData> datas;
 
-    /** Map of id -> contentBytes */
-    protected final Map<String, byte[]> contentBytes;
-
     /** Map of id -> children IDs */
     protected final Map<String, Set<String>> children;
 
     /** Map of id -> parent IDs, or null if unfiled */
     protected final Map<String, Set<String>> parents;
 
-    @SuppressWarnings("unchecked")
-    public SimpleRepository(String name, Collection<SimpleType> types) {
-        this.name = name;
-        this.types = new HashMap<String, Type>();
-        for (Collection<SimpleType> ts : Arrays.asList(getDefaultTypes(), types)) {
-            for (Type type : ts) {
-                String tid = type.getId();
-                if (this.types.containsKey(tid)) {
-                    throw new RuntimeException("Type already defined: " + tid);
-                }
-                this.types.put(tid, type);
-            }
-        }
-        rootFolderId = generateId();
+    public SimpleRepository(String name, Collection<SimpleType> types,
+            String rootId) {
+        this(name, rootId);
+        addTypes(getDefaultTypes());
+        addTypes(types);
+    }
+
+    public SimpleRepository(String name, String rootId) {
+        super(name);
 
         datas = new ConcurrentHashMap<String, SimpleData>();
-        contentBytes = new ConcurrentHashMap<String, byte[]>();
         children = new ConcurrentHashMap<String, Set<String>>();
         parents = new ConcurrentHashMap<String, Set<String>>();
 
         SimpleData rootData = new SimpleData(ROOT_TYPE_ID);
-        rootData.put(Property.ID, rootFolderId);
+        if (rootId == null) {
+            rootId = generateId();
+        }
+        this.rootId = rootId;
+        rootData.put(Property.ID, rootId);
         rootData.put(Property.NAME, ROOT_FOLDER_NAME);
-        datas.put(rootFolderId, rootData);
-        children.put(rootFolderId, newSet());
-        parents.put(rootFolderId, NO_PARENT);
+        datas.put(rootId, rootData);
+        children.put(rootId, newSet());
+        parents.put(rootId, NO_PARENT);
+        rootFolderId = new SimpleObjectId(rootId);
     }
 
     // private final AtomicLong idCounter = new AtomicLong(0);
@@ -147,11 +87,6 @@
         // return "ID_" + idCounter.incrementAndGet();
     }
 
-    protected Collection<SimpleType> getDefaultTypes() {
-        return Arrays.asList(DOCUMENT_TYPE, FOLDER_TYPE, RELATIONSHIP_TYPE,
-                POLICY_TYPE, ROOT_TYPE);
-    }
-
     protected Set<String> newSet() {
         return Collections.synchronizedSet(new HashSet<String>());
     }
@@ -160,14 +95,6 @@
      * ----- RepositoryEntry -----
      */
 
-    public String getId() {
-        return name;
-    }
-
-    public String getName() {
-        return name;
-    }
-
     public URI getURI() {
         // TODO Return a URI
         return null;
@@ -186,61 +113,13 @@
         return new SimpleConnection(this);
     }
 
-    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 SPI getSPI() {
+        // TODO credentials
+        return new SimpleConnection(this);
     }
 
-    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);
+    public <T> T getExtension(Class<T> klass) {
+        return null; // not supported
     }
 
     /*
@@ -251,40 +130,14 @@
         return "Repository " + name;
     }
 
-    public String getRootFolderId() {
+    public ObjectId getRootFolderId() {
         return rootFolderId;
     }
 
-    public String getVendorName() {
-        return "Nuxeo";
-    }
-
     public String getProductName() {
         return "Chemistry Simple Repository";
     }
 
-    public String getProductVersion() {
-        // TODO update this when releasing
-        return "0.1-SNAPSHOT";
-    }
-
-    public String getVersionSupported() {
-        // TODO may be overriden by generic client layer
-        return "0.51";
-    }
-
-    public org.w3c.dom.Document getRepositorySpecificInformation() {
-        return null;
-    }
-
-    public RepositoryCapabilities getCapabilities() {
-        return this;
-    }
-
-    public Collection<RepositoryEntry> getRelatedRepositories() {
-        return Collections.emptySet();
-    }
-
     /*
      * ----- RepositoryCapabilities -----
      */
@@ -321,7 +174,4 @@
         return QueryCapability.BOTH_COMBINED;
     }
 
-    public <T> T getExtension(Class<T> klass) {
-        return null; // Not Supported
-    }
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java Fri May  8 19:52:42 2009
@@ -26,176 +26,218 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.property.PropertyType;
-import org.apache.chemistry.property.Updatability;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.ContentStreamPresence;
-import org.apache.chemistry.type.Type;
+import org.apache.chemistry.BaseType;
+import org.apache.chemistry.ContentStreamPresence;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.Updatability;
 
 public class SimpleType implements Type {
 
-    protected static final SimplePropertyDefinition PROP_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_ID = new SimplePropertyDefinition(
             Property.ID, "def:id", "Id", "", false, PropertyType.ID, false,
             null, false, true, null, Updatability.READ_ONLY, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_URI = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_URI = new SimplePropertyDefinition(
             Property.URI, "def:uri", "URI", "", false, PropertyType.URI, false,
             null, false, false, null, Updatability.READ_ONLY, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_TYPE_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_TYPE_ID = new SimplePropertyDefinition(
             Property.TYPE_ID, "def:typeid", "Type ID", "", false,
             PropertyType.ID, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CREATED_BY = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CREATED_BY = new SimplePropertyDefinition(
             Property.CREATED_BY, "def:createdby", "Created By", "", false,
             PropertyType.STRING, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CREATION_DATE = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CREATION_DATE = new SimplePropertyDefinition(
             Property.CREATION_DATE, "def:creationdate", "Creation Date", "",
             false, PropertyType.DATETIME, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_LAST_MODIFIED_BY = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_LAST_MODIFIED_BY = new SimplePropertyDefinition(
             Property.LAST_MODIFIED_BY, "def:lastmodifiedby",
             "Last Modified By", "", false, PropertyType.STRING, false, null,
             false, true, null, Updatability.READ_ONLY, true, true, 0, null,
             null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_LAST_MODIFICATION_DATE = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_LAST_MODIFICATION_DATE = new SimplePropertyDefinition(
             Property.LAST_MODIFICATION_DATE, "def:lastmodificationdate",
             "Last Modification Date", "", false, PropertyType.DATETIME, false,
             null, false, true, null, Updatability.READ_ONLY, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CHANGE_TOKEN = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CHANGE_TOKEN = new SimplePropertyDefinition(
             Property.CHANGE_TOKEN, "def:changetoken", "Change Token", "",
             false, PropertyType.STRING, false, null, false, false, null,
             Updatability.READ_WRITE, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_NAME = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_NAME = new SimplePropertyDefinition(
             Property.NAME, "def:name", "Name", "", false, PropertyType.STRING,
             false, null, false, true, null, Updatability.READ_WRITE, true,
             true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_IS_LATEST_VERSION = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_IS_LATEST_VERSION = new SimplePropertyDefinition(
             Property.IS_LATEST_VERSION, "def:islatestversion",
             "Is Latest Version", "", false, PropertyType.BOOLEAN, false, null,
             false, true, null, Updatability.READ_ONLY, true, true, 0, null,
             null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_IS_MAJOR_VERSION = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_IS_MAJOR_VERSION = new SimplePropertyDefinition(
             Property.IS_MAJOR_VERSION, "def:ismajorversion",
             "Is Major Version", "", false, PropertyType.BOOLEAN, false, null,
             false, false, null, Updatability.READ_ONLY, true, true, 0, null,
             null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_IS_LATEST_MAJOR_VERSION = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_IS_LATEST_MAJOR_VERSION = new SimplePropertyDefinition(
             Property.IS_LATEST_MAJOR_VERSION, "def:islatestmajorversion",
             "Is Latest Major Version", "", false, PropertyType.BOOLEAN, false,
             null, false, true, null, Updatability.READ_ONLY, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_VERSION_LABEL = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_VERSION_LABEL = new SimplePropertyDefinition(
             Property.VERSION_LABEL, "def:versionlabel", "Version Label", "",
             false, PropertyType.STRING, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_VERSION_SERIES_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_VERSION_SERIES_ID = new SimplePropertyDefinition(
             Property.VERSION_SERIES_ID, "def:versionseriesid",
             "Version Series ID", "", false, PropertyType.ID, false, null,
             false, true, null, Updatability.READ_ONLY, true, true, 0, null,
             null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_IS_VERSION_SERIES_CHECKED_OUT = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_IS_VERSION_SERIES_CHECKED_OUT = new SimplePropertyDefinition(
             Property.IS_VERSION_SERIES_CHECKED_OUT,
             "def:isversionseriescheckedout", "Is Version Series Checked Out",
             "", false, PropertyType.BOOLEAN, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_VERSION_SERIES_CHECKED_OUT_BY = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_VERSION_SERIES_CHECKED_OUT_BY = new SimplePropertyDefinition(
             Property.VERSION_SERIES_CHECKED_OUT_BY,
             "def:versionseriescheckedoutby", "Version Series Checked Out By",
             "", false, PropertyType.STRING, false, null, false, false, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_VERSION_SERIES_CHECKED_OUT_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_VERSION_SERIES_CHECKED_OUT_ID = new SimplePropertyDefinition(
             Property.VERSION_SERIES_CHECKED_OUT_ID,
             "def:versionseriescheckedoutid", "Version Series Checked Out Id",
             "", false, PropertyType.ID, false, null, false, false, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CHECKIN_COMMENT = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CHECKIN_COMMENT = new SimplePropertyDefinition(
             Property.CHECKIN_COMMENT, "def:checkincomment", "Checkin Comment",
             "", false, PropertyType.STRING, false, null, false, false, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CONTENT_STREAM_ALLOWED = new SimplePropertyDefinition(
-            Property.CONTENT_STREAM_ALLOWED, "def:contentstreamallowed",
-            "Content Stream Allowed", "", false, PropertyType.STRING, false,
-            null, false, true, null, Updatability.READ_ONLY, true, true, 0,
-            null, null, -1, null, null);
-
-    protected static final SimplePropertyDefinition PROP_CONTENT_STREAM_LENGTH = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CONTENT_STREAM_LENGTH = new SimplePropertyDefinition(
             Property.CONTENT_STREAM_LENGTH, "def:contentstreamlength",
             "Content Stream Length", "", false, PropertyType.INTEGER, false,
             null, false, false, null, Updatability.READ_ONLY, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CONTENT_STREAM_MIME_TYPE = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CONTENT_STREAM_MIME_TYPE = new SimplePropertyDefinition(
             Property.CONTENT_STREAM_MIME_TYPE, "def:contentstreammimetype",
             "Content Stream MIME Type", "", false, PropertyType.STRING, false,
             null, false, false, null, Updatability.READ_ONLY, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CONTENT_STREAM_FILENAME = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CONTENT_STREAM_FILENAME = new SimplePropertyDefinition(
             Property.CONTENT_STREAM_FILENAME, "def:contentstreamfilename",
             "Content Stream Filename", "", false, PropertyType.STRING, false,
             null, false, false, null, Updatability.READ_WRITE, true, true, 0,
             null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_CONTENT_STREAM_URI = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_CONTENT_STREAM_URI = new SimplePropertyDefinition(
             Property.CONTENT_STREAM_URI, "def:contentstreamuri",
             "Content Stream URI", "", false, PropertyType.URI, false, null,
             false, false, null, Updatability.READ_ONLY, true, true, 0, null,
             null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_PARENT_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_PARENT_ID = new SimplePropertyDefinition(
             Property.PARENT_ID, "def:parentid", "Parent Id", "", false,
             PropertyType.ID, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS = new SimplePropertyDefinition(
             Property.ALLOWED_CHILD_OBJECT_TYPE_IDS,
             "def:allowedchildobjecttypeids", "Allowed Child Object Type Ids",
             "", false, PropertyType.ID, true, null, false, false, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_SOURCE_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_SOURCE_ID = new SimplePropertyDefinition(
             Property.SOURCE_ID, "def:sourceid", "Source Id", "", false,
             PropertyType.ID, false, null, false, true, null,
             Updatability.READ_WRITE, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_TARGET_ID = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_TARGET_ID = new SimplePropertyDefinition(
             Property.TARGET_ID, "def:targetid", "Target Id", "", false,
             PropertyType.ID, false, null, false, true, null,
             Updatability.READ_WRITE, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_POLICY_NAME = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_POLICY_NAME = new SimplePropertyDefinition(
             Property.POLICY_NAME, "def:policyname", "Policy Name", "", false,
             PropertyType.STRING, false, null, false, true, null,
             Updatability.READ_ONLY, true, true, 0, null, null, -1, null, null);
 
-    protected static final SimplePropertyDefinition PROP_POLICY_TEXT = new SimplePropertyDefinition(
+    public static final SimplePropertyDefinition PROP_POLICY_TEXT = new SimplePropertyDefinition(
             Property.POLICY_TEXT, "def:policytext", "Policy Text", "", false,
             PropertyType.STRING, false, null, false, true, null,
             Updatability.READ_WRITE, true, true, 0, null, null, -1, null, null);
 
+    private static final PropertyDefinition[] PROPS_COMMON = new SimplePropertyDefinition[] {
+            PROP_ID, //
+            PROP_URI, //
+            PROP_TYPE_ID, //
+            PROP_CREATED_BY, //
+            PROP_CREATION_DATE, //
+            PROP_LAST_MODIFIED_BY, //
+            PROP_LAST_MODIFICATION_DATE, //
+            PROP_CHANGE_TOKEN };
+
+    private static List<PropertyDefinition> commonPlus(
+            PropertyDefinition... array) {
+        ArrayList<PropertyDefinition> list = new ArrayList<PropertyDefinition>(
+                PROPS_COMMON.length + array.length);
+        list.addAll(Arrays.asList(PROPS_COMMON));
+        list.addAll(Arrays.asList(array));
+        return Collections.unmodifiableList(list);
+    }
+
+    public static final List<PropertyDefinition> PROPS_DOCUMENT_BASE = commonPlus(
+            PROP_NAME, //
+            PROP_IS_LATEST_VERSION, //
+            PROP_IS_MAJOR_VERSION, //
+            PROP_IS_LATEST_MAJOR_VERSION, //
+            PROP_VERSION_LABEL, //
+            PROP_VERSION_SERIES_ID, //
+            PROP_IS_VERSION_SERIES_CHECKED_OUT, //
+            PROP_VERSION_SERIES_CHECKED_OUT_BY, //
+            PROP_VERSION_SERIES_CHECKED_OUT_ID, //
+            PROP_CHECKIN_COMMENT, //
+            PROP_CONTENT_STREAM_LENGTH, //
+            PROP_CONTENT_STREAM_MIME_TYPE, //
+            PROP_CONTENT_STREAM_FILENAME, //
+            PROP_CONTENT_STREAM_URI);
+
+    public static final List<PropertyDefinition> PROPS_FOLDER_BASE = commonPlus(
+            PROP_NAME, //
+            PROP_PARENT_ID, //
+            PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS);
+
+    public static final List<PropertyDefinition> PROPS_RELATIONSHIP_BASE = commonPlus(
+            PROP_SOURCE_ID, //
+            PROP_TARGET_ID);
+
+    public static final List<PropertyDefinition> PROPS_POLICY_BASE = commonPlus(
+            PROP_POLICY_NAME, //
+            PROP_POLICY_TEXT);
+
     private final String id;
 
     private final String parentId;
@@ -228,14 +270,27 @@
 
     private final Map<String, PropertyDefinition> propertyDefinitions;
 
-    @SuppressWarnings("unchecked")
     public SimpleType(String id, String parentId, String queryName,
             String displayName, BaseType baseType, String description,
             boolean creatable, boolean queryable, boolean controllable,
             boolean includedInSuperTypeQuery, boolean fileable,
             boolean versionable, ContentStreamPresence contentStreamAllowed,
             String[] allowedSourceTypes, String[] allowedTargetTypes,
-            Collection<SimplePropertyDefinition> propertyDefinitions) {
+            Collection<PropertyDefinition> propertyDefinitions) {
+        this(id, parentId, queryName, displayName, baseType, description,
+                creatable, queryable, controllable, includedInSuperTypeQuery,
+                fileable, versionable, contentStreamAllowed,
+                allowedSourceTypes, allowedTargetTypes);
+        addPropertyDefinitions(getBasePropertyDefinitions(baseType));
+        addPropertyDefinitions(propertyDefinitions);
+    }
+
+    public SimpleType(String id, String parentId, String queryName,
+            String displayName, BaseType baseType, String description,
+            boolean creatable, boolean queryable, boolean controllable,
+            boolean includedInSuperTypeQuery, boolean fileable,
+            boolean versionable, ContentStreamPresence contentStreamAllowed,
+            String[] allowedSourceTypes, String[] allowedTargetTypes) {
         this.id = id;
         this.parentId = parentId;
         this.queryName = queryName;
@@ -251,51 +306,34 @@
         this.contentStreamAllowed = contentStreamAllowed;
         this.allowedSourceTypes = allowedSourceTypes;
         this.allowedTargetTypes = allowedTargetTypes;
-        Map<String, PropertyDefinition> map = new HashMap<String, PropertyDefinition>();
-        for (Collection<SimplePropertyDefinition> defs : Arrays.asList(
-                getBasePropertyDefinitions(baseType), propertyDefinitions)) {
-            for (PropertyDefinition def : defs) {
-                String name = def.getName();
-                if (map.containsKey(name)) {
-                    throw new RuntimeException(
-                            "Property already defined for name: " + name);
-                }
-                map.put(name, def);
+        propertyDefinitions = new HashMap<String, PropertyDefinition>();
+    }
+
+    protected void addPropertyDefinitions(Collection<PropertyDefinition> defs) {
+        for (PropertyDefinition def : defs) {
+            String name = def.getName();
+            if (propertyDefinitions.containsKey(name)) {
+                throw new RuntimeException(
+                        "Property already defined for name: " + name);
             }
+            propertyDefinitions.put(name, def);
         }
-        this.propertyDefinitions = map;
     }
 
-    protected List<SimplePropertyDefinition> getBasePropertyDefinitions(
+    protected static List<PropertyDefinition> getBasePropertyDefinitions(
             BaseType baseType) {
-        List<SimplePropertyDefinition> defs = new ArrayList<SimplePropertyDefinition>(
-                Arrays.asList(PROP_ID, PROP_URI, PROP_TYPE_ID, PROP_CREATED_BY,
-                        PROP_CREATION_DATE, PROP_LAST_MODIFIED_BY,
-                        PROP_LAST_MODIFICATION_DATE, PROP_CHANGE_TOKEN));
         switch (baseType) {
         case DOCUMENT:
-            defs.addAll(Arrays.asList(PROP_NAME, PROP_IS_LATEST_VERSION,
-                    PROP_IS_MAJOR_VERSION, PROP_IS_LATEST_MAJOR_VERSION,
-                    PROP_VERSION_LABEL, PROP_VERSION_SERIES_ID,
-                    PROP_IS_VERSION_SERIES_CHECKED_OUT,
-                    PROP_VERSION_SERIES_CHECKED_OUT_BY,
-                    PROP_VERSION_SERIES_CHECKED_OUT_ID, PROP_CHECKIN_COMMENT,
-                    PROP_CONTENT_STREAM_ALLOWED, PROP_CONTENT_STREAM_LENGTH,
-                    PROP_CONTENT_STREAM_MIME_TYPE,
-                    PROP_CONTENT_STREAM_FILENAME, PROP_CONTENT_STREAM_URI));
-            break;
+            return PROPS_DOCUMENT_BASE;
         case FOLDER:
-            defs.addAll(Arrays.asList(PROP_NAME, PROP_PARENT_ID,
-                    PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
-            break;
+            return PROPS_FOLDER_BASE;
         case RELATIONSHIP:
-            defs.addAll(Arrays.asList(PROP_SOURCE_ID, PROP_TARGET_ID));
-            break;
+            return PROPS_RELATIONSHIP_BASE;
         case POLICY:
-            defs.addAll(Arrays.asList(PROP_POLICY_NAME, PROP_POLICY_TEXT));
-            break;
+            return PROPS_POLICY_BASE;
+        default:
+            throw new AssertionError();
         }
-        return defs;
     }
 
     public String getId() {

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=773069&r1=773068&r2=773069&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 May  8 19:52:42 2009
@@ -21,23 +21,28 @@
 import java.net.URI;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
 import junit.framework.TestCase;
 
+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.property.Property;
-import org.apache.chemistry.property.PropertyType;
-import org.apache.chemistry.property.Updatability;
-import org.apache.chemistry.repository.JoinCapability;
-import org.apache.chemistry.repository.QueryCapability;
-import org.apache.chemistry.repository.RepositoryCapabilities;
-import org.apache.chemistry.repository.RepositoryInfo;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.ContentStreamPresence;
-import org.apache.chemistry.type.Type;
+import org.apache.chemistry.JoinCapability;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.QueryCapability;
+import org.apache.chemistry.RepositoryCapabilities;
+import org.apache.chemistry.RepositoryInfo;
+import org.apache.chemistry.ReturnVersion;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.Unfiling;
+import org.apache.chemistry.Updatability;
 
 public class TestSimpleRepository extends TestCase {
 
@@ -46,16 +51,16 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        SimplePropertyDefinition d1 = new SimplePropertyDefinition("title",
+        PropertyDefinition d1 = 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 d2 = new SimplePropertyDefinition(
-                "description", "def:description", "Description", "", false,
+        PropertyDefinition d2 = 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 d3 = new SimplePropertyDefinition("date",
+        PropertyDefinition d3 = 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);
@@ -67,7 +72,7 @@
                 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));
+        repo = new SimpleRepository("test", Arrays.asList(mt1, mt2), null);
 
     }
 
@@ -76,10 +81,10 @@
         assertEquals("test", repo.getName());
         RepositoryInfo info = repo.getInfo();
         assertNotNull(info.getRootFolderId());
-        assertEquals("Nuxeo", info.getVendorName());
+        assertEquals("Apache", info.getVendorName());
         assertEquals("Chemistry Simple Repository", info.getProductName());
         assertEquals("0.1-SNAPSHOT", info.getProductVersion());
-        assertEquals("0.51", info.getVersionSupported());
+        assertEquals("0.61", info.getVersionSupported());
         assertEquals(null, info.getRepositorySpecificInformation());
         RepositoryCapabilities capabilities = info.getCapabilities();
         assertFalse(capabilities.hasMultifiling());
@@ -100,7 +105,7 @@
         assertNotNull(conn);
         Folder root = conn.getRootFolder();
         assertNotNull(root);
-        assertEquals(repo.getRootFolderId(), root.getId());
+        assertEquals(repo.getRootFolderId().getId(), root.getId());
         assertEquals("CMIS_Root_Folder", root.getName());
         assertEquals(0, root.getChildren(null, null).size());
         assertNull(root.getParent());
@@ -111,28 +116,32 @@
         Folder root = conn.getRootFolder();
         Folder f1 = root.newFolder("fold");
         assertEquals(12 + 1, f1.getType().getPropertyDefinitions().size());
-        assertEquals(0, root.getChildren(null, null).size());
+        List<CMISObject> children = root.getChildren(null, null);
+        assertEquals(0, children.size());
         f1.save();
         assertEquals(root.getId(), f1.getParent().getId());
-        assertEquals(1, root.getChildren(null, null).size());
-        Folder f2 = root.newFolder("fold");
-        f2.save();
-        assertEquals(root.getId(), f2.getParent().getId());
-        assertEquals(2, root.getChildren(null, null).size());
+        children = root.getChildren(null, null);
+        assertEquals(1, children.size());
+        assertTrue(children.get(0) instanceof Folder);
+        Document d1 = root.newDocument("doc");
+        d1.save();
+        children = root.getChildren(null, null);
+        assertEquals(2, children.size());
+        assertTrue(children.get(0) instanceof Document
+                || children.get(1) instanceof Document);
     }
 
     public void testDocument() throws Exception {
         Connection conn = repo.getConnection(null);
         Folder root = conn.getRootFolder();
         Document d1 = root.newDocument("doc");
-        assertEquals(23 + 3, d1.getType().getPropertyDefinitions().size());
+        assertEquals(22 + 3, d1.getType().getPropertyDefinitions().size());
         d1.save();
-        String d1Id = d1.getId();
         assertEquals(root.getId(), d1.getParent().getId());
         d1.setValue("title", "Yo!");
         assertEquals("Yo!", d1.getString("title"));
         // refetch
-        d1 = (Document) conn.getObject(d1Id, null);
+        d1 = (Document) conn.getObject(d1, null);
         assertEquals("Yo!", d1.getString("title"));
         Property prop = d1.getProperty("title");
         assertNotNull(prop);
@@ -161,4 +170,37 @@
         assertEquals(string, new String(bytes, "UTF-8"));
     }
 
+    public void testRemoveDocument() {
+        Connection conn = repo.getConnection(null);
+        Folder root = conn.getRootFolder();
+        Document d1 = root.newDocument("doc");
+        d1.save();
+        conn.deleteObject(d1);
+        assertNull(conn.getObject(d1, ReturnVersion.THIS));
+    }
+
+    public void testRemoveFolder() {
+        Connection conn = repo.getConnection(null);
+        Folder root = conn.getRootFolder();
+        try {
+            conn.deleteObject(root);
+            fail();
+        } catch (Exception e) {
+            // ok
+        }
+        Folder f1 = root.newFolder("fold");
+        f1.setName("foo");
+        f1.save();
+        Folder f2 = f1.newFolder("fold");
+        f2.setName("foo2");
+        f2.save();
+        Document d1 = f2.newDocument("doc");
+        d1.setName("bar");
+        d1.save();
+        conn.deleteTree(f2, Unfiling.UNFILE, true);
+        assertEquals(f1.getId(), conn.getObject(f1, ReturnVersion.THIS).getId());
+        assertNull(conn.getObject(f2, ReturnVersion.THIS));
+        assertNull(conn.getObject(d1, ReturnVersion.THIS));
+    }
+
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java Fri May  8 19:52:42 2009
@@ -33,6 +33,7 @@
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.ContentStream;
@@ -42,12 +43,11 @@
 import org.apache.chemistry.Policy;
 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.Unfiling;
 import org.apache.chemistry.VersioningState;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.type.BaseType;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.JcrConstants;
@@ -238,7 +238,7 @@
                                  String folderId, ContentStream contentStream,
                                  VersioningState versioningState) {
 
-    	try {
+        try {
             JcrFolder folder = (JcrFolder) getObject(folderId,
                     ReturnVersion.LATEST);
             Document doc = folder.newDocument(null);
@@ -341,7 +341,7 @@
             }
             /* Problem with skipCount == 0, when there are no more elements */
             if (iter.hasNext()) {
-            	iter.skip(skipCount);
+                iter.skip(skipCount);
             }
 
             List<ObjectEntry> result = new ArrayList<ObjectEntry>();

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java Fri May  8 19:52:42 2009
@@ -24,11 +24,11 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.type.BaseType;
+import org.apache.chemistry.Property;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.JcrConstants;
@@ -124,6 +124,6 @@
 
     @Override
     protected BaseType getBaseType() {
-    	return BaseType.DOCUMENT;
+        return BaseType.DOCUMENT;
     }
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java Fri May  8 19:52:42 2009
@@ -25,10 +25,10 @@
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.type.BaseType;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.JcrConstants;
@@ -124,6 +124,6 @@
 
     @Override
     protected BaseType getBaseType() {
-    	return BaseType.FOLDER;
+        return BaseType.FOLDER;
     }
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrNewFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrNewFolder.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrNewFolder.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrNewFolder.java Fri May  8 19:52:42 2009
@@ -24,10 +24,10 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.type.BaseType;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.JcrConstants;

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java Fri May  8 19:52:42 2009
@@ -31,18 +31,18 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Policy;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
 import org.apache.chemistry.Relationship;
+import org.apache.chemistry.Type;
+import org.apache.chemistry.Updatability;
 import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.property.PropertyType;
-import org.apache.chemistry.property.Updatability;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.Type;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrProperty.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrProperty.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrProperty.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrProperty.java Fri May  8 19:52:42 2009
@@ -20,8 +20,8 @@
 
 import javax.jcr.RepositoryException;
 
-import org.apache.chemistry.property.Property;
-import org.apache.chemistry.property.PropertyDefinition;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.PropertyDefinition;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java Fri May  8 19:52:42 2009
@@ -20,10 +20,10 @@
 import java.net.URI;
 import java.util.List;
 
-import org.apache.chemistry.property.Choice;
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.property.PropertyType;
-import org.apache.chemistry.property.Updatability;
+import org.apache.chemistry.Choice;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.PropertyType;
+import org.apache.chemistry.Updatability;
 
 public class JcrPropertyDefinition implements PropertyDefinition {
 

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=773069&r1=773068&r2=773069&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 May  8 19:52:42 2009
@@ -30,15 +30,15 @@
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 
+import org.apache.chemistry.BaseType;
 import org.apache.chemistry.Connection;
-import org.apache.chemistry.repository.JoinCapability;
-import org.apache.chemistry.repository.QueryCapability;
-import org.apache.chemistry.repository.Repository;
-import org.apache.chemistry.repository.RepositoryCapabilities;
-import org.apache.chemistry.repository.RepositoryEntry;
-import org.apache.chemistry.repository.RepositoryInfo;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.Type;
+import org.apache.chemistry.JoinCapability;
+import org.apache.chemistry.QueryCapability;
+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.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.JcrConstants;
@@ -81,7 +81,7 @@
     }
 
     public Type getType(String typeId) {
-    	try {
+        try {
             // TODO pass credentials as parameters
             SimpleCredentials creds = new SimpleCredentials("admin", "admin"
                     .toCharArray());
@@ -101,13 +101,13 @@
             String msg = "Unable get type: " + typeId;
             log.error(msg, e);
         }
-    	return null;
+        return null;
     }
 
     public Collection<Type> getTypes(String typeId,
                                      boolean returnPropertyDefinitions) {
-    	boolean[] hasMoreItems = new boolean[1];
-    	return getTypes(typeId, returnPropertyDefinitions, 0, 0, hasMoreItems);
+        boolean[] hasMoreItems = new boolean[1];
+        return getTypes(typeId, returnPropertyDefinitions, 0, 0, hasMoreItems);
     }
 
     public List<Type> getTypes(String typeId,
@@ -116,7 +116,7 @@
 
         // TODO dynamically discover and return types.
 
-    	try {
+        try {
             // TODO pass credentials as parameters
             SimpleCredentials creds = new SimpleCredentials("admin", "admin"
                     .toCharArray());
@@ -134,10 +134,10 @@
             result.add(new JcrType(ntmgr.getNodeType(JcrConstants.NT_FILE),
                     BaseType.DOCUMENT));
             return result;
-    	} catch (RepositoryException e) {
-    		String msg = "Unable to retrieve node types.";
+        } catch (RepositoryException e) {
+            String msg = "Unable to retrieve node types.";
             log.error(msg, e);
-    	}
+        }
         return null;
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java?rev=773069&r1=773068&r2=773069&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java Fri May  8 19:52:42 2009
@@ -21,10 +21,10 @@
 
 import javax.jcr.nodetype.NodeType;
 
-import org.apache.chemistry.property.PropertyDefinition;
-import org.apache.chemistry.type.BaseType;
-import org.apache.chemistry.type.ContentStreamPresence;
-import org.apache.chemistry.type.Type;
+import org.apache.chemistry.BaseType;
+import org.apache.chemistry.ContentStreamPresence;
+import org.apache.chemistry.PropertyDefinition;
+import org.apache.chemistry.Type;
 
 public class JcrType implements Type {
 
@@ -47,11 +47,11 @@
     }
 
     public BaseType getBaseType() {
-    	return baseType;
+        return baseType;
     }
 
     public String getBaseTypeQueryName() {
-    	return baseType.toString();
+        return baseType.toString();
     }
 
     public ContentStreamPresence getContentStreamAllowed() {