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