This project has retired. For details please refer to its Attic page.
RelationshipTypeImpl 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  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          initialize(typeDefinition);
46          setAllowedSourceTypes(typeDefinition.getAllowedSourceTypeIds());
47          setAllowedTargetTypes(typeDefinition.getAllowedTargetTypeIds());
48          helper = new ObjectTypeHelper(session, this);
49      }
50  
51      public ObjectType getBaseType() {
52          return helper.getBaseType();
53      }
54  
55      public ItemIterable<ObjectType> getChildren() {
56          return helper.getChildren();
57      }
58  
59      public List<Tree<ObjectType>> getDescendants(int depth) {
60          return helper.getDescendants(depth);
61      }
62  
63      public ObjectType getParentType() {
64          return helper.getParentType();
65      }
66  
67      public boolean isBaseType() {
68          return helper.isBaseType();
69      }
70  
71      public List<ObjectType> getAllowedSourceTypes() {
72          if (allowedSourceTypes == null) {
73              List<String> ids = getAllowedSourceTypeIds();
74              List<ObjectType> types = new ArrayList<ObjectType>(ids == null ? 0 : ids.size());
75              if (ids != null) {
76                  for (String id : ids) {
77                      types.add(helper.getSession().getTypeDefinition(id));
78                  }
79              }
80              allowedSourceTypes = types;
81          }
82          return allowedSourceTypes;
83      }
84  
85      public List<ObjectType> getAllowedTargetTypes() {
86          if (allowedTargetTypes == null) {
87              List<String> ids = getAllowedTargetTypeIds();
88              List<ObjectType> types = new ArrayList<ObjectType>(ids == null ? 0 : ids.size());
89              if (ids != null) {
90                  for (String id : ids) {
91                      types.add(helper.getSession().getTypeDefinition(id));
92                  }
93              }
94              allowedTargetTypes = types;
95          }
96          return allowedTargetTypes;
97      }
98  
99  }