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 ApplicationData.
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class ApplicationData extends uk.ac.vamsas.objects.core.AppData
38 implements java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
45 * Version string describing the application specific data storage version
48 private java.lang.String _version;
51 * Canonical name of application
53 private java.lang.String _name;
58 private java.util.Vector _userList;
63 private uk.ac.vamsas.objects.core.Common _common;
66 * Field _instanceList.
68 private java.util.Vector _instanceList;
74 public ApplicationData() {
76 this._userList = new java.util.Vector();
77 this._instanceList = new java.util.Vector();
88 * @throws java.lang.IndexOutOfBoundsException
89 * if the index given is outside the bounds of the collection
91 public void addInstance(final uk.ac.vamsas.objects.core.Instance vInstance)
92 throws java.lang.IndexOutOfBoundsException {
93 this._instanceList.addElement(vInstance);
101 * @throws java.lang.IndexOutOfBoundsException
102 * if the index given is outside the bounds of the collection
104 public void addInstance(final int index,
105 final uk.ac.vamsas.objects.core.Instance vInstance)
106 throws java.lang.IndexOutOfBoundsException {
107 this._instanceList.add(index, vInstance);
114 * @throws java.lang.IndexOutOfBoundsException
115 * if the index given is outside the bounds of the collection
117 public void addUser(final uk.ac.vamsas.objects.core.User vUser)
118 throws java.lang.IndexOutOfBoundsException {
119 this._userList.addElement(vUser);
127 * @throws java.lang.IndexOutOfBoundsException
128 * if the index given is outside the bounds of the collection
130 public void addUser(final int index,
131 final uk.ac.vamsas.objects.core.User vUser)
132 throws java.lang.IndexOutOfBoundsException {
133 this._userList.add(index, vUser);
137 * Method enumerateInstance.
139 * @return an Enumeration over all uk.ac.vamsas.objects.core.Instance elements
141 public java.util.Enumeration enumerateInstance() {
142 return this._instanceList.elements();
146 * Method enumerateUser.
148 * @return an Enumeration over all uk.ac.vamsas.objects.core.User elements
150 public java.util.Enumeration enumerateUser() {
151 return this._userList.elements();
155 * Overrides the java.lang.Object.equals method.
158 * @return true if the objects are equal.
160 public boolean equals(final java.lang.Object obj) {
164 if (super.equals(obj) == false)
167 if (obj instanceof ApplicationData) {
169 ApplicationData temp = (ApplicationData) obj;
172 if (this._version != null) {
173 if (temp._version == null)
175 if (this._version != temp._version) {
176 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._version);
177 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._version);
178 if (thcycle != tmcycle) {
180 org.castor.util.CycleBreaker.releaseCycleHandle(this._version);
184 org.castor.util.CycleBreaker.releaseCycleHandle(temp._version);
190 if (!this._version.equals(temp._version)) {
191 org.castor.util.CycleBreaker.releaseCycleHandle(this._version);
192 org.castor.util.CycleBreaker.releaseCycleHandle(temp._version);
195 org.castor.util.CycleBreaker.releaseCycleHandle(this._version);
196 org.castor.util.CycleBreaker.releaseCycleHandle(temp._version);
199 } else if (temp._version != null)
201 if (this._name != null) {
202 if (temp._name == null)
204 if (this._name != temp._name) {
205 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._name);
206 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._name);
207 if (thcycle != tmcycle) {
209 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
213 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
219 if (!this._name.equals(temp._name)) {
220 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
221 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
224 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
225 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
228 } else if (temp._name != null)
230 if (this._userList != null) {
231 if (temp._userList == null)
233 if (this._userList != temp._userList) {
234 thcycle = org.castor.util.CycleBreaker
235 .startingToCycle(this._userList);
236 tmcycle = org.castor.util.CycleBreaker
237 .startingToCycle(temp._userList);
238 if (thcycle != tmcycle) {
240 org.castor.util.CycleBreaker.releaseCycleHandle(this._userList);
244 org.castor.util.CycleBreaker.releaseCycleHandle(temp._userList);
250 if (!this._userList.equals(temp._userList)) {
251 org.castor.util.CycleBreaker.releaseCycleHandle(this._userList);
252 org.castor.util.CycleBreaker.releaseCycleHandle(temp._userList);
255 org.castor.util.CycleBreaker.releaseCycleHandle(this._userList);
256 org.castor.util.CycleBreaker.releaseCycleHandle(temp._userList);
259 } else if (temp._userList != null)
261 if (this._common != null) {
262 if (temp._common == null)
264 if (this._common != temp._common) {
265 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._common);
266 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._common);
267 if (thcycle != tmcycle) {
269 org.castor.util.CycleBreaker.releaseCycleHandle(this._common);
273 org.castor.util.CycleBreaker.releaseCycleHandle(temp._common);
279 if (!this._common.equals(temp._common)) {
280 org.castor.util.CycleBreaker.releaseCycleHandle(this._common);
281 org.castor.util.CycleBreaker.releaseCycleHandle(temp._common);
284 org.castor.util.CycleBreaker.releaseCycleHandle(this._common);
285 org.castor.util.CycleBreaker.releaseCycleHandle(temp._common);
288 } else if (temp._common != null)
290 if (this._instanceList != null) {
291 if (temp._instanceList == null)
293 if (this._instanceList != temp._instanceList) {
294 thcycle = org.castor.util.CycleBreaker
295 .startingToCycle(this._instanceList);
296 tmcycle = org.castor.util.CycleBreaker
297 .startingToCycle(temp._instanceList);
298 if (thcycle != tmcycle) {
300 org.castor.util.CycleBreaker
301 .releaseCycleHandle(this._instanceList);
305 org.castor.util.CycleBreaker
306 .releaseCycleHandle(temp._instanceList);
312 if (!this._instanceList.equals(temp._instanceList)) {
313 org.castor.util.CycleBreaker
314 .releaseCycleHandle(this._instanceList);
315 org.castor.util.CycleBreaker
316 .releaseCycleHandle(temp._instanceList);
319 org.castor.util.CycleBreaker.releaseCycleHandle(this._instanceList);
320 org.castor.util.CycleBreaker.releaseCycleHandle(temp._instanceList);
323 } else if (temp._instanceList != null)
331 * Returns the value of field 'common'.
333 * @return the value of field 'Common'.
335 public uk.ac.vamsas.objects.core.Common getCommon() {
340 * Method getInstance.
343 * @throws java.lang.IndexOutOfBoundsException
344 * if the index given is outside the bounds of the collection
345 * @return the value of the uk.ac.vamsas.objects.core.Instance at the given
348 public uk.ac.vamsas.objects.core.Instance getInstance(final int index)
349 throws java.lang.IndexOutOfBoundsException {
350 // check bounds for index
351 if (index < 0 || index >= this._instanceList.size()) {
352 throw new IndexOutOfBoundsException("getInstance: Index value '" + index
353 + "' not in range [0.." + (this._instanceList.size() - 1) + "]");
356 return (uk.ac.vamsas.objects.core.Instance) _instanceList.get(index);
360 * Method getInstance.Returns the contents of the collection in an Array.
362 * Note: Just in case the collection contents are changing in another thread,
363 * we pass a 0-length Array of the correct type into the API call. This way we
364 * <i>know</i> that the Array returned is of exactly the correct length.
366 * @return this collection as an Array
368 public uk.ac.vamsas.objects.core.Instance[] getInstance() {
369 uk.ac.vamsas.objects.core.Instance[] array = new uk.ac.vamsas.objects.core.Instance[0];
370 return (uk.ac.vamsas.objects.core.Instance[]) this._instanceList
375 * Method getInstanceAsReference.Returns a reference to '_instanceList'. No
376 * type checking is performed on any modifications to the Vector.
378 * @return a reference to the Vector backing this class
380 public java.util.Vector getInstanceAsReference() {
381 return this._instanceList;
385 * Method getInstanceCount.
387 * @return the size of this collection
389 public int getInstanceCount() {
390 return this._instanceList.size();
394 * Returns the value of field 'name'. The field 'name' has the following
395 * description: Canonical name of application
397 * @return the value of field 'Name'.
399 public java.lang.String getName() {
407 * @throws java.lang.IndexOutOfBoundsException
408 * if the index given is outside the bounds of the collection
409 * @return the value of the uk.ac.vamsas.objects.core.User at the given index
411 public uk.ac.vamsas.objects.core.User getUser(final int index)
412 throws java.lang.IndexOutOfBoundsException {
413 // check bounds for index
414 if (index < 0 || index >= this._userList.size()) {
415 throw new IndexOutOfBoundsException("getUser: Index value '" + index
416 + "' not in range [0.." + (this._userList.size() - 1) + "]");
419 return (uk.ac.vamsas.objects.core.User) _userList.get(index);
423 * Method getUser.Returns the contents of the collection in an Array.
425 * Note: Just in case the collection contents are changing in another thread,
426 * we pass a 0-length Array of the correct type into the API call. This way we
427 * <i>know</i> that the Array returned is of exactly the correct length.
429 * @return this collection as an Array
431 public uk.ac.vamsas.objects.core.User[] getUser() {
432 uk.ac.vamsas.objects.core.User[] array = new uk.ac.vamsas.objects.core.User[0];
433 return (uk.ac.vamsas.objects.core.User[]) this._userList.toArray(array);
437 * Method getUserAsReference.Returns a reference to '_userList'. No type
438 * checking is performed on any modifications to the Vector.
440 * @return a reference to the Vector backing this class
442 public java.util.Vector getUserAsReference() {
443 return this._userList;
447 * Method getUserCount.
449 * @return the size of this collection
451 public int getUserCount() {
452 return this._userList.size();
456 * Returns the value of field 'version'. The field 'version' has the following
457 * description: Version string describing the application specific data
458 * storage version used
460 * @return the value of field 'Version'.
462 public java.lang.String getVersion() {
463 return this._version;
467 * Overrides the java.lang.Object.hashCode method.
469 * The following steps came from <b>Effective Java Programming Language
470 * Guide</b> by Joshua Bloch, Chapter 3
472 * @return a hash code value for the object.
474 public int hashCode() {
475 int result = super.hashCode();
479 && !org.castor.util.CycleBreaker.startingToCycle(_version)) {
480 result = 37 * result + _version.hashCode();
481 org.castor.util.CycleBreaker.releaseCycleHandle(_version);
483 if (_name != null && !org.castor.util.CycleBreaker.startingToCycle(_name)) {
484 result = 37 * result + _name.hashCode();
485 org.castor.util.CycleBreaker.releaseCycleHandle(_name);
487 if (_userList != null
488 && !org.castor.util.CycleBreaker.startingToCycle(_userList)) {
489 result = 37 * result + _userList.hashCode();
490 org.castor.util.CycleBreaker.releaseCycleHandle(_userList);
493 && !org.castor.util.CycleBreaker.startingToCycle(_common)) {
494 result = 37 * result + _common.hashCode();
495 org.castor.util.CycleBreaker.releaseCycleHandle(_common);
497 if (_instanceList != null
498 && !org.castor.util.CycleBreaker.startingToCycle(_instanceList)) {
499 result = 37 * result + _instanceList.hashCode();
500 org.castor.util.CycleBreaker.releaseCycleHandle(_instanceList);
509 * @return true if this object is valid according to the schema
511 public boolean isValid() {
514 } catch (org.exolab.castor.xml.ValidationException vex) {
524 * @throws org.exolab.castor.xml.MarshalException
525 * if object is null or if any SAXException is thrown during
527 * @throws org.exolab.castor.xml.ValidationException
528 * if this object is an invalid instance according to the schema
530 public void marshal(final java.io.Writer out)
531 throws org.exolab.castor.xml.MarshalException,
532 org.exolab.castor.xml.ValidationException {
533 Marshaller.marshal(this, out);
540 * @throws java.io.IOException
541 * if an IOException occurs during marshaling
542 * @throws org.exolab.castor.xml.ValidationException
543 * if this object is an invalid instance according to the schema
544 * @throws org.exolab.castor.xml.MarshalException
545 * if object is null or if any SAXException is thrown during
548 public void marshal(final org.xml.sax.ContentHandler handler)
549 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
550 org.exolab.castor.xml.ValidationException {
551 Marshaller.marshal(this, handler);
556 public void removeAllInstance() {
557 this._instanceList.clear();
562 public void removeAllUser() {
563 this._userList.clear();
567 * Method removeInstance.
570 * @return true if the object was removed from the collection.
572 public boolean removeInstance(
573 final uk.ac.vamsas.objects.core.Instance vInstance) {
574 boolean removed = _instanceList.remove(vInstance);
579 * Method removeInstanceAt.
582 * @return the element removed from the collection
584 public uk.ac.vamsas.objects.core.Instance removeInstanceAt(final int index) {
585 java.lang.Object obj = this._instanceList.remove(index);
586 return (uk.ac.vamsas.objects.core.Instance) obj;
593 * @return true if the object was removed from the collection.
595 public boolean removeUser(final uk.ac.vamsas.objects.core.User vUser) {
596 boolean removed = _userList.remove(vUser);
601 * Method removeUserAt.
604 * @return the element removed from the collection
606 public uk.ac.vamsas.objects.core.User removeUserAt(final int index) {
607 java.lang.Object obj = this._userList.remove(index);
608 return (uk.ac.vamsas.objects.core.User) obj;
612 * Sets the value of field 'common'.
615 * the value of field 'common'.
617 public void setCommon(final uk.ac.vamsas.objects.core.Common common) {
618 this._common = common;
626 * @throws java.lang.IndexOutOfBoundsException
627 * if the index given is outside the bounds of the collection
629 public void setInstance(final int index,
630 final uk.ac.vamsas.objects.core.Instance vInstance)
631 throws java.lang.IndexOutOfBoundsException {
632 // check bounds for index
633 if (index < 0 || index >= this._instanceList.size()) {
634 throw new IndexOutOfBoundsException("setInstance: Index value '" + index
635 + "' not in range [0.." + (this._instanceList.size() - 1) + "]");
638 this._instanceList.set(index, vInstance);
644 * @param vInstanceArray
646 public void setInstance(
647 final uk.ac.vamsas.objects.core.Instance[] vInstanceArray) {
649 _instanceList.clear();
651 for (int i = 0; i < vInstanceArray.length; i++) {
652 this._instanceList.add(vInstanceArray[i]);
657 * Sets the value of '_instanceList' by copying the given Vector. All elements
658 * will be checked for type safety.
660 * @param vInstanceList
661 * the Vector to copy.
663 public void setInstance(final java.util.Vector vInstanceList) {
665 this._instanceList.clear();
667 this._instanceList.addAll(vInstanceList);
671 * Sets the value of '_instanceList' by setting it to the given Vector. No
672 * type checking is performed.
676 * @param instanceVector
679 public void setInstanceAsReference(final java.util.Vector instanceVector) {
680 this._instanceList = instanceVector;
684 * Sets the value of field 'name'. The field 'name' has the following
685 * description: Canonical name of application
688 * the value of field 'name'.
690 public void setName(final java.lang.String name) {
699 * @throws java.lang.IndexOutOfBoundsException
700 * if the index given is outside the bounds of the collection
702 public void setUser(final int index,
703 final uk.ac.vamsas.objects.core.User vUser)
704 throws java.lang.IndexOutOfBoundsException {
705 // check bounds for index
706 if (index < 0 || index >= this._userList.size()) {
707 throw new IndexOutOfBoundsException("setUser: Index value '" + index
708 + "' not in range [0.." + (this._userList.size() - 1) + "]");
711 this._userList.set(index, vUser);
719 public void setUser(final uk.ac.vamsas.objects.core.User[] vUserArray) {
723 for (int i = 0; i < vUserArray.length; i++) {
724 this._userList.add(vUserArray[i]);
729 * Sets the value of '_userList' by copying the given Vector. All elements
730 * will be checked for type safety.
733 * the Vector to copy.
735 public void setUser(final java.util.Vector vUserList) {
737 this._userList.clear();
739 this._userList.addAll(vUserList);
743 * Sets the value of '_userList' by setting it to the given Vector. No type
744 * checking is performed.
751 public void setUserAsReference(final java.util.Vector userVector) {
752 this._userList = userVector;
756 * Sets the value of field 'version'. The field 'version' has the following
757 * description: Version string describing the application specific data
758 * storage version used
761 * the value of field 'version'.
763 public void setVersion(final java.lang.String version) {
764 this._version = version;
771 * @throws org.exolab.castor.xml.MarshalException
772 * if object is null or if any SAXException is thrown during
774 * @throws org.exolab.castor.xml.ValidationException
775 * if this object is an invalid instance according to the schema
776 * @return the unmarshaled uk.ac.vamsas.objects.core.AppData
778 public static uk.ac.vamsas.objects.core.AppData unmarshal(
779 final java.io.Reader reader)
780 throws org.exolab.castor.xml.MarshalException,
781 org.exolab.castor.xml.ValidationException {
782 return (uk.ac.vamsas.objects.core.AppData) Unmarshaller.unmarshal(
783 uk.ac.vamsas.objects.core.ApplicationData.class, reader);
789 * @throws org.exolab.castor.xml.ValidationException
790 * if this object is an invalid instance according to the schema
792 public void validate() throws org.exolab.castor.xml.ValidationException {
793 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
794 validator.validate(this);