chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r934878 [1/13] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/ main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/ mai...
Date Fri, 16 Apr 2010 14:00:25 GMT
Author: jens
Date: Fri Apr 16 14:00:23 2010
New Revision: 934878

URL: http://svn.apache.org/viewvc?rev=934878&view=rev
Log:
Apply new code formatter

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/FilterParser.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/RepositoryInfoCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/AbstractService.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/CmisInMemoryProvider.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/CmisInMemorySpi.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/CmisInMemorySpiFactory.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/DiscoveryServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/DummyCallContext.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/MultiFilingServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/NavigationServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/ObjectServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/RepositoryServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/VersioningServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AbstractServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AtomLinkInfoProvider.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryMultiFilingServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryNavigationServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/RuntimeContext.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/ServiceFactory.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/Children.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/Content.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/Document.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/DocumentVersion.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/Filing.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/Folder.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/MultiFiling.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/SingleFiling.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoreManager.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoredObject.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/Version.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/VersionedDocument.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/AbstractMultiFilingImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/AbstractSingleFilingImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerFactory.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/VersionedDocumentImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DefaultTypeSystemCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DocumentTypeCreationHelper.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/InMemoryDocumentTypeDefinition.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/InMemoryFolderTypeDefinition.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/InMemoryPolicyTypeDefinition.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/InMemoryRelationshipTypeDefinition.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/NavigationServiceTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/TypeValidationTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/UnitTestTypeSystemCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/VersionTestTypeSystemCreator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/VersioningTest.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.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/ConfigConstants.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java Fri Apr 16 14:00:23 2010
@@ -16,22 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
- package org.apache.chemistry.opencmis.inmemory;
+package org.apache.chemistry.opencmis.inmemory;
 
-public class ConfigConstants  {
-  public static final String REPOSITORY_ID = "InMemoryServer.RepositoryId";
-  public static final String TYPE_CREATOR_CLASS = "InMemoryServer.TypesCreatorClass";
-  public static final String REPOSITORY_INFO_CREATOR_CLASS = "InMemoryServer.RepositoryInfoCreatorClass";
-  public static final String REPOSITORY_CLASS = "InMemoryServer.Class";
+public class ConfigConstants {
+	public static final String REPOSITORY_ID = "InMemoryServer.RepositoryId";
+	public static final String TYPE_CREATOR_CLASS = "InMemoryServer.TypesCreatorClass";
+	public static final String REPOSITORY_INFO_CREATOR_CLASS = "InMemoryServer.RepositoryInfoCreatorClass";
+	public static final String REPOSITORY_CLASS = "InMemoryServer.Class";
 
-  // Helper constants that allow to fill a repository with data on initialization
-  public static final String USE_REPOSITORY_FILER = "RepositoryFiller.Enable";
-  public static final String FILLER_DOCUMENT_TYPE_ID = "RepositoryFiller.DocumentTypeId";
-  public static final String FILLER_FOLDER_TYPE_ID = "RepositoryFiller.FolderTypeId";
-  public static final String FILLER_DOCS_PER_FOLDER = "RepositoryFiller.DocsPerFolder";
-  public static final String FILLER_FOLDERS_PER_FOLDER = "RepositoryFiller.FolderPerFolder";
-  public static final String FILLER_DEPTH = "RepositoryFiller.Depth";
-  public static final String FILLER_CONTENT_SIZE = "RepositoryFiller.ContentSizeInKB";
-  public static final String FILLER_DOCUMENT_PROPERTY = "RepositoryFiller.DocumentProperty.";
-  public static final String FILLER_FOLDER_PROPERTY = "RepositoryFiller.FolderProperty.";
+	// Helper constants that allow to fill a repository with data on
+	// initialization
+	public static final String USE_REPOSITORY_FILER = "RepositoryFiller.Enable";
+	public static final String FILLER_DOCUMENT_TYPE_ID = "RepositoryFiller.DocumentTypeId";
+	public static final String FILLER_FOLDER_TYPE_ID = "RepositoryFiller.FolderTypeId";
+	public static final String FILLER_DOCS_PER_FOLDER = "RepositoryFiller.DocsPerFolder";
+	public static final String FILLER_FOLDERS_PER_FOLDER = "RepositoryFiller.FolderPerFolder";
+	public static final String FILLER_DEPTH = "RepositoryFiller.Depth";
+	public static final String FILLER_CONTENT_SIZE = "RepositoryFiller.ContentSizeInKB";
+	public static final String FILLER_DOCUMENT_PROPERTY = "RepositoryFiller.DocumentProperty.";
+	public static final String FILLER_FOLDER_PROPERTY = "RepositoryFiller.FolderProperty.";
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.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/DataObjectCreator.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java Fri Apr 16 14:00:23 2010
@@ -47,119 +47,118 @@ import org.apache.chemistry.opencmis.inm
 import org.apache.chemistry.opencmis.server.spi.CallContext;
 
 /**
- * @author Jens A collection of utility functions to fill the data objects used as return values for
- *         the service object calls
+ * @author Jens A collection of utility functions to fill the data objects used
+ *         as return values for the service object calls
  */
 public class DataObjectCreator {
 
-  public static AllowableActions fillAllowableActions(ObjectStore objStore, StoredObject so) {
+	public static AllowableActions fillAllowableActions(ObjectStore objStore, StoredObject so) {
 
-    boolean isFolder = so instanceof Folder;
-    boolean isDocument = so instanceof Content;
-    boolean isCheckedOut = false;
-    boolean canCheckOut = false;
-    boolean canCheckIn = false;
-    boolean isVersioned = so instanceof Version || so instanceof VersionedDocument;
-    boolean hasContent = so instanceof Content && ((Content) so).hasContent();
-
-    String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
-    if (so instanceof Version) {
-      isCheckedOut = ((Version)so).isPwc();
-      canCheckIn = isCheckedOut && ((Version)so).getParentDocument().getCheckedOutBy().equals(user);
-    } else if (so instanceof VersionedDocument) {
-      isCheckedOut = ((VersionedDocument)so).isCheckedOut();
-      canCheckOut = !((VersionedDocument)so).isCheckedOut();
-      canCheckIn = isCheckedOut && ((VersionedDocument)so).getCheckedOutBy().equals(user);
-    }
-
-    AllowableActionsImpl allowableActions = new AllowableActionsImpl();
-    Set<Action> set = allowableActions.getAllowableActions();
-
-    set.add(Action.CAN_DELETE_OBJECT);
-    set.add(Action.CAN_UPDATE_PROPERTIES);
-
-    if (isFolder || isDocument) {
-      set.add(Action.CAN_GET_PROPERTIES);
-      if (!so.equals(objStore.getRootFolder())) {
-          set.add(Action.CAN_GET_OBJECT_PARENTS);
-      }
-      set.add(Action.CAN_MOVE_OBJECT);
-    }
-
-    if (isFolder) {
-        if (!so.equals(objStore.getRootFolder())) {
-            set.add(Action.CAN_GET_FOLDER_PARENT);
-        }
-        set.add(Action.CAN_GET_FOLDER_TREE);
-        set.add(Action.CAN_GET_DESCENDANTS);
-
-        set.add(Action.CAN_ADD_OBJECT_TO_FOLDER);
-        set.add(Action.CAN_REMOVE_OBJECT_FROM_FOLDER);
-        set.add(Action.CAN_CREATE_DOCUMENT);
-        set.add(Action.CAN_CREATE_FOLDER);
-        set.add(Action.CAN_GET_CHILDREN);
-        set.add(Action.CAN_DELETE_TREE);
-    }
-
-    if (hasContent) {
-        set.add(Action.CAN_DELETE_CONTENT_STREAM);
-        set.add(Action.CAN_GET_CONTENT_STREAM);
-    }
-
-   if (isVersioned) {
-       if (canCheckOut) {
-           set.add(Action.CAN_CHECK_OUT);
-       }
-       if (isCheckedOut) {
-           set.add(Action.CAN_CANCEL_CHECK_OUT);
-       }
-       if (canCheckIn) {
-           set.add(Action.CAN_CHECK_IN);
-       }
-       set.add(Action.CAN_GET_ALL_VERSIONS);
-    }
-
-    if (isDocument) {
-        if (!isVersioned || canCheckIn) {
-            set.add(Action.CAN_SET_CONTENT_STREAM);
-        }
-    }
-
-    allowableActions.setAllowableActions(set);
-    return allowableActions;
-  }
-
-  public static Acl fillACL(StoredObject so) {
-    AccessControlListImpl acl = new AccessControlListImpl();
-    List<Ace> aces = new ArrayList<Ace>();
-    // TODO to be completed if ACLs are implemented
-    acl.setAces(aces);
-    return acl;
-  }
-
-  public static PolicyIdList fillPolicyIds(StoredObject so) {
-    // TODO: to be completed if policies are implemented
-    PolicyIdListImpl polIds = new PolicyIdListImpl();
-    // polIds.setPolicyIds(...);
-    return polIds;
-  }
-
-  public static List<ObjectData> fillRelationships(IncludeRelationships includeRelationships,
-      StoredObject so) {
-    // TODO: to be completed if relationships are implemented
-    List<ObjectData> relationships = new ArrayList<ObjectData>();
-    return relationships;
-  }
-
-  public static List<RenditionData> fillRenditions(StoredObject so) {
-    // TODO: to be completed if renditions are implemented
-    List<RenditionData> renditions = new ArrayList<RenditionData>();
-    return renditions;
-  }
-
-  public static ChangeEventInfo fillChangeEventInfo(StoredObject so) {
-    // TODO: to be completed if change information is implemented
-    ChangeEventInfo changeEventInfo = new ChangeEventInfoDataImpl();
-    return changeEventInfo;
-  }
+		boolean isFolder = so instanceof Folder;
+		boolean isDocument = so instanceof Content;
+		boolean isCheckedOut = false;
+		boolean canCheckOut = false;
+		boolean canCheckIn = false;
+		boolean isVersioned = so instanceof Version || so instanceof VersionedDocument;
+		boolean hasContent = so instanceof Content && ((Content) so).hasContent();
+
+		String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
+		if (so instanceof Version) {
+			isCheckedOut = ((Version) so).isPwc();
+			canCheckIn = isCheckedOut && ((Version) so).getParentDocument().getCheckedOutBy().equals(user);
+		} else if (so instanceof VersionedDocument) {
+			isCheckedOut = ((VersionedDocument) so).isCheckedOut();
+			canCheckOut = !((VersionedDocument) so).isCheckedOut();
+			canCheckIn = isCheckedOut && ((VersionedDocument) so).getCheckedOutBy().equals(user);
+		}
+
+		AllowableActionsImpl allowableActions = new AllowableActionsImpl();
+		Set<Action> set = allowableActions.getAllowableActions();
+
+		set.add(Action.CAN_DELETE_OBJECT);
+		set.add(Action.CAN_UPDATE_PROPERTIES);
+
+		if (isFolder || isDocument) {
+			set.add(Action.CAN_GET_PROPERTIES);
+			if (!so.equals(objStore.getRootFolder())) {
+				set.add(Action.CAN_GET_OBJECT_PARENTS);
+			}
+			set.add(Action.CAN_MOVE_OBJECT);
+		}
+
+		if (isFolder) {
+			if (!so.equals(objStore.getRootFolder())) {
+				set.add(Action.CAN_GET_FOLDER_PARENT);
+			}
+			set.add(Action.CAN_GET_FOLDER_TREE);
+			set.add(Action.CAN_GET_DESCENDANTS);
+
+			set.add(Action.CAN_ADD_OBJECT_TO_FOLDER);
+			set.add(Action.CAN_REMOVE_OBJECT_FROM_FOLDER);
+			set.add(Action.CAN_CREATE_DOCUMENT);
+			set.add(Action.CAN_CREATE_FOLDER);
+			set.add(Action.CAN_GET_CHILDREN);
+			set.add(Action.CAN_DELETE_TREE);
+		}
+
+		if (hasContent) {
+			set.add(Action.CAN_DELETE_CONTENT_STREAM);
+			set.add(Action.CAN_GET_CONTENT_STREAM);
+		}
+
+		if (isVersioned) {
+			if (canCheckOut) {
+				set.add(Action.CAN_CHECK_OUT);
+			}
+			if (isCheckedOut) {
+				set.add(Action.CAN_CANCEL_CHECK_OUT);
+			}
+			if (canCheckIn) {
+				set.add(Action.CAN_CHECK_IN);
+			}
+			set.add(Action.CAN_GET_ALL_VERSIONS);
+		}
+
+		if (isDocument) {
+			if (!isVersioned || canCheckIn) {
+				set.add(Action.CAN_SET_CONTENT_STREAM);
+			}
+		}
+
+		allowableActions.setAllowableActions(set);
+		return allowableActions;
+	}
+
+	public static Acl fillACL(StoredObject so) {
+		AccessControlListImpl acl = new AccessControlListImpl();
+		List<Ace> aces = new ArrayList<Ace>();
+		// TODO to be completed if ACLs are implemented
+		acl.setAces(aces);
+		return acl;
+	}
+
+	public static PolicyIdList fillPolicyIds(StoredObject so) {
+		// TODO: to be completed if policies are implemented
+		PolicyIdListImpl polIds = new PolicyIdListImpl();
+		// polIds.setPolicyIds(...);
+		return polIds;
+	}
+
+	public static List<ObjectData> fillRelationships(IncludeRelationships includeRelationships, StoredObject so) {
+		// TODO: to be completed if relationships are implemented
+		List<ObjectData> relationships = new ArrayList<ObjectData>();
+		return relationships;
+	}
+
+	public static List<RenditionData> fillRenditions(StoredObject so) {
+		// TODO: to be completed if renditions are implemented
+		List<RenditionData> renditions = new ArrayList<RenditionData>();
+		return renditions;
+	}
+
+	public static ChangeEventInfo fillChangeEventInfo(StoredObject so) {
+		// TODO: to be completed if change information is implemented
+		ChangeEventInfo changeEventInfo = new ChangeEventInfoDataImpl();
+		return changeEventInfo;
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.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/DummyCallContext.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java Fri Apr 16 14:00:23 2010
@@ -6,35 +6,35 @@ import java.util.Map;
 import org.apache.chemistry.opencmis.server.spi.CallContext;
 
 public class DummyCallContext implements CallContext {
-  private Map<String, String> fParameter = new HashMap<String, String>();
+	private Map<String, String> fParameter = new HashMap<String, String>();
 
-  public DummyCallContext() {
-    fParameter.put( USERNAME, "TestUser");
-    fParameter.put( PASSWORD, "secret");
-    fParameter.put( LOCALE, "en");
-  }
-  
-  public String get(String key) {
-    return fParameter.get(key);
-  }
-
-  public String getBinding() {
-    return BINDING_ATOMPUB;
-  }
-
-  public String getLocale() {
-    return get(LOCALE);
-  }
-
-  public String getPassword() {
-    return get(PASSWORD);
-  }
-
-  public String getUsername() {
-    return get(USERNAME);
-  }
-
-  public void put(String key, String value) {
-    fParameter.put(key, value);
-  }
+	public DummyCallContext() {
+		fParameter.put(USERNAME, "TestUser");
+		fParameter.put(PASSWORD, "secret");
+		fParameter.put(LOCALE, "en");
+	}
+
+	public String get(String key) {
+		return fParameter.get(key);
+	}
+
+	public String getBinding() {
+		return BINDING_ATOMPUB;
+	}
+
+	public String getLocale() {
+		return get(LOCALE);
+	}
+
+	public String getPassword() {
+		return get(PASSWORD);
+	}
+
+	public String getUsername() {
+		return get(USERNAME);
+	}
+
+	public void put(String key, String value) {
+		fParameter.put(key, value);
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/FilterParser.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/FilterParser.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/FilterParser.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/FilterParser.java Fri Apr 16 14:00:23 2010
@@ -20,7 +20,7 @@ package org.apache.chemistry.opencmis.in
 
 /**
  * @author Jens
-*/
+ */
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -28,21 +28,23 @@ import java.util.List;
 
 public class FilterParser {
 
-  public static boolean isContainedInFilter(String propertyId, List<String> requestedIds) {
-    if (requestedIds.contains("*"))
-      return true;
-    return requestedIds.contains(propertyId);
-  }
-
-  public static List<String> getRequestedIdsFromFilter(String filter) {
-    if (filter == null || filter.length() == 0)
-      return Collections.singletonList("*");
-    else {
-      List<String> requestedIds = Arrays.asList(filter.split(",\\s*")); // comma plus whitespace
-      if (requestedIds.contains("*"))
-        requestedIds = Collections.singletonList("*");
-      return requestedIds;
-    }
-  }
+	public static boolean isContainedInFilter(String propertyId, List<String> requestedIds) {
+		if (requestedIds.contains("*"))
+			return true;
+		return requestedIds.contains(propertyId);
+	}
+
+	public static List<String> getRequestedIdsFromFilter(String filter) {
+		if (filter == null || filter.length() == 0)
+			return Collections.singletonList("*");
+		else {
+			List<String> requestedIds = Arrays.asList(filter.split(",\\s*")); // comma
+																				// plus
+																				// whitespace
+			if (requestedIds.contains("*"))
+				requestedIds = Collections.singletonList("*");
+			return requestedIds;
+		}
+	}
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.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/NameValidator.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java Fri Apr 16 14:00:23 2010
@@ -20,59 +20,57 @@
 package org.apache.chemistry.opencmis.inmemory;
 
 public class NameValidator {
-  public static final String ERROR_ILLEGAL_ID = 
-    "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_'";
+	public static final String ERROR_ILLEGAL_ID = "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_'";
 
-  public static final String ERROR_ILLEGAL_NAME = 
-    "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_', '.', ' '";
+	public static final String ERROR_ILLEGAL_NAME = "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_', '.', ' '";
 
-  /**
-   * check whether id contains only valid characters Allowed are 'a'..'z', 'A'..'Z', '0'..'9', '.', '-', ' ',
-   * '_';
-   * 
-   * @param s
-   *          string to verify
-   */
-  static public boolean isValidId(String s) {
-    if (s.startsWith("cmis:"))
-        s = s.substring(5);
-    		
-    for (int i = 0; i < s.length(); i++) {
-      char c = s.charAt(i);
-      if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.'
-          || c == '-' || c == '_' || c == ' '))
-        return false;
-    }
-    return true;
-  }
-
-  static public boolean isValidLocalName(String s) {
-    return isValidId(s);
-  }
-
-  /**
-   * check whether id contains only valid characters Allowed are 'a'..'z', 'A'..'Z', '0'..'9', '.', '-', ' ',
-   * '_';
-   * 
-   * @param s
-   *          string to verify
-   */
-  static public boolean isValidName(String s) {
-    for (int i = 0; i < s.length(); i++) {
-      char c = s.charAt(i);
-      if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.'
-          || c == '-' || c == '_' || c == ' '))
-        return false;
-    }
-    return true;
-  }
-
-  static public boolean isValidNamespace(String s) {
-    return isValidId(s);
-  }
-
-  static public boolean isValidQueryName(String s) {
-    return isValidId(s);
-  }
+	/**
+	 * check whether id contains only valid characters Allowed are 'a'..'z',
+	 * 'A'..'Z', '0'..'9', '.', '-', ' ', '_';
+	 * 
+	 * @param s
+	 *            string to verify
+	 */
+	static public boolean isValidId(String s) {
+		if (s.startsWith("cmis:"))
+			s = s.substring(5);
+
+		for (int i = 0; i < s.length(); i++) {
+			char c = s.charAt(i);
+			if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-'
+					|| c == '_' || c == ' '))
+				return false;
+		}
+		return true;
+	}
+
+	static public boolean isValidLocalName(String s) {
+		return isValidId(s);
+	}
+
+	/**
+	 * check whether id contains only valid characters Allowed are 'a'..'z',
+	 * 'A'..'Z', '0'..'9', '.', '-', ' ', '_';
+	 * 
+	 * @param s
+	 *            string to verify
+	 */
+	static public boolean isValidName(String s) {
+		for (int i = 0; i < s.length(); i++) {
+			char c = s.charAt(i);
+			if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-'
+					|| c == '_' || c == ' '))
+				return false;
+		}
+		return true;
+	}
+
+	static public boolean isValidNamespace(String s) {
+		return isValidId(s);
+	}
+
+	static public boolean isValidQueryName(String s) {
+		return isValidId(s);
+	}
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/RepositoryInfoCreator.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/RepositoryInfoCreator.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/RepositoryInfoCreator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/RepositoryInfoCreator.java Fri Apr 16 14:00:23 2010
@@ -21,13 +21,14 @@ package org.apache.chemistry.opencmis.in
 import org.apache.chemistry.opencmis.commons.api.RepositoryInfo;
 
 /**
- * A simple interface to create the repository info. This needs to be implemented by a client (like a unit
- * test) in class and the name of the class is passed to the session. The in-memory repository
- * creates an instance of this class to generate the repository info for its instance.
+ * A simple interface to create the repository info. This needs to be
+ * implemented by a client (like a unit test) in class and the name of the class
+ * is passed to the session. The in-memory repository creates an instance of
+ * this class to generate the repository info for its instance.
  * 
  * @author Jens
  * 
  */
 public interface RepositoryInfoCreator {
-  RepositoryInfo createRepositoryInfo();
+	RepositoryInfo createRepositoryInfo();
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeCreator.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/TypeCreator.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeCreator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeCreator.java Fri Apr 16 14:00:23 2010
@@ -23,14 +23,15 @@ import java.util.List;
 import org.apache.chemistry.opencmis.commons.api.TypeDefinition;
 
 /**
- * A simple interface to create a type system. This needs to be implemented by a client (like a unit
- * test) in class and the name of the class is passed to the session. The in-memory repository
- * creates an instance of this class to generate the type system for this instance
+ * A simple interface to create a type system. This needs to be implemented by a
+ * client (like a unit test) in class and the name of the class is passed to the
+ * session. The in-memory repository creates an instance of this class to
+ * generate the type system for this instance
  * 
  * @author Jens
  * 
  */
 public interface TypeCreator {
 
-  List<TypeDefinition> createTypesList();
+	List<TypeDefinition> createTypesList();
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.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/TypeManager.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.java Fri Apr 16 14:00:23 2010
@@ -39,193 +39,193 @@ import org.apache.chemistry.opencmis.inm
 import org.apache.chemistry.opencmis.inmemory.types.InMemoryRelationshipTypeDefinition;
 
 /**
- * Class that manages a type system for a repository types can be added, the inheritance can be
- * managed and type can be retrieved for a given type id.
+ * Class that manages a type system for a repository types can be added, the
+ * inheritance can be managed and type can be retrieved for a given type id.
  * 
  * @author Jens
  * 
  */
 public class TypeManager {
 
-  /**
-   * map from repository id to a types map
-   */
-  private Map<String, TypeDefinitionContainer> fTypesMap = new HashMap<String, TypeDefinitionContainer>();
-
-  /**
-   * return a type definition from the type definition id
-   * 
-   * @param typeId
-   *    id of the type definition
-   * @return
-   *    type definition for this id
-   */
-  public TypeDefinitionContainer getTypeById(String typeId) {
-    return fTypesMap.get(typeId);
-  }
-
-  /**
-   * return a list of all types known in this repository
-   * @return
-   */
-  public synchronized Collection<TypeDefinitionContainer> getTypeDefinitionList() {
-    
-    List<TypeDefinitionContainer> typeRoots = new ArrayList<TypeDefinitionContainer>();
-    // iterate types map and return a list collecting the root types:
-    for (TypeDefinitionContainer typeDef : fTypesMap.values()) {
-      if (typeDef.getTypeDefinition().getParentTypeId()==null)
-        typeRoots.add(typeDef);
-    }
-    
-    return typeRoots;
-  }
-
-  /**
-   * return a list of the root types as defined in the CMIS spec (for document,
-   * folder, policy and relationship
-   * 
-   * @return
-   */
-  public List<TypeDefinitionContainer> getRootTypes() {
-    // just take first repository
-    List<TypeDefinitionContainer> rootTypes = new ArrayList<TypeDefinitionContainer>();
-
-    for (TypeDefinitionContainer type : fTypesMap.values())
-      if (isRootType(type))
-        rootTypes.add(type);
-
-    return rootTypes;
-  }
-
-  /**
-   * Initialize the type system with the given types. This list must not contain the CMIS
-   * default types. The default type are always contained by default.
-   * 
-   * @param typesList
-   *    list of types to add to the repository
-   *    
-   */
-  public void initTypeSystem(List<TypeDefinition> typesList) {
-    
-    createCmisDefaultTypes();
-    
-    // merge all types from the list and build the correct hierachy with children
-    // and property lists
-    if (null != typesList) {
-      for (TypeDefinition typeDef : typesList)
-        addTypeDefinition(typeDef);
-    }
-
-  }
-  
-
-  /**
-   * Add a type to the type system. Add all properties from inherited types, add type to children of
-   * parent types.
-   * 
-   * @param repositoryId
-   *          repository to which the type is added
-   * @param cmisType
-   *          new type to add
-   */
-  public void addTypeDefinition(TypeDefinition cmisType) {
-    if (fTypesMap.containsKey(cmisType.getId()))
-      throw new RuntimeException("You cannot add type with id " + cmisType.getId()
-          + " because it already exists.");
-
-    TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(cmisType);
-
-    if (!fTypesMap.containsKey(cmisType.getParentTypeId()))
-      throw new RuntimeException("Cannot add type, because parent with id "
-          + cmisType.getParentTypeId() + " does not exist.");
-
-    // add new type to children of parent types
-    TypeDefinitionContainer parentTypeContainer = fTypesMap.get(cmisType.getParentTypeId());
-    parentTypeContainer.getChildren().add(typeContainer);
-
-    // recursively add inherited properties
-    Map<String, PropertyDefinition<?>> propDefs = typeContainer.getTypeDefinition()
-        .getPropertyDefinitions();
-    addInheritedProperties(propDefs, parentTypeContainer.getTypeDefinition());
-
-    // add type to type map
-    fTypesMap.put(cmisType.getId(), typeContainer);
-  }
-
-  /**
-   * Remove all types from the type system. After this call only the default CMIS types are present
-   * in the type system. Use this method with care, its mainly intended for unit tests
-   * 
-   * @param repositoryId
-   */
-  public void clearTypeSystem() {
-    fTypesMap.clear();
-    createCmisDefaultTypes();
-  }
-
-  private void addInheritedProperties(Map<String, PropertyDefinition<?>> propDefs,
-      TypeDefinition typeDefinition) {
-
-    if (null == typeDefinition)
-      return;
-
-    if (null != typeDefinition.getPropertyDefinitions())
-      addInheritedPropertyDefinitions(propDefs, typeDefinition.getPropertyDefinitions());
-      // propDefs.putAll(typeDefinition.getPropertyDefinitions());
-
-    TypeDefinitionContainer parentTypeContainer = fTypesMap.get(typeDefinition.getParentTypeId());
-    TypeDefinition parentType = (null == parentTypeContainer ? null : parentTypeContainer
-        .getTypeDefinition());
-    addInheritedProperties(propDefs, parentType);
-  }
-
-  private void addInheritedPropertyDefinitions(Map<String, PropertyDefinition<?>> propDefs,
-      Map<String, PropertyDefinition<?>> superPropDefs) {
-    
-    for (Entry<String, PropertyDefinition<?>> superProp: superPropDefs.entrySet() ) {
-      PropertyDefinition<?> superPropDef = superProp.getValue();
-      PropertyDefinition<?> clone = clonePropertyDefinition(superPropDef);
-      ((AbstractPropertyDefinition<?>)clone).setIsInherited(true);
-      propDefs.put(superProp.getKey(), clone);
-    }
-  }
-
-  private void createCmisDefaultTypes() {
-    List<TypeDefinition> typesList = DocumentTypeCreationHelper.createDefaultTypes();
-    for (TypeDefinition typeDef : typesList) {
-      TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(typeDef);
-      fTypesMap.put(typeDef.getId(), typeContainer);
-    }
-  }
-
-  private static boolean isRootType(TypeDefinitionContainer c) {
-    if (c.getTypeDefinition().equals(InMemoryFolderTypeDefinition.getRootFolderType())
-        || c.getTypeDefinition().equals(InMemoryDocumentTypeDefinition.getRootDocumentType())
-        || c.getTypeDefinition().equals(InMemoryRelationshipTypeDefinition.getRootRelationshipType())
-        || c.getTypeDefinition().equals(InMemoryPolicyTypeDefinition.getRootPolicyType()))
-      return true;
-    else
-      return false;
-  }
-  
-  private static PropertyDefinition<?> clonePropertyDefinition(PropertyDefinition<?> src) {
-    // use JAXB converter to easily clone a property definition
-    CmisPropertyDefinitionType tmp = Converter.convert(src);
-    PropertyDefinition<?> clone = Converter.convert(tmp);
-    return clone;
-  }
-  
-//  private static PropertyDefinition<?> clonePropertyDefinition2(PropertyDefinition<?> src)
-//      throws IOException, ClassNotFoundException {
-//    ByteArrayOutputStream bout = new ByteArrayOutputStream();
-//    ObjectOutputStream oout = new ObjectOutputStream(bout);
-//    oout.writeObject(src);
-//    byte[] bytes = bout.toByteArray();
-//
-//    ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
-//    ObjectInputStream oin = new ObjectInputStream(bin);
-//    PropertyDefinition<?> clone = (PropertyDefinition<?>) oin.readObject();
-//    return clone;
-//  }
+	/**
+	 * map from repository id to a types map
+	 */
+	private Map<String, TypeDefinitionContainer> fTypesMap = new HashMap<String, TypeDefinitionContainer>();
+
+	/**
+	 * return a type definition from the type definition id
+	 * 
+	 * @param typeId
+	 *            id of the type definition
+	 * @return type definition for this id
+	 */
+	public TypeDefinitionContainer getTypeById(String typeId) {
+		return fTypesMap.get(typeId);
+	}
+
+	/**
+	 * return a list of all types known in this repository
+	 * 
+	 * @return
+	 */
+	public synchronized Collection<TypeDefinitionContainer> getTypeDefinitionList() {
+
+		List<TypeDefinitionContainer> typeRoots = new ArrayList<TypeDefinitionContainer>();
+		// iterate types map and return a list collecting the root types:
+		for (TypeDefinitionContainer typeDef : fTypesMap.values()) {
+			if (typeDef.getTypeDefinition().getParentTypeId() == null)
+				typeRoots.add(typeDef);
+		}
+
+		return typeRoots;
+	}
+
+	/**
+	 * return a list of the root types as defined in the CMIS spec (for
+	 * document, folder, policy and relationship
+	 * 
+	 * @return
+	 */
+	public List<TypeDefinitionContainer> getRootTypes() {
+		// just take first repository
+		List<TypeDefinitionContainer> rootTypes = new ArrayList<TypeDefinitionContainer>();
+
+		for (TypeDefinitionContainer type : fTypesMap.values())
+			if (isRootType(type))
+				rootTypes.add(type);
+
+		return rootTypes;
+	}
+
+	/**
+	 * Initialize the type system with the given types. This list must not
+	 * contain the CMIS default types. The default type are always contained by
+	 * default.
+	 * 
+	 * @param typesList
+	 *            list of types to add to the repository
+	 * 
+	 */
+	public void initTypeSystem(List<TypeDefinition> typesList) {
+
+		createCmisDefaultTypes();
+
+		// merge all types from the list and build the correct hierachy with
+		// children
+		// and property lists
+		if (null != typesList) {
+			for (TypeDefinition typeDef : typesList)
+				addTypeDefinition(typeDef);
+		}
+
+	}
+
+	/**
+	 * Add a type to the type system. Add all properties from inherited types,
+	 * add type to children of parent types.
+	 * 
+	 * @param repositoryId
+	 *            repository to which the type is added
+	 * @param cmisType
+	 *            new type to add
+	 */
+	public void addTypeDefinition(TypeDefinition cmisType) {
+		if (fTypesMap.containsKey(cmisType.getId()))
+			throw new RuntimeException("You cannot add type with id " + cmisType.getId()
+					+ " because it already exists.");
+
+		TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(cmisType);
+
+		if (!fTypesMap.containsKey(cmisType.getParentTypeId()))
+			throw new RuntimeException("Cannot add type, because parent with id " + cmisType.getParentTypeId()
+					+ " does not exist.");
+
+		// add new type to children of parent types
+		TypeDefinitionContainer parentTypeContainer = fTypesMap.get(cmisType.getParentTypeId());
+		parentTypeContainer.getChildren().add(typeContainer);
+
+		// recursively add inherited properties
+		Map<String, PropertyDefinition<?>> propDefs = typeContainer.getTypeDefinition().getPropertyDefinitions();
+		addInheritedProperties(propDefs, parentTypeContainer.getTypeDefinition());
+
+		// add type to type map
+		fTypesMap.put(cmisType.getId(), typeContainer);
+	}
+
+	/**
+	 * Remove all types from the type system. After this call only the default
+	 * CMIS types are present in the type system. Use this method with care, its
+	 * mainly intended for unit tests
+	 * 
+	 * @param repositoryId
+	 */
+	public void clearTypeSystem() {
+		fTypesMap.clear();
+		createCmisDefaultTypes();
+	}
+
+	private void addInheritedProperties(Map<String, PropertyDefinition<?>> propDefs, TypeDefinition typeDefinition) {
+
+		if (null == typeDefinition)
+			return;
+
+		if (null != typeDefinition.getPropertyDefinitions())
+			addInheritedPropertyDefinitions(propDefs, typeDefinition.getPropertyDefinitions());
+		// propDefs.putAll(typeDefinition.getPropertyDefinitions());
+
+		TypeDefinitionContainer parentTypeContainer = fTypesMap.get(typeDefinition.getParentTypeId());
+		TypeDefinition parentType = (null == parentTypeContainer ? null : parentTypeContainer.getTypeDefinition());
+		addInheritedProperties(propDefs, parentType);
+	}
+
+	private void addInheritedPropertyDefinitions(Map<String, PropertyDefinition<?>> propDefs,
+			Map<String, PropertyDefinition<?>> superPropDefs) {
+
+		for (Entry<String, PropertyDefinition<?>> superProp : superPropDefs.entrySet()) {
+			PropertyDefinition<?> superPropDef = superProp.getValue();
+			PropertyDefinition<?> clone = clonePropertyDefinition(superPropDef);
+			((AbstractPropertyDefinition<?>) clone).setIsInherited(true);
+			propDefs.put(superProp.getKey(), clone);
+		}
+	}
+
+	private void createCmisDefaultTypes() {
+		List<TypeDefinition> typesList = DocumentTypeCreationHelper.createDefaultTypes();
+		for (TypeDefinition typeDef : typesList) {
+			TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(typeDef);
+			fTypesMap.put(typeDef.getId(), typeContainer);
+		}
+	}
+
+	private static boolean isRootType(TypeDefinitionContainer c) {
+		if (c.getTypeDefinition().equals(InMemoryFolderTypeDefinition.getRootFolderType())
+				|| c.getTypeDefinition().equals(InMemoryDocumentTypeDefinition.getRootDocumentType())
+				|| c.getTypeDefinition().equals(InMemoryRelationshipTypeDefinition.getRootRelationshipType())
+				|| c.getTypeDefinition().equals(InMemoryPolicyTypeDefinition.getRootPolicyType()))
+			return true;
+		else
+			return false;
+	}
+
+	private static PropertyDefinition<?> clonePropertyDefinition(PropertyDefinition<?> src) {
+		// use JAXB converter to easily clone a property definition
+		CmisPropertyDefinitionType tmp = Converter.convert(src);
+		PropertyDefinition<?> clone = Converter.convert(tmp);
+		return clone;
+	}
+
+	// private static PropertyDefinition<?>
+	// clonePropertyDefinition2(PropertyDefinition<?> src)
+	// throws IOException, ClassNotFoundException {
+	// ByteArrayOutputStream bout = new ByteArrayOutputStream();
+	// ObjectOutputStream oout = new ObjectOutputStream(bout);
+	// oout.writeObject(src);
+	// byte[] bytes = bout.toByteArray();
+	//
+	// ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
+	// ObjectInputStream oin = new ObjectInputStream(bin);
+	// PropertyDefinition<?> clone = (PropertyDefinition<?>) oin.readObject();
+	// return clone;
+	// }
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.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/TypeValidator.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java Fri Apr 16 14:00:23 2010
@@ -47,402 +47,364 @@ import org.apache.chemistry.opencmis.com
  */
 public class TypeValidator {
 
-  public static void validateRequiredSystemProperties(Properties properties) {
-    if (properties == null || properties.getProperties() == null)
-      throw new RuntimeException("Cannot create object, no properties are given");
-
-    if (!properties.getProperties().containsKey(PropertyIds.OBJECT_TYPE_ID))
-      throw new RuntimeException("Cannot create object, type id is missing");
-
-  }
-  
-  private static boolean isMandatorySystemProperty(String propertyId) {
-    // TODO Auto-generated method stub
-    return propertyId.equals(PropertyIds.OBJECT_TYPE_ID);
-  }
-
-  @SuppressWarnings("unchecked")
-  static <T> PropertyValidator<T> createPropertyValidator(PropertyDefinition<?> propDef) {
-    PropertyValidator<T> result = null;
-    if (propDef instanceof PropertyIntegerDefinition) {
-      result = (PropertyValidator<T>) new PropertyValidatorInteger();
-    }
-    else if (propDef instanceof PropertyDecimalDefinition) {
-      result = (PropertyValidator<T>) new PropertyValidatorDecimal();
-    }
-    else if (propDef instanceof PropertyStringDefinition) {
-      result = (PropertyValidator<T>) new PropertyValidatorString();
-    }
-    else {
-      result = new PropertyValidator<T>();
-    }
-    return result;
-  }
-
-  /*
-   * property validations: not readonly, all required are given, all are known in type
-   * cardinality: no multi values for single value, def min max check for Integer and Decimal,
-   * choices and in list Strings, max length set default value for omitted properties
-   */
-  static class PropertyValidator<T> {
-
-    public void validate(PropertyDefinition<T> propDef, PropertyData<T> prop) {
-
-      // check general constraints for all property types
-      if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1)
-        throw new CmisConstraintException("The property with id " + propDef.getId()
-            + " is single valued, but multiple values are passed " + prop.getValues());
-
-      if (propDef.getChoices() != null && propDef.getChoices().size() > 0) {
-        validateChoices(propDef, prop);
-      }
-    }
-
-    private void validateChoices(PropertyDefinition<T> propDef, PropertyData<T> prop) {
-      boolean isAllowedValue = true;
-      boolean hasMultiValueChoiceLists = false;
-      for (Choice<?> allowedValue : propDef.getChoices()) {
-        if (allowedValue.getValue() != null && allowedValue.getValue().size() > 1)
-          hasMultiValueChoiceLists = true;
-      }
-
-      // check if value is in list
-      if (hasMultiValueChoiceLists) {
-        // do a complex check if this combination of actual values is allowed
-        // check if value is in list
-        isAllowedValue = false;
-        List<?> actualValues = prop.getValues();
-        for (Choice<?> allowedValue : propDef.getChoices()) {
-          if (allowedValue.getValue().size() == actualValues.size()) {
-            boolean listValuesAreEqual = true;
-            Iterator<?> it = allowedValue.getValue().iterator();
-            for (Object actualValue : actualValues) {
-              if (!actualValue.equals(it.next())) {
-                listValuesAreEqual = false;
-                break;
-              }
-            }
-            if (listValuesAreEqual) {
-              isAllowedValue = true;
-            }
-          }
-
-          if (isAllowedValue)
-            break;
-        }
-
-      }
-      else {
-        List<T> allowedValues = getAllowedValues(propDef.getChoices());
-        // do a simpler check if all values are choice elements
-
-        for (Object actualValue : prop.getValues()) {
-          if (!allowedValues.contains(actualValue)) {
-            isAllowedValue = false;
-            break;
-          }
-        }
-      }
-
-      if (!isAllowedValue)
-        throw new CmisConstraintException("The property with id " + propDef.getId()
-            + " has a fixed set of values. Value(s) " + prop.getValues() + " are not listed.");
-    }
-    
-    /**
-     * Calculate the list of allowed values for this property definition by recursively
-     * collecting all choice values from property definition
-     * 
-     * @param propDef
-     *          property definition
-     * @return
-     *    list of possible values in complete hierarchy
-     */
-    private List<T> getAllowedValues (List<Choice<T>> choices) {
-      List<T> allowedValues = new ArrayList<T>(choices.size());
-      for (Choice<T> choice : choices) {
-        if (choice.getValue() != null)
-          allowedValues.add(choice.getValue().get(0));
-        if (choice.getChoice() != null) {
-          List<Choice<T>> x = choice.getChoice();
-          allowedValues.addAll(getAllowedValues(x));
-        }
-      }  
-      return allowedValues;
-    }
-  }
-
-  static class PropertyValidatorInteger extends PropertyValidator<BigInteger> {
-
-    public void validate(PropertyDefinition<BigInteger> propDef, PropertyData<BigInteger> property) {
-
-      super.validate(propDef, property);
-
-      BigInteger propVal = ((PropertyInteger) property).getFirstValue();
-      BigInteger minVal = ((PropertyIntegerDefinition) propDef).getMinValue();
-      BigInteger maxVal = ((PropertyIntegerDefinition) propDef).getMaxValue();
-
-      // check min and max
-      if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) {
-        throw new CmisConstraintException("For property with id " + propDef.getId() + " the value "
-            + propVal + " is less than the minimum value " + minVal);
-      }
-      if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) {
-        throw new CmisConstraintException("For property with id " + propDef.getId() + " the value "
-            + propVal + " is bigger than the maximum value " + maxVal);
-      }
-    }
-  }
-
-  static class PropertyValidatorDecimal extends PropertyValidator<BigDecimal> {
-
-    public void validate(PropertyDefinition<BigDecimal> propDef, PropertyData<BigDecimal> property) {
-
-      super.validate(propDef, property);
-
-      BigDecimal propVal = ((PropertyDecimal) property).getFirstValue();
-      BigDecimal minVal = ((PropertyDecimalDefinition) propDef).getMinValue();
-      BigDecimal maxVal = ((PropertyDecimalDefinition) propDef).getMaxValue();
-
-      // check min and max
-      if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) {
-        throw new CmisConstraintException("For property with id " + propDef.getId() + " the value "
-            + propVal + " is less than the minimum value " + minVal);
-      }
-      if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) {
-        throw new CmisConstraintException("For property with id " + propDef.getId() + " the value "
-            + propVal + " is bigger than the maximum value " + maxVal);
-      }
-    }
-  }
-
-  static class PropertyValidatorString extends PropertyValidator<String> {
-
-    public void validate(PropertyDefinition<String> propDef, PropertyData<String> property) {
-
-      super.validate(propDef, property);
-
-      long maxLen = ((PropertyStringDefinition) propDef).getMaxLength() == null ? -1
-          : ((PropertyStringDefinition) propDef).getMaxLength().longValue();
-      long len = ((PropertyData<String>) property).getFirstValue() == null ? -1
-          : ((PropertyData<String>) property).getFirstValue().length();
-
-      // check max length
-      if (maxLen >= 0 && len >= 0 && maxLen < len) {
-        throw new CmisConstraintException("For property with id " + propDef.getId()
-            + " the length of " + len + "is bigger than the maximum allowed length  " + maxLen);
-      }
-    }
-  }
-
-  @SuppressWarnings("unchecked")
-  public static <T> void validateProperties(TypeDefinition typeDef, Properties properties,
-      boolean checkMandatory) {
-
-    List<String> propDefsRequired = getMandatoryPropDefs(typeDef.getPropertyDefinitions());
-
-    for (PropertyData<?> prop : properties.getProperties().values()) {
-      String propertyId = prop.getId();
-      BaseTypeId baseTypeId = typeDef.getBaseTypeId();
-
-      if (isSystemProperty(baseTypeId, propertyId))
-        continue; // ignore system properties for validation
-
-      // Check if all properties are known in the type
-      if (!typeContainsProperty(typeDef, propertyId)) {
-        throw new CmisConstraintException("Unknown property " + propertyId + " in type "
-            + typeDef.getId());
-      }
-
-      // check that all mandatory attributes are present
-      if (checkMandatory && propDefsRequired.contains(propertyId))
-        propDefsRequired.remove(propertyId);
-
-      // check all type specific constraints:
-      PropertyDefinition<T> propDef = getPropertyDefinition(typeDef, propertyId);
-      PropertyValidator<T> validator = createPropertyValidator(propDef);
-      validator.validate(propDef, (PropertyData<T>) prop);
-    }
-
-    if (checkMandatory && !propDefsRequired.isEmpty())
-      throw new CmisConstraintException("The following mandatory properties are missing: "
-          + propDefsRequired);
-  }
-  
-  public static void validateVersionStateForCreate(DocumentTypeDefinition typeDef, VersioningState verState) {
-    if (null==verState)
-      return;
-    if (typeDef.isVersionable() && verState.equals(VersioningState.NONE) || 
-        ! typeDef.isVersionable() && !verState.equals(VersioningState.NONE)) {
-      throw new CmisConstraintException("The versioning state flag is imcompatible to the type definition.");
-    }
-
-  }
-  public static void validateAllowedChildObjectTypes(TypeDefinition childTypeDef, List<String> allowedChildTypes) {
-    
-    if (null == allowedChildTypes)
-      return; // all types are allowed
-    
-    for (String allowedChildType : allowedChildTypes ) {
-      if (allowedChildType.equals(childTypeDef.getId()))
-        return;
-    }
-    throw new RuntimeException("The requested type " + childTypeDef.getId() + " is not allowed in this folder");    
-  }
-
-  private static List<String> getMandatoryPropDefs(Map<String, PropertyDefinition<?>> propDefs) {
-    List<String> res = new ArrayList<String>();
-    if (null != propDefs) {
-      for (PropertyDefinition<?> propDef : propDefs.values()) {
-        if (propDef.isRequired() && !isMandatorySystemProperty(propDef.getId()) )
-          res.add(propDef.getId());
-      }
-    }
-    return res;
-  }
-
-  public static boolean typeContainsProperty(TypeDefinition typeDef, String propertyId) {
-
-    Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
-    if (null == propDefs)
-      return false;
-    
-    PropertyDefinition<?> propDef = propDefs.get(propertyId);
-    
-    if (null == propDef)
-      return false; // unknown property id in this type
-    else
-      return true;
-  }
-
-  @SuppressWarnings("unchecked")
-  private static<T> PropertyDefinition<T> getPropertyDefinition(TypeDefinition typeDef,
-      String propertyId) {
-
-    Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
-    if (null == propDefs)
-      return null;
-    
-    PropertyDefinition<?> propDef = propDefs.get(propertyId);
-    
-    if (null == propDef)
-      return null; // not found
-    else
-      return (PropertyDefinition<T>)propDef;
-  }
-
-  private static boolean isSystemProperty(BaseTypeId baseTypeId, String propertyId) {
-
-    if (propertyId.equals(PropertyIds.NAME)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.OBJECT_ID)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.OBJECT_TYPE_ID)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.BASE_TYPE_ID)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.CREATED_BY)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.CREATION_DATE)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.LAST_MODIFIED_BY)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.LAST_MODIFICATION_DATE)) {
-      return true;
-    }
-    else if (propertyId.equals(PropertyIds.CHANGE_TOKEN)) {
-      return true;
-    }
-
-    if (baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT)) {
-      if (propertyId.equals(PropertyIds.IS_IMMUTABLE)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.IS_LATEST_VERSION)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.IS_MAJOR_VERSION)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.IS_LATEST_MAJOR_VERSION)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.VERSION_LABEL)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.CHECKIN_COMMENT)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.CONTENT_STREAM_ID)) {
-        return true;
-      }
-      else {
-        return false;
-      }
-    }
-    else if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER)) {
-      if (propertyId.equals(PropertyIds.PARENT_ID)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.PATH)) {
-        return true;
-      }
-      else {
-        return false;
-      }
-    }
-    else if (baseTypeId.equals(BaseTypeId.CMIS_POLICY)) {
-      if (propertyId.equals(PropertyIds.SOURCE_ID)) {
-        return true;
-      }
-      else if (propertyId.equals(PropertyIds.TARGET_ID)) {
-        return true;
-      }
-      else {
-        return false;
-      }
-    }
-    else { // relationship
-      if (propertyId.equals(PropertyIds.POLICY_TEXT)) {
-        return true;
-      }
-      else {
-        return false;
-      }
-    }
-  }
+	public static void validateRequiredSystemProperties(Properties properties) {
+		if (properties == null || properties.getProperties() == null)
+			throw new RuntimeException("Cannot create object, no properties are given");
+
+		if (!properties.getProperties().containsKey(PropertyIds.OBJECT_TYPE_ID))
+			throw new RuntimeException("Cannot create object, type id is missing");
+
+	}
+
+	private static boolean isMandatorySystemProperty(String propertyId) {
+		// TODO Auto-generated method stub
+		return propertyId.equals(PropertyIds.OBJECT_TYPE_ID);
+	}
+
+	@SuppressWarnings("unchecked")
+	static <T> PropertyValidator<T> createPropertyValidator(PropertyDefinition<?> propDef) {
+		PropertyValidator<T> result = null;
+		if (propDef instanceof PropertyIntegerDefinition) {
+			result = (PropertyValidator<T>) new PropertyValidatorInteger();
+		} else if (propDef instanceof PropertyDecimalDefinition) {
+			result = (PropertyValidator<T>) new PropertyValidatorDecimal();
+		} else if (propDef instanceof PropertyStringDefinition) {
+			result = (PropertyValidator<T>) new PropertyValidatorString();
+		} else {
+			result = new PropertyValidator<T>();
+		}
+		return result;
+	}
+
+	/*
+	 * property validations: not readonly, all required are given, all are known
+	 * in type cardinality: no multi values for single value, def min max check
+	 * for Integer and Decimal, choices and in list Strings, max length set
+	 * default value for omitted properties
+	 */
+	static class PropertyValidator<T> {
+
+		public void validate(PropertyDefinition<T> propDef, PropertyData<T> prop) {
+
+			// check general constraints for all property types
+			if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1)
+				throw new CmisConstraintException("The property with id " + propDef.getId()
+						+ " is single valued, but multiple values are passed " + prop.getValues());
+
+			if (propDef.getChoices() != null && propDef.getChoices().size() > 0) {
+				validateChoices(propDef, prop);
+			}
+		}
+
+		private void validateChoices(PropertyDefinition<T> propDef, PropertyData<T> prop) {
+			boolean isAllowedValue = true;
+			boolean hasMultiValueChoiceLists = false;
+			for (Choice<?> allowedValue : propDef.getChoices()) {
+				if (allowedValue.getValue() != null && allowedValue.getValue().size() > 1)
+					hasMultiValueChoiceLists = true;
+			}
+
+			// check if value is in list
+			if (hasMultiValueChoiceLists) {
+				// do a complex check if this combination of actual values is
+				// allowed
+				// check if value is in list
+				isAllowedValue = false;
+				List<?> actualValues = prop.getValues();
+				for (Choice<?> allowedValue : propDef.getChoices()) {
+					if (allowedValue.getValue().size() == actualValues.size()) {
+						boolean listValuesAreEqual = true;
+						Iterator<?> it = allowedValue.getValue().iterator();
+						for (Object actualValue : actualValues) {
+							if (!actualValue.equals(it.next())) {
+								listValuesAreEqual = false;
+								break;
+							}
+						}
+						if (listValuesAreEqual) {
+							isAllowedValue = true;
+						}
+					}
+
+					if (isAllowedValue)
+						break;
+				}
+
+			} else {
+				List<T> allowedValues = getAllowedValues(propDef.getChoices());
+				// do a simpler check if all values are choice elements
+
+				for (Object actualValue : prop.getValues()) {
+					if (!allowedValues.contains(actualValue)) {
+						isAllowedValue = false;
+						break;
+					}
+				}
+			}
+
+			if (!isAllowedValue)
+				throw new CmisConstraintException("The property with id " + propDef.getId()
+						+ " has a fixed set of values. Value(s) " + prop.getValues() + " are not listed.");
+		}
+
+		/**
+		 * Calculate the list of allowed values for this property definition by
+		 * recursively collecting all choice values from property definition
+		 * 
+		 * @param propDef
+		 *            property definition
+		 * @return list of possible values in complete hierarchy
+		 */
+		private List<T> getAllowedValues(List<Choice<T>> choices) {
+			List<T> allowedValues = new ArrayList<T>(choices.size());
+			for (Choice<T> choice : choices) {
+				if (choice.getValue() != null)
+					allowedValues.add(choice.getValue().get(0));
+				if (choice.getChoice() != null) {
+					List<Choice<T>> x = choice.getChoice();
+					allowedValues.addAll(getAllowedValues(x));
+				}
+			}
+			return allowedValues;
+		}
+	}
+
+	static class PropertyValidatorInteger extends PropertyValidator<BigInteger> {
+
+		public void validate(PropertyDefinition<BigInteger> propDef, PropertyData<BigInteger> property) {
+
+			super.validate(propDef, property);
+
+			BigInteger propVal = ((PropertyInteger) property).getFirstValue();
+			BigInteger minVal = ((PropertyIntegerDefinition) propDef).getMinValue();
+			BigInteger maxVal = ((PropertyIntegerDefinition) propDef).getMaxValue();
+
+			// check min and max
+			if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) {
+				throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal
+						+ " is less than the minimum value " + minVal);
+			}
+			if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) {
+				throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal
+						+ " is bigger than the maximum value " + maxVal);
+			}
+		}
+	}
+
+	static class PropertyValidatorDecimal extends PropertyValidator<BigDecimal> {
+
+		public void validate(PropertyDefinition<BigDecimal> propDef, PropertyData<BigDecimal> property) {
+
+			super.validate(propDef, property);
+
+			BigDecimal propVal = ((PropertyDecimal) property).getFirstValue();
+			BigDecimal minVal = ((PropertyDecimalDefinition) propDef).getMinValue();
+			BigDecimal maxVal = ((PropertyDecimalDefinition) propDef).getMaxValue();
+
+			// check min and max
+			if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) {
+				throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal
+						+ " is less than the minimum value " + minVal);
+			}
+			if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) {
+				throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal
+						+ " is bigger than the maximum value " + maxVal);
+			}
+		}
+	}
+
+	static class PropertyValidatorString extends PropertyValidator<String> {
+
+		public void validate(PropertyDefinition<String> propDef, PropertyData<String> property) {
+
+			super.validate(propDef, property);
+
+			long maxLen = ((PropertyStringDefinition) propDef).getMaxLength() == null ? -1
+					: ((PropertyStringDefinition) propDef).getMaxLength().longValue();
+			long len = ((PropertyData<String>) property).getFirstValue() == null ? -1
+					: ((PropertyData<String>) property).getFirstValue().length();
+
+			// check max length
+			if (maxLen >= 0 && len >= 0 && maxLen < len) {
+				throw new CmisConstraintException("For property with id " + propDef.getId() + " the length of " + len
+						+ "is bigger than the maximum allowed length  " + maxLen);
+			}
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	public static <T> void validateProperties(TypeDefinition typeDef, Properties properties, boolean checkMandatory) {
+
+		List<String> propDefsRequired = getMandatoryPropDefs(typeDef.getPropertyDefinitions());
+
+		for (PropertyData<?> prop : properties.getProperties().values()) {
+			String propertyId = prop.getId();
+			BaseTypeId baseTypeId = typeDef.getBaseTypeId();
+
+			if (isSystemProperty(baseTypeId, propertyId))
+				continue; // ignore system properties for validation
+
+			// Check if all properties are known in the type
+			if (!typeContainsProperty(typeDef, propertyId)) {
+				throw new CmisConstraintException("Unknown property " + propertyId + " in type " + typeDef.getId());
+			}
+
+			// check that all mandatory attributes are present
+			if (checkMandatory && propDefsRequired.contains(propertyId))
+				propDefsRequired.remove(propertyId);
+
+			// check all type specific constraints:
+			PropertyDefinition<T> propDef = getPropertyDefinition(typeDef, propertyId);
+			PropertyValidator<T> validator = createPropertyValidator(propDef);
+			validator.validate(propDef, (PropertyData<T>) prop);
+		}
+
+		if (checkMandatory && !propDefsRequired.isEmpty())
+			throw new CmisConstraintException("The following mandatory properties are missing: " + propDefsRequired);
+	}
+
+	public static void validateVersionStateForCreate(DocumentTypeDefinition typeDef, VersioningState verState) {
+		if (null == verState)
+			return;
+		if (typeDef.isVersionable() && verState.equals(VersioningState.NONE) || !typeDef.isVersionable()
+				&& !verState.equals(VersioningState.NONE)) {
+			throw new CmisConstraintException("The versioning state flag is imcompatible to the type definition.");
+		}
+
+	}
+
+	public static void validateAllowedChildObjectTypes(TypeDefinition childTypeDef, List<String> allowedChildTypes) {
+
+		if (null == allowedChildTypes)
+			return; // all types are allowed
+
+		for (String allowedChildType : allowedChildTypes) {
+			if (allowedChildType.equals(childTypeDef.getId()))
+				return;
+		}
+		throw new RuntimeException("The requested type " + childTypeDef.getId() + " is not allowed in this folder");
+	}
+
+	private static List<String> getMandatoryPropDefs(Map<String, PropertyDefinition<?>> propDefs) {
+		List<String> res = new ArrayList<String>();
+		if (null != propDefs) {
+			for (PropertyDefinition<?> propDef : propDefs.values()) {
+				if (propDef.isRequired() && !isMandatorySystemProperty(propDef.getId()))
+					res.add(propDef.getId());
+			}
+		}
+		return res;
+	}
+
+	public static boolean typeContainsProperty(TypeDefinition typeDef, String propertyId) {
+
+		Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
+		if (null == propDefs)
+			return false;
+
+		PropertyDefinition<?> propDef = propDefs.get(propertyId);
+
+		if (null == propDef)
+			return false; // unknown property id in this type
+		else
+			return true;
+	}
+
+	@SuppressWarnings("unchecked")
+	private static <T> PropertyDefinition<T> getPropertyDefinition(TypeDefinition typeDef, String propertyId) {
+
+		Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
+		if (null == propDefs)
+			return null;
+
+		PropertyDefinition<?> propDef = propDefs.get(propertyId);
+
+		if (null == propDef)
+			return null; // not found
+		else
+			return (PropertyDefinition<T>) propDef;
+	}
+
+	private static boolean isSystemProperty(BaseTypeId baseTypeId, String propertyId) {
+
+		if (propertyId.equals(PropertyIds.NAME)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.OBJECT_ID)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.OBJECT_TYPE_ID)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.BASE_TYPE_ID)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.CREATED_BY)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.CREATION_DATE)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.LAST_MODIFIED_BY)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.LAST_MODIFICATION_DATE)) {
+			return true;
+		} else if (propertyId.equals(PropertyIds.CHANGE_TOKEN)) {
+			return true;
+		}
+
+		if (baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT)) {
+			if (propertyId.equals(PropertyIds.IS_IMMUTABLE)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.IS_LATEST_VERSION)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.IS_MAJOR_VERSION)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.IS_LATEST_MAJOR_VERSION)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.VERSION_LABEL)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.CHECKIN_COMMENT)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.CONTENT_STREAM_ID)) {
+				return true;
+			} else {
+				return false;
+			}
+		} else if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER)) {
+			if (propertyId.equals(PropertyIds.PARENT_ID)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.PATH)) {
+				return true;
+			} else {
+				return false;
+			}
+		} else if (baseTypeId.equals(BaseTypeId.CMIS_POLICY)) {
+			if (propertyId.equals(PropertyIds.SOURCE_ID)) {
+				return true;
+			} else if (propertyId.equals(PropertyIds.TARGET_ID)) {
+				return true;
+			} else {
+				return false;
+			}
+		} else { // relationship
+			if (propertyId.equals(PropertyIds.POLICY_TEXT)) {
+				return true;
+			} else {
+				return false;
+			}
+		}
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/AbstractService.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/clientprovider/AbstractService.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/AbstractService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/AbstractService.java Fri Apr 16 14:00:23 2010
@@ -21,19 +21,19 @@ package org.apache.chemistry.opencmis.in
 import org.apache.chemistry.opencmis.inmemory.server.RuntimeContext;
 import org.apache.chemistry.opencmis.server.spi.CallContext;
 
-public class AbstractService  {
-  protected CallContext fDummyCallContext;
-  
-  protected AbstractService() {
-    // use an existing context if there is one, otherwise use null
-    fDummyCallContext = RuntimeContext.getCurrentContext(); 
-  }
-  
-  public void setCallContext(CallContext ctx) {
-    fDummyCallContext = ctx;
-  }
+public class AbstractService {
+	protected CallContext fDummyCallContext;
 
-  public CallContext getCallContext() {
-    return fDummyCallContext;
-  }
+	protected AbstractService() {
+		// use an existing context if there is one, otherwise use null
+		fDummyCallContext = RuntimeContext.getCurrentContext();
+	}
+
+	public void setCallContext(CallContext ctx) {
+		fDummyCallContext = ctx;
+	}
+
+	public CallContext getCallContext() {
+		return fDummyCallContext;
+	}
 }



Mime
View raw message