chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcaru...@apache.org
Subject svn commit: r936938 [18/29] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server: chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/ chemistry-opencmis-server-bindings/src/main/java/org/apache/chem...
Date Thu, 22 Apr 2010 16:28:00 GMT
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java Thu Apr 22 16:27:57 2010
@@ -41,212 +41,212 @@ import org.apache.chemistry.opencmis.inm
  */
 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, ContentStream content,
-			VersioningState verState, ObjectStoreImpl objStore) {
-		super(objStore);
-		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(ContentStream 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 void setCheckinComment(String comment) {
-		fComment = comment;
-	}
-
-	public String getCheckinComment() {
-		return fComment;
-	}
-
-	public String getVersionLabel() {
-		int majorNo = 0;
-		int minorNo = 0;
-		List<DocumentVersion> allVersions = fContainer.getAllVersions();
-		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 ContentStream getContent(long offset, long length) {
-		if (offset <= 0 && length < 0)
-			return fContent;
-		else
-			return fContent.getCloneWithLimits(offset, length);
-	}
-
-	public VersionedDocument getParentDocument() {
-		return fContainer;
-	}
-
-	private boolean isLatestVersion() {
-		List<DocumentVersion> allVers = fContainer.getAllVersions();
-		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();
-		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(Map<String, PropertyData<?>> properties, BindingsObjectFactory 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.IS_LATEST_VERSION, requestedIds)) {
-			properties.put(PropertyIds.IS_LATEST_VERSION, objFactory.createPropertyBooleanData(
-					PropertyIds.IS_LATEST_VERSION, isLatestVersion()));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.IS_MAJOR_VERSION, requestedIds)) {
-			properties.put(PropertyIds.IS_MAJOR_VERSION, objFactory.createPropertyBooleanData(
-					PropertyIds.IS_MAJOR_VERSION, fIsMajor));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_MAJOR_VERSION, requestedIds)) {
-			properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, objFactory.createPropertyBooleanData(
-					PropertyIds.IS_LATEST_MAJOR_VERSION, isLatestMajorVersion()));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_ID, requestedIds)) {
-			properties.put(PropertyIds.VERSION_SERIES_ID, objFactory.createPropertyIdData(
-					PropertyIds.VERSION_SERIES_ID, fContainer.getId()));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
-			properties.put(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, objFactory.createPropertyBooleanData(
-					PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, fContainer.isCheckedOut()));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
-			properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, objFactory.createPropertyStringData(
-					PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, fContainer.getCheckedOutBy()));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
-			properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, objFactory.createPropertyIdData(
-					PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, pwc == null ? null : pwc.getId()));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.CHECKIN_COMMENT, requestedIds)) {
-			properties.put(PropertyIds.CHECKIN_COMMENT, objFactory.createPropertyStringData(
-					PropertyIds.CHECKIN_COMMENT, fComment));
-		}
-		if (FilterParser.isContainedInFilter(PropertyIds.VERSION_LABEL, requestedIds)) {
-			properties.put(PropertyIds.VERSION_LABEL, objFactory.createPropertyStringData(PropertyIds.VERSION_LABEL,
-					getVersionLabel()));
-		}
-
-		// Set the content related properties
-		if (null != fContent) {
-			if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_FILE_NAME, requestedIds)) {
-				properties.put(PropertyIds.CONTENT_STREAM_FILE_NAME, objFactory.createPropertyStringData(
-						PropertyIds.CONTENT_STREAM_FILE_NAME, fContent.getFileName()));
-			}
-
-			// omit: PropertyIds.CMIS_CONTENT_STREAM_ID
-
-			if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_LENGTH, requestedIds)) {
-				properties.put(PropertyIds.CONTENT_STREAM_LENGTH, objFactory.createPropertyIntegerData(
-						PropertyIds.CONTENT_STREAM_LENGTH, fContent.getBigLength()));
-			}
-			if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_MIME_TYPE, requestedIds)) {
-				properties.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, objFactory.createPropertyStringData(
-						PropertyIds.CONTENT_STREAM_MIME_TYPE, fContent.getMimeType()));
-			}
-		}
-	}
-
-	public List<Folder> getParents() {
-		return fContainer.getParents();
-	}
-
-	public String getPathSegment() {
-		return fContainer.getPathSegment();
-	}
-
-	public void move(Folder oldParent, Folder newParent) {
-		fContainer.move(oldParent, newParent);
-	}
-
-	public void addParent(Folder parent) {
-		fContainer.addParent(parent);
-	}
-
-	public void removeParent(Folder parent) {
-		fContainer.removeParent(parent);
-	}
-
-	public boolean hasContent() {
-		return null != fContent;
-	}
+    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, ContentStream content,
+            VersioningState verState, ObjectStoreImpl objStore) {
+        super(objStore);
+        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(ContentStream 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 void setCheckinComment(String comment) {
+        fComment = comment;
+    }
+
+    public String getCheckinComment() {
+        return fComment;
+    }
+
+    public String getVersionLabel() {
+        int majorNo = 0;
+        int minorNo = 0;
+        List<DocumentVersion> allVersions = fContainer.getAllVersions();
+        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 ContentStream getContent(long offset, long length) {
+        if (offset <= 0 && length < 0)
+            return fContent;
+        else
+            return fContent.getCloneWithLimits(offset, length);
+    }
+
+    public VersionedDocument getParentDocument() {
+        return fContainer;
+    }
+
+    private boolean isLatestVersion() {
+        List<DocumentVersion> allVers = fContainer.getAllVersions();
+        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();
+        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(Map<String, PropertyData<?>> properties, BindingsObjectFactory 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.IS_LATEST_VERSION, requestedIds)) {
+            properties.put(PropertyIds.IS_LATEST_VERSION, objFactory.createPropertyBooleanData(
+                    PropertyIds.IS_LATEST_VERSION, isLatestVersion()));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.IS_MAJOR_VERSION, requestedIds)) {
+            properties.put(PropertyIds.IS_MAJOR_VERSION, objFactory.createPropertyBooleanData(
+                    PropertyIds.IS_MAJOR_VERSION, fIsMajor));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_MAJOR_VERSION, requestedIds)) {
+            properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, objFactory.createPropertyBooleanData(
+                    PropertyIds.IS_LATEST_MAJOR_VERSION, isLatestMajorVersion()));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_ID, requestedIds)) {
+            properties.put(PropertyIds.VERSION_SERIES_ID, objFactory.createPropertyIdData(
+                    PropertyIds.VERSION_SERIES_ID, fContainer.getId()));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
+            properties.put(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, objFactory.createPropertyBooleanData(
+                    PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, fContainer.isCheckedOut()));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
+            properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, objFactory.createPropertyStringData(
+                    PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, fContainer.getCheckedOutBy()));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
+            properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, objFactory.createPropertyIdData(
+                    PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, pwc == null ? null : pwc.getId()));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.CHECKIN_COMMENT, requestedIds)) {
+            properties.put(PropertyIds.CHECKIN_COMMENT, objFactory.createPropertyStringData(
+                    PropertyIds.CHECKIN_COMMENT, fComment));
+        }
+        if (FilterParser.isContainedInFilter(PropertyIds.VERSION_LABEL, requestedIds)) {
+            properties.put(PropertyIds.VERSION_LABEL, objFactory.createPropertyStringData(PropertyIds.VERSION_LABEL,
+                    getVersionLabel()));
+        }
+
+        // Set the content related properties
+        if (null != fContent) {
+            if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_FILE_NAME, requestedIds)) {
+                properties.put(PropertyIds.CONTENT_STREAM_FILE_NAME, objFactory.createPropertyStringData(
+                        PropertyIds.CONTENT_STREAM_FILE_NAME, fContent.getFileName()));
+            }
+
+            // omit: PropertyIds.CMIS_CONTENT_STREAM_ID
+
+            if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_LENGTH, requestedIds)) {
+                properties.put(PropertyIds.CONTENT_STREAM_LENGTH, objFactory.createPropertyIntegerData(
+                        PropertyIds.CONTENT_STREAM_LENGTH, fContent.getBigLength()));
+            }
+            if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_MIME_TYPE, requestedIds)) {
+                properties.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, objFactory.createPropertyStringData(
+                        PropertyIds.CONTENT_STREAM_MIME_TYPE, fContent.getMimeType()));
+            }
+        }
+    }
+
+    public List<Folder> getParents() {
+        return fContainer.getParents();
+    }
+
+    public String getPathSegment() {
+        return fContainer.getPathSegment();
+    }
+
+    public void move(Folder oldParent, Folder newParent) {
+        fContainer.move(oldParent, newParent);
+    }
+
+    public void addParent(Folder parent) {
+        fContainer.addParent(parent);
+    }
+
+    public void removeParent(Folder parent) {
+        fContainer.removeParent(parent);
+    }
+
+    public boolean hasContent() {
+        return null != fContent;
+    }
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java Thu Apr 22 16:27:57 2010
@@ -24,206 +24,206 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 public class FolderImpl extends AbstractSingleFilingImpl implements Folder {
-	private static final Log LOG = LogFactory.getLog(AbstractSingleFilingImpl.class.getName());
+    private static final Log LOG = LogFactory.getLog(AbstractSingleFilingImpl.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);
-		folder.persist();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.opencmis.client.provider.spi.inmemory.IFolder#addChildDocument(org
-	 * .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 CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
-
-		boolean hasChild;
-		hasChild = hasChild(name);
-		if (hasChild)
-			throw new RuntimeException("Cannot create document " + name + ". Name already exists in parent folder");
-
-		if (so instanceof SingleFiling)
-			((SingleFiling) so).setParent(this);
-		else if (so instanceof MultiFiling)
-			((MultiFiling) so).addParent(this);
-		else
-			throw new RuntimeException("Cannot create document, object is not fileable.");
-
-		so.persist();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.opencmis.client.provider.spi.inmemory.IFolder#getChildren()
-	 */
-	public List<StoredObject> getChildren(int maxItems, int skipCount) {
-		List<StoredObject> result = new ArrayList<StoredObject>();
-		for (String id : fObjStore.getIds()) {
-			StoredObject obj = fObjStore.getObject(id);
-			Filing pathObj = (Filing) obj;
-			if (pathObj.getParents().contains(this)) {
-				if (pathObj instanceof VersionedDocument) {
-					DocumentVersion ver = ((VersionedDocument) pathObj).getLatestVersion(false);
-					result.add(ver);
-				} else if (pathObj instanceof DocumentVersion) {
-					// ignore
-				} else {
-					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.opencmis.client.provider.spi.inmemory.IFolder#getFolderChildren()
-	 */
-	public List<Folder> getFolderChildren(int maxItems, int skipCount) {
-		List<Folder> result = new ArrayList<Folder>();
-		for (String id : fObjStore.getIds()) {
-			StoredObject obj = fObjStore.getObject(id);
-			if (obj instanceof SingleFiling) {
-				SingleFiling pathObj = (SingleFiling) obj;
-				if (pathObj.getParent() == this && 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.opencmis.client.provider.spi.inmemory.IFolder#hasChild(java.lang.
-	 * String)
-	 */
-	public boolean hasChild(String name) {
-		for (String id : fObjStore.getIds()) {
-			StoredObject obj = fObjStore.getObject(id);
-			if (obj instanceof Filing) {
-				Filing pathObj = (Filing) obj;
-				if (pathObj.getParents().contains(this) && obj.getName().equals(name))
-					return true;
-			}
-		}
-		return false;
-	}
-
-	public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
-			List<String> requestedIds) {
-
-		super.fillProperties(properties, objFactory, requestedIds);
-
-		// add folder specific properties
-
-		if (FilterParser.isContainedInFilter(PropertyIds.PARENT_ID, requestedIds)) {
-			String parentId = getParent() == null ? null : getParent().getId();
-			if (parentId != null)
-				properties.put(PropertyIds.PARENT_ID, objFactory.createPropertyStringData(PropertyIds.PARENT_ID,
-						parentId));
-		}
-
-		if (FilterParser.isContainedInFilter(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, requestedIds)) {
-			String allowedChildObjects = "*"; // TODO: not yet supported
-			properties.put(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, objFactory.createPropertyStringData(
-					PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, allowedChildObjects));
-		}
-
-		if (FilterParser.isContainedInFilter(PropertyIds.PATH, requestedIds)) {
-			String path = getPath();
-			properties.put(PropertyIds.PATH, objFactory.createPropertyStringData(PropertyIds.PATH, path));
-		}
-	}
-
-	// Helper functions
-	private void init(String name, Folder parent) {
-		if (!NameValidator.isValidId(name))
-			throw new CmisInvalidArgumentException(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 moveChildDocument(StoredObject so, Folder oldParent, Folder newParent) {
-		if (newParent.hasChild(so.getName()))
-			throw new IllegalArgumentException("Cannot move object, this name already exists in target.");
-		if (!(so instanceof Filing))
-			throw new IllegalArgumentException("Cannot move object, object does not have a path.");
-
-		if (so instanceof SingleFiling) {
-			SingleFiling pathObj = (SingleFiling) so;
-			pathObj.setParent(newParent);
-		} else if (so instanceof MultiFiling) {
-			MultiFiling pathObj = (MultiFiling) so;
-			pathObj.addParent(newParent);
-			pathObj.removeParent(oldParent);
-		}
-	}
-
-	public List<String> getAllowedChildObjectTypeIds() {
-		// TODO implement this.
-		return null;
-	}
+    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);
+        folder.persist();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.opencmis.client.provider.spi.inmemory.IFolder#addChildDocument(org
+     * .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 CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+
+        boolean hasChild;
+        hasChild = hasChild(name);
+        if (hasChild)
+            throw new RuntimeException("Cannot create document " + name + ". Name already exists in parent folder");
+
+        if (so instanceof SingleFiling)
+            ((SingleFiling) so).setParent(this);
+        else if (so instanceof MultiFiling)
+            ((MultiFiling) so).addParent(this);
+        else
+            throw new RuntimeException("Cannot create document, object is not fileable.");
+
+        so.persist();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.opencmis.client.provider.spi.inmemory.IFolder#getChildren()
+     */
+    public List<StoredObject> getChildren(int maxItems, int skipCount) {
+        List<StoredObject> result = new ArrayList<StoredObject>();
+        for (String id : fObjStore.getIds()) {
+            StoredObject obj = fObjStore.getObject(id);
+            Filing pathObj = (Filing) obj;
+            if (pathObj.getParents().contains(this)) {
+                if (pathObj instanceof VersionedDocument) {
+                    DocumentVersion ver = ((VersionedDocument) pathObj).getLatestVersion(false);
+                    result.add(ver);
+                } else if (pathObj instanceof DocumentVersion) {
+                    // ignore
+                } else {
+                    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.opencmis.client.provider.spi.inmemory.IFolder#getFolderChildren()
+     */
+    public List<Folder> getFolderChildren(int maxItems, int skipCount) {
+        List<Folder> result = new ArrayList<Folder>();
+        for (String id : fObjStore.getIds()) {
+            StoredObject obj = fObjStore.getObject(id);
+            if (obj instanceof SingleFiling) {
+                SingleFiling pathObj = (SingleFiling) obj;
+                if (pathObj.getParent() == this && 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.opencmis.client.provider.spi.inmemory.IFolder#hasChild(java.lang.
+     * String)
+     */
+    public boolean hasChild(String name) {
+        for (String id : fObjStore.getIds()) {
+            StoredObject obj = fObjStore.getObject(id);
+            if (obj instanceof Filing) {
+                Filing pathObj = (Filing) obj;
+                if (pathObj.getParents().contains(this) && obj.getName().equals(name))
+                    return true;
+            }
+        }
+        return false;
+    }
+
+    public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
+            List<String> requestedIds) {
+
+        super.fillProperties(properties, objFactory, requestedIds);
+
+        // add folder specific properties
+
+        if (FilterParser.isContainedInFilter(PropertyIds.PARENT_ID, requestedIds)) {
+            String parentId = getParent() == null ? null : getParent().getId();
+            if (parentId != null)
+                properties.put(PropertyIds.PARENT_ID, objFactory.createPropertyStringData(PropertyIds.PARENT_ID,
+                        parentId));
+        }
+
+        if (FilterParser.isContainedInFilter(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, requestedIds)) {
+            String allowedChildObjects = "*"; // TODO: not yet supported
+            properties.put(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, objFactory.createPropertyStringData(
+                    PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, allowedChildObjects));
+        }
+
+        if (FilterParser.isContainedInFilter(PropertyIds.PATH, requestedIds)) {
+            String path = getPath();
+            properties.put(PropertyIds.PATH, objFactory.createPropertyStringData(PropertyIds.PATH, path));
+        }
+    }
+
+    // Helper functions
+    private void init(String name, Folder parent) {
+        if (!NameValidator.isValidId(name))
+            throw new CmisInvalidArgumentException(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 moveChildDocument(StoredObject so, Folder oldParent, Folder newParent) {
+        if (newParent.hasChild(so.getName()))
+            throw new IllegalArgumentException("Cannot move object, this name already exists in target.");
+        if (!(so instanceof Filing))
+            throw new IllegalArgumentException("Cannot move object, object does not have a path.");
+
+        if (so instanceof SingleFiling) {
+            SingleFiling pathObj = (SingleFiling) so;
+            pathObj.setParent(newParent);
+        } else if (so instanceof MultiFiling) {
+            MultiFiling pathObj = (MultiFiling) so;
+            pathObj.addParent(newParent);
+            pathObj.removeParent(oldParent);
+        }
+    }
+
+    public List<String> getAllowedChildObjectTypeIds() {
+        // TODO implement this.
+        return null;
+    }
 
 }
\ No newline at end of file

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java Thu Apr 22 16:27:57 2010
@@ -47,242 +47,242 @@ import org.apache.chemistry.opencmis.inm
 
 public class ObjectStoreImpl implements ObjectStore {
 
-	/**
-	 * Simple id generator that uses just an integer
-	 */
-	private static int NEXT_UNUSED_ID = 100;
-
-	/**
-	 * 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();
-	}
-
-	private static synchronized Integer getNextId() {
-		return NEXT_UNUSED_ID++;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#
-	 * getRootFolder()
-	 */
-	public Folder getRootFolder() {
-		return fRootFolder;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#
-	 * getFolderByPath(java.lang .String)
-	 */
-	public StoredObject getObjectByPath(String path) {
-
-		for (StoredObject so : fStoredObjectMap.values()) {
-			if (so instanceof SingleFiling) {
-				String soPath = ((SingleFiling) so).getPath();
-				if (soPath.equals(path))
-					return so;
-			} else if (so instanceof MultiFiling) {
-				MultiFiling mfo = (MultiFiling) so;
-				List<Folder> parents = mfo.getParents();
-				for (Folder parent : parents) {
-					String parentPath = parent.getPath();
-					String mfPath = parentPath.equals(Folder.PATH_SEPARATOR) ? parentPath + mfo.getPathSegment()
-							: parentPath + Folder.PATH_SEPARATOR + mfo.getPathSegment();
-					if (mfPath.equals(path))
-						return so;
-				}
-			} else
-				return null;
-		}
-		return null;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.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.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 if (obj instanceof DocumentVersion) {
-			DocumentVersion vers = (DocumentVersion) obj;
-			VersionedDocument parentDoc = vers.getParentDocument();
-			fStoredObjectMap.remove(path);
-			boolean otherVersionsExist = vers.getParentDocument().deleteVersion(vers);
-			if (!otherVersionsExist)
-				fStoredObjectMap.remove(parentDoc.getId());
-		} else {
-			fStoredObjectMap.remove(path);
-		}
-	}
-
-	public void removeVersion(DocumentVersion vers) {
-		StoredObject found = fStoredObjectMap.remove(vers.getId());
-
-		if (null == found)
-			throw new RuntimeException("Cannot delete object with id  " + vers.getId() + ". Object does not exist.");
-	}
-
-	// 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);
-	// }
-
-	public String storeObject(StoredObject so) {
-		String id = so.getId();
-		// check if update or create
-		if (null == id)
-			id = getNextId().toString();
-		fStoredObjectMap.put(id, so);
-		return id;
-	}
-
-	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(BaseTypeId.CMIS_FOLDER.value());
-		rootFolder.setCreatedBy("Admin");
-		rootFolder.setModifiedBy("Admin");
-		rootFolder.setModifiedAtNow();
-		rootFolder.setRepositoryId(fRepositoryId);
-		rootFolder.persist();
-		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) {
-		StoredObject folder = fStoredObjectMap.get(folderId);
-		if (folder == null)
-			throw new RuntimeException("Unknown object with id:  " + folderId);
-
-		if (!(folder instanceof FolderImpl)) {
-			throw new RuntimeException("Cannot delete folder with id:  " + folderId
-					+ ". Object exists but is not a folder.");
-		}
-
-		// check if children exist
-		List<StoredObject> children = ((Folder) folder).getChildren(-1, -1);
-		if (children != null && !children.isEmpty())
-			throw new CmisConstraintException("Cannot delete folder with id:  " + folderId + ". Folder is not empty.");
+    /**
+     * Simple id generator that uses just an integer
+     */
+    private static int NEXT_UNUSED_ID = 100;
+
+    /**
+     * 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();
+    }
+
+    private static synchronized Integer getNextId() {
+        return NEXT_UNUSED_ID++;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#
+     * getRootFolder()
+     */
+    public Folder getRootFolder() {
+        return fRootFolder;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.opencmis.client.provider.spi.inmemory.storedobj.impl.ObjectStore#
+     * getFolderByPath(java.lang .String)
+     */
+    public StoredObject getObjectByPath(String path) {
+
+        for (StoredObject so : fStoredObjectMap.values()) {
+            if (so instanceof SingleFiling) {
+                String soPath = ((SingleFiling) so).getPath();
+                if (soPath.equals(path))
+                    return so;
+            } else if (so instanceof MultiFiling) {
+                MultiFiling mfo = (MultiFiling) so;
+                List<Folder> parents = mfo.getParents();
+                for (Folder parent : parents) {
+                    String parentPath = parent.getPath();
+                    String mfPath = parentPath.equals(Folder.PATH_SEPARATOR) ? parentPath + mfo.getPathSegment()
+                            : parentPath + Folder.PATH_SEPARATOR + mfo.getPathSegment();
+                    if (mfPath.equals(path))
+                        return so;
+                }
+            } else
+                return null;
+        }
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.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.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 if (obj instanceof DocumentVersion) {
+            DocumentVersion vers = (DocumentVersion) obj;
+            VersionedDocument parentDoc = vers.getParentDocument();
+            fStoredObjectMap.remove(path);
+            boolean otherVersionsExist = vers.getParentDocument().deleteVersion(vers);
+            if (!otherVersionsExist)
+                fStoredObjectMap.remove(parentDoc.getId());
+        } else {
+            fStoredObjectMap.remove(path);
+        }
+    }
+
+    public void removeVersion(DocumentVersion vers) {
+        StoredObject found = fStoredObjectMap.remove(vers.getId());
+
+        if (null == found)
+            throw new RuntimeException("Cannot delete object with id  " + vers.getId() + ". Object does not exist.");
+    }
+
+    // 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);
+    // }
+
+    public String storeObject(StoredObject so) {
+        String id = so.getId();
+        // check if update or create
+        if (null == id)
+            id = getNextId().toString();
+        fStoredObjectMap.put(id, so);
+        return id;
+    }
+
+    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(BaseTypeId.CMIS_FOLDER.value());
+        rootFolder.setCreatedBy("Admin");
+        rootFolder.setModifiedBy("Admin");
+        rootFolder.setModifiedAtNow();
+        rootFolder.setRepositoryId(fRepositoryId);
+        rootFolder.persist();
+        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) {
+        StoredObject folder = fStoredObjectMap.get(folderId);
+        if (folder == null)
+            throw new RuntimeException("Unknown object with id:  " + folderId);
+
+        if (!(folder instanceof FolderImpl)) {
+            throw new RuntimeException("Cannot delete folder with id:  " + folderId
+                    + ". Object exists but is not a folder.");
+        }
+
+        // check if children exist
+        List<StoredObject> children = ((Folder) folder).getChildren(-1, -1);
+        if (children != null && !children.isEmpty())
+            throw new CmisConstraintException("Cannot delete folder with id:  " + folderId + ". Folder is not empty.");
 
-		fStoredObjectMap.remove(folderId);
-	}
+        fStoredObjectMap.remove(folderId);
+    }
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java Thu Apr 22 16:27:57 2010
@@ -29,38 +29,38 @@ import org.apache.commons.logging.LogFac
  */
 
 public class StoreManagerFactory {
-	private static Log log = LogFactory.getLog(StoreManagerFactory.class);
+    private static Log log = LogFactory.getLog(StoreManagerFactory.class);
 
-	public static StoreManager createInstance(String className) {
+    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;
-		}
-	}
+        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;
+        }
+    }
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java Thu Apr 22 16:27:57 2010
@@ -55,298 +55,298 @@ import org.apache.chemistry.opencmis.inm
  */
 public class StoreManagerImpl implements StoreManager {
 
-	protected BindingsObjectFactory fObjectFactory;
-	protected RepositoryInfo fRepositoryInfo;
+    protected BindingsObjectFactory fObjectFactory;
+    protected RepositoryInfo 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 BindingsObjectFactoryImpl();
-	}
-
-	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) {
-		fMapRepositoryToObjectStore.put(repositoryId, new ObjectStoreImpl(repositoryId));
-		fMapRepositoryToTypeManager.put(repositoryId, new TypeManager());
-	}
-
-	public void createAndInitRepository(String repositoryId, String typeCreatorClassName) {
-		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());
-
-		// initialize the type system:
-		initTypeSystem(repositoryId, typeCreatorClassName);
-	}
-
-	public ObjectStore getObjectStore(String repositoryId) {
-		return fMapRepositoryToObjectStore.get(repositoryId);
-	}
-
-	public BindingsObjectFactory getObjectFactory() {
-		return fObjectFactory;
-	}
-
-	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 TypeDefinitionContainer getTypeById(String repositoryId, String typeId, boolean includePropertyDefinitions,
-			int depth) {
-		TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
-		if (null == typeManager)
-			throw new RuntimeException("Unknown repository " + repositoryId);
-
-		TypeDefinitionContainer tc = typeManager.getTypeById(typeId);
-		List<TypeDefinitionContainer> result = null;
-
-		if (tc != null) {
-			if (depth == -1) {
-				result = tc.getChildren();
-				if (!includePropertyDefinitions)
-					cloneTypeList(depth - 1, false, result);
-			} else if (depth == 0 || depth < -1)
-				throw new CmisInvalidArgumentException("illegal depth value: " + depth);
-			else {
-				result = tc.getChildren();
-				cloneTypeList(depth - 1, includePropertyDefinitions, result);
-			}
-		}
-		return tc;
-	}
-
-	public Collection<TypeDefinitionContainer> getTypeDefinitionList(String repositoryId,
-			boolean includePropertyDefinitions) {
-		Collection<TypeDefinitionContainer> result;
-		TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
-		if (null == typeManager)
-			throw new RuntimeException("Unknown repository " + repositoryId);
-		Collection<TypeDefinitionContainer> typeColl = typeManager.getTypeDefinitionList();
-		if (includePropertyDefinitions) {
-			result = typeColl;
-		} else {
-			result = new ArrayList<TypeDefinitionContainer>(typeColl);
-			// copy list and omit properties
-			for (TypeDefinitionContainer c : result) {
-				AbstractTypeDefinition td = ((AbstractTypeDefinition) c.getTypeDefinition()).clone();
-				TypeDefinitionContainerImpl tdc = new TypeDefinitionContainerImpl(td);
-				tdc.setChildren(c.getChildren());
-				td.setPropertyDefinitions(null);
-			}
-		}
-		return result;
-	}
-
-	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 RepositoryInfo getRepositoryInfo(String repositoryId) {
-		ObjectStore sm = fMapRepositoryToObjectStore.get(repositoryId);
-		if (null == sm)
-			return null;
-
-		RepositoryInfo repoInfo = createDefaultRepositoryInfo(repositoryId);
-
-		return repoInfo;
-	}
-
-	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 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;
-	}
-
-	private 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);
-	}
-
-	private RepositoryInfo createDefaultRepositoryInfo(String repositoryId) {
-		ObjectStore objStore = getObjectStore(repositoryId);
-		String rootFolderId = objStore.getRootFolder().getId();
-		// repository info
-		RepositoryInfoImpl repoInfo;
-		repoInfo = new RepositoryInfoImpl();
-		repoInfo.setRepositoryId(repositoryId == null ? "inMem" : repositoryId);
-		repoInfo.setRepositoryName("InMemory Repository");
-		repoInfo.setRepositoryDescription("InMemory Test Repository");
-		repoInfo.setCmisVersionSupported("1.0");
-		repoInfo.setRepositoryCapabilities(null);
-		repoInfo.setRootFolder(rootFolderId);
-		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
-		RepositoryCapabilitiesImpl caps = new RepositoryCapabilitiesImpl();
-		caps.setAllVersionsSearchable(false);
-		caps.setCapabilityAcl(CapabilityAcl.NONE);
-		caps.setCapabilityChanges(CapabilityChanges.PROPERTIES); // just for
-																	// testing
-		caps.setCapabilityContentStreamUpdates(CapabilityContentStreamUpdates.PWCONLY);
-		caps.setCapabilityJoin(CapabilityJoin.NONE);
-		caps.setCapabilityQuery(CapabilityQuery.METADATAONLY); // just for
-																// testing
-		caps.setCapabilityRendition(CapabilityRenditions.NONE);
-		caps.setIsPwcSearchable(false);
-		caps.setIsPwcUpdatable(true);
-		caps.setSupportsGetDescendants(true);
-		caps.setSupportsGetFolderTree(true);
-		caps.setSupportsMultifiling(true);
-		caps.setSupportsUnfiling(true);
-		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;
-	}
-
-	/**
-	 * traverse tree and replace each need node with a clone. remove properties
-	 * on clone if requested, cut children of clone if depth is exceeded.
-	 * 
-	 * @param depth
-	 * @param types
-	 */
-	private void cloneTypeList(int depth, boolean includePropertyDefinitions, List<TypeDefinitionContainer> types) {
-
-		ListIterator<TypeDefinitionContainer> it = types.listIterator();
-		while (it.hasNext()) {
-			TypeDefinitionContainer tdc = it.next();
-			AbstractTypeDefinition td = ((AbstractTypeDefinition) tdc.getTypeDefinition()).clone();
-			if (!includePropertyDefinitions)
-				td.setPropertyDefinitions(null);
-			TypeDefinitionContainerImpl tdcClone = new TypeDefinitionContainerImpl(td);
-			if (depth > 0) {
-				ArrayList<TypeDefinitionContainer> children = new ArrayList<TypeDefinitionContainer>(tdc.getChildren()
-						.size());
-				children.addAll(tdc.getChildren());
-				tdcClone.setChildren(children);
-				cloneTypeList(depth - 1, includePropertyDefinitions, children);
-			}
-			it.set(tdcClone);
-		}
-	}
+    /**
+     * 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 BindingsObjectFactoryImpl();
+    }
+
+    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) {
+        fMapRepositoryToObjectStore.put(repositoryId, new ObjectStoreImpl(repositoryId));
+        fMapRepositoryToTypeManager.put(repositoryId, new TypeManager());
+    }
+
+    public void createAndInitRepository(String repositoryId, String typeCreatorClassName) {
+        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());
+
+        // initialize the type system:
+        initTypeSystem(repositoryId, typeCreatorClassName);
+    }
+
+    public ObjectStore getObjectStore(String repositoryId) {
+        return fMapRepositoryToObjectStore.get(repositoryId);
+    }
+
+    public BindingsObjectFactory getObjectFactory() {
+        return fObjectFactory;
+    }
+
+    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 TypeDefinitionContainer getTypeById(String repositoryId, String typeId, boolean includePropertyDefinitions,
+            int depth) {
+        TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+        if (null == typeManager)
+            throw new RuntimeException("Unknown repository " + repositoryId);
+
+        TypeDefinitionContainer tc = typeManager.getTypeById(typeId);
+        List<TypeDefinitionContainer> result = null;
+
+        if (tc != null) {
+            if (depth == -1) {
+                result = tc.getChildren();
+                if (!includePropertyDefinitions)
+                    cloneTypeList(depth - 1, false, result);
+            } else if (depth == 0 || depth < -1)
+                throw new CmisInvalidArgumentException("illegal depth value: " + depth);
+            else {
+                result = tc.getChildren();
+                cloneTypeList(depth - 1, includePropertyDefinitions, result);
+            }
+        }
+        return tc;
+    }
+
+    public Collection<TypeDefinitionContainer> getTypeDefinitionList(String repositoryId,
+            boolean includePropertyDefinitions) {
+        Collection<TypeDefinitionContainer> result;
+        TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
+        if (null == typeManager)
+            throw new RuntimeException("Unknown repository " + repositoryId);
+        Collection<TypeDefinitionContainer> typeColl = typeManager.getTypeDefinitionList();
+        if (includePropertyDefinitions) {
+            result = typeColl;
+        } else {
+            result = new ArrayList<TypeDefinitionContainer>(typeColl);
+            // copy list and omit properties
+            for (TypeDefinitionContainer c : result) {
+                AbstractTypeDefinition td = ((AbstractTypeDefinition) c.getTypeDefinition()).clone();
+                TypeDefinitionContainerImpl tdc = new TypeDefinitionContainerImpl(td);
+                tdc.setChildren(c.getChildren());
+                td.setPropertyDefinitions(null);
+            }
+        }
+        return result;
+    }
+
+    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 RepositoryInfo getRepositoryInfo(String repositoryId) {
+        ObjectStore sm = fMapRepositoryToObjectStore.get(repositoryId);
+        if (null == sm)
+            return null;
+
+        RepositoryInfo repoInfo = createDefaultRepositoryInfo(repositoryId);
+
+        return repoInfo;
+    }
+
+    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 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;
+    }
+
+    private 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);
+    }
+
+    private RepositoryInfo createDefaultRepositoryInfo(String repositoryId) {
+        ObjectStore objStore = getObjectStore(repositoryId);
+        String rootFolderId = objStore.getRootFolder().getId();
+        // repository info
+        RepositoryInfoImpl repoInfo;
+        repoInfo = new RepositoryInfoImpl();
+        repoInfo.setRepositoryId(repositoryId == null ? "inMem" : repositoryId);
+        repoInfo.setRepositoryName("InMemory Repository");
+        repoInfo.setRepositoryDescription("InMemory Test Repository");
+        repoInfo.setCmisVersionSupported("1.0");
+        repoInfo.setRepositoryCapabilities(null);
+        repoInfo.setRootFolder(rootFolderId);
+        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
+        RepositoryCapabilitiesImpl caps = new RepositoryCapabilitiesImpl();
+        caps.setAllVersionsSearchable(false);
+        caps.setCapabilityAcl(CapabilityAcl.NONE);
+        caps.setCapabilityChanges(CapabilityChanges.PROPERTIES); // just for
+        // testing
+        caps.setCapabilityContentStreamUpdates(CapabilityContentStreamUpdates.PWCONLY);
+        caps.setCapabilityJoin(CapabilityJoin.NONE);
+        caps.setCapabilityQuery(CapabilityQuery.METADATAONLY); // just for
+        // testing
+        caps.setCapabilityRendition(CapabilityRenditions.NONE);
+        caps.setIsPwcSearchable(false);
+        caps.setIsPwcUpdatable(true);
+        caps.setSupportsGetDescendants(true);
+        caps.setSupportsGetFolderTree(true);
+        caps.setSupportsMultifiling(true);
+        caps.setSupportsUnfiling(true);
+        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;
+    }
+
+    /**
+     * traverse tree and replace each need node with a clone. remove properties
+     * on clone if requested, cut children of clone if depth is exceeded.
+     * 
+     * @param depth
+     * @param types
+     */
+    private void cloneTypeList(int depth, boolean includePropertyDefinitions, List<TypeDefinitionContainer> types) {
+
+        ListIterator<TypeDefinitionContainer> it = types.listIterator();
+        while (it.hasNext()) {
+            TypeDefinitionContainer tdc = it.next();
+            AbstractTypeDefinition td = ((AbstractTypeDefinition) tdc.getTypeDefinition()).clone();
+            if (!includePropertyDefinitions)
+                td.setPropertyDefinitions(null);
+            TypeDefinitionContainerImpl tdcClone = new TypeDefinitionContainerImpl(td);
+            if (depth > 0) {
+                ArrayList<TypeDefinitionContainer> children = new ArrayList<TypeDefinitionContainer>(tdc.getChildren()
+                        .size());
+                children.addAll(tdc.getChildren());
+                tdcClone.setChildren(children);
+                cloneTypeList(depth - 1, includePropertyDefinitions, children);
+            }
+            it.set(tdcClone);
+        }
+    }
 
 }



Mime
View raw message