2 * This file is part of the Vamsas Client version 0.2.
3 * Copyright 2010 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;
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class Provenance extends uk.ac.vamsas.client.Vobject implements
38 java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
47 private java.util.Vector _entryList;
55 this._entryList = new java.util.Vector();
66 * @throws java.lang.IndexOutOfBoundsException
67 * if the index given is outside the bounds of the collection
69 public void addEntry(final uk.ac.vamsas.objects.core.Entry vEntry)
70 throws java.lang.IndexOutOfBoundsException {
71 this._entryList.addElement(vEntry);
79 * @throws java.lang.IndexOutOfBoundsException
80 * if the index given is outside the bounds of the collection
82 public void addEntry(final int index,
83 final uk.ac.vamsas.objects.core.Entry vEntry)
84 throws java.lang.IndexOutOfBoundsException {
85 this._entryList.add(index, vEntry);
89 * Method enumerateEntry.
91 * @return an Enumeration over all uk.ac.vamsas.objects.core.Entry elements
93 public java.util.Enumeration enumerateEntry() {
94 return this._entryList.elements();
98 * Overrides the java.lang.Object.equals method.
101 * @return true if the objects are equal.
103 public boolean equals(final java.lang.Object obj) {
107 if (super.equals(obj) == false)
110 if (obj instanceof Provenance) {
112 Provenance temp = (Provenance) obj;
115 if (this._entryList != null) {
116 if (temp._entryList == null)
118 if (this._entryList != temp._entryList) {
119 thcycle = org.castor.util.CycleBreaker
120 .startingToCycle(this._entryList);
121 tmcycle = org.castor.util.CycleBreaker
122 .startingToCycle(temp._entryList);
123 if (thcycle != tmcycle) {
125 org.castor.util.CycleBreaker.releaseCycleHandle(this._entryList);
129 org.castor.util.CycleBreaker.releaseCycleHandle(temp._entryList);
135 if (!this._entryList.equals(temp._entryList)) {
136 org.castor.util.CycleBreaker.releaseCycleHandle(this._entryList);
137 org.castor.util.CycleBreaker.releaseCycleHandle(temp._entryList);
140 org.castor.util.CycleBreaker.releaseCycleHandle(this._entryList);
141 org.castor.util.CycleBreaker.releaseCycleHandle(temp._entryList);
144 } else if (temp._entryList != null)
155 * @throws java.lang.IndexOutOfBoundsException
156 * if the index given is outside the bounds of the collection
157 * @return the value of the uk.ac.vamsas.objects.core.Entry at the given index
159 public uk.ac.vamsas.objects.core.Entry getEntry(final int index)
160 throws java.lang.IndexOutOfBoundsException {
161 // check bounds for index
162 if (index < 0 || index >= this._entryList.size()) {
163 throw new IndexOutOfBoundsException("getEntry: Index value '" + index
164 + "' not in range [0.." + (this._entryList.size() - 1) + "]");
167 return (uk.ac.vamsas.objects.core.Entry) _entryList.get(index);
171 * Method getEntry.Returns the contents of the collection in an Array.
173 * Note: Just in case the collection contents are changing in another thread,
174 * we pass a 0-length Array of the correct type into the API call. This way we
175 * <i>know</i> that the Array returned is of exactly the correct length.
177 * @return this collection as an Array
179 public uk.ac.vamsas.objects.core.Entry[] getEntry() {
180 uk.ac.vamsas.objects.core.Entry[] array = new uk.ac.vamsas.objects.core.Entry[0];
181 return (uk.ac.vamsas.objects.core.Entry[]) this._entryList.toArray(array);
185 * Method getEntryAsReference.Returns a reference to '_entryList'. No type
186 * checking is performed on any modifications to the Vector.
188 * @return a reference to the Vector backing this class
190 public java.util.Vector getEntryAsReference() {
191 return this._entryList;
195 * Method getEntryCount.
197 * @return the size of this collection
199 public int getEntryCount() {
200 return this._entryList.size();
204 * Overrides the java.lang.Object.hashCode method.
206 * The following steps came from <b>Effective Java Programming Language
207 * Guide</b> by Joshua Bloch, Chapter 3
209 * @return a hash code value for the object.
211 public int hashCode() {
212 int result = super.hashCode();
215 if (_entryList != null
216 && !org.castor.util.CycleBreaker.startingToCycle(_entryList)) {
217 result = 37 * result + _entryList.hashCode();
218 org.castor.util.CycleBreaker.releaseCycleHandle(_entryList);
227 * @return true if this object is valid according to the schema
229 public boolean isValid() {
232 } catch (org.exolab.castor.xml.ValidationException vex) {
242 * @throws org.exolab.castor.xml.MarshalException
243 * if object is null or if any SAXException is thrown during
245 * @throws org.exolab.castor.xml.ValidationException
246 * if this object is an invalid instance according to the schema
248 public void marshal(final java.io.Writer out)
249 throws org.exolab.castor.xml.MarshalException,
250 org.exolab.castor.xml.ValidationException {
251 Marshaller.marshal(this, out);
258 * @throws java.io.IOException
259 * if an IOException occurs during marshaling
260 * @throws org.exolab.castor.xml.ValidationException
261 * if this object is an invalid instance according to the schema
262 * @throws org.exolab.castor.xml.MarshalException
263 * if object is null or if any SAXException is thrown during
266 public void marshal(final org.xml.sax.ContentHandler handler)
267 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
268 org.exolab.castor.xml.ValidationException {
269 Marshaller.marshal(this, handler);
274 public void removeAllEntry() {
275 this._entryList.clear();
279 * Method removeEntry.
282 * @return true if the object was removed from the collection.
284 public boolean removeEntry(final uk.ac.vamsas.objects.core.Entry vEntry) {
285 boolean removed = _entryList.remove(vEntry);
290 * Method removeEntryAt.
293 * @return the element removed from the collection
295 public uk.ac.vamsas.objects.core.Entry removeEntryAt(final int index) {
296 java.lang.Object obj = this._entryList.remove(index);
297 return (uk.ac.vamsas.objects.core.Entry) obj;
305 * @throws java.lang.IndexOutOfBoundsException
306 * if the index given is outside the bounds of the collection
308 public void setEntry(final int index,
309 final uk.ac.vamsas.objects.core.Entry vEntry)
310 throws java.lang.IndexOutOfBoundsException {
311 // check bounds for index
312 if (index < 0 || index >= this._entryList.size()) {
313 throw new IndexOutOfBoundsException("setEntry: Index value '" + index
314 + "' not in range [0.." + (this._entryList.size() - 1) + "]");
317 this._entryList.set(index, vEntry);
325 public void setEntry(final uk.ac.vamsas.objects.core.Entry[] vEntryArray) {
329 for (int i = 0; i < vEntryArray.length; i++) {
330 this._entryList.add(vEntryArray[i]);
335 * Sets the value of '_entryList' by copying the given Vector. All elements
336 * will be checked for type safety.
339 * the Vector to copy.
341 public void setEntry(final java.util.Vector vEntryList) {
343 this._entryList.clear();
345 this._entryList.addAll(vEntryList);
349 * Sets the value of '_entryList' by setting it to the given Vector. No type
350 * checking is performed.
357 public void setEntryAsReference(final java.util.Vector entryVector) {
358 this._entryList = entryVector;
365 * @throws org.exolab.castor.xml.MarshalException
366 * if object is null or if any SAXException is thrown during
368 * @throws org.exolab.castor.xml.ValidationException
369 * if this object is an invalid instance according to the schema
370 * @return the unmarshaled uk.ac.vamsas.objects.core.Provenance
372 public static uk.ac.vamsas.objects.core.Provenance unmarshal(
373 final java.io.Reader reader)
374 throws org.exolab.castor.xml.MarshalException,
375 org.exolab.castor.xml.ValidationException {
376 return (uk.ac.vamsas.objects.core.Provenance) Unmarshaller.unmarshal(
377 uk.ac.vamsas.objects.core.Provenance.class, reader);
383 * @throws org.exolab.castor.xml.ValidationException
384 * if this object is an invalid instance according to the schema
386 public void validate() throws org.exolab.castor.xml.ValidationException {
387 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
388 validator.validate(this);