1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.RelationshipType;
27 import org.apache.chemistry.opencmis.commons.PropertyIds;
28 import org.apache.chemistry.opencmis.commons.data.ObjectData;
29
30 public class RelationshipImpl extends AbstractCmisObject implements Relationship {
31
32 private static final long serialVersionUID = 1L;
33
34
35
36
37 public RelationshipImpl(SessionImpl session, ObjectType objectType, ObjectData objectData, OperationContext context) {
38 initialize(session, objectType, objectData, context);
39 }
40
41 @Override
42 public RelationshipType getRelationshipType() {
43 ObjectType objectType = super.getType();
44 if (objectType instanceof RelationshipType) {
45 return (RelationshipType) objectType;
46 } else {
47 throw new ClassCastException("Object type is not a relationship type.");
48 }
49 }
50
51 @Override
52 public CmisObject getSource() {
53 return getSource(getSession().getDefaultContext());
54 }
55
56 @Override
57 public CmisObject getSource(OperationContext context) {
58 readLock();
59 try {
60 ObjectId sourceId = getSourceId();
61 if (sourceId == null) {
62 return null;
63 }
64
65 return getSession().getObject(sourceId, context);
66 } finally {
67 readUnlock();
68 }
69 }
70
71 @Override
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 @Override
82 public CmisObject getTarget() {
83 return getTarget(getSession().getDefaultContext());
84 }
85
86 @Override
87 public CmisObject getTarget(OperationContext context) {
88 readLock();
89 try {
90 ObjectId targetId = getTargetId();
91 if (targetId == null) {
92 return null;
93 }
94
95 return getSession().getObject(targetId, context);
96 } finally {
97 readUnlock();
98 }
99 }
100
101 @Override
102 public ObjectId getTargetId() {
103 String targetId = getPropertyValue(PropertyIds.TARGET_ID);
104 if (targetId == null || targetId.length() == 0) {
105 return null;
106 }
107
108 return getSession().createObjectId(targetId);
109 }
110 }