6c06137afe466fa1b6e22789c7cc4e12d8cd0bea
[vamsas.git] / src / uk / ac / vamsas / objects / core / ReferenceType.java
1 /*\r
2  * This class was automatically generated with \r
3  * <a href="http://www.castor.org">Castor 1.1</a>, using an XML\r
4  * Schema.\r
5  * $Id$\r
6  */\r
7 \r
8 package uk.ac.vamsas.objects.core;\r
9 \r
10   //---------------------------------/\r
11  //- Imported classes and packages -/\r
12 //---------------------------------/\r
13 \r
14 import org.exolab.castor.xml.Marshaller;\r
15 import org.exolab.castor.xml.Unmarshaller;\r
16 \r
17 /**\r
18  * base type for citing arbitrary links between vamsas objects\r
19  *  Optional human readable description of the relationship\r
20  *  \r
21  * \r
22  * @version $Revision$ $Date$\r
23  */\r
24 public class ReferenceType extends uk.ac.vamsas.client.Vobject \r
25 implements java.io.Serializable\r
26 {\r
27 \r
28 \r
29       //--------------------------/\r
30      //- Class/Member Variables -/\r
31     //--------------------------/\r
32 \r
33     /**\r
34      * internal content storage\r
35      */\r
36     private java.lang.String _content = "";\r
37 \r
38     /**\r
39      * Primary Key for vamsas object referencing\r
40      *  \r
41      */\r
42     private java.lang.String _id;\r
43 \r
44     /**\r
45      * List of one or more vamsas object\r
46      *  references\r
47      */\r
48     private java.util.Vector _refs;\r
49 \r
50 \r
51       //----------------/\r
52      //- Constructors -/\r
53     //----------------/\r
54 \r
55     public ReferenceType() {\r
56         super();\r
57         setContent("");\r
58         this._refs = new java.util.Vector();\r
59     }\r
60 \r
61 \r
62       //-----------/\r
63      //- Methods -/\r
64     //-----------/\r
65 \r
66     /**\r
67      * \r
68      * \r
69      * @param vRefs\r
70      * @throws java.lang.IndexOutOfBoundsException if the index\r
71      * given is outside the bounds of the collection\r
72      */\r
73     public void addRefs(\r
74             final java.lang.Object vRefs)\r
75     throws java.lang.IndexOutOfBoundsException {\r
76         this._refs.addElement(vRefs);\r
77     }\r
78 \r
79     /**\r
80      * \r
81      * \r
82      * @param index\r
83      * @param vRefs\r
84      * @throws java.lang.IndexOutOfBoundsException if the index\r
85      * given is outside the bounds of the collection\r
86      */\r
87     public void addRefs(\r
88             final int index,\r
89             final java.lang.Object vRefs)\r
90     throws java.lang.IndexOutOfBoundsException {\r
91         this._refs.add(index, vRefs);\r
92     }\r
93 \r
94     /**\r
95      * Method enumerateRefs.\r
96      * \r
97      * @return an Enumeration over all java.lang.Object elements\r
98      */\r
99     public java.util.Enumeration enumerateRefs(\r
100     ) {\r
101         return this._refs.elements();\r
102     }\r
103 \r
104     /**\r
105      * Overrides the java.lang.Object.equals method.\r
106      * \r
107      * @param obj\r
108      * @return true if the objects are equal.\r
109      */\r
110     public boolean equals(\r
111             final java.lang.Object obj) {\r
112         if ( this == obj )\r
113             return true;\r
114         \r
115         if (super.equals(obj)==false)\r
116             return false;\r
117         \r
118         if (obj instanceof ReferenceType) {\r
119         \r
120             ReferenceType temp = (ReferenceType)obj;\r
121             boolean thcycle;\r
122             boolean tmcycle;\r
123             if (this._content != null) {\r
124                 if (temp._content == null) return false;\r
125                 if (this._content != temp._content) {\r
126                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._content);\r
127                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._content);\r
128                     if (thcycle!=tmcycle) {\r
129                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._content); };\r
130                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._content); };\r
131                         return false;\r
132                     }\r
133                     if (!thcycle) {\r
134                         if (!this._content.equals(temp._content)) {\r
135                             org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
136                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
137                             return false;\r
138                         }\r
139                         org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
140                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
141                     }\r
142                 }\r
143             } else if (temp._content != null)\r
144                 return false;\r
145             if (this._id != null) {\r
146                 if (temp._id == null) return false;\r
147                 if (this._id != temp._id) {\r
148                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._id);\r
149                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._id);\r
150                     if (thcycle!=tmcycle) {\r
151                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._id); };\r
152                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._id); };\r
153                         return false;\r
154                     }\r
155                     if (!thcycle) {\r
156                         if (!this._id.equals(temp._id)) {\r
157                             org.castor.util.CycleBreaker.releaseCycleHandle(this._id);\r
158                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);\r
159                             return false;\r
160                         }\r
161                         org.castor.util.CycleBreaker.releaseCycleHandle(this._id);\r
162                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);\r
163                     }\r
164                 }\r
165             } else if (temp._id != null)\r
166                 return false;\r
167             if (this._refs != null) {\r
168                 if (temp._refs == null) return false;\r
169                 if (this._refs != temp._refs) {\r
170                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._refs);\r
171                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._refs);\r
172                     if (thcycle!=tmcycle) {\r
173                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._refs); };\r
174                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._refs); };\r
175                         return false;\r
176                     }\r
177                     if (!thcycle) {\r
178                         if (!this._refs.equals(temp._refs)) {\r
179                             org.castor.util.CycleBreaker.releaseCycleHandle(this._refs);\r
180                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._refs);\r
181                             return false;\r
182                         }\r
183                         org.castor.util.CycleBreaker.releaseCycleHandle(this._refs);\r
184                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._refs);\r
185                     }\r
186                 }\r
187             } else if (temp._refs != null)\r
188                 return false;\r
189             return true;\r
190         }\r
191         return false;\r
192     }\r
193 \r
194     /**\r
195      * Returns the value of field 'content'. The field 'content'\r
196      * has the following description: internal content storage\r
197      * \r
198      * @return the value of field 'Content'.\r
199      */\r
200     public java.lang.String getContent(\r
201     ) {\r
202         return this._content;\r
203     }\r
204 \r
205     /**\r
206      * Returns the value of field 'id'. The field 'id' has the\r
207      * following description: Primary Key for vamsas object\r
208      * referencing\r
209      *  \r
210      * \r
211      * @return the value of field 'Id'.\r
212      */\r
213     public java.lang.String getId(\r
214     ) {\r
215         return this._id;\r
216     }\r
217 \r
218     /**\r
219      * Method getRefs.\r
220      * \r
221      * @param index\r
222      * @throws java.lang.IndexOutOfBoundsException if the index\r
223      * given is outside the bounds of the collection\r
224      * @return the value of the java.lang.Object at the given index\r
225      */\r
226     public java.lang.Object getRefs(\r
227             final int index)\r
228     throws java.lang.IndexOutOfBoundsException {\r
229         // check bounds for index\r
230         if (index < 0 || index >= this._refs.size()) {\r
231             throw new IndexOutOfBoundsException("getRefs: Index value '" + index + "' not in range [0.." + (this._refs.size() - 1) + "]");\r
232         }\r
233         \r
234         return _refs.get(index);\r
235     }\r
236 \r
237     /**\r
238      * Method getRefs.Returns the contents of the collection in an\r
239      * Array.  <p>Note:  Just in case the collection contents are\r
240      * changing in another thread, we pass a 0-length Array of the\r
241      * correct type into the API call.  This way we <i>know</i>\r
242      * that the Array returned is of exactly the correct length.\r
243      * \r
244      * @return this collection as an Array\r
245      */\r
246     public java.lang.Object[] getRefs(\r
247     ) {\r
248         java.lang.Object[] array = new java.lang.Object[0];\r
249         return (java.lang.Object[]) this._refs.toArray(array);\r
250     }\r
251 \r
252     /**\r
253      * Method getRefsAsReference.Returns a reference to '_refs'. No\r
254      * type checking is performed on any modifications to the\r
255      * Vector.\r
256      * \r
257      * @return a reference to the Vector backing this class\r
258      */\r
259     public java.util.Vector getRefsAsReference(\r
260     ) {\r
261         return this._refs;\r
262     }\r
263 \r
264     /**\r
265      * Method getRefsCount.\r
266      * \r
267      * @return the size of this collection\r
268      */\r
269     public int getRefsCount(\r
270     ) {\r
271         return this._refs.size();\r
272     }\r
273 \r
274     /**\r
275      * Overrides the java.lang.Object.hashCode method.\r
276      * <p>\r
277      * The following steps came from <b>Effective Java Programming\r
278      * Language Guide</b> by Joshua Bloch, Chapter 3\r
279      * \r
280      * @return a hash code value for the object.\r
281      */\r
282     public int hashCode(\r
283     ) {\r
284         int result = super.hashCode();\r
285         \r
286         long tmp;\r
287         if (_content != null\r
288             && !org.castor.util.CycleBreaker.startingToCycle(_content)) {\r
289            result = 37 * result + _content.hashCode();\r
290            org.castor.util.CycleBreaker.releaseCycleHandle(_content);\r
291         }\r
292         if (_id != null\r
293             && !org.castor.util.CycleBreaker.startingToCycle(_id)) {\r
294            result = 37 * result + _id.hashCode();\r
295            org.castor.util.CycleBreaker.releaseCycleHandle(_id);\r
296         }\r
297         if (_refs != null\r
298             && !org.castor.util.CycleBreaker.startingToCycle(_refs)) {\r
299            result = 37 * result + _refs.hashCode();\r
300            org.castor.util.CycleBreaker.releaseCycleHandle(_refs);\r
301         }\r
302         \r
303         return result;\r
304     }\r
305 \r
306     /**\r
307      * Method isValid.\r
308      * \r
309      * @return true if this object is valid according to the schema\r
310      */\r
311     public boolean isValid(\r
312     ) {\r
313         try {\r
314             validate();\r
315         } catch (org.exolab.castor.xml.ValidationException vex) {\r
316             return false;\r
317         }\r
318         return true;\r
319     }\r
320 \r
321     /**\r
322      * \r
323      * \r
324      * @param out\r
325      * @throws org.exolab.castor.xml.MarshalException if object is\r
326      * null or if any SAXException is thrown during marshaling\r
327      * @throws org.exolab.castor.xml.ValidationException if this\r
328      * object is an invalid instance according to the schema\r
329      */\r
330     public void marshal(\r
331             final java.io.Writer out)\r
332     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
333         Marshaller.marshal(this, out);\r
334     }\r
335 \r
336     /**\r
337      * \r
338      * \r
339      * @param handler\r
340      * @throws java.io.IOException if an IOException occurs during\r
341      * marshaling\r
342      * @throws org.exolab.castor.xml.ValidationException if this\r
343      * object is an invalid instance according to the schema\r
344      * @throws org.exolab.castor.xml.MarshalException if object is\r
345      * null or if any SAXException is thrown during marshaling\r
346      */\r
347     public void marshal(\r
348             final org.xml.sax.ContentHandler handler)\r
349     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
350         Marshaller.marshal(this, handler);\r
351     }\r
352 \r
353     /**\r
354      */\r
355     public void removeAllRefs(\r
356     ) {\r
357         this._refs.clear();\r
358     }\r
359 \r
360     /**\r
361      * Method removeRefs.\r
362      * \r
363      * @param vRefs\r
364      * @return true if the object was removed from the collection.\r
365      */\r
366     public boolean removeRefs(\r
367             final java.lang.Object vRefs) {\r
368         boolean removed = _refs.remove(vRefs);\r
369         return removed;\r
370     }\r
371 \r
372     /**\r
373      * Method removeRefsAt.\r
374      * \r
375      * @param index\r
376      * @return the element removed from the collection\r
377      */\r
378     public java.lang.Object removeRefsAt(\r
379             final int index) {\r
380         java.lang.Object obj = this._refs.remove(index);\r
381         return obj;\r
382     }\r
383 \r
384     /**\r
385      * Sets the value of field 'content'. The field 'content' has\r
386      * the following description: internal content storage\r
387      * \r
388      * @param content the value of field 'content'.\r
389      */\r
390     public void setContent(\r
391             final java.lang.String content) {\r
392         this._content = content;\r
393     }\r
394 \r
395     /**\r
396      * Sets the value of field 'id'. The field 'id' has the\r
397      * following description: Primary Key for vamsas object\r
398      * referencing\r
399      *  \r
400      * \r
401      * @param id the value of field 'id'.\r
402      */\r
403     public void setId(\r
404             final java.lang.String id) {\r
405         this._id = id;\r
406     }\r
407 \r
408     /**\r
409      * \r
410      * \r
411      * @param index\r
412      * @param vRefs\r
413      * @throws java.lang.IndexOutOfBoundsException if the index\r
414      * given is outside the bounds of the collection\r
415      */\r
416     public void setRefs(\r
417             final int index,\r
418             final java.lang.Object vRefs)\r
419     throws java.lang.IndexOutOfBoundsException {\r
420         // check bounds for index\r
421         if (index < 0 || index >= this._refs.size()) {\r
422             throw new IndexOutOfBoundsException("setRefs: Index value '" + index + "' not in range [0.." + (this._refs.size() - 1) + "]");\r
423         }\r
424         \r
425         this._refs.set(index, vRefs);\r
426     }\r
427 \r
428     /**\r
429      * \r
430      * \r
431      * @param vRefsArray\r
432      */\r
433     public void setRefs(\r
434             final java.lang.Object[] vRefsArray) {\r
435         //-- copy array\r
436         _refs.clear();\r
437         \r
438         for (int i = 0; i < vRefsArray.length; i++) {\r
439                 this._refs.add(vRefsArray[i]);\r
440         }\r
441     }\r
442 \r
443     /**\r
444      * Sets the value of '_refs' by copying the given Vector. All\r
445      * elements will be checked for type safety.\r
446      * \r
447      * @param vRefsList the Vector to copy.\r
448      */\r
449     public void setRefs(\r
450             final java.util.Vector vRefsList) {\r
451         // copy vector\r
452         this._refs.clear();\r
453         \r
454         this._refs.addAll(vRefsList);\r
455     }\r
456 \r
457     /**\r
458      * Sets the value of '_refs' by setting it to the given Vector.\r
459      * No type checking is performed.\r
460      * @deprecated\r
461      * \r
462      * @param refsVector the Vector to set.\r
463      */\r
464     public void setRefsAsReference(\r
465             final java.util.Vector refsVector) {\r
466         this._refs = refsVector;\r
467     }\r
468 \r
469     /**\r
470      * Method unmarshal.\r
471      * \r
472      * @param reader\r
473      * @throws org.exolab.castor.xml.MarshalException if object is\r
474      * null or if any SAXException is thrown during marshaling\r
475      * @throws org.exolab.castor.xml.ValidationException if this\r
476      * object is an invalid instance according to the schema\r
477      * @return the unmarshaled\r
478      * uk.ac.vamsas.objects.core.ReferenceType\r
479      */\r
480     public static uk.ac.vamsas.objects.core.ReferenceType unmarshal(\r
481             final java.io.Reader reader)\r
482     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
483         return (uk.ac.vamsas.objects.core.ReferenceType) Unmarshaller.unmarshal(uk.ac.vamsas.objects.core.ReferenceType.class, reader);\r
484     }\r
485 \r
486     /**\r
487      * \r
488      * \r
489      * @throws org.exolab.castor.xml.ValidationException if this\r
490      * object is an invalid instance according to the schema\r
491      */\r
492     public void validate(\r
493     )\r
494     throws org.exolab.castor.xml.ValidationException {\r
495         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
496         validator.validate(this);\r
497     }\r
498 \r
499 }\r