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
34 * @version $Revision$ $Date$
\r
36 public class NodeType extends uk.ac.vamsas.client.Vobject implements
\r
37 java.io.Serializable {
\r
39 // --------------------------/
\r
40 // - Class/Member Variables -/
\r
41 // --------------------------/
\r
44 * Primary Key for vamsas object referencing
\r
46 private java.lang.String _id;
\r
49 * Field _modifiable.
\r
51 private java.lang.String _modifiable;
\r
54 * Short name for this node
\r
56 private java.lang.String _name;
\r
59 * Descriptive text for this node
\r
61 private java.lang.String _description;
\r
64 * Direct associations between this node and any vamsas objects
\r
66 private java.util.Vector _vrefList;
\r
69 * Field _propertyList.
\r
71 private java.util.Vector _propertyList;
\r
73 // ----------------/
\r
74 // - Constructors -/
\r
75 // ----------------/
\r
79 this._vrefList = new java.util.Vector();
\r
80 this._propertyList = new java.util.Vector();
\r
91 * @throws java.lang.IndexOutOfBoundsException
\r
92 * if the index given is outside the bounds of the collection
\r
94 public void addProperty(final uk.ac.vamsas.objects.core.Property vProperty)
\r
95 throws java.lang.IndexOutOfBoundsException {
\r
96 this._propertyList.addElement(vProperty);
\r
104 * @throws java.lang.IndexOutOfBoundsException
\r
105 * if the index given is outside the bounds of the collection
\r
107 public void addProperty(final int index,
\r
108 final uk.ac.vamsas.objects.core.Property vProperty)
\r
109 throws java.lang.IndexOutOfBoundsException {
\r
110 this._propertyList.add(index, vProperty);
\r
117 * @throws java.lang.IndexOutOfBoundsException
\r
118 * if the index given is outside the bounds of the collection
\r
120 public void addVref(final uk.ac.vamsas.objects.core.Vref vVref)
\r
121 throws java.lang.IndexOutOfBoundsException {
\r
122 this._vrefList.addElement(vVref);
\r
130 * @throws java.lang.IndexOutOfBoundsException
\r
131 * if the index given is outside the bounds of the collection
\r
133 public void addVref(final int index,
\r
134 final uk.ac.vamsas.objects.core.Vref vVref)
\r
135 throws java.lang.IndexOutOfBoundsException {
\r
136 this._vrefList.add(index, vVref);
\r
140 * Method enumerateProperty.
\r
142 * @return an Enumeration over all uk.ac.vamsas.objects.core.Property elements
\r
144 public java.util.Enumeration enumerateProperty() {
\r
145 return this._propertyList.elements();
\r
149 * Method enumerateVref.
\r
151 * @return an Enumeration over all uk.ac.vamsas.objects.core.Vref elements
\r
153 public java.util.Enumeration enumerateVref() {
\r
154 return this._vrefList.elements();
\r
158 * Overrides the java.lang.Object.equals method.
\r
161 * @return true if the objects are equal.
\r
163 public boolean equals(final java.lang.Object obj) {
\r
167 if (super.equals(obj) == false)
\r
170 if (obj instanceof NodeType) {
\r
172 NodeType temp = (NodeType) obj;
\r
175 if (this._id != null) {
\r
176 if (temp._id == null)
\r
178 if (this._id != temp._id) {
\r
179 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
\r
180 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
\r
181 if (thcycle != tmcycle) {
\r
183 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
187 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
193 if (!this._id.equals(temp._id)) {
\r
194 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
195 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
198 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
199 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
202 } else if (temp._id != null)
\r
204 if (this._modifiable != null) {
\r
205 if (temp._modifiable == null)
\r
207 if (this._modifiable != temp._modifiable) {
\r
208 thcycle = org.castor.util.CycleBreaker
\r
209 .startingToCycle(this._modifiable);
\r
210 tmcycle = org.castor.util.CycleBreaker
\r
211 .startingToCycle(temp._modifiable);
\r
212 if (thcycle != tmcycle) {
\r
214 org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
\r
218 org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
\r
224 if (!this._modifiable.equals(temp._modifiable)) {
\r
225 org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
\r
226 org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
\r
229 org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
\r
230 org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
\r
233 } else if (temp._modifiable != null)
\r
235 if (this._name != null) {
\r
236 if (temp._name == null)
\r
238 if (this._name != temp._name) {
\r
239 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._name);
\r
240 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._name);
\r
241 if (thcycle != tmcycle) {
\r
243 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
\r
247 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
\r
253 if (!this._name.equals(temp._name)) {
\r
254 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
\r
255 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
\r
258 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
\r
259 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
\r
262 } else if (temp._name != null)
\r
264 if (this._description != null) {
\r
265 if (temp._description == null)
\r
267 if (this._description != temp._description) {
\r
268 thcycle = org.castor.util.CycleBreaker
\r
269 .startingToCycle(this._description);
\r
270 tmcycle = org.castor.util.CycleBreaker
\r
271 .startingToCycle(temp._description);
\r
272 if (thcycle != tmcycle) {
\r
274 org.castor.util.CycleBreaker
\r
275 .releaseCycleHandle(this._description);
\r
279 org.castor.util.CycleBreaker
\r
280 .releaseCycleHandle(temp._description);
\r
286 if (!this._description.equals(temp._description)) {
\r
287 org.castor.util.CycleBreaker
\r
288 .releaseCycleHandle(this._description);
\r
289 org.castor.util.CycleBreaker
\r
290 .releaseCycleHandle(temp._description);
\r
293 org.castor.util.CycleBreaker.releaseCycleHandle(this._description);
\r
294 org.castor.util.CycleBreaker.releaseCycleHandle(temp._description);
\r
297 } else if (temp._description != null)
\r
299 if (this._vrefList != null) {
\r
300 if (temp._vrefList == null)
\r
302 if (this._vrefList != temp._vrefList) {
\r
303 thcycle = org.castor.util.CycleBreaker
\r
304 .startingToCycle(this._vrefList);
\r
305 tmcycle = org.castor.util.CycleBreaker
\r
306 .startingToCycle(temp._vrefList);
\r
307 if (thcycle != tmcycle) {
\r
309 org.castor.util.CycleBreaker.releaseCycleHandle(this._vrefList);
\r
313 org.castor.util.CycleBreaker.releaseCycleHandle(temp._vrefList);
\r
319 if (!this._vrefList.equals(temp._vrefList)) {
\r
320 org.castor.util.CycleBreaker.releaseCycleHandle(this._vrefList);
\r
321 org.castor.util.CycleBreaker.releaseCycleHandle(temp._vrefList);
\r
324 org.castor.util.CycleBreaker.releaseCycleHandle(this._vrefList);
\r
325 org.castor.util.CycleBreaker.releaseCycleHandle(temp._vrefList);
\r
328 } else if (temp._vrefList != null)
\r
330 if (this._propertyList != null) {
\r
331 if (temp._propertyList == null)
\r
333 if (this._propertyList != temp._propertyList) {
\r
334 thcycle = org.castor.util.CycleBreaker
\r
335 .startingToCycle(this._propertyList);
\r
336 tmcycle = org.castor.util.CycleBreaker
\r
337 .startingToCycle(temp._propertyList);
\r
338 if (thcycle != tmcycle) {
\r
340 org.castor.util.CycleBreaker
\r
341 .releaseCycleHandle(this._propertyList);
\r
345 org.castor.util.CycleBreaker
\r
346 .releaseCycleHandle(temp._propertyList);
\r
352 if (!this._propertyList.equals(temp._propertyList)) {
\r
353 org.castor.util.CycleBreaker
\r
354 .releaseCycleHandle(this._propertyList);
\r
355 org.castor.util.CycleBreaker
\r
356 .releaseCycleHandle(temp._propertyList);
\r
359 org.castor.util.CycleBreaker.releaseCycleHandle(this._propertyList);
\r
360 org.castor.util.CycleBreaker.releaseCycleHandle(temp._propertyList);
\r
363 } else if (temp._propertyList != null)
\r
371 * Returns the value of field 'description'. The field 'description' has the
\r
372 * following description: Descriptive text for this node
\r
374 * @return the value of field 'Description'.
\r
376 public java.lang.String getDescription() {
\r
377 return this._description;
\r
381 * Returns the value of field 'id'. The field 'id' has the following
\r
382 * description: Primary Key for vamsas object referencing
\r
384 * @return the value of field 'Id'.
\r
386 public java.lang.String getId() {
\r
391 * Returns the value of field 'modifiable'.
\r
393 * @return the value of field 'Modifiable'.
\r
395 public java.lang.String getModifiable() {
\r
396 return this._modifiable;
\r
400 * Returns the value of field 'name'. The field 'name' has the following
\r
401 * description: Short name for this node
\r
403 * @return the value of field 'Name'.
\r
405 public java.lang.String getName() {
\r
410 * Method getProperty.
\r
413 * @throws java.lang.IndexOutOfBoundsException
\r
414 * if the index given is outside the bounds of the collection
\r
415 * @return the value of the uk.ac.vamsas.objects.core.Property at the given
\r
418 public uk.ac.vamsas.objects.core.Property getProperty(final int index)
\r
419 throws java.lang.IndexOutOfBoundsException {
\r
420 // check bounds for index
\r
421 if (index < 0 || index >= this._propertyList.size()) {
\r
422 throw new IndexOutOfBoundsException("getProperty: Index value '" + index
\r
423 + "' not in range [0.." + (this._propertyList.size() - 1) + "]");
\r
426 return (uk.ac.vamsas.objects.core.Property) _propertyList.get(index);
\r
430 * Method getProperty.Returns the contents of the collection in an Array.
\r
432 * Note: Just in case the collection contents are changing in another thread,
\r
433 * we pass a 0-length Array of the correct type into the API call. This way we
\r
434 * <i>know</i> that the Array returned is of exactly the correct length.
\r
436 * @return this collection as an Array
\r
438 public uk.ac.vamsas.objects.core.Property[] getProperty() {
\r
439 uk.ac.vamsas.objects.core.Property[] array = new uk.ac.vamsas.objects.core.Property[0];
\r
440 return (uk.ac.vamsas.objects.core.Property[]) this._propertyList
\r
445 * Method getPropertyAsReference.Returns a reference to '_propertyList'. No
\r
446 * type checking is performed on any modifications to the Vector.
\r
448 * @return a reference to the Vector backing this class
\r
450 public java.util.Vector getPropertyAsReference() {
\r
451 return this._propertyList;
\r
455 * Method getPropertyCount.
\r
457 * @return the size of this collection
\r
459 public int getPropertyCount() {
\r
460 return this._propertyList.size();
\r
467 * @throws java.lang.IndexOutOfBoundsException
\r
468 * if the index given is outside the bounds of the collection
\r
469 * @return the value of the uk.ac.vamsas.objects.core.Vref at the given index
\r
471 public uk.ac.vamsas.objects.core.Vref getVref(final int index)
\r
472 throws java.lang.IndexOutOfBoundsException {
\r
473 // check bounds for index
\r
474 if (index < 0 || index >= this._vrefList.size()) {
\r
475 throw new IndexOutOfBoundsException("getVref: Index value '" + index
\r
476 + "' not in range [0.." + (this._vrefList.size() - 1) + "]");
\r
479 return (uk.ac.vamsas.objects.core.Vref) _vrefList.get(index);
\r
483 * Method getVref.Returns the contents of the collection in an Array.
\r
485 * Note: Just in case the collection contents are changing in another thread,
\r
486 * we pass a 0-length Array of the correct type into the API call. This way we
\r
487 * <i>know</i> that the Array returned is of exactly the correct length.
\r
489 * @return this collection as an Array
\r
491 public uk.ac.vamsas.objects.core.Vref[] getVref() {
\r
492 uk.ac.vamsas.objects.core.Vref[] array = new uk.ac.vamsas.objects.core.Vref[0];
\r
493 return (uk.ac.vamsas.objects.core.Vref[]) this._vrefList.toArray(array);
\r
497 * Method getVrefAsReference.Returns a reference to '_vrefList'. No type
\r
498 * checking is performed on any modifications to the Vector.
\r
500 * @return a reference to the Vector backing this class
\r
502 public java.util.Vector getVrefAsReference() {
\r
503 return this._vrefList;
\r
507 * Method getVrefCount.
\r
509 * @return the size of this collection
\r
511 public int getVrefCount() {
\r
512 return this._vrefList.size();
\r
516 * Overrides the java.lang.Object.hashCode method.
\r
518 * The following steps came from <b>Effective Java Programming Language
\r
519 * Guide</b> by Joshua Bloch, Chapter 3
\r
521 * @return a hash code value for the object.
\r
523 public int hashCode() {
\r
524 int result = super.hashCode();
\r
527 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
\r
528 result = 37 * result + _id.hashCode();
\r
529 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
\r
531 if (_modifiable != null
\r
532 && !org.castor.util.CycleBreaker.startingToCycle(_modifiable)) {
\r
533 result = 37 * result + _modifiable.hashCode();
\r
534 org.castor.util.CycleBreaker.releaseCycleHandle(_modifiable);
\r
536 if (_name != null && !org.castor.util.CycleBreaker.startingToCycle(_name)) {
\r
537 result = 37 * result + _name.hashCode();
\r
538 org.castor.util.CycleBreaker.releaseCycleHandle(_name);
\r
540 if (_description != null
\r
541 && !org.castor.util.CycleBreaker.startingToCycle(_description)) {
\r
542 result = 37 * result + _description.hashCode();
\r
543 org.castor.util.CycleBreaker.releaseCycleHandle(_description);
\r
545 if (_vrefList != null
\r
546 && !org.castor.util.CycleBreaker.startingToCycle(_vrefList)) {
\r
547 result = 37 * result + _vrefList.hashCode();
\r
548 org.castor.util.CycleBreaker.releaseCycleHandle(_vrefList);
\r
550 if (_propertyList != null
\r
551 && !org.castor.util.CycleBreaker.startingToCycle(_propertyList)) {
\r
552 result = 37 * result + _propertyList.hashCode();
\r
553 org.castor.util.CycleBreaker.releaseCycleHandle(_propertyList);
\r
562 * @return true if this object is valid according to the schema
\r
564 public boolean isValid() {
\r
567 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
577 * @throws org.exolab.castor.xml.MarshalException
\r
578 * if object is null or if any SAXException is thrown during
\r
580 * @throws org.exolab.castor.xml.ValidationException
\r
581 * if this object is an invalid instance according to the schema
\r
583 public void marshal(final java.io.Writer out)
\r
584 throws org.exolab.castor.xml.MarshalException,
\r
585 org.exolab.castor.xml.ValidationException {
\r
586 Marshaller.marshal(this, out);
\r
593 * @throws java.io.IOException
\r
594 * if an IOException occurs during marshaling
\r
595 * @throws org.exolab.castor.xml.ValidationException
\r
596 * if this object is an invalid instance according to the schema
\r
597 * @throws org.exolab.castor.xml.MarshalException
\r
598 * if object is null or if any SAXException is thrown during
\r
601 public void marshal(final org.xml.sax.ContentHandler handler)
\r
602 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
\r
603 org.exolab.castor.xml.ValidationException {
\r
604 Marshaller.marshal(this, handler);
\r
609 public void removeAllProperty() {
\r
610 this._propertyList.clear();
\r
615 public void removeAllVref() {
\r
616 this._vrefList.clear();
\r
620 * Method removeProperty.
\r
623 * @return true if the object was removed from the collection.
\r
625 public boolean removeProperty(
\r
626 final uk.ac.vamsas.objects.core.Property vProperty) {
\r
627 boolean removed = _propertyList.remove(vProperty);
\r
632 * Method removePropertyAt.
\r
635 * @return the element removed from the collection
\r
637 public uk.ac.vamsas.objects.core.Property removePropertyAt(final int index) {
\r
638 java.lang.Object obj = this._propertyList.remove(index);
\r
639 return (uk.ac.vamsas.objects.core.Property) obj;
\r
643 * Method removeVref.
\r
646 * @return true if the object was removed from the collection.
\r
648 public boolean removeVref(final uk.ac.vamsas.objects.core.Vref vVref) {
\r
649 boolean removed = _vrefList.remove(vVref);
\r
654 * Method removeVrefAt.
\r
657 * @return the element removed from the collection
\r
659 public uk.ac.vamsas.objects.core.Vref removeVrefAt(final int index) {
\r
660 java.lang.Object obj = this._vrefList.remove(index);
\r
661 return (uk.ac.vamsas.objects.core.Vref) obj;
\r
665 * Sets the value of field 'description'. The field 'description' has the
\r
666 * following description: Descriptive text for this node
\r
668 * @param description
\r
669 * the value of field 'description'.
\r
671 public void setDescription(final java.lang.String description) {
\r
672 this._description = description;
\r
676 * Sets the value of field 'id'. The field 'id' has the following description:
\r
677 * Primary Key for vamsas object referencing
\r
680 * the value of field 'id'.
\r
682 public void setId(final java.lang.String id) {
\r
687 * Sets the value of field 'modifiable'.
\r
689 * @param modifiable
\r
690 * the value of field 'modifiable'.
\r
692 public void setModifiable(final java.lang.String modifiable) {
\r
693 this._modifiable = modifiable;
\r
697 * Sets the value of field 'name'. The field 'name' has the following
\r
698 * description: Short name for this node
\r
701 * the value of field 'name'.
\r
703 public void setName(final java.lang.String name) {
\r
712 * @throws java.lang.IndexOutOfBoundsException
\r
713 * if the index given is outside the bounds of the collection
\r
715 public void setProperty(final int index,
\r
716 final uk.ac.vamsas.objects.core.Property vProperty)
\r
717 throws java.lang.IndexOutOfBoundsException {
\r
718 // check bounds for index
\r
719 if (index < 0 || index >= this._propertyList.size()) {
\r
720 throw new IndexOutOfBoundsException("setProperty: Index value '" + index
\r
721 + "' not in range [0.." + (this._propertyList.size() - 1) + "]");
\r
724 this._propertyList.set(index, vProperty);
\r
730 * @param vPropertyArray
\r
732 public void setProperty(
\r
733 final uk.ac.vamsas.objects.core.Property[] vPropertyArray) {
\r
735 _propertyList.clear();
\r
737 for (int i = 0; i < vPropertyArray.length; i++) {
\r
738 this._propertyList.add(vPropertyArray[i]);
\r
743 * Sets the value of '_propertyList' by copying the given Vector. All elements
\r
744 * will be checked for type safety.
\r
746 * @param vPropertyList
\r
747 * the Vector to copy.
\r
749 public void setProperty(final java.util.Vector vPropertyList) {
\r
751 this._propertyList.clear();
\r
753 this._propertyList.addAll(vPropertyList);
\r
757 * Sets the value of '_propertyList' by setting it to the given Vector. No
\r
758 * type checking is performed.
\r
762 * @param propertyVector
\r
763 * the Vector to set.
\r
765 public void setPropertyAsReference(final java.util.Vector propertyVector) {
\r
766 this._propertyList = propertyVector;
\r
774 * @throws java.lang.IndexOutOfBoundsException
\r
775 * if the index given is outside the bounds of the collection
\r
777 public void setVref(final int index,
\r
778 final uk.ac.vamsas.objects.core.Vref vVref)
\r
779 throws java.lang.IndexOutOfBoundsException {
\r
780 // check bounds for index
\r
781 if (index < 0 || index >= this._vrefList.size()) {
\r
782 throw new IndexOutOfBoundsException("setVref: Index value '" + index
\r
783 + "' not in range [0.." + (this._vrefList.size() - 1) + "]");
\r
786 this._vrefList.set(index, vVref);
\r
792 * @param vVrefArray
\r
794 public void setVref(final uk.ac.vamsas.objects.core.Vref[] vVrefArray) {
\r
798 for (int i = 0; i < vVrefArray.length; i++) {
\r
799 this._vrefList.add(vVrefArray[i]);
\r
804 * Sets the value of '_vrefList' by copying the given Vector. All elements
\r
805 * will be checked for type safety.
\r
808 * the Vector to copy.
\r
810 public void setVref(final java.util.Vector vVrefList) {
\r
812 this._vrefList.clear();
\r
814 this._vrefList.addAll(vVrefList);
\r
818 * Sets the value of '_vrefList' by setting it to the given Vector. No type
\r
819 * checking is performed.
\r
823 * @param vrefVector
\r
824 * the Vector to set.
\r
826 public void setVrefAsReference(final java.util.Vector vrefVector) {
\r
827 this._vrefList = vrefVector;
\r
831 * Method unmarshal.
\r
834 * @throws org.exolab.castor.xml.MarshalException
\r
835 * if object is null or if any SAXException is thrown during
\r
837 * @throws org.exolab.castor.xml.ValidationException
\r
838 * if this object is an invalid instance according to the schema
\r
839 * @return the unmarshaled uk.ac.vamsas.objects.core.NodeType
\r
841 public static uk.ac.vamsas.objects.core.NodeType unmarshal(
\r
842 final java.io.Reader reader)
\r
843 throws org.exolab.castor.xml.MarshalException,
\r
844 org.exolab.castor.xml.ValidationException {
\r
845 return (uk.ac.vamsas.objects.core.NodeType) Unmarshaller.unmarshal(
\r
846 uk.ac.vamsas.objects.core.NodeType.class, reader);
\r
852 * @throws org.exolab.castor.xml.ValidationException
\r
853 * if this object is an invalid instance according to the schema
\r
855 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
856 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
857 validator.validate(this);
\r