1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.document; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.Collection; |
20 | |
|
21 | |
import javax.xml.bind.annotation.XmlAccessType; |
22 | |
import javax.xml.bind.annotation.XmlAccessorType; |
23 | |
import javax.xml.bind.annotation.XmlAnyElement; |
24 | |
import javax.xml.bind.annotation.XmlElement; |
25 | |
import javax.xml.bind.annotation.XmlRootElement; |
26 | |
import javax.xml.bind.annotation.XmlType; |
27 | |
|
28 | |
import org.apache.commons.lang.StringUtils; |
29 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
30 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
31 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
32 | |
import org.kuali.rice.core.api.CoreConstants; |
33 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
34 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
35 | |
import org.w3c.dom.Element; |
36 | |
|
37 | |
@XmlRootElement(name = DocumentLink.Constants.ROOT_ELEMENT_NAME) |
38 | |
@XmlAccessorType(XmlAccessType.NONE) |
39 | |
@XmlType(name = DocumentLink.Constants.TYPE_NAME, propOrder = { |
40 | |
DocumentLink.Elements.ID, |
41 | |
DocumentLink.Elements.ORIGINATING_DOCUMENT_ID, |
42 | |
DocumentLink.Elements.DESTINATION_DOCUMENT_ID, |
43 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
44 | |
}) |
45 | 0 | public final class DocumentLink implements ModelObjectComplete, DocumentLinkContract { |
46 | |
|
47 | |
private static final long serialVersionUID = -1193048221115914280L; |
48 | |
|
49 | |
@XmlElement(name = Elements.ID, required = false) |
50 | |
private final String id; |
51 | |
|
52 | |
@XmlElement(name = Elements.ORIGINATING_DOCUMENT_ID, required = true) |
53 | |
private final String originatingDocumentId; |
54 | |
|
55 | |
@XmlElement(name = Elements.DESTINATION_DOCUMENT_ID, required = true) |
56 | |
private final String destinationDocumentId; |
57 | |
|
58 | 0 | @SuppressWarnings("unused") |
59 | |
@XmlAnyElement |
60 | |
private final Collection<Element> _futureElements = null; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 0 | private DocumentLink() { |
66 | 0 | this.id = null; |
67 | 0 | this.originatingDocumentId = null; |
68 | 0 | this.destinationDocumentId = null; |
69 | 0 | } |
70 | |
|
71 | 0 | private DocumentLink(Builder builder) { |
72 | 0 | this.id = builder.getId(); |
73 | 0 | this.originatingDocumentId = builder.getOriginatingDocumentId(); |
74 | 0 | this.destinationDocumentId = builder.getDestinationDocumentId(); |
75 | 0 | } |
76 | |
|
77 | |
@Override |
78 | |
public String getId() { |
79 | 0 | return this.id; |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public String getOriginatingDocumentId() { |
84 | 0 | return this.originatingDocumentId; |
85 | |
} |
86 | |
|
87 | |
@Override |
88 | |
public String getDestinationDocumentId() { |
89 | 0 | return this.destinationDocumentId; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public int hashCode() { |
94 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
95 | |
} |
96 | |
|
97 | |
@Override |
98 | |
public boolean equals(Object object) { |
99 | 0 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
100 | |
} |
101 | |
|
102 | |
@Override |
103 | |
public String toString() { |
104 | 0 | return ToStringBuilder.reflectionToString(this); |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | 0 | public final static class Builder implements Serializable, ModelBuilder, DocumentLinkContract { |
111 | |
|
112 | |
private static final long serialVersionUID = -6713990840543140054L; |
113 | |
|
114 | |
private String id; |
115 | |
private String originatingDocumentId; |
116 | |
private String destinationDocumentId; |
117 | |
|
118 | 0 | private Builder(String originatingDocumentId, String destinationDocumentId) { |
119 | 0 | setOriginatingDocumentId(originatingDocumentId); |
120 | 0 | setDestinationDocumentId(destinationDocumentId); |
121 | 0 | if (getOriginatingDocumentId().equals(getDestinationDocumentId())) { |
122 | 0 | throw new IllegalArgumentException("originating and destination document ids were the same, cannot link a document with itself"); |
123 | |
} |
124 | 0 | } |
125 | |
|
126 | |
public static Builder create(String originatingDocumentId, String destinationDocumentId) { |
127 | 0 | return new Builder(originatingDocumentId, destinationDocumentId); |
128 | |
} |
129 | |
|
130 | |
public static Builder create(DocumentLinkContract contract) { |
131 | 0 | if (contract == null) { |
132 | 0 | throw new IllegalArgumentException("contract was null"); |
133 | |
} |
134 | 0 | Builder builder = create(contract.getOriginatingDocumentId(), contract.getDestinationDocumentId()); |
135 | 0 | builder.setId(contract.getId()); |
136 | 0 | return builder; |
137 | |
} |
138 | |
|
139 | |
public DocumentLink build() { |
140 | 0 | return new DocumentLink(this); |
141 | |
} |
142 | |
|
143 | |
@Override |
144 | |
public String getId() { |
145 | 0 | return this.id; |
146 | |
} |
147 | |
|
148 | |
@Override |
149 | |
public String getOriginatingDocumentId() { |
150 | 0 | return this.originatingDocumentId; |
151 | |
} |
152 | |
|
153 | |
@Override |
154 | |
public String getDestinationDocumentId() { |
155 | 0 | return this.destinationDocumentId; |
156 | |
} |
157 | |
|
158 | |
public void setId(String id) { |
159 | 0 | this.id = id; |
160 | 0 | } |
161 | |
|
162 | |
public void setOriginatingDocumentId(String originatingDocumentId) { |
163 | 0 | if (StringUtils.isBlank(originatingDocumentId)) { |
164 | 0 | throw new IllegalArgumentException("originatingDocumentId was null or blank"); |
165 | |
} |
166 | 0 | this.originatingDocumentId = originatingDocumentId; |
167 | 0 | } |
168 | |
|
169 | |
public void setDestinationDocumentId(String destinationDocumentId) { |
170 | 0 | if (StringUtils.isBlank(destinationDocumentId)) { |
171 | 0 | throw new IllegalArgumentException("destinationDocumentId was null or blank"); |
172 | |
} |
173 | 0 | this.destinationDocumentId = destinationDocumentId; |
174 | 0 | } |
175 | |
|
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | 0 | static class Constants { |
182 | |
final static String ROOT_ELEMENT_NAME = "documentLink"; |
183 | |
final static String TYPE_NAME = "DocumentLinkType"; |
184 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
185 | |
} |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | 0 | static class Elements { |
191 | |
final static String ID = "id"; |
192 | |
final static String ORIGINATING_DOCUMENT_ID = "originatingDocumentId"; |
193 | |
final static String DESTINATION_DOCUMENT_ID = "destinationDocumentId"; |
194 | |
} |
195 | |
|
196 | |
} |