This project has retired. For details please refer to its Attic page.
InMemoryFolderTypeDefinition xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.chemistry.opencmis.inmemory.types;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
26  import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
27  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
28  import org.apache.chemistry.opencmis.commons.impl.dataobjects.FolderTypeDefinitionImpl;
29  import org.apache.chemistry.opencmis.inmemory.NameValidator;
30  
31  public class InMemoryFolderTypeDefinition extends FolderTypeDefinitionImpl {
32  
33      private static final long serialVersionUID = 1L;
34      private static final InMemoryFolderTypeDefinition FOLDER_TYPE = new InMemoryFolderTypeDefinition();
35  
36      public static InMemoryFolderTypeDefinition getRootFolderType() {
37          return FOLDER_TYPE;
38      }
39  
40      /* This constructor is just for creating the root document */
41      public InMemoryFolderTypeDefinition() {
42          init(BaseTypeId.CMIS_FOLDER.value(), "CMIS Folder");
43          setParentTypeId(null);
44          // set base properties
45          Map<String, PropertyDefinition<?>> props = getPropertyDefinitions();
46          DocumentTypeCreationHelper.setBasicFolderPropertyDefinitions(props);
47      }
48  
49      public InMemoryFolderTypeDefinition(String id, String displayName) {
50          init(id, displayName);
51          setParentTypeId(FOLDER_TYPE.getId());
52      }
53  
54      public InMemoryFolderTypeDefinition(String id, String displayName, InMemoryFolderTypeDefinition parentType) {
55          // get root type
56          init(id, displayName);
57          if (parentType != null) {
58              setBaseTypeId(parentType.getBaseTypeId());
59          } else {
60              throw new IllegalArgumentException("Must provide a parent type when creating a folder type definition");
61          }
62          setParentTypeId(parentType.getId());
63      }
64  
65      /**
66       * Set the property definitions for this type. The parameter
67       * propertyDefinitions should only contain the custom property definitions
68       * for this type. The standard property definitions are added automatically.
69       *
70       * @see org.apache.opencmis.commons.impl.dataobjects.AbstractTypeDefinition#
71       * setPropertyDefinitions(java.util.Map)
72       */
73      public void addCustomPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
74          DocumentTypeCreationHelper.mergePropertyDefinitions(getPropertyDefinitions(), propertyDefinitions);
75      }
76  
77      private void init(String id, String displayName) {
78          if (!NameValidator.isValidId(id)) {
79              throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
80          }
81  
82          setBaseTypeId(BaseTypeId.CMIS_FOLDER);
83          setId(id);
84          if (displayName == null) {
85              displayName = id;
86          }
87          setDisplayName(displayName);
88          // create some suitable defaults for convenience
89          setDescription("Description of " + getDisplayName() + " Type");
90          setLocalName(id);
91          setLocalNamespace("local");
92          setQueryName(id);
93          setIsControllableAcl(true);
94          setIsControllablePolicy(false);
95          setIsCreatable(true);
96          setIsFileable(true);
97          setIsFulltextIndexed(false);
98          setIsIncludedInSupertypeQuery(true);
99          setIsQueryable(false);
100 
101         // TODO: add with CMIS 1.1 extensions
102 //        TypeMutabilityCapabilitiesImpl caps = new TypeMutabilityCapabilitiesImpl();
103 //        caps.setSupportsCreate(createAndDeletable);
104 //        caps.setSupportsUpdate(false);
105 //        caps.setSupportsDelete(createAndDeletable);
106 //        super.setTypeMutability(caps);
107 
108         Map<String, PropertyDefinition<?>> props = new HashMap<String, PropertyDefinition<?>>();
109         setPropertyDefinitions(props); // set initial empty set of properties
110     }
111 }