1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.bo;
17
18 import java.io.Serializable;
19 import java.util.HashMap;
20 import java.util.Map;
21
22
23
24
25
26
27
28
29
30
31
32 public class DataObjectRelationship implements Serializable {
33 private Class<?> relatedClass;
34 private Class<?> parentClass;
35 private String parentAttributeName;
36 private String userVisibleIdentifierKey = null;
37
38 private Map<String, String> parentToChildReferences = new HashMap<String, String>(4);
39
40 public DataObjectRelationship() {
41 }
42
43 public DataObjectRelationship(Class<?> parentClass, String parentAttributeName, Class<?> relatedClass) {
44 super();
45
46 this.relatedClass = relatedClass;
47 this.parentClass = parentClass;
48 this.parentAttributeName = parentAttributeName;
49 }
50
51
52
53
54
55
56 public Class<?> getParentClass() {
57 return parentClass;
58 }
59
60
61
62
63
64
65 public Class<?> getRelatedClass() {
66 return this.relatedClass;
67 }
68
69
70
71
72
73
74
75
76
77
78 public String getParentAttributeName() {
79 return parentAttributeName;
80 }
81
82
83
84
85
86
87
88
89 public Map<String, String> getParentToChildReferences() {
90 return parentToChildReferences;
91 }
92
93
94
95
96
97
98 public void setParentToChildReferences(Map<String, String> referenceAttributes) {
99 this.parentToChildReferences = referenceAttributes;
100 }
101
102
103
104
105
106
107
108
109 public String getParentAttributeForChildAttribute(String childAttributeName) {
110 for (Map.Entry<String, String> entry : parentToChildReferences.entrySet()) {
111 if (entry.getValue().equals(childAttributeName)) {
112 return entry.getKey();
113 }
114 }
115 return null;
116 }
117
118
119
120
121
122
123
124
125 public String getChildAttributeForParentAttribute(String parentAttributeName) {
126 return parentToChildReferences.get(parentAttributeName);
127 }
128
129 public String getUserVisibleIdentifierKey() {
130 return userVisibleIdentifierKey;
131 }
132
133 public void setUserVisibleIdentifierKey(String userVisibleIdentifierKey) {
134 this.userVisibleIdentifierKey = userVisibleIdentifierKey;
135 }
136
137 public String toString() {
138 StringBuffer sb = new StringBuffer();
139 sb.append("Relationship: ").append(parentClass.getName()).append(" -> ").append(relatedClass.getName());
140 for (Map.Entry<String, String> refs : parentToChildReferences.entrySet()) {
141 sb.append("\n ").append(refs.getKey()).append(" -> ").append(refs.getValue());
142 }
143 return sb.toString();
144 }
145 }