View Javadoc

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  package org.apache.chemistry.opencmis.client.runtime.objecttype;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.chemistry.opencmis.client.api.ItemIterable;
26  import org.apache.chemistry.opencmis.client.api.ObjectType;
27  import org.apache.chemistry.opencmis.client.api.RelationshipType;
28  import org.apache.chemistry.opencmis.client.api.Session;
29  import org.apache.chemistry.opencmis.client.api.Tree;
30  import org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
31  import org.apache.chemistry.opencmis.commons.impl.dataobjects.RelationshipTypeDefinitionImpl;
32  
33  /**
34   * Relationship type.
35   */
36  public class RelationshipTypeImpl extends RelationshipTypeDefinitionImpl implements RelationshipType, Serializable {
37  
38      private static final long serialVersionUID = 1L;
39  
40      private final ObjectTypeHelper helper;
41      private List<ObjectType> allowedSourceTypes;
42      private List<ObjectType> allowedTargetTypes;
43  
44      public RelationshipTypeImpl(Session session, RelationshipTypeDefinition typeDefinition) {
45          assert session != null;
46          assert typeDefinition != null;
47  
48          initialize(typeDefinition);
49          setAllowedSourceTypes(typeDefinition.getAllowedSourceTypeIds());
50          setAllowedTargetTypes(typeDefinition.getAllowedTargetTypeIds());
51          helper = new ObjectTypeHelper(session, this);
52      }
53  
54      @Override
55      public ObjectType getBaseType() {
56          return helper.getBaseType();
57      }
58  
59      @Override
60      public ItemIterable<ObjectType> getChildren() {
61          return helper.getChildren();
62      }
63  
64      @Override
65      public List<Tree<ObjectType>> getDescendants(int depth) {
66          return helper.getDescendants(depth);
67      }
68  
69      @Override
70      public ObjectType getParentType() {
71          return helper.getParentType();
72      }
73  
74      @Override
75      public boolean isBaseType() {
76          return helper.isBaseType();
77      }
78  
79      @Override
80      public List<ObjectType> getAllowedSourceTypes() {
81          if (allowedSourceTypes == null) {
82              List<String> ids = getAllowedSourceTypeIds();
83              List<ObjectType> types = new ArrayList<ObjectType>(ids == null ? 0 : ids.size());
84              if (ids != null) {
85                  for (String id : ids) {
86                      types.add(helper.getSession().getTypeDefinition(id));
87                  }
88              }
89              allowedSourceTypes = types;
90          }
91          return allowedSourceTypes;
92      }
93  
94      @Override
95      public List<ObjectType> getAllowedTargetTypes() {
96          if (allowedTargetTypes == null) {
97              List<String> ids = getAllowedTargetTypeIds();
98              List<ObjectType> types = new ArrayList<ObjectType>(ids == null ? 0 : ids.size());
99              if (ids != null) {
100                 for (String id : ids) {
101                     types.add(helper.getSession().getTypeDefinition(id));
102                 }
103             }
104             allowedTargetTypes = types;
105         }
106         return allowedTargetTypes;
107     }
108 
109 }