1
2
3
4
5
6
7
8 package org.astrogrid.registry.beans.v10.resource;
9
10
11
12
13
14 import java.io.IOException;
15 import java.io.Reader;
16 import java.io.Serializable;
17 import java.io.Writer;
18 import java.util.ArrayList;
19 import java.util.Enumeration;
20 import org.exolab.castor.xml.MarshalException;
21 import org.exolab.castor.xml.Marshaller;
22 import org.exolab.castor.xml.Unmarshaller;
23 import org.exolab.castor.xml.ValidationException;
24 import org.xml.sax.ContentHandler;
25
26 /***
27 * A description of the relationship between one resource and one
28 * or
29 * more other resources.
30 *
31 *
32 * @version $Revision: 1.2 $ $Date: 2007/01/04 16:26:24 $
33 */
34 public class Relationship extends org.astrogrid.common.bean.BaseBean
35 implements java.io.Serializable
36 {
37
38
39
40
41
42
43 /***
44 * the named type of relationship
45 *
46 */
47 private java.lang.String _relationshipType;
48
49 /***
50 * the name of resource that this resource is related to.
51 *
52 */
53 private java.util.ArrayList _relatedResourceList;
54
55
56
57
58
59
60 public Relationship() {
61 super();
62 _relatedResourceList = new ArrayList();
63 }
64
65
66
67
68
69
70 /***
71 * Method addRelatedResource
72 *
73 * @param vRelatedResource
74 */
75 public void addRelatedResource(org.astrogrid.registry.beans.v10.resource.ResourceName vRelatedResource)
76 throws java.lang.IndexOutOfBoundsException
77 {
78 _relatedResourceList.add(vRelatedResource);
79 }
80
81 /***
82 * Method addRelatedResource
83 *
84 * @param index
85 * @param vRelatedResource
86 */
87 public void addRelatedResource(int index, org.astrogrid.registry.beans.v10.resource.ResourceName vRelatedResource)
88 throws java.lang.IndexOutOfBoundsException
89 {
90 _relatedResourceList.add(index, vRelatedResource);
91 }
92
93 /***
94 * Method clearRelatedResource
95 */
96 public void clearRelatedResource()
97 {
98 _relatedResourceList.clear();
99 }
100
101 /***
102 * Method enumerateRelatedResource
103 */
104 public java.util.Enumeration enumerateRelatedResource()
105 {
106 return new org.exolab.castor.util.IteratorEnumeration(_relatedResourceList.iterator());
107 }
108
109 /***
110 * Note: hashCode() has not been overriden
111 *
112 * @param obj
113 */
114 public boolean equals(java.lang.Object obj)
115 {
116 if ( this == obj )
117 return true;
118
119 if (super.equals(obj)==false)
120 return false;
121
122 if (obj instanceof Relationship) {
123
124 Relationship temp = (Relationship)obj;
125 if (this._relationshipType != null) {
126 if (temp._relationshipType == null) return false;
127 else if (!(this._relationshipType.equals(temp._relationshipType)))
128 return false;
129 }
130 else if (temp._relationshipType != null)
131 return false;
132 if (this._relatedResourceList != null) {
133 if (temp._relatedResourceList == null) return false;
134 else if (!(this._relatedResourceList.equals(temp._relatedResourceList)))
135 return false;
136 }
137 else if (temp._relatedResourceList != null)
138 return false;
139 return true;
140 }
141 return false;
142 }
143
144 /***
145 * Method getRelatedResource
146 *
147 * @param index
148 */
149 public org.astrogrid.registry.beans.v10.resource.ResourceName getRelatedResource(int index)
150 throws java.lang.IndexOutOfBoundsException
151 {
152
153 if ((index < 0) || (index > _relatedResourceList.size())) {
154 throw new IndexOutOfBoundsException();
155 }
156
157 return (org.astrogrid.registry.beans.v10.resource.ResourceName) _relatedResourceList.get(index);
158 }
159
160 /***
161 * Method getRelatedResource
162 */
163 public org.astrogrid.registry.beans.v10.resource.ResourceName[] getRelatedResource()
164 {
165 int size = _relatedResourceList.size();
166 org.astrogrid.registry.beans.v10.resource.ResourceName[] mArray = new org.astrogrid.registry.beans.v10.resource.ResourceName[size];
167 for (int index = 0; index < size; index++) {
168 mArray[index] = (org.astrogrid.registry.beans.v10.resource.ResourceName) _relatedResourceList.get(index);
169 }
170 return mArray;
171 }
172
173 /***
174 * Method getRelatedResourceCount
175 */
176 public int getRelatedResourceCount()
177 {
178 return _relatedResourceList.size();
179 }
180
181 /***
182 * Returns the value of field 'relationshipType'. The field
183 * 'relationshipType' has the following description: the named
184 * type of relationship
185 *
186 *
187 * @return the value of field 'relationshipType'.
188 */
189 public java.lang.String getRelationshipType()
190 {
191 return this._relationshipType;
192 }
193
194 /***
195 * Method isValid
196 */
197 public boolean isValid()
198 {
199 try {
200 validate();
201 }
202 catch (org.exolab.castor.xml.ValidationException vex) {
203 return false;
204 }
205 return true;
206 }
207
208 /***
209 * Method marshal
210 *
211 * @param out
212 */
213 public void marshal(java.io.Writer out)
214 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
215 {
216
217 Marshaller.marshal(this, out);
218 }
219
220 /***
221 * Method marshal
222 *
223 * @param handler
224 */
225 public void marshal(org.xml.sax.ContentHandler handler)
226 throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
227 {
228
229 Marshaller.marshal(this, handler);
230 }
231
232 /***
233 * Method removeRelatedResource
234 *
235 * @param vRelatedResource
236 */
237 public boolean removeRelatedResource(org.astrogrid.registry.beans.v10.resource.ResourceName vRelatedResource)
238 {
239 boolean removed = _relatedResourceList.remove(vRelatedResource);
240 return removed;
241 }
242
243 /***
244 * Method setRelatedResource
245 *
246 * @param index
247 * @param vRelatedResource
248 */
249 public void setRelatedResource(int index, org.astrogrid.registry.beans.v10.resource.ResourceName vRelatedResource)
250 throws java.lang.IndexOutOfBoundsException
251 {
252
253 if ((index < 0) || (index > _relatedResourceList.size())) {
254 throw new IndexOutOfBoundsException();
255 }
256 _relatedResourceList.set(index, vRelatedResource);
257 }
258
259 /***
260 * Method setRelatedResource
261 *
262 * @param relatedResourceArray
263 */
264 public void setRelatedResource(org.astrogrid.registry.beans.v10.resource.ResourceName[] relatedResourceArray)
265 {
266
267 _relatedResourceList.clear();
268 for (int i = 0; i < relatedResourceArray.length; i++) {
269 _relatedResourceList.add(relatedResourceArray[i]);
270 }
271 }
272
273 /***
274 * Sets the value of field 'relationshipType'. The field
275 * 'relationshipType' has the following description: the named
276 * type of relationship
277 *
278 *
279 * @param relationshipType the value of field 'relationshipType'
280 */
281 public void setRelationshipType(java.lang.String relationshipType)
282 {
283 this._relationshipType = relationshipType;
284 }
285
286 /***
287 * Method unmarshalRelationship
288 *
289 * @param reader
290 */
291 public static org.astrogrid.registry.beans.v10.resource.Relationship unmarshalRelationship(java.io.Reader reader)
292 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
293 {
294 return (org.astrogrid.registry.beans.v10.resource.Relationship) Unmarshaller.unmarshal(org.astrogrid.registry.beans.v10.resource.Relationship.class, reader);
295 }
296
297 /***
298 * Method validate
299 */
300 public void validate()
301 throws org.exolab.castor.xml.ValidationException
302 {
303 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
304 validator.validate(this);
305 }
306
307 }