2 * This file is part of the Vamsas Client version 0.2.
\r
3 * Copyright 2010 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 Attachment extends uk.ac.vamsas.objects.core.AppData implements
\r
37 java.io.Serializable {
\r
39 // --------------------------/
\r
40 // - Class/Member Variables -/
\r
41 // --------------------------/
\r
44 * true implies data will be decompresses with Zip before presenting to
\r
47 private boolean _compressed = false;
\r
50 * keeps track of state for field: _compressed
\r
52 private boolean _has_compressed;
\r
55 * Type of arbitrary data - TODO: decide format - use (extended) MIME types ?
\r
57 private java.lang.String _type;
\r
60 * Object the arbitrary data is associated with
\r
63 private java.lang.Object _objectref;
\r
66 * Primary Key for vamsas object referencing
\r
69 private java.lang.String _id;
\r
71 // ----------------/
\r
72 // - Constructors -/
\r
73 // ----------------/
\r
75 public Attachment() {
\r
85 public void deleteCompressed() {
\r
86 this._has_compressed = false;
\r
90 * Overrides the java.lang.Object.equals method.
\r
93 * @return true if the objects are equal.
\r
95 public boolean equals(final java.lang.Object obj) {
\r
99 if (super.equals(obj) == false)
\r
102 if (obj instanceof Attachment) {
\r
104 Attachment temp = (Attachment) obj;
\r
107 if (this._compressed != temp._compressed)
\r
109 if (this._has_compressed != temp._has_compressed)
\r
111 if (this._type != null) {
\r
112 if (temp._type == null)
\r
114 if (this._type != temp._type) {
\r
115 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._type);
\r
116 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._type);
\r
117 if (thcycle != tmcycle) {
\r
119 org.castor.util.CycleBreaker.releaseCycleHandle(this._type);
\r
123 org.castor.util.CycleBreaker.releaseCycleHandle(temp._type);
\r
129 if (!this._type.equals(temp._type)) {
\r
130 org.castor.util.CycleBreaker.releaseCycleHandle(this._type);
\r
131 org.castor.util.CycleBreaker.releaseCycleHandle(temp._type);
\r
134 org.castor.util.CycleBreaker.releaseCycleHandle(this._type);
\r
135 org.castor.util.CycleBreaker.releaseCycleHandle(temp._type);
\r
138 } else if (temp._type != null)
\r
140 if (this._objectref != null) {
\r
141 if (temp._objectref == null)
\r
143 if (this._objectref != temp._objectref) {
\r
144 thcycle = org.castor.util.CycleBreaker
\r
145 .startingToCycle(this._objectref);
\r
146 tmcycle = org.castor.util.CycleBreaker
\r
147 .startingToCycle(temp._objectref);
\r
148 if (thcycle != tmcycle) {
\r
150 org.castor.util.CycleBreaker.releaseCycleHandle(this._objectref);
\r
154 org.castor.util.CycleBreaker.releaseCycleHandle(temp._objectref);
\r
160 if (!this._objectref.equals(temp._objectref)) {
\r
161 org.castor.util.CycleBreaker.releaseCycleHandle(this._objectref);
\r
162 org.castor.util.CycleBreaker.releaseCycleHandle(temp._objectref);
\r
165 org.castor.util.CycleBreaker.releaseCycleHandle(this._objectref);
\r
166 org.castor.util.CycleBreaker.releaseCycleHandle(temp._objectref);
\r
169 } else if (temp._objectref != null)
\r
171 if (this._id != null) {
\r
172 if (temp._id == null)
\r
174 if (this._id != temp._id) {
\r
175 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
\r
176 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
\r
177 if (thcycle != tmcycle) {
\r
179 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
183 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
189 if (!this._id.equals(temp._id)) {
\r
190 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
191 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
194 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
\r
195 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
\r
198 } else if (temp._id != null)
\r
206 * Returns the value of field 'compressed'. The field 'compressed' has the
\r
207 * following description: true implies data will be decompresses with Zip
\r
208 * before presenting to application
\r
210 * @return the value of field 'Compressed'.
\r
212 public boolean getCompressed() {
\r
213 return this._compressed;
\r
217 * Returns the value of field 'id'. The field 'id' has the following
\r
218 * description: Primary Key for vamsas object referencing
\r
221 * @return the value of field 'Id'.
\r
223 public java.lang.String getId() {
\r
228 * Returns the value of field 'objectref'. The field 'objectref' has the
\r
229 * following description: Object the arbitrary data is associated with
\r
232 * @return the value of field 'Objectref'.
\r
234 public java.lang.Object getObjectref() {
\r
235 return this._objectref;
\r
239 * Returns the value of field 'type'. The field 'type' has the following
\r
240 * description: Type of arbitrary data - TODO: decide format - use (extended)
\r
243 * @return the value of field 'Type'.
\r
245 public java.lang.String getType() {
\r
250 * Method hasCompressed.
\r
252 * @return true if at least one Compressed has been added
\r
254 public boolean hasCompressed() {
\r
255 return this._has_compressed;
\r
259 * Overrides the java.lang.Object.hashCode method.
\r
261 * The following steps came from <b>Effective Java Programming Language
\r
262 * Guide</b> by Joshua Bloch, Chapter 3
\r
264 * @return a hash code value for the object.
\r
266 public int hashCode() {
\r
267 int result = super.hashCode();
\r
270 result = 37 * result + (_compressed ? 0 : 1);
\r
271 if (_type != null && !org.castor.util.CycleBreaker.startingToCycle(_type)) {
\r
272 result = 37 * result + _type.hashCode();
\r
273 org.castor.util.CycleBreaker.releaseCycleHandle(_type);
\r
275 if (_objectref != null
\r
276 && !org.castor.util.CycleBreaker.startingToCycle(_objectref)) {
\r
277 result = 37 * result + _objectref.hashCode();
\r
278 org.castor.util.CycleBreaker.releaseCycleHandle(_objectref);
\r
280 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
\r
281 result = 37 * result + _id.hashCode();
\r
282 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
\r
289 * Returns the value of field 'compressed'. The field 'compressed' has the
\r
290 * following description: true implies data will be decompresses with Zip
\r
291 * before presenting to application
\r
293 * @return the value of field 'Compressed'.
\r
295 public boolean isCompressed() {
\r
296 return this._compressed;
\r
302 * @return true if this object is valid according to the schema
\r
304 public boolean isValid() {
\r
307 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
317 * @throws org.exolab.castor.xml.MarshalException
\r
318 * if object is null or if any SAXException is thrown during
\r
320 * @throws org.exolab.castor.xml.ValidationException
\r
321 * if this object is an invalid instance according to the schema
\r
323 public void marshal(final java.io.Writer out)
\r
324 throws org.exolab.castor.xml.MarshalException,
\r
325 org.exolab.castor.xml.ValidationException {
\r
326 Marshaller.marshal(this, out);
\r
333 * @throws java.io.IOException
\r
334 * if an IOException occurs during marshaling
\r
335 * @throws org.exolab.castor.xml.ValidationException
\r
336 * if this object is an invalid instance according to the schema
\r
337 * @throws org.exolab.castor.xml.MarshalException
\r
338 * if object is null or if any SAXException is thrown during
\r
341 public void marshal(final org.xml.sax.ContentHandler handler)
\r
342 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
\r
343 org.exolab.castor.xml.ValidationException {
\r
344 Marshaller.marshal(this, handler);
\r
348 * Sets the value of field 'compressed'. The field 'compressed' has the
\r
349 * following description: true implies data will be decompresses with Zip
\r
350 * before presenting to application
\r
352 * @param compressed
\r
353 * the value of field 'compressed'.
\r
355 public void setCompressed(final boolean compressed) {
\r
356 this._compressed = compressed;
\r
357 this._has_compressed = true;
\r
361 * Sets the value of field 'id'. The field 'id' has the following description:
\r
362 * Primary Key for vamsas object referencing
\r
366 * the value of field 'id'.
\r
368 public void setId(final java.lang.String id) {
\r
373 * Sets the value of field 'objectref'. The field 'objectref' has the
\r
374 * following description: Object the arbitrary data is associated with
\r
378 * the value of field 'objectref'.
\r
380 public void setObjectref(final java.lang.Object objectref) {
\r
381 this._objectref = objectref;
\r
385 * Sets the value of field 'type'. The field 'type' has the following
\r
386 * description: Type of arbitrary data - TODO: decide format - use (extended)
\r
390 * the value of field 'type'.
\r
392 public void setType(final java.lang.String type) {
\r
397 * Method unmarshal.
\r
400 * @throws org.exolab.castor.xml.MarshalException
\r
401 * if object is null or if any SAXException is thrown during
\r
403 * @throws org.exolab.castor.xml.ValidationException
\r
404 * if this object is an invalid instance according to the schema
\r
405 * @return the unmarshaled uk.ac.vamsas.objects.core.AppData
\r
407 public static uk.ac.vamsas.objects.core.AppData unmarshal(
\r
408 final java.io.Reader reader)
\r
409 throws org.exolab.castor.xml.MarshalException,
\r
410 org.exolab.castor.xml.ValidationException {
\r
411 return (uk.ac.vamsas.objects.core.AppData) Unmarshaller.unmarshal(
\r
412 uk.ac.vamsas.objects.core.Attachment.class, reader);
\r
418 * @throws org.exolab.castor.xml.ValidationException
\r
419 * if this object is an invalid instance according to the schema
\r
421 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
422 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
423 validator.validate(this);
\r