2 * This file is part of the Vamsas Client version 0.1.
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
4 * Andrew Waterhouse and Dominik Lindner.
6 * Earlier versions have also been incorporated into Jalview version 2.4
7 * since 2008, and TOPALi version 2 since 2007.
9 * The Vamsas Client is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * The Vamsas Client is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
22 package uk.ac.vamsas.objects.core;
24 //---------------------------------/
25 //- Imported classes and packages -/
26 //---------------------------------/
28 import org.exolab.castor.xml.Marshaller;
29 import org.exolab.castor.xml.Unmarshaller;
32 * Class DataSetAnnotations.
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class DataSetAnnotations extends
38 uk.ac.vamsas.objects.core.RangeAnnotation implements java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
45 * annotation is associated with a particular dataset sequence
47 private java.util.Vector _seqRef;
52 private uk.ac.vamsas.objects.core.Provenance _provenance;
58 public DataSetAnnotations() {
60 this._seqRef = new java.util.Vector();
71 * @throws java.lang.IndexOutOfBoundsException
72 * if the index given is outside the bounds of the collection
74 public void addSeqRef(final java.lang.Object vSeqRef)
75 throws java.lang.IndexOutOfBoundsException {
76 this._seqRef.addElement(vSeqRef);
84 * @throws java.lang.IndexOutOfBoundsException
85 * if the index given is outside the bounds of the collection
87 public void addSeqRef(final int index, final java.lang.Object vSeqRef)
88 throws java.lang.IndexOutOfBoundsException {
89 this._seqRef.add(index, vSeqRef);
93 * Method enumerateSeqRef.
95 * @return an Enumeration over all java.lang.Object elements
97 public java.util.Enumeration enumerateSeqRef() {
98 return this._seqRef.elements();
102 * Overrides the java.lang.Object.equals method.
105 * @return true if the objects are equal.
107 public boolean equals(final java.lang.Object obj) {
111 if (super.equals(obj) == false)
114 if (obj instanceof DataSetAnnotations) {
116 DataSetAnnotations temp = (DataSetAnnotations) obj;
119 if (this._seqRef != null) {
120 if (temp._seqRef == null)
122 if (this._seqRef != temp._seqRef) {
123 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._seqRef);
124 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._seqRef);
125 if (thcycle != tmcycle) {
127 org.castor.util.CycleBreaker.releaseCycleHandle(this._seqRef);
131 org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqRef);
137 if (!this._seqRef.equals(temp._seqRef)) {
138 org.castor.util.CycleBreaker.releaseCycleHandle(this._seqRef);
139 org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqRef);
142 org.castor.util.CycleBreaker.releaseCycleHandle(this._seqRef);
143 org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqRef);
146 } else if (temp._seqRef != null)
148 if (this._provenance != null) {
149 if (temp._provenance == null)
151 if (this._provenance != temp._provenance) {
152 thcycle = org.castor.util.CycleBreaker
153 .startingToCycle(this._provenance);
154 tmcycle = org.castor.util.CycleBreaker
155 .startingToCycle(temp._provenance);
156 if (thcycle != tmcycle) {
158 org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
162 org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
168 if (!this._provenance.equals(temp._provenance)) {
169 org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
170 org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
173 org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
174 org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
177 } else if (temp._provenance != null)
185 * Returns the value of field 'provenance'.
187 * @return the value of field 'Provenance'.
189 public uk.ac.vamsas.objects.core.Provenance getProvenance() {
190 return this._provenance;
197 * @throws java.lang.IndexOutOfBoundsException
198 * if the index given is outside the bounds of the collection
199 * @return the value of the java.lang.Object at the given index
201 public java.lang.Object getSeqRef(final int index)
202 throws java.lang.IndexOutOfBoundsException {
203 // check bounds for index
204 if (index < 0 || index >= this._seqRef.size()) {
205 throw new IndexOutOfBoundsException("getSeqRef: Index value '" + index
206 + "' not in range [0.." + (this._seqRef.size() - 1) + "]");
209 return _seqRef.get(index);
213 * Method getSeqRef.Returns the contents of the collection in an Array.
215 * Note: Just in case the collection contents are changing in another thread,
216 * we pass a 0-length Array of the correct type into the API call. This way we
217 * <i>know</i> that the Array returned is of exactly the correct length.
219 * @return this collection as an Array
221 public java.lang.Object[] getSeqRef() {
222 java.lang.Object[] array = new java.lang.Object[0];
223 return (java.lang.Object[]) this._seqRef.toArray(array);
227 * Method getSeqRefAsReference.Returns a reference to '_seqRef'. No type
228 * checking is performed on any modifications to the Vector.
230 * @return a reference to the Vector backing this class
232 public java.util.Vector getSeqRefAsReference() {
237 * Method getSeqRefCount.
239 * @return the size of this collection
241 public int getSeqRefCount() {
242 return this._seqRef.size();
246 * Overrides the java.lang.Object.hashCode method.
248 * The following steps came from <b>Effective Java Programming Language
249 * Guide</b> by Joshua Bloch, Chapter 3
251 * @return a hash code value for the object.
253 public int hashCode() {
254 int result = super.hashCode();
258 && !org.castor.util.CycleBreaker.startingToCycle(_seqRef)) {
259 result = 37 * result + _seqRef.hashCode();
260 org.castor.util.CycleBreaker.releaseCycleHandle(_seqRef);
262 if (_provenance != null
263 && !org.castor.util.CycleBreaker.startingToCycle(_provenance)) {
264 result = 37 * result + _provenance.hashCode();
265 org.castor.util.CycleBreaker.releaseCycleHandle(_provenance);
274 * @return true if this object is valid according to the schema
276 public boolean isValid() {
279 } catch (org.exolab.castor.xml.ValidationException vex) {
289 * @throws org.exolab.castor.xml.MarshalException
290 * if object is null or if any SAXException is thrown during
292 * @throws org.exolab.castor.xml.ValidationException
293 * if this object is an invalid instance according to the schema
295 public void marshal(final java.io.Writer out)
296 throws org.exolab.castor.xml.MarshalException,
297 org.exolab.castor.xml.ValidationException {
298 Marshaller.marshal(this, out);
305 * @throws java.io.IOException
306 * if an IOException occurs during marshaling
307 * @throws org.exolab.castor.xml.ValidationException
308 * if this object is an invalid instance according to the schema
309 * @throws org.exolab.castor.xml.MarshalException
310 * if object is null or if any SAXException is thrown during
313 public void marshal(final org.xml.sax.ContentHandler handler)
314 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
315 org.exolab.castor.xml.ValidationException {
316 Marshaller.marshal(this, handler);
321 public void removeAllSeqRef() {
322 this._seqRef.clear();
326 * Method removeSeqRef.
329 * @return true if the object was removed from the collection.
331 public boolean removeSeqRef(final java.lang.Object vSeqRef) {
332 boolean removed = _seqRef.remove(vSeqRef);
337 * Method removeSeqRefAt.
340 * @return the element removed from the collection
342 public java.lang.Object removeSeqRefAt(final int index) {
343 java.lang.Object obj = this._seqRef.remove(index);
348 * Sets the value of field 'provenance'.
351 * the value of field 'provenance'.
353 public void setProvenance(
354 final uk.ac.vamsas.objects.core.Provenance provenance) {
355 this._provenance = provenance;
363 * @throws java.lang.IndexOutOfBoundsException
364 * if the index given is outside the bounds of the collection
366 public void setSeqRef(final int index, final java.lang.Object vSeqRef)
367 throws java.lang.IndexOutOfBoundsException {
368 // check bounds for index
369 if (index < 0 || index >= this._seqRef.size()) {
370 throw new IndexOutOfBoundsException("setSeqRef: Index value '" + index
371 + "' not in range [0.." + (this._seqRef.size() - 1) + "]");
374 this._seqRef.set(index, vSeqRef);
380 * @param vSeqRefArray
382 public void setSeqRef(final java.lang.Object[] vSeqRefArray) {
386 for (int i = 0; i < vSeqRefArray.length; i++) {
387 this._seqRef.add(vSeqRefArray[i]);
392 * Sets the value of '_seqRef' by copying the given Vector. All elements will
393 * be checked for type safety.
396 * the Vector to copy.
398 public void setSeqRef(final java.util.Vector vSeqRefList) {
400 this._seqRef.clear();
402 this._seqRef.addAll(vSeqRefList);
406 * Sets the value of '_seqRef' by setting it to the given Vector. No type
407 * checking is performed.
411 * @param seqRefVector
414 public void setSeqRefAsReference(final java.util.Vector seqRefVector) {
415 this._seqRef = seqRefVector;
422 * @throws org.exolab.castor.xml.MarshalException
423 * if object is null or if any SAXException is thrown during
425 * @throws org.exolab.castor.xml.ValidationException
426 * if this object is an invalid instance according to the schema
427 * @return the unmarshaled uk.ac.vamsas.objects.core.RangeType
429 public static uk.ac.vamsas.objects.core.RangeType unmarshal(
430 final java.io.Reader reader)
431 throws org.exolab.castor.xml.MarshalException,
432 org.exolab.castor.xml.ValidationException {
433 return (uk.ac.vamsas.objects.core.RangeType) Unmarshaller.unmarshal(
434 uk.ac.vamsas.objects.core.DataSetAnnotations.class, reader);
440 * @throws org.exolab.castor.xml.ValidationException
441 * if this object is an invalid instance according to the schema
443 public void validate() throws org.exolab.castor.xml.ValidationException {
444 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
445 validator.validate(this);