chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcaru...@apache.org
Subject svn commit: r910572 [30/36] - in /incubator/chemistry/trunk/opencmis: ./ _dev/ opencmis-client/ opencmis-client/opencmis-client-api/ opencmis-client/opencmis-client-api/src/ opencmis-client/opencmis-client-api/src/main/ opencmis-client/opencmis-client-...
Date Tue, 16 Feb 2010 16:04:07 GMT
Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.opencmis.commons.PropertyIds;
+import org.apache.opencmis.commons.enums.VersioningState;
+import org.apache.opencmis.commons.provider.ContentStreamData;
+import org.apache.opencmis.commons.provider.PropertyData;
+import org.apache.opencmis.commons.provider.ProviderObjectFactory;
+import org.apache.opencmis.inmemory.FilterParser;
+import org.apache.opencmis.inmemory.storedobj.api.DocumentVersion;
+import org.apache.opencmis.inmemory.storedobj.api.VersionedDocument;
+
+/**
+ * A class representing a single version of a document
+ * 
+ * @author Jens
+ *
+ */
+public class DocumentVersionImpl extends StoredObjectImpl implements DocumentVersion {
+  
+  private ContentStreamDataImpl fContent;  
+  private VersionedDocument fContainer; // the document this version belongs to
+  private String fComment; // checkin comment
+  boolean fIsMajor;
+  boolean fIsPwc; // true if this is the PWC
+  
+  public DocumentVersionImpl(String repositoryId, VersionedDocument container, ContentStreamData content,
+      VersioningState verState) {
+    setRepositoryId(repositoryId);
+    fContainer = container;
+    setContent(content, false);
+    fIsMajor = verState == VersioningState.MAJOR;
+    fIsPwc = verState == VersioningState.CHECKEDOUT;
+    fProperties = new HashMap<String, PropertyData<?>>(); // ensure that we have a map
+  }
+  
+  public void setContent(ContentStreamData content, boolean mustPersist) {
+    if (null == content) {
+      fContent = null;
+    } else {     
+      fContent = new ContentStreamDataImpl();
+      fContent.setFileName(content.getFilename());
+      fContent.setMimeType(content.getMimeType());
+      try {
+        fContent.setContent(content.getStream());
+      }
+      catch (IOException e) {
+        e.printStackTrace();
+        throw new RuntimeException("Failed to get content from InputStream" , e);
+      }
+    }  
+  }
+  
+  public String getCheckinComment() {
+    return fComment;
+  }
+
+  public String getVersionLabel() {
+    int majorNo = 0;
+    int minorNo = 0;
+    List<DocumentVersion> allVersions = fContainer.getAllVersions(null);
+    for (DocumentVersion ver : allVersions) {
+      if (ver.isMajor()) {
+        ++majorNo;
+        minorNo = 0;
+      } else
+        ++minorNo;
+    }
+    String label = "V " + majorNo + "." + minorNo;
+    return label;
+  }
+
+  public boolean isMajor() {
+    return fIsMajor && !isPwc();
+  }
+
+  public boolean isPwc() {
+    return fIsPwc;
+  }
+
+  public void commit(boolean isMajor) {
+    fIsPwc = false; // unset working copy flag
+    fIsMajor = isMajor;
+  }
+  
+  public ContentStreamData getContent() {
+    return fContent;
+  }
+  
+  public VersionedDocument getParentDocument() {
+    return fContainer;
+  }
+
+  private boolean isLatestVersion() {
+    List<DocumentVersion> allVers = fContainer.getAllVersions(null);
+    boolean isLatestVersion;
+    if (isPwc())
+      isLatestVersion = allVers.size()>1 && allVers.get(allVers.size()-2).equals(this);
+    else
+      isLatestVersion = allVers.get(allVers.size()-1).equals(this);
+    return isLatestVersion;
+  }
+
+  private boolean isLatestMajorVersion() {
+    if (!fIsMajor)
+      return false;
+    
+    List<DocumentVersion> allVersions = fContainer.getAllVersions(null);
+    DocumentVersion latestMajor=null;
+    
+    for (DocumentVersion ver : allVersions)
+      if (ver.isMajor() && !ver.isPwc()) 
+        latestMajor = ver;
+
+    boolean isLatestMajorVersion = latestMajor == this;
+    return isLatestMajorVersion;
+  }
+  
+  public void persist() {
+    if (null==fId)
+      fId = UUID.randomUUID().toString();
+  }
+  
+  public void fillProperties(List<PropertyData<?>> properties, ProviderObjectFactory objFactory,
+      List<String> requestedIds) {
+    
+    DocumentVersion pwc = fContainer.getPwc();
+
+    // First get the properties of the container (like custom type properties, etc)
+    fContainer.fillProperties(properties, objFactory, requestedIds);
+    
+    // overwrite the version specific properties (like modification date, user, etc.)
+    // and set some properties specific to the version
+    super.fillProperties(properties, objFactory, requestedIds);
+    
+    // fill the version related properties 
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_IS_LATEST_VERSION, requestedIds)) {
+      properties.add(objFactory.createPropertyBooleanData(PropertyIds.CMIS_IS_LATEST_VERSION, isLatestVersion()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_IS_MAJOR_VERSION, requestedIds)) {
+      properties.add(objFactory.createPropertyBooleanData(PropertyIds.CMIS_IS_MAJOR_VERSION, fIsMajor));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_IS_LATEST_MAJOR_VERSION, requestedIds)) {
+      properties.add(objFactory.createPropertyBooleanData(PropertyIds.CMIS_IS_LATEST_MAJOR_VERSION, isLatestMajorVersion()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_SERIES_ID, requestedIds)) { 
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_VERSION_SERIES_ID, fContainer.getId()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
+      properties.add(objFactory.createPropertyBooleanData(PropertyIds.CMIS_IS_VERSION_SERIES_CHECKED_OUT, fContainer.isCheckedOut()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_BY, fContainer.getCheckedOutBy()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_ID, pwc == null ? null : pwc.getId()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_CHECKIN_COMMENT, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_CHECKIN_COMMENT, fComment));
+    }    
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_LABEL, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_VERSION_LABEL, getVersionLabel()));
+    }
+  }
+  
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/FolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/FolderImpl.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/FolderImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/FolderImpl.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,226 @@
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.opencmis.commons.PropertyIds;
+import org.apache.opencmis.commons.provider.PropertyData;
+import org.apache.opencmis.commons.provider.ProviderObjectFactory;
+import org.apache.opencmis.inmemory.FilterParser;
+import org.apache.opencmis.inmemory.NameValidator;
+import org.apache.opencmis.inmemory.storedobj.api.Document;
+import org.apache.opencmis.inmemory.storedobj.api.Folder;
+import org.apache.opencmis.inmemory.storedobj.api.Path;
+import org.apache.opencmis.inmemory.storedobj.api.StoredObject;
+import org.apache.opencmis.inmemory.storedobj.api.VersionedDocument;
+
+public class FolderImpl extends AbstractPathImpl implements Folder {
+  private static final Log LOG = LogFactory.getLog(AbstractPathImpl.class.getName());
+
+  FolderImpl(ObjectStoreImpl objStore) {
+    super(objStore);
+  }
+
+  public FolderImpl(ObjectStoreImpl objStore, String name, Folder parent) {
+    super(objStore);
+    init(name, parent);
+  }
+
+  public void addChildFolder(Folder folder) {
+    boolean hasChild;
+    String name = folder.getName();
+    hasChild = hasChild(name);
+    if (hasChild)
+      throw new RuntimeException("Cannot create folder " + name
+          + ". Name already exists in parent folder");
+    folder.setParent(this);
+    fObjStore.storeObject(folder.getPath(), folder);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.provider.spi.inmemory.IFolder#addChildDocument(org.apache.opencmis.client.provider
+   * .spi.inmemory.storedobj.impl.DocumentImpl)
+   */
+  public void addChildDocument(Document doc) {
+    addChildObject(doc);
+  }
+
+  public void addChildDocument(VersionedDocument doc) {
+    addChildObject(doc);
+  }
+  
+  private void addChildObject(StoredObject so) {
+    String name = so.getName();
+    if (!NameValidator.isValidId(name))
+      throw new IllegalArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+
+    boolean hasChild;
+    hasChild = hasChild(name);
+    if (hasChild)
+      throw new RuntimeException("Cannot create document " + name
+          + ". Name already exists in parent folder");
+
+    String documentPath = getPath();
+    if (documentPath.equals(PATH_SEPARATOR))
+      documentPath += name;
+    else
+      documentPath += PATH_SEPARATOR + name;
+    ((Path)so).setParent(this);
+    fObjStore.storeObject(documentPath, so);    
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IFolder#getChildren()
+   */
+  public List<StoredObject> getChildren(int maxItems, int skipCount) {
+    List<StoredObject> result = new ArrayList<StoredObject>();
+    String path = getPath();
+    for (String id : fObjStore.getIds()) {
+      StoredObject obj = fObjStore.getObject(id);
+      if (obj instanceof Path) {
+        Path pathObj = (Path) obj;
+        if (pathObj.getParent() != null && path.equals(pathObj.getParent().getPath()))
+            result.add(obj);
+      }
+    }
+    sortFolderList(result);
+
+    if (maxItems < 0)
+      maxItems = result.size();
+    if (skipCount < 0)
+      skipCount = 0;
+    int from = Math.min(skipCount, result.size());
+    int to = Math.min(maxItems + from, result.size());
+    result = result.subList(from, to);
+    return result;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IFolder#getFolderChildren()
+   */
+  public List<Folder> getFolderChildren(int maxItems, int skipCount) {
+    List<Folder> result = new ArrayList<Folder>();
+    String path = getPath();
+    for (String id : fObjStore.getIds()) {
+      StoredObject obj = fObjStore.getObject(id);
+      if (obj instanceof Path) {
+        Path pathObj = (Path) obj;
+        if (pathObj.getParent() != null && path.equals(pathObj.getParent().getPath())
+            && pathObj instanceof Folder)
+          result.add((Folder)obj);
+        
+      }
+    }
+    sortFolderList(result);
+    int from = Math.min(skipCount, result.size());
+    int to = Math.min(maxItems + from, result.size());
+    result = result.subList(from, to);
+    return result;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IFolder#hasChild(java.lang.String)
+   */
+  public boolean hasChild(String name) {
+    String path = getPath();
+    if (path.equals(PATH_SEPARATOR))
+      path = path + name;
+    else
+      path = path + PATH_SEPARATOR + name;
+    for (String objPath : fObjStore.getIds()) {
+      if (path.equals(objPath))
+        return true;
+    }
+    return false;
+  }
+
+  public void fillProperties(List<PropertyData<?>> properties, ProviderObjectFactory objFactory,
+      List<String> requestedIds) {
+
+    super.fillProperties(properties, objFactory, requestedIds);
+
+    // add folder specific properties
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_OBJECT_ID, requestedIds)) {
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_OBJECT_ID, getPath()));
+      // for folders we use the path as id in this provider
+    }
+
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_PARENT_ID, requestedIds)) {
+      String parentId = getParent() == null ? null : getParent().getId();
+      if ( parentId != null )
+        properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_PARENT_ID, parentId));
+    }
+
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_ALLOWED_CHILD_OBJECT_TYPE_IDS,
+        requestedIds)) {
+      String allowedChildObjects = "*"; // TODO: not yet supported
+      properties.add(objFactory.createPropertyStringData(
+          PropertyIds.CMIS_ALLOWED_CHILD_OBJECT_TYPE_IDS, allowedChildObjects));
+    }
+
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_PATH, requestedIds)) {
+      String path = getPath();
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_PATH, path));
+    }
+  }
+
+  // Helper functions
+  private void init(String name, Folder parent) {
+    if (!NameValidator.isValidId(name))
+      throw new IllegalArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+    setName(name);
+    setParent(parent);
+  }
+
+  private void sortFolderList(List<? extends StoredObject> list) {
+
+    // TODO evaluate orderBy, for now sort by path segment
+    class FolderComparator implements Comparator<StoredObject> {
+
+      public int compare(StoredObject f1, StoredObject f2) {
+        String segment1 = f1.getName();
+        String segment2 = f2.getName();
+
+        return segment1.compareTo(segment2);
+      }
+    }
+
+    Collections.sort(list, new FolderComparator());
+  }
+
+  public void persist() {
+    // The in-memory implementation doesn't have to do anything here, but sets the id
+//    fId = getPath();
+  }
+
+  public void moveChildDocument(Document doc, Folder newParent) {
+    if (newParent.hasChild(doc.getName()))
+      throw new IllegalArgumentException(
+          "Cannot move folder, this name already exists in target.");
+
+    String oldPath = doc.getPath(); // old path of document to move
+    doc.setParent(newParent);
+    String newPath = doc.getPath(); // new path of document to move
+    fObjStore.removeObject(oldPath);
+    fObjStore.storeObject(newPath, doc);
+  }
+
+  public List<String> getAllowedChildObjectTypeIds() {
+    // TODO implement this.
+    return null;
+  }
+
+}
\ No newline at end of file

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/FolderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.opencmis.commons.enums.BaseObjectTypeIds;
+import org.apache.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.opencmis.inmemory.storedobj.api.Document;
+import org.apache.opencmis.inmemory.storedobj.api.Folder;
+import org.apache.opencmis.inmemory.storedobj.api.ObjectStore;
+import org.apache.opencmis.inmemory.storedobj.api.Path;
+import org.apache.opencmis.inmemory.storedobj.api.StoredObject;
+import org.apache.opencmis.inmemory.storedobj.api.VersionedDocument;
+
+/**
+ * InMemory folder implementation
+ * 
+ * @author Jens
+ * 
+ */
+
+public class ObjectStoreImpl implements ObjectStore {
+
+  /**
+   * Maps the absolute folder path to the corresponding folder object
+   */
+  private Map<String, StoredObject> fStoredObjectMap = new HashMap<String, StoredObject>();
+  final String fRepositoryId; 
+  FolderImpl fRootFolder = null;
+
+  public ObjectStoreImpl(String repositoryId) {
+    fRepositoryId = repositoryId;
+    createRootFolder();
+  }
+
+  
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#getRootFolder()
+   */
+  public Folder getRootFolder() {
+    return fRootFolder;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#getFolderByPath(java.lang
+   * .String)
+   */
+  public StoredObject getObjectByPath(String path) {
+    StoredObject obj = fStoredObjectMap.get(path);
+    return obj;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#getObjectById(java.lang
+   * .String)
+   */
+  public StoredObject getObjectById(String objectId) {
+    // we use path as id so we just can look it up in the map
+    StoredObject so = fStoredObjectMap.get(objectId);
+    return so;
+  }
+
+ /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#deleteObject(java.lang
+   * .String)
+   */
+  public void deleteObject(String objectId) {
+    String path = objectId; // currently the same
+    StoredObject obj = fStoredObjectMap.get(path);
+
+    if (null == obj)
+      throw new RuntimeException("Cannot delete object with id  " + objectId
+          + ". Object does not exist.");
+
+    if (obj instanceof FolderImpl) {
+      deleteFolder(objectId);
+    }
+    else {
+      fStoredObjectMap.remove(path);
+    }
+  }
+
+  public void changePath(StoredObject obj, String oldPath, String newPath) {
+    fStoredObjectMap.remove(oldPath);
+    fStoredObjectMap.put(newPath, obj);
+  }
+
+  // /////////////////////////////////////////
+  // methods used by folders and documents, but not for public use
+  
+  void storeObject(String id, StoredObject sop) {
+    fStoredObjectMap.put(id, sop);
+  }
+
+  StoredObject getObject(String id) {
+    return fStoredObjectMap.get(id);
+  }
+
+  void removeObject(String id) {
+    fStoredObjectMap.remove(id);
+  }
+  
+  Set<String> getIds() {
+   Set<String> entries = fStoredObjectMap.keySet();
+   return entries;
+  }
+  
+  void renameAllIdsWithPrefix(String oldPath, String newPath) {
+    Iterator<Entry<String, StoredObject>> it = fStoredObjectMap.entrySet().iterator();
+    Map<String, StoredObject> newMap = new HashMap<String, StoredObject>();
+    while (it.hasNext()) {
+      Map.Entry<String, StoredObject> entry = (Map.Entry<String, StoredObject>) it
+          .next();
+
+      if (entry.getKey().startsWith(oldPath)) {
+        if (entry.getValue() instanceof Path) {
+          newPath = ((Path)entry.getValue()).getPath();
+          it.remove(); // the only safe way to modify while iteration
+          newMap.put(newPath, entry.getValue()); // we can't add to the current collection while
+                                                 // iterating          
+        }
+      }
+    }
+    fStoredObjectMap.putAll(newMap); // add all at once when iteration is complete  
+  }
+  
+  // /////////////////////////////////////////
+  // private helper methods
+
+  private void createRootFolder() {
+    FolderImpl rootFolder = new FolderImpl(this);
+    rootFolder.setName("RootFolder");
+    rootFolder.setParent(null);
+    rootFolder.setTypeId(BaseObjectTypeIds.CMIS_FOLDER.value());
+    rootFolder.setCreatedBy("Admin");
+    rootFolder.setModifiedBy("Admin");
+    rootFolder.setModifiedAtNow();
+    rootFolder.setRepositoryId(fRepositoryId);
+
+    fStoredObjectMap.put(Path.PATH_SEPARATOR, rootFolder);
+    fRootFolder =  rootFolder;
+  }
+
+  public Document createDocument(String name) {
+    Document doc = new DocumentImpl(this);
+    doc.setRepositoryId(fRepositoryId);
+    doc.setName(name);
+    return doc;
+  }
+
+  public VersionedDocument createVersionedDocument(String name) {
+    VersionedDocument doc = new VersionedDocumentImpl(this);
+    doc.setRepositoryId(fRepositoryId);
+    doc.setName(name);
+    return doc;
+  }
+
+  public Folder createFolder(String name) {
+    Folder folder = new FolderImpl(this, name, null);;
+    folder.setRepositoryId(fRepositoryId);
+    return folder;
+  }
+
+  public List<VersionedDocument> getCheckedOutDocuments(String orderBy) {
+    List<VersionedDocument> res = new ArrayList<VersionedDocument>();
+    
+    for (StoredObject so : fStoredObjectMap.values() ) {
+      if (so instanceof VersionedDocument) {
+        VersionedDocument verDoc = (VersionedDocument) so;
+        if (verDoc.isCheckedOut()) {
+          res.add(verDoc);
+        }
+      }
+    }
+    
+    return res;
+  }
+  
+  private void deleteFolder(String folderId) {
+    String path = folderId; // we use path as id
+    StoredObject obj = fStoredObjectMap.get(path);
+    if (obj != null) {
+      if (!(obj instanceof FolderImpl))
+        throw new RuntimeException("Cannot delete folder with path:  " + path
+            + ". Object exists but is not a folder.");
+    }
+
+    // check if children exist
+    fStoredObjectMap.remove(path);
+    for (String objPath : fStoredObjectMap.keySet()) {
+      if (objPath.startsWith(path)) {
+        fStoredObjectMap.put(path, obj); // restore object
+        throw new CmisConstraintException("Cannot delete folder with path:  " + path
+            + ". Folder is not empty.");
+      }
+    }
+  }
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/SessionConfigReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/SessionConfigReader.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/SessionConfigReader.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/SessionConfigReader.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import org.apache.opencmis.client.provider.spi.Session;
+import org.apache.opencmis.inmemory.ConfigMap;
+
+public class SessionConfigReader implements ConfigMap {
+
+  private Session fSession;
+  
+  public SessionConfigReader(Session session) {
+    fSession = session;
+  }
+  
+  public String get(String paramName) {    
+    return (String) fSession.get(paramName);
+  }
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/SessionConfigReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.opencmis.inmemory.storedobj.api.StoreManager;
+
+/**
+ * create objects that are stored in a persistent store
+ * 
+ * @author Jens
+ */
+
+public class StoreManagerFactory {
+  private static Log log = LogFactory.getLog(StoreManagerFactory.class);
+
+  public static StoreManager createInstance(String className) {
+
+    Class<?> clazz = null;
+    try {
+      clazz = Class.forName(className);
+    }
+    catch (ClassNotFoundException e) {
+      String msg = "Failed to create StoredObjectCreator, class " + className + " does not exist.";
+      log.error(msg, e);
+      e.printStackTrace();
+      throw new RuntimeException(msg, e);
+    }
+
+    Object obj = null;
+    try {
+      obj = clazz.newInstance();
+    }
+    catch (InstantiationException e) {
+      log.error("Failed to create StoredObjectCreator from class " + className, e);
+      e.printStackTrace();
+    }
+    catch (IllegalAccessException e) {
+      log.error("Failed to create StoredObjectCreator from class " + className, e);
+      e.printStackTrace();
+    }
+
+    if (obj instanceof StoreManager)
+      return (StoreManager) obj;
+    else {
+      log.error("Failed to create StoredObjectCreator, class " + className
+          + " does not implement interface StoredObjectCreator");
+      return null;
+    }
+  }
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,313 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.opencmis.commons.api.TypeDefinition;
+import org.apache.opencmis.commons.api.TypeDefinitionContainer;
+import org.apache.opencmis.commons.enums.CapabilityChanges;
+import org.apache.opencmis.commons.enums.CapabilityContentStreamUpdates;
+import org.apache.opencmis.commons.enums.CapabilityJoin;
+import org.apache.opencmis.commons.enums.CapabilityQuery;
+import org.apache.opencmis.commons.enums.CapabilityRendition;
+import org.apache.opencmis.commons.impl.dataobjects.ProviderObjectFactoryImpl;
+import org.apache.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesDataImpl;
+import org.apache.opencmis.commons.impl.dataobjects.RepositoryInfoDataImpl;
+import org.apache.opencmis.commons.provider.ProviderObjectFactory;
+import org.apache.opencmis.commons.provider.RepositoryInfoData;
+import org.apache.opencmis.inmemory.ConfigMap;
+import org.apache.opencmis.inmemory.RepositoryInfo;
+import org.apache.opencmis.inmemory.RepositoryInfoCreator;
+import org.apache.opencmis.inmemory.TypeCreator;
+import org.apache.opencmis.inmemory.TypeManager;
+import org.apache.opencmis.inmemory.storedobj.api.ObjectStore;
+import org.apache.opencmis.inmemory.storedobj.api.StoreManager;
+
+
+/**
+ * factory to create objects that are stored in the InMemory store
+ * 
+ * @author Jens
+ */
+public class StoreManagerImpl implements StoreManager {
+
+  protected ProviderObjectFactory fObjectFactory;
+  protected ConfigMap fConfigMap;
+  protected RepositoryInfoData fRepositoryInfo;
+  
+  /**
+   * map from repository id to a type manager 
+   */
+  private Map<String,  TypeManager> fMapRepositoryToTypeManager
+    = new HashMap<String,  TypeManager>();
+
+  /**
+   * map from repository id to a object store
+   */
+  private Map<String, ObjectStore> fMapRepositoryToObjectStore
+    = new HashMap<String, ObjectStore>();
+
+  public ObjectStoreImpl getStore(String repositoryId) {
+    return (ObjectStoreImpl)fMapRepositoryToObjectStore.get(repositoryId);
+  }  
+  
+  public StoreManagerImpl() {
+    fObjectFactory = new ProviderObjectFactoryImpl();
+  }
+
+  public void setConfigReader(ConfigMap configMap) {
+    fConfigMap = configMap;
+  }
+
+  public List<String> getAllRepositoryIds() {
+    Set<String> repIds = fMapRepositoryToObjectStore.keySet();
+    List<String> result = new ArrayList<String>();
+    result.addAll(repIds);
+    return result;
+  }
+
+  public void initRepository(String repositoryId, boolean isCreated) {
+    TypeManager typeManager;
+    if (isCreated)
+      typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+    else {
+      typeManager = new TypeManager();
+      fMapRepositoryToObjectStore.put(repositoryId, new ObjectStoreImpl(repositoryId));  
+      fMapRepositoryToTypeManager.put(repositoryId, typeManager);      
+    }
+   
+  }
+  
+  public ObjectStore getObjectStore(String repositoryId) {
+    return fMapRepositoryToObjectStore.get(repositoryId);
+  }
+
+  public ProviderObjectFactory getObjectFactory() {
+    return fObjectFactory;
+  }
+
+  public String getParameter(String parameter) {
+    return fConfigMap.get(parameter);
+  }
+
+  public TypeDefinitionContainer getTypeById(String repositoryId, String typeId) {
+    TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+    if (null == typeManager)
+      throw new RuntimeException("Unknown repository " + repositoryId);
+
+    return typeManager.getTypeById(typeId);
+  }
+
+  public Collection<TypeDefinitionContainer> getTypeDefinitionList(String repositoryId) {
+    TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+    if (null == typeManager)
+      throw new RuntimeException("Unknown repository " + repositoryId);
+    return typeManager.getTypeDefinitionList();
+  }
+  
+  public Map<String, TypeDefinitionContainer> getTypeDefinitionMap(String repositoryId) {
+    return null;
+  }
+
+  public List<TypeDefinitionContainer> getRootTypes(String repositoryId) {
+    TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+    if (null == typeManager)
+      throw new RuntimeException("Unknown repository " + repositoryId);
+    List<TypeDefinitionContainer> rootTypes = typeManager.getRootTypes();
+
+    return rootTypes;
+  }
+
+  public RepositoryInfoData getRepositoryInfo(String repositoryId) {
+    ObjectStore sm = fMapRepositoryToObjectStore.get(repositoryId);
+    if (null == sm)
+      return null;
+    
+    RepositoryInfoData repoInfo = createDefaultRepositoryInfo(repositoryId);
+
+    return repoInfo;
+  }
+
+  public void initTypeSystem(String repositoryId, String typeCreatorClassName) {
+
+    List<TypeDefinition> typeDefs = null;
+    TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+    if (null == typeManager)
+      throw new RuntimeException("Unknown repository " + repositoryId);
+
+    if (null != typeCreatorClassName)
+      typeDefs = initTypeSystem(typeCreatorClassName);
+
+    typeManager.initTypeSystem(typeDefs);
+  }
+
+  public void clearTypeSystem(String repositoryId) {
+    TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+    if (null == typeManager)
+      throw new RuntimeException("Unknown repository " + repositoryId);
+
+    
+    typeManager.clearTypeSystem();
+  }
+
+  public void initRepositoryInfo(String repositoryId, String repoInfoCreatorClassName) {
+    RepositoryInfoCreator repoCreator = null;
+
+    if (repoInfoCreatorClassName != null) {
+      Object obj = null;
+      try {
+        obj = Class.forName(repoInfoCreatorClassName).newInstance();
+      }
+      catch (InstantiationException e) {
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement RepositoryInfoCreator interface.",
+            e);
+      }
+      catch (IllegalAccessException e) {
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement RepositoryInfoCreator interface.",
+            e);
+      }
+      catch (ClassNotFoundException e) {
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement RepositoryInfoCreator interface.",
+            e);
+      }
+
+      if (obj instanceof RepositoryInfoCreator) {
+        repoCreator = (RepositoryInfoCreator) obj;
+        fRepositoryInfo = repoCreator.createRepositoryInfo();
+      }
+      else
+        throw new RuntimeException(
+            "Illegal class to create repository info, must implement RepositoryInfoCreator interface.");
+    }
+    else {
+      // create a default repository info
+      createDefaultRepositoryInfo(repositoryId);
+    }
+  }
+
+  public void createRepository(String repositoryId) {
+    if (fMapRepositoryToObjectStore.containsKey(repositoryId)
+        || fMapRepositoryToTypeManager.containsKey(repositoryId))
+      throw new RuntimeException("Cannot add repository, repository " + repositoryId
+          + " already exists.");
+    
+    fMapRepositoryToObjectStore.put(repositoryId, new ObjectStoreImpl(repositoryId));  
+    fMapRepositoryToTypeManager.put(repositoryId, new TypeManager());
+  }
+  
+  public RepositoryInfo loadRepository(String repositoryId) {
+    return null;
+  }
+  
+  private RepositoryInfoData createDefaultRepositoryInfo(String repositoryId) {
+    // repository info
+    RepositoryInfoDataImpl repoInfo;
+    repoInfo = new RepositoryInfoDataImpl();
+    repoInfo.setRepositoryId(repositoryId==null ? "inMem" : repositoryId);
+    repoInfo.setRepositoryName("InMemory Repository");
+    repoInfo.setRepositoryDescription("InMemory Test Repository");
+    repoInfo.setCmisVersionSupported("1.0");
+    repoInfo.setRepositoryCapabilities(null);
+    repoInfo.setRootFolder("/");
+    repoInfo.setPrincipalAnonymous("anonymous");
+    repoInfo.setPrincipalAnyone("anyone");
+    repoInfo.setThinClientUri(null);
+    repoInfo.setChangesIncomplete(Boolean.TRUE);
+    repoInfo.setChangesOnType(null);
+    repoInfo.setLatestChangeLogToken(null);
+    repoInfo.setVendorName("OpenCMIS");
+    repoInfo.setProductName("OpenCMIS InMemory-Server");
+    repoInfo.setProductVersion("0.1");
+    
+    // set capabilities
+    RepositoryCapabilitiesDataImpl caps = new RepositoryCapabilitiesDataImpl();
+    caps.setAllVersionsSearchable(false);
+    caps.setCapabilityAcl(org.apache.opencmis.commons.enums.CapabilityAcl.NONE);
+    caps.setCapabilityChanges(CapabilityChanges.PROPERTIES); // just for testing
+    caps.setCapabilityContentStreamUpdates(CapabilityContentStreamUpdates.ANYTIME);
+    caps.setCapabilityJoin(CapabilityJoin.NONE);
+    caps.setCapabilityQuery(CapabilityQuery.METADATAONLY); // just for testing
+    caps.setCapabilityRendition(CapabilityRendition.NONE);
+    caps.setIsPwcSearchable(false);
+    caps.setIsPwcUpdatable(true);
+    caps.setSupportsGetDescendants(true);
+    caps.setSupportsGetFolderTree(true);
+    caps.setSupportsMultifiling(false);
+    caps.setSupportsUnfiling(false);
+    caps.setSupportsVersionSpecificFiling(false);
+    repoInfo.setRepositoryCapabilities(caps);
+    
+//    AclCapabilitiesDataImpl aclCaps = new AclCapabilitiesDataImpl();
+//    aclCaps.setACLPropagation(AclPropagation.REPOSITORYDETERMINED);
+//    aclCaps.setPermissionDefinitionData(null);
+//    aclCaps.setPermissionMappingData(null);
+//    repoInfo.setACLCapabilities(aclCaps);
+    repoInfo.setAclCapabilities(null);
+    fRepositoryInfo = repoInfo;
+    return repoInfo;
+  }
+
+  public List<TypeDefinition> initTypeSystem(String typeCreatorClassName) {
+   
+    List<TypeDefinition> typesList = null;
+
+    if (typeCreatorClassName != null) {
+      Object obj = null;
+      TypeCreator typeCreator = null;
+
+      try {
+        obj = Class.forName(typeCreatorClassName).newInstance();
+      }
+      catch (InstantiationException e) {
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement TypeCreator interface.", e);
+      }
+      catch (IllegalAccessException e) {
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement TypeCreator interface.", e);
+      }
+      catch (ClassNotFoundException e) {
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement TypeCreator interface.", e);
+      }
+
+      if (obj instanceof TypeCreator)
+        typeCreator = (TypeCreator) obj;
+      else
+        throw new RuntimeException(
+            "Illegal class to create type system, must implement TypeCreator interface.");
+
+      // retrieve the list of available types from the configured class.
+      // test
+      typesList = typeCreator.createTypesList();      
+    }
+    
+    return typesList;
+  }
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,413 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.Map.Entry;
+
+import org.apache.opencmis.commons.PropertyIds;
+import org.apache.opencmis.commons.provider.PropertyData;
+import org.apache.opencmis.commons.provider.ProviderObjectFactory;
+import org.apache.opencmis.inmemory.FilterParser;
+import org.apache.opencmis.inmemory.storedobj.api.StoredObject;
+
+/**
+ * InMemory Stored Object
+ * 
+ * @author Jens
+ * 
+ */
+
+/**
+ * StoredObject is the common superclass of all objects hold in the repository Documents, Folders,
+ * Relationships and Policies
+ */
+
+public class StoredObjectImpl implements StoredObject {
+  protected String fId;
+  protected String fName;
+  protected String fTypeId;
+  protected String fCreatedBy;
+  protected String fModifiedBy;
+  protected GregorianCalendar fCreatedAt;
+  protected GregorianCalendar fModifiedAt;
+  protected String fRepositoryId;
+  protected Map<String, PropertyData<?>> fProperties;
+  
+  StoredObjectImpl() {  // visibility should be package    
+    GregorianCalendar now = getNow();
+    now.setTime(new Date());
+    fCreatedAt = now;
+    fModifiedAt = now;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getId()
+   */
+  public String getId() {
+    return fId;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getName()
+   */
+  public String getName() {
+    return fName;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setName(java.lang.String)
+   */
+  public void setName(String name) {
+    fName = name;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getTypeId()
+   */
+  public String getTypeId() {
+    return fTypeId;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setTypeId(java.lang.String)
+   */
+  public void setTypeId(String type) {
+    fTypeId = type;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getCreatedBy()
+   */
+  public String getCreatedBy() {
+    return fCreatedBy;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setCreatedBy(java.lang.String)
+   */
+  public void setCreatedBy(String createdBy) {
+    this.fCreatedBy = createdBy;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getModifiedBy()
+   */
+  public String getModifiedBy() {
+    return fModifiedBy;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setModifiedBy(java.lang.String)
+   */
+  public void setModifiedBy(String modifiedBy) {
+    this.fModifiedBy = modifiedBy;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getCreatedAt()
+   */
+  public GregorianCalendar getCreatedAt() {
+    return fCreatedAt;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setCreatedAt(java.util.GregorianCalendar)
+   */
+  public void setCreatedAt(GregorianCalendar createdAt) {
+    this.fCreatedAt = createdAt;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getModifiedAt()
+   */
+  public GregorianCalendar getModifiedAt() {
+    return fModifiedAt;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setModifiedAtNow()
+   */
+  public void setModifiedAtNow() {
+    this.fModifiedAt = getNow();
+  }
+  
+  public void setRepositoryId(String repositoryId) {
+	  fRepositoryId = repositoryId;
+  }
+  
+  public String getRepositoryId() {
+	  return fRepositoryId;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setProperties(java.util.Map)
+   */
+  public void setProperties(Map<String, PropertyData<?>> props) {
+    fProperties = props;
+  }
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#getProperties()
+   */
+  public Map<String, PropertyData<?>> getProperties() {
+    return fProperties;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.storedobj.api.StoredObject#getChangeToken()
+   */
+  public String getChangeToken() {
+    GregorianCalendar lastModified = getModifiedAt();
+    String token = Long.valueOf(lastModified.getTimeInMillis()).toString();
+    return token;
+  }
+  
+  public void rename(String newName) {
+    setName(newName);
+    persist();
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#createSystemBasePropertiesWhenCreated(java.util.Map, java.lang.String)
+   */
+  public void createSystemBasePropertiesWhenCreated(
+      Map<String, PropertyData<?>> properties,
+      String user) {
+    addSystemBaseProperties(properties, user, true);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#updateSystemBasePropertiesWhenModified(java.util.Map, java.lang.String)
+   */
+  public void updateSystemBasePropertiesWhenModified(
+      Map<String, PropertyData<?>> properties,
+      String user) {
+    addSystemBaseProperties(properties, user, false);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#fillProperties(java.util.List, org.apache.opencmis.client.provider.ProviderObjectFactory, java.util.List)
+   */
+  public void fillProperties(List<PropertyData<?>> properties,
+      ProviderObjectFactory objFactory, List<String> requestedIds) {
+    
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_NAME, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_NAME, getName()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_OBJECT_ID, requestedIds)) {
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_OBJECT_ID, getId()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_OBJECT_TYPE_ID, requestedIds)) {
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_OBJECT_TYPE_ID, getTypeId()));
+    }
+    // set the base type id outside becaus it requires the type definition
+//    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_BASE_TYPE_ID, requestedIds)) {
+//      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_BASE_TYPE_ID, getBaseTypeId()));
+//    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_CREATED_BY, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_CREATED_BY, getCreatedBy()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_CREATION_DATE, requestedIds)) {
+      properties.add(objFactory.createPropertyDateTimeData(PropertyIds.CMIS_CREATION_DATE, getCreatedAt()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_LAST_MODIFIED_BY, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_LAST_MODIFIED_BY, getModifiedBy()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_LAST_MODIFICATION_DATE, requestedIds)) {
+      properties.add(objFactory.createPropertyDateTimeData(PropertyIds.CMIS_LAST_MODIFICATION_DATE, getModifiedAt()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_CHANGE_TOKEN, requestedIds)) {
+      String token = getChangeToken();
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_CHANGE_TOKEN, token));
+    }
+
+    // add custom properties of type definition to the collection
+    if (null != fProperties) {
+      for (Entry<String, PropertyData<?>> prop: fProperties.entrySet()) {
+        properties.add(prop.getValue());      
+      }
+    }
+  }
+
+
+  /////////////////////////////////////////////
+  // private helper methods
+  
+  /* (non-Javadoc)
+   * @see org.apache.opencmis.client.provider.spi.inmemory.IStoredObject#setCustomProperties(java.util.Map)
+   */
+  public void setCustomProperties(Map<String, PropertyData<?>> properties) {
+    properties = new HashMap<String, PropertyData<?>>(properties); // get a writable collection
+    removeAllSystemProperties(properties);    
+    setProperties(properties);        
+  }
+
+  private GregorianCalendar getNow() {
+    GregorianCalendar now = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
+    return now; 
+  }
+  
+  /**
+   * Add CMIS_CREATED_BY, CMIS_CREATION_DATE, CMIS_LAST_MODIFIED_BY, CMIS_LAST_MODIFICATION_DATE,
+   * CMIS_CHANGE_TOKEN system properties to the list of properties with current values
+   */
+  private void addSystemBaseProperties(Map<String, PropertyData<?>> properties, String user, boolean isCreated) {
+    if (user == null)
+      user = "unknown";
+
+    // Note that initial creation and modification date is set in constructor.
+    setModifiedBy(user);
+    if (isCreated) {
+      setCreatedBy(user);
+      setName((String) properties.get(PropertyIds.CMIS_NAME).getFirstValue());
+      setTypeId((String) properties.get(PropertyIds.CMIS_OBJECT_TYPE_ID).getFirstValue());
+    } else {
+      setModifiedAtNow();
+    }      
+  }
+  
+  /**
+   * Add CMIS_CREATED_BY, CMIS_CREATION_DATE, CMIS_LAST_MODIFIED_BY, CMIS_LAST_MODIFICATION_DATE,
+   * CMIS_CHANGE_TOKEN system properties to the list of properties with current values
+   */
+  protected void setSystemBasePropertiesWhenCreatedDirect(String name, String typeId, String user) {
+    // Note that initial creation and modification date is set in constructor.
+    setModifiedBy(user);
+    setCreatedBy(user);
+    setName(name);
+    setTypeId(typeId);    
+  }
+  
+/*  
+  CMIS_NAME
+  CMIS_OBJECT_ID
+  CMIS_OBJECT_TYPE_ID
+  CMIS_BASE_TYPE_ID
+  CMIS_CREATED_BY
+  CMIS_CREATION_DATE
+  CMIS_LAST_MODIFIED_BY
+  CMIS_LAST_MODIFICATION_DATE
+  CMIS_CHANGE_TOKEN 
+
+  // ---- document ----
+  CMIS_IS_IMMUTABLE
+  CMIS_IS_LATEST_VERSION
+  CMIS_IS_MAJOR_VERSION
+  CMIS_IS_LATEST_MAJOR_VERSION
+  CMIS_VERSION_LABEL
+  CMIS_VERSION_SERIES_ID
+  CMIS_IS_VERSION_SERIES_CHECKED_OUT
+  CMIS_VERSION_SERIES_CHECKED_OUT_BY
+  CMIS_VERSION_SERIES_CHECKED_OUT_ID
+  CMIS_CHECKIN_COMMENT
+  CMIS_CONTENT_STREAM_LENGTH
+  CMIS_CONTENT_STREAM_MIME_TYPE
+  CMIS_CONTENT_STREAM_FILE_NAME
+  CMIS_CONTENT_STREAM_ID
+
+   // ---- folder ---- 
+  CMIS_PARENT_ID
+  CMIS_ALLOWED_CHILD_OBJECT_TYPE_IDS
+  CMIS_PATH
+
+    // ---- relationship ----
+  CMIS_SOURCE_ID
+  CMIS_TARGET_ID
+
+    // ---- policy ----
+  CMIS_POLICY_TEXT
+  */
+  private void removeAllSystemProperties(Map<String, PropertyData<?>> properties) {
+    // ---- base ----
+    if (properties.containsKey(PropertyIds.CMIS_NAME))
+      properties.remove(PropertyIds.CMIS_NAME);
+    if (properties.containsKey(PropertyIds.CMIS_OBJECT_ID))
+      properties.remove(PropertyIds.CMIS_OBJECT_ID);
+    if (properties.containsKey(PropertyIds.CMIS_OBJECT_TYPE_ID))
+      properties.remove(PropertyIds.CMIS_OBJECT_TYPE_ID);
+    if (properties.containsKey(PropertyIds.CMIS_BASE_TYPE_ID))
+      properties.remove(PropertyIds.CMIS_BASE_TYPE_ID);
+    if (properties.containsKey(PropertyIds.CMIS_CREATED_BY))
+      properties.remove(PropertyIds.CMIS_CREATED_BY);
+    if (properties.containsKey(PropertyIds.CMIS_CREATION_DATE))
+      properties.remove(PropertyIds.CMIS_CREATION_DATE);
+    if (properties.containsKey(PropertyIds.CMIS_LAST_MODIFIED_BY))
+      properties.remove(PropertyIds.CMIS_LAST_MODIFIED_BY);
+    if (properties.containsKey(PropertyIds.CMIS_LAST_MODIFICATION_DATE))
+      properties.remove(PropertyIds.CMIS_LAST_MODIFICATION_DATE);
+    if (properties.containsKey(PropertyIds.CMIS_CHANGE_TOKEN))
+      properties.remove(PropertyIds.CMIS_CHANGE_TOKEN);
+    // ---- document ----
+    if (properties.containsKey(PropertyIds.CMIS_IS_IMMUTABLE))
+      properties.remove(PropertyIds.CMIS_IS_IMMUTABLE);
+    if (properties.containsKey(PropertyIds.CMIS_IS_LATEST_VERSION))
+      properties.remove(PropertyIds.CMIS_IS_LATEST_VERSION);
+    if (properties.containsKey(PropertyIds.CMIS_IS_MAJOR_VERSION))
+      properties.remove(PropertyIds.CMIS_IS_MAJOR_VERSION);
+    if (properties.containsKey(PropertyIds.CMIS_IS_LATEST_MAJOR_VERSION))
+      properties.remove(PropertyIds.CMIS_IS_LATEST_MAJOR_VERSION);
+    if (properties.containsKey(PropertyIds.CMIS_VERSION_LABEL))
+      properties.remove(PropertyIds.CMIS_VERSION_LABEL);
+    if (properties.containsKey(PropertyIds.CMIS_VERSION_SERIES_ID))
+      properties.remove(PropertyIds.CMIS_VERSION_SERIES_ID);
+    if (properties.containsKey(PropertyIds.CMIS_IS_VERSION_SERIES_CHECKED_OUT))
+      properties.remove(PropertyIds.CMIS_IS_VERSION_SERIES_CHECKED_OUT);
+    if (properties.containsKey(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_BY))
+      properties.remove(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_BY);
+    if (properties.containsKey(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_ID))
+      properties.remove(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_ID);
+    if (properties.containsKey(PropertyIds.CMIS_CHECKIN_COMMENT))
+      properties.remove(PropertyIds.CMIS_CHECKIN_COMMENT);
+    if (properties.containsKey(PropertyIds.CMIS_CONTENT_STREAM_LENGTH))
+      properties.remove(PropertyIds.CMIS_CONTENT_STREAM_LENGTH);
+    if (properties.containsKey(PropertyIds.CMIS_CONTENT_STREAM_MIME_TYPE))
+      properties.remove(PropertyIds.CMIS_CONTENT_STREAM_MIME_TYPE);
+    if (properties.containsKey(PropertyIds.CMIS_CONTENT_STREAM_FILE_NAME))
+      properties.remove(PropertyIds.CMIS_CONTENT_STREAM_FILE_NAME);
+    if (properties.containsKey(PropertyIds.CMIS_CONTENT_STREAM_ID))
+      properties.remove(PropertyIds.CMIS_CONTENT_STREAM_ID);
+    // ---- folder ----     
+    if (properties.containsKey(PropertyIds.CMIS_PARENT_ID))
+      properties.remove(PropertyIds.CMIS_PARENT_ID);
+    if (properties.containsKey(PropertyIds.CMIS_ALLOWED_CHILD_OBJECT_TYPE_IDS))
+      properties.remove(PropertyIds.CMIS_ALLOWED_CHILD_OBJECT_TYPE_IDS);
+    if (properties.containsKey(PropertyIds.CMIS_PATH))
+      properties.remove(PropertyIds.CMIS_PATH);
+    // ---- relationship ----
+    if (properties.containsKey(PropertyIds.CMIS_SOURCE_ID))
+      properties.remove(PropertyIds.CMIS_SOURCE_ID);
+    if (properties.containsKey(PropertyIds.CMIS_TARGET_ID))
+      properties.remove(PropertyIds.CMIS_TARGET_ID);
+    // ---- policy ----
+    if (properties.containsKey(PropertyIds.CMIS_POLICY_TEXT))
+      properties.remove(PropertyIds.CMIS_POLICY_TEXT);
+  }
+
+public void persist() {
+  // in-memory implementation does not need to to anything to persist,
+  // but after this call the id should be set.
+}
+
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/VersionedDocumentImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/VersionedDocumentImpl.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/VersionedDocumentImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/VersionedDocumentImpl.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.storedobj.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.opencmis.commons.PropertyIds;
+import org.apache.opencmis.commons.enums.VersioningState;
+import org.apache.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.opencmis.commons.provider.ContentStreamData;
+import org.apache.opencmis.commons.provider.PropertyData;
+import org.apache.opencmis.commons.provider.ProviderObjectFactory;
+import org.apache.opencmis.inmemory.FilterParser;
+import org.apache.opencmis.inmemory.storedobj.api.DocumentVersion;
+import org.apache.opencmis.inmemory.storedobj.api.VersionedDocument;
+
+public class VersionedDocumentImpl extends AbstractPathImpl implements VersionedDocument {
+  
+  private boolean fIsCheckedOut;
+  private String fCheckedOutUser;
+  private List<DocumentVersion> fVersions;
+  
+  
+  public VersionedDocumentImpl(ObjectStoreImpl objStore) {
+    super(objStore);
+    fVersions = new ArrayList<DocumentVersion>();
+    fIsCheckedOut = false;
+  }
+  
+  public DocumentVersion addVersion(ContentStreamData content,
+      VersioningState verState, String user) {
+    
+    if (isCheckedOut())
+        throw new CmisConstraintException("Cannot add a version to document, document is checked out.");
+    
+    DocumentVersionImpl ver = new DocumentVersionImpl(fRepositoryId, this, content, verState);
+    ver.setSystemBasePropertiesWhenCreatedDirect(getName(), getTypeId(), user); // copy name and type id from version series.
+    ver.persist();
+    fObjStore.storeObject(ver.getId(), ver);
+    fVersions.add(ver);
+    if (verState == VersioningState.CHECKEDOUT) {
+      fCheckedOutUser = user;
+      fIsCheckedOut = true;
+    }
+    
+    return ver;
+  }
+
+  public void cancelCheckOut(String user) {
+    DocumentVersion pwc = getPwc();
+    fVersions.remove(pwc);
+    fObjStore.deleteObject(pwc.getId());
+  }
+
+  public void checkIn(boolean isMajor, String checkinComment, String user) {
+    if (fIsCheckedOut) {
+      if (fCheckedOutUser.equals(user)) {
+        fIsCheckedOut = false;
+        fCheckedOutUser = null;
+      } else {
+        throw new CmisConstraintException("Error: Can't checkin. Document " + getId()
+            + " user " + user + " has not checked out the document");
+      }
+    }
+    else
+      throw new CmisConstraintException("Error: Can't cancel checkout, Document " + getId() + " is not checked out.");
+    
+    DocumentVersion pwc = getPwc();
+    pwc.commit(isMajor);
+  }
+
+  public DocumentVersion checkOut(ContentStreamData content, String user) {
+    if (fIsCheckedOut) {
+      throw new CmisConstraintException("Error: Can't checkout, Document " + getId() + " is already checked out.");
+    }
+    
+    // create PWC
+    DocumentVersion pwc = addVersion(content, VersioningState.CHECKEDOUT, user); // will set check-out flag
+    return pwc;
+  }
+
+  public List<DocumentVersion> getAllVersions(String filter) {
+    //TODO: implement filter
+    return fVersions;
+  }
+
+  public DocumentVersion getLatestVersion(boolean major) {
+    
+    DocumentVersion latest = null;
+    if (major) {
+      for (DocumentVersion ver : fVersions) {
+        if (ver.isMajor())
+          latest = ver;
+      }
+    } else {
+      latest = fVersions.get(fVersions.size() - 1);
+    }
+    return latest;
+  }
+
+  public boolean isCheckedOut() {
+    return fIsCheckedOut;
+  }
+
+  public String getCheckedOutBy() {
+    return fCheckedOutUser;
+  }
+  
+  public DocumentVersion getPwc() {
+    for ( DocumentVersion ver : fVersions) {
+      if (ver.isPwc())
+        return ver;
+    }
+    return null;
+  }
+
+  public void fillProperties(List<PropertyData<?>> properties, ProviderObjectFactory objFactory,
+      List<String> requestedIds) {
+    
+    DocumentVersion pwc = getPwc();
+    
+    super.fillProperties(properties, objFactory, requestedIds);
+    
+    // overwrite the version related properties 
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_SERIES_ID, requestedIds)) { 
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_VERSION_SERIES_ID, getId()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
+      properties.add(objFactory.createPropertyBooleanData(PropertyIds.CMIS_IS_VERSION_SERIES_CHECKED_OUT, isCheckedOut()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
+      properties.add(objFactory.createPropertyStringData(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_BY, getCheckedOutBy()));
+    }
+    if (FilterParser.isContainedInFilter(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
+      properties.add(objFactory.createPropertyIdData(PropertyIds.CMIS_VERSION_SERIES_CHECKED_OUT_ID, pwc == null ? null : pwc.getId()));
+    }
+    
+  }
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/VersionedDocumentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/DefaultTypeSystemCreator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/DefaultTypeSystemCreator.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/DefaultTypeSystemCreator.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/DefaultTypeSystemCreator.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.opencmis.inmemory.types;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.opencmis.commons.api.Choice;
+import org.apache.opencmis.commons.api.DocumentTypeDefinition;
+import org.apache.opencmis.commons.api.PropertyDefinition;
+import org.apache.opencmis.commons.api.TypeDefinition;
+import org.apache.opencmis.commons.impl.dataobjects.ChoiceImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl;
+import org.apache.opencmis.inmemory.TypeCreator;
+
+public class DefaultTypeSystemCreator implements TypeCreator {
+  static public List<TypeDefinition> singletonTypes = buildTypesList();
+  public static final String COMPLEX_TYPE = "ComplexType";
+  public static final String TOPLEVEL_TYPE = "DocumentTopLevel";
+  public static final String VERSIONED_TYPE = "VersionableType";
+  public static final String LEVEL1_TYPE = "DocumentLevel1";;
+  public static final String LEVEL2_TYPE = "DocumentLevel2";
+
+  /**
+   * in the public interface of this class we return the singleton containing the required types for
+   * testing
+   */
+  public List<TypeDefinition> createTypesList() {
+    return singletonTypes;
+  }
+
+  public static List<TypeDefinition> getTypesList() {
+    return singletonTypes;
+  }
+
+  static public TypeDefinition getTypeById(String typeId) {
+    for (TypeDefinition typeDef : singletonTypes)
+      if (typeDef.getId().equals(typeId))
+        return typeDef;
+    return null;
+  }
+
+  /**
+   * create root types and a collection of sample types
+   * 
+   * @return typesMap map filled with created types
+   */
+  private static List<TypeDefinition> buildTypesList() {
+    // always add CMIS default types
+    List<TypeDefinition> typesList = new LinkedList<TypeDefinition>();
+
+    InMemoryDocumentTypeDefinition cmisType1 = new InMemoryDocumentTypeDefinition("MyDocType1",
+        "My Type 1 Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
+    typesList.add(cmisType1);
+
+    InMemoryDocumentTypeDefinition cmisType2 = new InMemoryDocumentTypeDefinition("MyDocType2",
+        "My Type 2 Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
+    typesList.add(cmisType2);
+
+    InMemoryDocumentTypeDefinition cmisType11 = new InMemoryDocumentTypeDefinition("MyDocType1.1",
+        "My Type 3 Level 2", cmisType1);
+    typesList.add(cmisType11);
+
+    InMemoryDocumentTypeDefinition cmisType111 = new InMemoryDocumentTypeDefinition("MyDocType1.1.1",
+        "My Type 4 Level 3", cmisType11);
+    typesList.add(cmisType111);
+
+    InMemoryDocumentTypeDefinition cmisType112 = new InMemoryDocumentTypeDefinition("MyDocType1.1.2",
+        "My Type 5 Level 3", cmisType11);
+    typesList.add(cmisType112);
+
+    InMemoryDocumentTypeDefinition cmisType12 = new InMemoryDocumentTypeDefinition("MyDocType1.2",
+        "My Type 6 Level 2", cmisType1);
+    typesList.add(cmisType12);
+
+    InMemoryDocumentTypeDefinition cmisType21 = new InMemoryDocumentTypeDefinition("MyDocType2.1",
+        "My Type 7 Level 2", cmisType2);
+    typesList.add(cmisType21);
+
+    InMemoryDocumentTypeDefinition cmisType22 = new InMemoryDocumentTypeDefinition("MyDocType2.2",
+        "My Type 8 Level 2", cmisType2);
+    typesList.add(cmisType22);
+    InMemoryDocumentTypeDefinition cmisType23 = new InMemoryDocumentTypeDefinition("MyDocType2.3",
+        "My Type 9 Level 2", cmisType2);
+    typesList.add(cmisType23);
+    DocumentTypeDefinition cmisType24 = new InMemoryDocumentTypeDefinition("MyDocType2.4",
+        "My Type 10 Level 2", cmisType2);
+    typesList.add(cmisType24);
+    InMemoryDocumentTypeDefinition cmisType25 = new InMemoryDocumentTypeDefinition("MyDocType2.5",
+        "My Type 11 Level 2", cmisType2);
+    typesList.add(cmisType25);
+
+    InMemoryDocumentTypeDefinition cmisType26 = new InMemoryDocumentTypeDefinition("MyDocType2.6",
+        "My Type 12 Level 2", cmisType2);
+    typesList.add(cmisType26);
+    InMemoryDocumentTypeDefinition cmisType27 = new InMemoryDocumentTypeDefinition("MyDocType2.7",
+        "My Type 13 Level 2", cmisType2);
+    typesList.add(cmisType27);
+    InMemoryDocumentTypeDefinition cmisType28 = new InMemoryDocumentTypeDefinition("MyDocType2.8",
+        "My Type 14 Level 2", cmisType2);
+    typesList.add(cmisType28);
+    InMemoryDocumentTypeDefinition cmisType29 = new InMemoryDocumentTypeDefinition("MyDocType2.9",
+        "My Type 15 Level 2", cmisType2);
+    typesList.add(cmisType29);
+
+    // create a complex type with properties
+    InMemoryDocumentTypeDefinition cmisComplexType = new InMemoryDocumentTypeDefinition(COMPLEX_TYPE,
+        "Complex type with properties, Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
+
+    // create a boolean property definition
+
+    Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
+
+    PropertyDefinition<Boolean> prop = PropertyCreationHelper.createBooleanDefinition(
+        "BooleanProp", "Sample Boolean Property");
+    propertyDefinitions.put(prop.getId(), prop);
+
+    prop = PropertyCreationHelper.createBooleanMultiDefinition("BooleanPropMV",
+        "Sample Boolean multi-value Property");
+    propertyDefinitions.put(prop.getId(), prop);
+
+    PropertyDateTimeDefinitionImpl prop2 = PropertyCreationHelper.createDateTimeDefinition(
+        "DateTimeProp", "Sample DateTime Property");
+    propertyDefinitions.put(prop2.getId(), prop2);
+
+    prop2 = PropertyCreationHelper.createDateTimeMultiDefinition("DateTimePropMV",
+        "Sample DateTime multi-value Property");
+    propertyDefinitions.put(prop2.getId(), prop2);
+
+    PropertyDecimalDefinitionImpl prop3 = PropertyCreationHelper.createDecimalDefinition(
+        "DecimalProp", "Sample Decimal Property");
+    propertyDefinitions.put(prop3.getId(), prop3);
+
+    prop3 = PropertyCreationHelper.createDecimalDefinition("DecimalPropMV",
+        "Sample Decimal multi-value Property");
+    propertyDefinitions.put(prop3.getId(), prop3);
+
+    PropertyHtmlDefinitionImpl prop4 = PropertyCreationHelper.createHtmlDefinition("HtmlProp",
+        "Sample Html Property");
+    propertyDefinitions.put(prop4.getId(), prop4);
+
+    prop4 = PropertyCreationHelper.createHtmlDefinition("HtmlPropMV",
+        "Sample Html multi-value Property");
+    propertyDefinitions.put(prop4.getId(), prop4);
+
+    PropertyIdDefinitionImpl prop5 = PropertyCreationHelper.createIdDefinition("IdProp",
+        "Sample Id Property");
+    propertyDefinitions.put(prop5.getId(), prop5);
+
+    prop5 = PropertyCreationHelper.createIdDefinition("IdPropMV",
+        "Sample Id Html multi-value Property");
+    propertyDefinitions.put(prop5.getId(), prop5);
+
+    PropertyIntegerDefinitionImpl prop6 = PropertyCreationHelper.createIntegerDefinition(
+        "IntProp", "Sample Int Property");
+    propertyDefinitions.put(prop6.getId(), prop6);
+
+    prop6 = PropertyCreationHelper.createIntegerDefinition("IntPropMV",
+        "Sample Int multi-value Property");
+    propertyDefinitions.put(prop6.getId(), prop6);
+
+    PropertyStringDefinitionImpl prop7 = PropertyCreationHelper.createStringDefinition(
+        "StringProp", "Sample String Property");
+    propertyDefinitions.put(prop7.getId(), prop7);
+
+    PropertyUriDefinitionImpl prop8 = PropertyCreationHelper.createUriDefinition("UriProp",
+        "Sample Uri Property");
+    propertyDefinitions.put(prop8.getId(), prop8);
+
+    prop8 = PropertyCreationHelper.createUriDefinition("UriPropMV",
+        "Sample Uri multi-value Property");
+    propertyDefinitions.put(prop8.getId(), prop8);
+
+    PropertyStringDefinitionImpl prop9 = PropertyCreationHelper.createStringDefinition(
+        "PickListProp", "Sample Pick List Property");
+    List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
+    ChoiceImpl<String> elem = new ChoiceImpl<String>();
+    elem.setValue(Collections.singletonList("red"));
+    choiceList.add(elem);
+    elem = new ChoiceImpl<String>();
+    elem.setValue(Collections.singletonList("green"));
+    choiceList.add(elem);
+    elem = new ChoiceImpl<String>();
+    elem.setValue(Collections.singletonList("blue"));
+    choiceList.add(elem);
+    elem = new ChoiceImpl<String>();
+    elem.setValue(Collections.singletonList("black"));
+    choiceList.add(elem);
+    prop9.setChoices(choiceList);
+    prop9.setDefaultValue(Collections.singletonList("blue"));
+
+    /*
+     * try short form: * / PropertyCreationHelper.addElemToPicklist(prop9, "red");
+     * PropertyCreationHelper.addElemToPicklist(prop9, "green");
+     * PropertyCreationHelper.addElemToPicklist(prop9, "blue");
+     * PropertyCreationHelper.addElemToPicklist(prop9, "black");
+     * PropertyCreationHelper.setDefaultValue(prop9, "blue"); /*
+     */
+
+    cmisComplexType.setPropertyDefinitions(propertyDefinitions);
+
+    // add type to types collection
+    typesList.add(cmisComplexType);
+
+    // create a type hierarchy with inherited properties
+    InMemoryDocumentTypeDefinition cmisDocTypeTopLevel = new InMemoryDocumentTypeDefinition(TOPLEVEL_TYPE,
+        "Document type with properties, Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
+
+    InMemoryDocumentTypeDefinition cmisDocTypeLevel1 = new InMemoryDocumentTypeDefinition(LEVEL1_TYPE,
+        "Document type with inherited properties, Level 2", cmisDocTypeTopLevel);
+
+    InMemoryDocumentTypeDefinition cmisDocTypeLevel2 = new InMemoryDocumentTypeDefinition(LEVEL2_TYPE,
+        "Document type with inherited properties, Level 3", cmisDocTypeLevel1);
+
+    propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
+    PropertyStringDefinitionImpl propTop = PropertyCreationHelper.createStringDefinition(
+        "StringPropTopLevel", "Sample String Property");
+    propertyDefinitions.put(propTop.getId(), propTop);
+    cmisDocTypeTopLevel.setPropertyDefinitions(propertyDefinitions);
+
+    propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
+    PropertyStringDefinitionImpl propLevel1 = PropertyCreationHelper.createStringDefinition(
+        "StringPropLevel1", "String Property Level 1");
+    propertyDefinitions.put(propLevel1.getId(), propLevel1);
+    cmisDocTypeLevel1.setPropertyDefinitions(propertyDefinitions);
+
+    propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
+    PropertyStringDefinitionImpl propLevel2 = PropertyCreationHelper.createStringDefinition(
+        "StringPropLevel2", "String Property Level 2");
+    propertyDefinitions.put(propLevel2.getId(), propLevel2);
+    cmisDocTypeLevel2.setPropertyDefinitions(propertyDefinitions);
+
+    // add type to types collection
+    typesList.add(cmisDocTypeTopLevel);
+    typesList.add(cmisDocTypeLevel1);
+    typesList.add(cmisDocTypeLevel2);
+
+    // Create a type that is versionable
+    InMemoryDocumentTypeDefinition cmisVersionedType = new InMemoryDocumentTypeDefinition(VERSIONED_TYPE,
+        "VersionedType", InMemoryDocumentTypeDefinition.getRootDocumentType());
+    
+    // create a single String property definition
+    
+    propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
+    
+    PropertyStringDefinitionImpl prop1 = PropertyCreationHelper.createStringDefinition("VersionedStringProp", "Sample String Property");
+    propertyDefinitions.put(prop1.getId(), prop1);
+    
+    cmisVersionedType.addCustomPropertyDefinitions(propertyDefinitions);    
+    cmisVersionedType.setIsVersionable(true); // make it a versionable type;
+    
+    // add type to types collection
+    typesList.add(cmisVersionedType);
+
+    return typesList;
+  }
+
+}

Propchange: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/DefaultTypeSystemCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message