This project has retired. For details please refer to its Attic page.
InMemoryDocumentTypeDefinition 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.enums.ContentStreamAllowed;
28  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
29  import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
30  import org.apache.chemistry.opencmis.inmemory.NameValidator;
31  
32  /**
33   * A small convenience class simplifying document type creation
34   */
35  public class InMemoryDocumentTypeDefinition extends DocumentTypeDefinitionImpl {
36  
37      private static final long serialVersionUID = 1L;
38      private static final InMemoryDocumentTypeDefinition DOCUMENT_TYPE = new InMemoryDocumentTypeDefinition();
39  
40      public static InMemoryDocumentTypeDefinition getRootDocumentType() {
41          return DOCUMENT_TYPE;
42      }
43  
44      /* This constructor is just for creating the root document */
45      public InMemoryDocumentTypeDefinition() {
46          init(BaseTypeId.CMIS_DOCUMENT.value(), "CMIS Document");
47          setParentTypeId(null);
48          // set base properties
49          Map<String, PropertyDefinition<?>> props = getPropertyDefinitions();
50          DocumentTypeCreationHelper.setBasicDocumentPropertyDefinitions(props);
51      }
52  
53      public InMemoryDocumentTypeDefinition(String id, String displayName) {
54          init(id, displayName);
55          setParentTypeId(DOCUMENT_TYPE.getId());
56      }
57  
58      public InMemoryDocumentTypeDefinition(String id, String displayName, InMemoryDocumentTypeDefinition parentType) {
59          // get root type
60          init(id, displayName);
61          if (parentType != null) {
62              setBaseTypeId(parentType.getBaseTypeId());
63          } else {
64              throw new IllegalArgumentException("Must provide a parent type when creating a document type definition");
65          }
66          setParentTypeId(parentType.getId());
67      }
68  
69      /**
70       * Set the property definitions for this type. The parameter
71       * propertyDefinitions should only contain the custom property definitions
72       * for this type. The standard property definitions are added automatically.
73       *
74       * @see org.apache.opencmis.commons.impl.dataobjects.AbstractTypeDefinition#
75       * setPropertyDefinitions(java.util.Map)
76       */
77      public void addCustomPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
78          DocumentTypeCreationHelper.mergePropertyDefinitions(getPropertyDefinitions(), propertyDefinitions);
79      }
80  
81      private void init(String id, String displayName) {
82          if (!NameValidator.isValidId(id)) {
83              throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_ID);
84          }
85  
86          setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
87          setId(id);
88          if (displayName == null) {
89              displayName = id;
90          }
91          setDisplayName(displayName);
92          // create some suitable defaults for convenience
93          setDescription("Description of " + getDisplayName() + " Type");
94          setLocalName(id);
95          setLocalNamespace("local");
96          setQueryName(id);
97          setIsControllableAcl(true);
98          setIsControllablePolicy(false);
99          setIsCreatable(true);
100         setIsFileable(true);
101         setIsFulltextIndexed(false);
102         setIsIncludedInSupertypeQuery(true);
103         setIsQueryable(false);
104 
105         // TODO: add with CMIS 1.1 extensions
106 //        TypeMutabilityCapabilitiesImpl caps = new TypeMutabilityCapabilitiesImpl();
107 //        caps.setSupportsCreate(createAndDeletable);
108 //        caps.setSupportsUpdate(false);
109 //        caps.setSupportsDelete(createAndDeletable);
110 //        super.setTypeMutability(caps);
111 
112         Map<String, PropertyDefinition<?>> props = new HashMap<String, PropertyDefinition<?>>();
113         setPropertyDefinitions(props); // set initial empty set of properties
114 
115         // document specifics:
116         setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
117         setIsVersionable(false);
118     }
119 }