From: jprocter Date: Fri, 29 Jun 2007 12:23:12 +0000 (+0000) Subject: 0 to unbounded Dataset/Sequence/DbRef/Map elements. Allows alternate mappings between... X-Git-Tag: Release_0.2~96 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=717959cb5ca21c6183c3588361f43782767a88df;p=vamsas.git 0 to unbounded Dataset/Sequence/DbRef/Map elements. Allows alternate mappings between a sequence and its DbRef. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@424 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/schemas/vamsas.xsd b/schemas/vamsas.xsd index 946b609..80f5d91 100644 --- a/schemas/vamsas.xsd +++ b/schemas/vamsas.xsd @@ -442,7 +442,7 @@ + maxOccurs="unbounded"> the local mapType maps from the parent diff --git a/src/uk/ac/vamsas/objects/core/.castor.cdr b/src/uk/ac/vamsas/objects/core/.castor.cdr index 6847de4..ed2e77c 100644 --- a/src/uk/ac/vamsas/objects/core/.castor.cdr +++ b/src/uk/ac/vamsas/objects/core/.castor.cdr @@ -1,4 +1,4 @@ -#Thu Jun 21 15:41:21 BST 2007 +#Thu Jun 28 21:34:58 BST 2007 uk.ac.vamsas.objects.core.Vref=uk.ac.vamsas.objects.core.descriptors.VrefDescriptor uk.ac.vamsas.objects.core.ReferenceType=uk.ac.vamsas.objects.core.descriptors.ReferenceTypeDescriptor uk.ac.vamsas.objects.core.SequenceType=uk.ac.vamsas.objects.core.descriptors.SequenceTypeDescriptor diff --git a/src/uk/ac/vamsas/objects/core/DbRef.java b/src/uk/ac/vamsas/objects/core/DbRef.java index 54dfa2c..7206791 100644 --- a/src/uk/ac/vamsas/objects/core/DbRef.java +++ b/src/uk/ac/vamsas/objects/core/DbRef.java @@ -73,7 +73,7 @@ implements java.io.Serializable * However, it may be used to avoid ambiguity. * */ - private uk.ac.vamsas.objects.core.Map _map; + private java.util.Vector _mapList; /** * Field _linkList. @@ -92,6 +92,7 @@ implements java.io.Serializable public DbRef() { super(); + this._mapList = new java.util.Vector(); this._linkList = new java.util.Vector(); this._propertyList = new java.util.Vector(); } @@ -132,6 +133,34 @@ implements java.io.Serializable /** * * + * @param vMap + * @throws java.lang.IndexOutOfBoundsException if the index + * given is outside the bounds of the collection + */ + public void addMap( + final uk.ac.vamsas.objects.core.Map vMap) + throws java.lang.IndexOutOfBoundsException { + this._mapList.addElement(vMap); + } + + /** + * + * + * @param index + * @param vMap + * @throws java.lang.IndexOutOfBoundsException if the index + * given is outside the bounds of the collection + */ + public void addMap( + final int index, + final uk.ac.vamsas.objects.core.Map vMap) + throws java.lang.IndexOutOfBoundsException { + this._mapList.add(index, vMap); + } + + /** + * + * * @param vProperty * @throws java.lang.IndexOutOfBoundsException if the index * given is outside the bounds of the collection @@ -169,6 +198,17 @@ implements java.io.Serializable } /** + * Method enumerateMap. + * + * @return an Enumeration over all + * uk.ac.vamsas.objects.core.Map elements + */ + public java.util.Enumeration enumerateMap( + ) { + return this._mapList.elements(); + } + + /** * Method enumerateProperty. * * @return an Enumeration over all @@ -286,27 +326,27 @@ implements java.io.Serializable } } else if (temp._id != null) return false; - if (this._map != null) { - if (temp._map == null) return false; - if (this._map != temp._map) { - thcycle=org.castor.util.CycleBreaker.startingToCycle(this._map); - tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._map); + if (this._mapList != null) { + if (temp._mapList == null) return false; + if (this._mapList != temp._mapList) { + thcycle=org.castor.util.CycleBreaker.startingToCycle(this._mapList); + tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._mapList); if (thcycle!=tmcycle) { - if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._map); }; - if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._map); }; + if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._mapList); }; + if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapList); }; return false; } if (!thcycle) { - if (!this._map.equals(temp._map)) { - org.castor.util.CycleBreaker.releaseCycleHandle(this._map); - org.castor.util.CycleBreaker.releaseCycleHandle(temp._map); + if (!this._mapList.equals(temp._mapList)) { + org.castor.util.CycleBreaker.releaseCycleHandle(this._mapList); + org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapList); return false; } - org.castor.util.CycleBreaker.releaseCycleHandle(this._map); - org.castor.util.CycleBreaker.releaseCycleHandle(temp._map); + org.castor.util.CycleBreaker.releaseCycleHandle(this._mapList); + org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapList); } } - } else if (temp._map != null) + } else if (temp._mapList != null) return false; if (this._linkList != null) { if (temp._linkList == null) return false; @@ -443,25 +483,60 @@ implements java.io.Serializable } /** - * Returns the value of field 'map'. The field 'map' has the - * following description: the local mapType maps from the - * parent - * sequence coordinate frame to the reference - * frame defined by the dbRef element. - * The mapped mapType is the mapped range defined - * on the dbRef element's reference frame. - * Conventionally, the unit attribute defaults to 1, or - * will be inferred from the local sequence's - * dictionary type and any dictionary type associated - * with the database being mapped to. - * However, it may be used to avoid ambiguity. - * + * Method getMap. * - * @return the value of field 'Map'. + * @param index + * @throws java.lang.IndexOutOfBoundsException if the index + * given is outside the bounds of the collection + * @return the value of the uk.ac.vamsas.objects.core.Map at + * the given index */ public uk.ac.vamsas.objects.core.Map getMap( + final int index) + throws java.lang.IndexOutOfBoundsException { + // check bounds for index + if (index < 0 || index >= this._mapList.size()) { + throw new IndexOutOfBoundsException("getMap: Index value '" + index + "' not in range [0.." + (this._mapList.size() - 1) + "]"); + } + + return (uk.ac.vamsas.objects.core.Map) _mapList.get(index); + } + + /** + * Method getMap.Returns the contents of the collection in an + * Array.

Note: Just in case the collection contents are + * changing in another thread, we pass a 0-length Array of the + * correct type into the API call. This way we know + * that the Array returned is of exactly the correct length. + * + * @return this collection as an Array + */ + public uk.ac.vamsas.objects.core.Map[] getMap( ) { - return this._map; + uk.ac.vamsas.objects.core.Map[] array = new uk.ac.vamsas.objects.core.Map[0]; + return (uk.ac.vamsas.objects.core.Map[]) this._mapList.toArray(array); + } + + /** + * Method getMapAsReference.Returns a reference to '_mapList'. + * No type checking is performed on any modifications to the + * Vector. + * + * @return a reference to the Vector backing this class + */ + public java.util.Vector getMapAsReference( + ) { + return this._mapList; + } + + /** + * Method getMapCount. + * + * @return the size of this collection + */ + public int getMapCount( + ) { + return this._mapList.size(); } /** @@ -581,10 +656,10 @@ implements java.io.Serializable result = 37 * result + _id.hashCode(); org.castor.util.CycleBreaker.releaseCycleHandle(_id); } - if (_map != null - && !org.castor.util.CycleBreaker.startingToCycle(_map)) { - result = 37 * result + _map.hashCode(); - org.castor.util.CycleBreaker.releaseCycleHandle(_map); + if (_mapList != null + && !org.castor.util.CycleBreaker.startingToCycle(_mapList)) { + result = 37 * result + _mapList.hashCode(); + org.castor.util.CycleBreaker.releaseCycleHandle(_mapList); } if (_linkList != null && !org.castor.util.CycleBreaker.startingToCycle(_linkList)) { @@ -656,6 +731,13 @@ implements java.io.Serializable /** */ + public void removeAllMap( + ) { + this._mapList.clear(); + } + + /** + */ public void removeAllProperty( ) { this._propertyList.clear(); @@ -686,6 +768,30 @@ implements java.io.Serializable } /** + * Method removeMap. + * + * @param vMap + * @return true if the object was removed from the collection. + */ + public boolean removeMap( + final uk.ac.vamsas.objects.core.Map vMap) { + boolean removed = _mapList.remove(vMap); + return removed; + } + + /** + * Method removeMapAt. + * + * @param index + * @return the element removed from the collection + */ + public uk.ac.vamsas.objects.core.Map removeMapAt( + final int index) { + java.lang.Object obj = this._mapList.remove(index); + return (uk.ac.vamsas.objects.core.Map) obj; + } + + /** * Method removeProperty. * * @param vProperty @@ -799,25 +905,64 @@ implements java.io.Serializable } /** - * Sets the value of field 'map'. The field 'map' has the - * following description: the local mapType maps from the - * parent - * sequence coordinate frame to the reference - * frame defined by the dbRef element. - * The mapped mapType is the mapped range defined - * on the dbRef element's reference frame. - * Conventionally, the unit attribute defaults to 1, or - * will be inferred from the local sequence's - * dictionary type and any dictionary type associated - * with the database being mapped to. - * However, it may be used to avoid ambiguity. - * * - * @param map the value of field 'map'. + * + * @param index + * @param vMap + * @throws java.lang.IndexOutOfBoundsException if the index + * given is outside the bounds of the collection */ public void setMap( - final uk.ac.vamsas.objects.core.Map map) { - this._map = map; + final int index, + final uk.ac.vamsas.objects.core.Map vMap) + throws java.lang.IndexOutOfBoundsException { + // check bounds for index + if (index < 0 || index >= this._mapList.size()) { + throw new IndexOutOfBoundsException("setMap: Index value '" + index + "' not in range [0.." + (this._mapList.size() - 1) + "]"); + } + + this._mapList.set(index, vMap); + } + + /** + * + * + * @param vMapArray + */ + public void setMap( + final uk.ac.vamsas.objects.core.Map[] vMapArray) { + //-- copy array + _mapList.clear(); + + for (int i = 0; i < vMapArray.length; i++) { + this._mapList.add(vMapArray[i]); + } + } + + /** + * Sets the value of '_mapList' by copying the given Vector. + * All elements will be checked for type safety. + * + * @param vMapList the Vector to copy. + */ + public void setMap( + final java.util.Vector vMapList) { + // copy vector + this._mapList.clear(); + + this._mapList.addAll(vMapList); + } + + /** + * Sets the value of '_mapList' by setting it to the given + * Vector. No type checking is performed. + * @deprecated + * + * @param mapVector the Vector to set. + */ + public void setMapAsReference( + final java.util.Vector mapVector) { + this._mapList = mapVector; } /** diff --git a/src/uk/ac/vamsas/objects/core/descriptors/DbRefDescriptor.java b/src/uk/ac/vamsas/objects/core/descriptors/DbRefDescriptor.java index ef04791..9f13e4f 100644 --- a/src/uk/ac/vamsas/objects/core/descriptors/DbRefDescriptor.java +++ b/src/uk/ac/vamsas/objects/core/descriptors/DbRefDescriptor.java @@ -218,8 +218,8 @@ public class DbRefDescriptor extends org.exolab.castor.xml.util.XMLClassDescript desc.setValidator(fieldValidator); //-- initialize element descriptors - //-- _map - desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(uk.ac.vamsas.objects.core.Map.class, "_map", "map", org.exolab.castor.xml.NodeType.Element); + //-- _mapList + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(uk.ac.vamsas.objects.core.Map.class, "_mapList", "map", org.exolab.castor.xml.NodeType.Element); handler = new org.exolab.castor.xml.XMLFieldHandler() { public java.lang.Object getValue( java.lang.Object object ) throws IllegalStateException @@ -232,7 +232,15 @@ public class DbRefDescriptor extends org.exolab.castor.xml.util.XMLClassDescript { try { DbRef target = (DbRef) object; - target.setMap( (uk.ac.vamsas.objects.core.Map) value); + target.addMap( (uk.ac.vamsas.objects.core.Map) value); + } catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public void resetValue(Object object) throws IllegalStateException, IllegalArgumentException { + try { + DbRef target = (DbRef) object; + target.removeAllMap(); } catch (java.lang.Exception ex) { throw new IllegalStateException(ex.toString()); } @@ -243,11 +251,12 @@ public class DbRefDescriptor extends org.exolab.castor.xml.util.XMLClassDescript }; desc.setHandler(handler); desc.setNameSpaceURI("http://www.vamsas.ac.uk/schemas/1.0/vamsasTypes"); - desc.setMultivalued(false); + desc.setMultivalued(true); addFieldDescriptor(desc); - //-- validation code for: _map + //-- validation code for: _mapList fieldValidator = new org.exolab.castor.xml.FieldValidator(); + fieldValidator.setMinOccurs(0); { //-- local scope } desc.setValidator(fieldValidator);