This project has retired. For details please refer to its Attic page.
RelationshipImpl 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;
20  
21  import org.apache.chemistry.opencmis.client.api.CmisObject;
22  import org.apache.chemistry.opencmis.client.api.ObjectId;
23  import org.apache.chemistry.opencmis.client.api.ObjectType;
24  import org.apache.chemistry.opencmis.client.api.OperationContext;
25  import org.apache.chemistry.opencmis.client.api.Relationship;
26  import org.apache.chemistry.opencmis.client.api.TransientCmisObject;
27  import org.apache.chemistry.opencmis.client.api.TransientRelationship;
28  import org.apache.chemistry.opencmis.commons.PropertyIds;
29  import org.apache.chemistry.opencmis.commons.data.ObjectData;
30  
31  public class RelationshipImpl extends AbstractCmisObject implements Relationship {
32  
33      private static final long serialVersionUID = 1L;
34  
35      /**
36       * Constructor.
37       */
38      public RelationshipImpl(SessionImpl session, ObjectType objectType, ObjectData objectData, OperationContext context) {
39          initialize(session, objectType, objectData, context);
40      }
41  
42      @Override
43      protected TransientCmisObject createTransientCmisObject() {
44          TransientRelationshipImpl tr = new TransientRelationshipImpl();
45          tr.initialize(getSession(), this);
46  
47          return tr;
48      }
49  
50      public TransientRelationship getTransientRelationship() {
51          return (TransientRelationship) getTransientObject();
52      }
53  
54      public CmisObject getSource() {
55          return getSource(getSession().getDefaultContext());
56      }
57  
58      public CmisObject getSource(OperationContext context) {
59          readLock();
60          try {
61              ObjectId sourceId = getSourceId();
62              if (sourceId == null) {
63                  return null;
64              }
65  
66              return getSession().getObject(sourceId, context);
67          } finally {
68              readUnlock();
69          }
70      }
71  
72      public ObjectId getSourceId() {
73          String sourceId = getPropertyValue(PropertyIds.SOURCE_ID);
74          if ((sourceId == null) || (sourceId.length() == 0)) {
75              return null;
76          }
77  
78          return getSession().createObjectId(sourceId);
79      }
80  
81      public CmisObject getTarget() {
82          return getTarget(getSession().getDefaultContext());
83      }
84  
85      public CmisObject getTarget(OperationContext context) {
86          readLock();
87          try {
88              ObjectId targetId = getTargetId();
89              if (targetId == null) {
90                  return null;
91              }
92  
93              return getSession().getObject(targetId, context);
94          } finally {
95              readUnlock();
96          }
97      }
98  
99      public ObjectId getTargetId() {
100         String targetId = getPropertyValue(PropertyIds.TARGET_ID);
101         if ((targetId == null) || (targetId.length() == 0)) {
102             return null;
103         }
104 
105         return getSession().createObjectId(targetId);
106     }
107 }