1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.PolicyTypeDefinitionImpl;
29 import org.apache.chemistry.opencmis.inmemory.NameValidator;
30
31 public class InMemoryPolicyTypeDefinition extends PolicyTypeDefinitionImpl {
32
33 private static final long serialVersionUID = 1L;
34 private static final InMemoryPolicyTypeDefinition POLICY_TYPE = new InMemoryPolicyTypeDefinition();
35
36 public static InMemoryPolicyTypeDefinition getRootPolicyType() {
37 return POLICY_TYPE;
38 }
39
40
41 public InMemoryPolicyTypeDefinition() {
42 init(BaseTypeId.CMIS_POLICY.value(), "CMIS Policy");
43 setParentTypeId(null);
44
45 Map<String, PropertyDefinition<?>> props = getPropertyDefinitions();
46 DocumentTypeCreationHelper.setBasicPolicyPropertyDefinitions(props);
47 }
48
49 public InMemoryPolicyTypeDefinition(String id, String displayName) {
50 init(id, displayName);
51 setParentTypeId(POLICY_TYPE.getId());
52 }
53
54 public InMemoryPolicyTypeDefinition(String id, String displayName, InMemoryPolicyTypeDefinition parentType) {
55
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 policy definition");
61 }
62 setParentTypeId(parentType.getId());
63 }
64
65
66
67
68
69
70
71
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_POLICY);
83 setId(id);
84 if (displayName == null) {
85 displayName = id;
86 }
87 setDisplayName(displayName);
88
89 setDescription("Description of " + getDisplayName() + " Type");
90 setLocalName(id);
91 setLocalNamespace("local");
92 setQueryName(id);
93 setIsControllableAcl(false);
94 setIsControllablePolicy(false);
95 setIsCreatable(true);
96 setIsFileable(true);
97 setIsFulltextIndexed(false);
98 setIsIncludedInSupertypeQuery(true);
99 setIsQueryable(false);
100
101
102
103
104
105
106
107
108
109 Map<String, PropertyDefinition<?>> props = new HashMap<String, PropertyDefinition<?>>();
110 setPropertyDefinitions(props);
111
112
113 }
114 }