2 * This file is part of the Vamsas Client version 0.1.
\r
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.objects.core;
\r
24 //---------------------------------/
\r
25 //- Imported classes and packages -/
\r
26 //---------------------------------/
\r
28 import org.exolab.castor.xml.Marshaller;
\r
29 import org.exolab.castor.xml.Unmarshaller;
\r
32 * base type for citing arbitrary links between vamsas objects Optional human
\r
33 * readable description of the relationship
\r
36 * @version $Revision$ $Date$
\r
38 public class ReferenceType extends uk.ac.vamsas.client.Vobject implements
\r
39 java.io.Serializable {
\r
41 // --------------------------/
\r
42 // - Class/Member Variables -/
\r
43 // --------------------------/
\r
46 * internal content storage
\r
48 private java.lang.String _content = "";
\r
51 * Primary Key for vamsas object referencing
\r
54 private java.lang.String _id;
\r
57 * List of one or more vamsas object references
\r
59 private java.util.Vector _refs;
\r
61 // ----------------/
\r
62 // - Constructors -/
\r
63 // ----------------/
\r
65 public ReferenceType() {
\r
68 this._refs = new java.util.Vector();
\r
79 * @throws java.lang.IndexOutOfBoundsException
\r
80 * if the index given is outside the bounds of the collection
\r
82 public void addRefs(final java.lang.Object vRefs)
\r
83 throws java.lang.IndexOutOfBoundsException {
\r
84 this._refs.addElement(vRefs);
\r
92 * @throws java.lang.IndexOutOfBoundsException
\r
93 * if the index given is outside the bounds of the collection
\r
95 public void addRefs(final int index, final java.lang.Object vRefs)
\r
96 throws java.lang.IndexOutOfBoundsException {
\r
97 this._refs.add(index, vRefs);
\r
101 * Method enumerateRefs.
\r
103 * @return an Enumeration over all java.lang.Object elements
\r
105 public java.util.Enumeration enumerateRefs() {
\r
106 return this._refs.elements();
\r
110 * Overrides the java.lang.Object.equals method.
\r
113 * @return true if the objects are equal.
\r
115 public boolean equals(final java.lang.Object obj) {
\r
119 if (super.equals(obj) == false)
\r
122 if (obj instanceof ReferenceType) {
\r
124 ReferenceType temp = (ReferenceType) obj;
\r
127 if (this._content != null) {
\r
128 if (temp._content == null)
\r
130 if (this._content != temp._content) {
\r
131 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._content);
\r
132 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._content);
\r
133 if (thcycle != tmcycle) {
\r
135 org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
\r
139 org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
\r
145 if (!this._content.equals(temp._content)) {
\r
146 org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
\r
147 org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
\r
150 org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
\r
151 org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
\r
154 } else if (temp._content != null)
\r
156 if (this._id != null) {
\r
157 if (temp._id == null)
\r
159 if (this._id != temp._id) {
\r
160 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
\r
161 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
\r
162 if (thcycle != tmcycle) {
\r
164 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
168 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
174 if (!this._id.equals(temp._id)) {
\r
175 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
176 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
179 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
180 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
183 } else if (temp._id != null)
\r
185 if (this._refs != null) {
\r
186 if (temp._refs == null)
\r
188 if (this._refs != temp._refs) {
\r
189 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._refs);
\r
190 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._refs);
\r
191 if (thcycle != tmcycle) {
\r
193 org.castor.util.CycleBreaker.releaseCycleHandle(this._refs);
\r
197 org.castor.util.CycleBreaker.releaseCycleHandle(temp._refs);
\r
203 if (!this._refs.equals(temp._refs)) {
\r
204 org.castor.util.CycleBreaker.releaseCycleHandle(this._refs);
\r
205 org.castor.util.CycleBreaker.releaseCycleHandle(temp._refs);
\r
208 org.castor.util.CycleBreaker.releaseCycleHandle(this._refs);
\r
209 org.castor.util.CycleBreaker.releaseCycleHandle(temp._refs);
\r
212 } else if (temp._refs != null)
\r
220 * Returns the value of field 'content'. The field 'content' has the following
\r
221 * description: internal content storage
\r
223 * @return the value of field 'Content'.
\r
225 public java.lang.String getContent() {
\r
226 return this._content;
\r
230 * Returns the value of field 'id'. The field 'id' has the following
\r
231 * description: Primary Key for vamsas object referencing
\r
234 * @return the value of field 'Id'.
\r
236 public java.lang.String getId() {
\r
244 * @throws java.lang.IndexOutOfBoundsException
\r
245 * if the index given is outside the bounds of the collection
\r
246 * @return the value of the java.lang.Object at the given index
\r
248 public java.lang.Object getRefs(final int index)
\r
249 throws java.lang.IndexOutOfBoundsException {
\r
250 // check bounds for index
\r
251 if (index < 0 || index >= this._refs.size()) {
\r
252 throw new IndexOutOfBoundsException("getRefs: Index value '" + index
\r
253 + "' not in range [0.." + (this._refs.size() - 1) + "]");
\r
256 return _refs.get(index);
\r
260 * Method getRefs.Returns the contents of the collection in an Array.
\r
262 * Note: Just in case the collection contents are changing in another thread,
\r
263 * we pass a 0-length Array of the correct type into the API call. This way we
\r
264 * <i>know</i> that the Array returned is of exactly the correct length.
\r
266 * @return this collection as an Array
\r
268 public java.lang.Object[] getRefs() {
\r
269 java.lang.Object[] array = new java.lang.Object[0];
\r
270 return (java.lang.Object[]) this._refs.toArray(array);
\r
274 * Method getRefsAsReference.Returns a reference to '_refs'. No type checking
\r
275 * is performed on any modifications to the Vector.
\r
277 * @return a reference to the Vector backing this class
\r
279 public java.util.Vector getRefsAsReference() {
\r
284 * Method getRefsCount.
\r
286 * @return the size of this collection
\r
288 public int getRefsCount() {
\r
289 return this._refs.size();
\r
293 * Overrides the java.lang.Object.hashCode method.
\r
295 * The following steps came from <b>Effective Java Programming Language
\r
296 * Guide</b> by Joshua Bloch, Chapter 3
\r
298 * @return a hash code value for the object.
\r
300 public int hashCode() {
\r
301 int result = super.hashCode();
\r
304 if (_content != null
\r
305 && !org.castor.util.CycleBreaker.startingToCycle(_content)) {
\r
306 result = 37 * result + _content.hashCode();
\r
307 org.castor.util.CycleBreaker.releaseCycleHandle(_content);
\r
309 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
\r
310 result = 37 * result + _id.hashCode();
\r
311 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
\r
313 if (_refs != null && !org.castor.util.CycleBreaker.startingToCycle(_refs)) {
\r
314 result = 37 * result + _refs.hashCode();
\r
315 org.castor.util.CycleBreaker.releaseCycleHandle(_refs);
\r
324 * @return true if this object is valid according to the schema
\r
326 public boolean isValid() {
\r
329 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
339 * @throws org.exolab.castor.xml.MarshalException
\r
340 * if object is null or if any SAXException is thrown during
\r
342 * @throws org.exolab.castor.xml.ValidationException
\r
343 * if this object is an invalid instance according to the schema
\r
345 public void marshal(final java.io.Writer out)
\r
346 throws org.exolab.castor.xml.MarshalException,
\r
347 org.exolab.castor.xml.ValidationException {
\r
348 Marshaller.marshal(this, out);
\r
355 * @throws java.io.IOException
\r
356 * if an IOException occurs during marshaling
\r
357 * @throws org.exolab.castor.xml.ValidationException
\r
358 * if this object is an invalid instance according to the schema
\r
359 * @throws org.exolab.castor.xml.MarshalException
\r
360 * if object is null or if any SAXException is thrown during
\r
363 public void marshal(final org.xml.sax.ContentHandler handler)
\r
364 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
\r
365 org.exolab.castor.xml.ValidationException {
\r
366 Marshaller.marshal(this, handler);
\r
371 public void removeAllRefs() {
\r
372 this._refs.clear();
\r
376 * Method removeRefs.
\r
379 * @return true if the object was removed from the collection.
\r
381 public boolean removeRefs(final java.lang.Object vRefs) {
\r
382 boolean removed = _refs.remove(vRefs);
\r
387 * Method removeRefsAt.
\r
390 * @return the element removed from the collection
\r
392 public java.lang.Object removeRefsAt(final int index) {
\r
393 java.lang.Object obj = this._refs.remove(index);
\r
398 * Sets the value of field 'content'. The field 'content' has the following
\r
399 * description: internal content storage
\r
402 * the value of field 'content'.
\r
404 public void setContent(final java.lang.String content) {
\r
405 this._content = content;
\r
409 * Sets the value of field 'id'. The field 'id' has the following description:
\r
410 * Primary Key for vamsas object referencing
\r
414 * the value of field 'id'.
\r
416 public void setId(final java.lang.String id) {
\r
425 * @throws java.lang.IndexOutOfBoundsException
\r
426 * if the index given is outside the bounds of the collection
\r
428 public void setRefs(final int index, final java.lang.Object vRefs)
\r
429 throws java.lang.IndexOutOfBoundsException {
\r
430 // check bounds for index
\r
431 if (index < 0 || index >= this._refs.size()) {
\r
432 throw new IndexOutOfBoundsException("setRefs: Index value '" + index
\r
433 + "' not in range [0.." + (this._refs.size() - 1) + "]");
\r
436 this._refs.set(index, vRefs);
\r
442 * @param vRefsArray
\r
444 public void setRefs(final java.lang.Object[] vRefsArray) {
\r
448 for (int i = 0; i < vRefsArray.length; i++) {
\r
449 this._refs.add(vRefsArray[i]);
\r
454 * Sets the value of '_refs' by copying the given Vector. All elements will be
\r
455 * checked for type safety.
\r
458 * the Vector to copy.
\r
460 public void setRefs(final java.util.Vector vRefsList) {
\r
462 this._refs.clear();
\r
464 this._refs.addAll(vRefsList);
\r
468 * Sets the value of '_refs' by setting it to the given Vector. No type
\r
469 * checking is performed.
\r
473 * @param refsVector
\r
474 * the Vector to set.
\r
476 public void setRefsAsReference(final java.util.Vector refsVector) {
\r
477 this._refs = refsVector;
\r
481 * Method unmarshal.
\r
484 * @throws org.exolab.castor.xml.MarshalException
\r
485 * if object is null or if any SAXException is thrown during
\r
487 * @throws org.exolab.castor.xml.ValidationException
\r
488 * if this object is an invalid instance according to the schema
\r
489 * @return the unmarshaled uk.ac.vamsas.objects.core.ReferenceType
\r
491 public static uk.ac.vamsas.objects.core.ReferenceType unmarshal(
\r
492 final java.io.Reader reader)
\r
493 throws org.exolab.castor.xml.MarshalException,
\r
494 org.exolab.castor.xml.ValidationException {
\r
495 return (uk.ac.vamsas.objects.core.ReferenceType) Unmarshaller.unmarshal(
\r
496 uk.ac.vamsas.objects.core.ReferenceType.class, reader);
\r
502 * @throws org.exolab.castor.xml.ValidationException
\r
503 * if this object is an invalid instance according to the schema
\r
505 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
506 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
507 validator.validate(this);
\r