applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / LockFile.java
1 /*
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.
5  * 
6  * Earlier versions have also been incorporated into Jalview version 2.4 
7  * since 2008, and TOPALi version 2 since 2007.
8  * 
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.
13  *  
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.
18  * 
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/>.
21  */
22 package uk.ac.vamsas.objects.core;
23
24 //---------------------------------/
25 //- Imported classes and packages -/
26 //---------------------------------/
27
28 import org.exolab.castor.xml.Marshaller;
29 import org.exolab.castor.xml.Unmarshaller;
30
31 /**
32  * Class LockFile.
33  * 
34  * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
35  *          $
36  */
37 public class LockFile extends uk.ac.vamsas.client.Vobject implements
38     java.io.Serializable {
39
40   // --------------------------/
41   // - Class/Member Variables -/
42   // --------------------------/
43
44   /**
45    * internal content storage
46    */
47   private java.lang.String _content = "";
48
49   // ----------------/
50   // - Constructors -/
51   // ----------------/
52
53   public LockFile() {
54     super();
55     setContent("");
56   }
57
58   // -----------/
59   // - Methods -/
60   // -----------/
61
62   /**
63    * Overrides the java.lang.Object.equals method.
64    * 
65    * @param obj
66    * @return true if the objects are equal.
67    */
68   public boolean equals(final java.lang.Object obj) {
69     if (this == obj)
70       return true;
71
72     if (super.equals(obj) == false)
73       return false;
74
75     if (obj instanceof LockFile) {
76
77       LockFile temp = (LockFile) obj;
78       boolean thcycle;
79       boolean tmcycle;
80       if (this._content != null) {
81         if (temp._content == null)
82           return false;
83         if (this._content != temp._content) {
84           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._content);
85           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._content);
86           if (thcycle != tmcycle) {
87             if (!thcycle) {
88               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
89             }
90             ;
91             if (!tmcycle) {
92               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
93             }
94             ;
95             return false;
96           }
97           if (!thcycle) {
98             if (!this._content.equals(temp._content)) {
99               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
100               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
101               return false;
102             }
103             org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
104             org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
105           }
106         }
107       } else if (temp._content != null)
108         return false;
109       return true;
110     }
111     return false;
112   }
113
114   /**
115    * Returns the value of field 'content'. The field 'content' has the following
116    * description: internal content storage
117    * 
118    * @return the value of field 'Content'.
119    */
120   public java.lang.String getContent() {
121     return this._content;
122   }
123
124   /**
125    * Overrides the java.lang.Object.hashCode method.
126    * <p>
127    * The following steps came from <b>Effective Java Programming Language
128    * Guide</b> by Joshua Bloch, Chapter 3
129    * 
130    * @return a hash code value for the object.
131    */
132   public int hashCode() {
133     int result = super.hashCode();
134
135     long tmp;
136     if (_content != null
137         && !org.castor.util.CycleBreaker.startingToCycle(_content)) {
138       result = 37 * result + _content.hashCode();
139       org.castor.util.CycleBreaker.releaseCycleHandle(_content);
140     }
141
142     return result;
143   }
144
145   /**
146    * Method isValid.
147    * 
148    * @return true if this object is valid according to the schema
149    */
150   public boolean isValid() {
151     try {
152       validate();
153     } catch (org.exolab.castor.xml.ValidationException vex) {
154       return false;
155     }
156     return true;
157   }
158
159   /**
160    * 
161    * 
162    * @param out
163    * @throws org.exolab.castor.xml.MarshalException
164    *           if object is null or if any SAXException is thrown during
165    *           marshaling
166    * @throws org.exolab.castor.xml.ValidationException
167    *           if this object is an invalid instance according to the schema
168    */
169   public void marshal(final java.io.Writer out)
170       throws org.exolab.castor.xml.MarshalException,
171       org.exolab.castor.xml.ValidationException {
172     Marshaller.marshal(this, out);
173   }
174
175   /**
176    * 
177    * 
178    * @param handler
179    * @throws java.io.IOException
180    *           if an IOException occurs during marshaling
181    * @throws org.exolab.castor.xml.ValidationException
182    *           if this object is an invalid instance according to the schema
183    * @throws org.exolab.castor.xml.MarshalException
184    *           if object is null or if any SAXException is thrown during
185    *           marshaling
186    */
187   public void marshal(final org.xml.sax.ContentHandler handler)
188       throws java.io.IOException, org.exolab.castor.xml.MarshalException,
189       org.exolab.castor.xml.ValidationException {
190     Marshaller.marshal(this, handler);
191   }
192
193   /**
194    * Sets the value of field 'content'. The field 'content' has the following
195    * description: internal content storage
196    * 
197    * @param content
198    *          the value of field 'content'.
199    */
200   public void setContent(final java.lang.String content) {
201     this._content = content;
202   }
203
204   /**
205    * Method unmarshal.
206    * 
207    * @param reader
208    * @throws org.exolab.castor.xml.MarshalException
209    *           if object is null or if any SAXException is thrown during
210    *           marshaling
211    * @throws org.exolab.castor.xml.ValidationException
212    *           if this object is an invalid instance according to the schema
213    * @return the unmarshaled uk.ac.vamsas.objects.core.LockFile
214    */
215   public static uk.ac.vamsas.objects.core.LockFile unmarshal(
216       final java.io.Reader reader)
217       throws org.exolab.castor.xml.MarshalException,
218       org.exolab.castor.xml.ValidationException {
219     return (uk.ac.vamsas.objects.core.LockFile) Unmarshaller.unmarshal(
220         uk.ac.vamsas.objects.core.LockFile.class, reader);
221   }
222
223   /**
224    * 
225    * 
226    * @throws org.exolab.castor.xml.ValidationException
227    *           if this object is an invalid instance according to the schema
228    */
229   public void validate() throws org.exolab.castor.xml.ValidationException {
230     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
231     validator.validate(this);
232   }
233
234 }