This project has retired. For details please refer to its Attic page.
ObjectTypeHelper 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.List;
23  
24  import org.apache.chemistry.opencmis.client.api.ItemIterable;
25  import org.apache.chemistry.opencmis.client.api.ObjectType;
26  import org.apache.chemistry.opencmis.client.api.Session;
27  import org.apache.chemistry.opencmis.client.api.Tree;
28  
29  /**
30   * Helper for object types, containing session-related info.
31   * <p>
32   * This is needed because Java doesn't support multiple inheritance.
33   */
34  public class ObjectTypeHelper implements Serializable {
35  
36      private static final long serialVersionUID = 1L;
37  
38      private final Session session;
39      private final ObjectType objectType;
40      private ObjectType baseType;
41      private ObjectType parentType;
42  
43      public ObjectTypeHelper(Session session, ObjectType objectType) {
44          this.session = session;
45          this.objectType = objectType;
46      }
47  
48      public Session getSession() {
49          return session;
50      }
51  
52      public boolean isBaseType() {
53          return objectType.getParentTypeId() == null || objectType.getParentTypeId().length() == 0;
54      }
55  
56      public ObjectType getBaseType() {
57          if (isBaseType()) {
58              return null;
59          }
60          if (baseType != null) {
61              return baseType;
62          }
63          if (objectType.getBaseTypeId() == null) {
64              return null;
65          }
66          baseType = session.getTypeDefinition(objectType.getBaseTypeId().value());
67          return baseType;
68      }
69  
70      public ObjectType getParentType() {
71          if (parentType != null) {
72              return parentType;
73          }
74          if (objectType.getParentTypeId() == null || objectType.getParentTypeId().length() == 0) {
75              return null;
76          }
77          parentType = session.getTypeDefinition(objectType.getParentTypeId());
78          return parentType;
79      }
80  
81      public ItemIterable<ObjectType> getChildren() {
82          return session.getTypeChildren(objectType.getId(), true);
83      }
84  
85      public List<Tree<ObjectType>> getDescendants(int depth) {
86          return session.getTypeDescendants(objectType.getId(), depth, true);
87      }
88  }