1
2
3
4
5
6
7
8 package org.astrogrid.registry.beans.resource.dataservice;
9
10
11
12
13
14 import java.io.IOException;
15 import java.io.Reader;
16 import java.io.Serializable;
17 import java.io.Writer;
18 import java.util.ArrayList;
19 import java.util.Enumeration;
20 import org.exolab.castor.xml.MarshalException;
21 import org.exolab.castor.xml.Marshaller;
22 import org.exolab.castor.xml.Unmarshaller;
23 import org.exolab.castor.xml.ValidationException;
24 import org.xml.sax.ContentHandler;
25
26 /***
27 * Class SpatialType.
28 *
29 * @version $Revision: 1.14 $ $Date: 2007/01/04 16:26:07 $
30 */
31 public class SpatialType extends org.astrogrid.common.bean.BaseBean
32 implements java.io.Serializable
33 {
34
35
36
37
38
39
40 /***
41 * Multiple occurances imply a coverage that is a union
42 * of the regions given (i.e. a logical "or", according
43 * to RM).
44 *
45 */
46 private java.util.ArrayList _regionList;
47
48 /***
49 * The spatial (angular) resolution that is typical of the
50 * observations of interest, in decimal degrees.
51 *
52 */
53 private float _spatialResolution;
54
55 /***
56 * keeps track of state for field: _spatialResolution
57 */
58 private boolean _has_spatialResolution;
59
60 /***
61 * The intrinsic size scale, given in arcseconds, associated
62 * with data items contained in a resource.
63 *
64 */
65 private float _regionOfRegard;
66
67 /***
68 * keeps track of state for field: _regionOfRegard
69 */
70 private boolean _has_regionOfRegard;
71
72
73
74
75
76
77 public SpatialType() {
78 super();
79 _regionList = new ArrayList();
80 }
81
82
83
84
85
86
87 /***
88 * Method addRegion
89 *
90 * @param vRegion
91 */
92 public void addRegion(org.astrogrid.registry.beans.resource.dataservice.RegionType vRegion)
93 throws java.lang.IndexOutOfBoundsException
94 {
95 _regionList.add(vRegion);
96 }
97
98 /***
99 * Method addRegion
100 *
101 * @param index
102 * @param vRegion
103 */
104 public void addRegion(int index, org.astrogrid.registry.beans.resource.dataservice.RegionType vRegion)
105 throws java.lang.IndexOutOfBoundsException
106 {
107 _regionList.add(index, vRegion);
108 }
109
110 /***
111 * Method clearRegion
112 */
113 public void clearRegion()
114 {
115 _regionList.clear();
116 }
117
118 /***
119 * Method deleteRegionOfRegard
120 */
121 public void deleteRegionOfRegard()
122 {
123 this._has_regionOfRegard= false;
124 }
125
126 /***
127 * Method deleteSpatialResolution
128 */
129 public void deleteSpatialResolution()
130 {
131 this._has_spatialResolution= false;
132 }
133
134 /***
135 * Method enumerateRegion
136 */
137 public java.util.Enumeration enumerateRegion()
138 {
139 return new org.exolab.castor.util.IteratorEnumeration(_regionList.iterator());
140 }
141
142 /***
143 * Note: hashCode() has not been overriden
144 *
145 * @param obj
146 */
147 public boolean equals(java.lang.Object obj)
148 {
149 if ( this == obj )
150 return true;
151
152 if (super.equals(obj)==false)
153 return false;
154
155 if (obj instanceof SpatialType) {
156
157 SpatialType temp = (SpatialType)obj;
158 if (this._regionList != null) {
159 if (temp._regionList == null) return false;
160 else if (!(this._regionList.equals(temp._regionList)))
161 return false;
162 }
163 else if (temp._regionList != null)
164 return false;
165 if (this._spatialResolution != temp._spatialResolution)
166 return false;
167 if (this._has_spatialResolution != temp._has_spatialResolution)
168 return false;
169 if (this._regionOfRegard != temp._regionOfRegard)
170 return false;
171 if (this._has_regionOfRegard != temp._has_regionOfRegard)
172 return false;
173 return true;
174 }
175 return false;
176 }
177
178 /***
179 * Method getRegion
180 *
181 * @param index
182 */
183 public org.astrogrid.registry.beans.resource.dataservice.RegionType getRegion(int index)
184 throws java.lang.IndexOutOfBoundsException
185 {
186
187 if ((index < 0) || (index > _regionList.size())) {
188 throw new IndexOutOfBoundsException();
189 }
190
191 return (org.astrogrid.registry.beans.resource.dataservice.RegionType) _regionList.get(index);
192 }
193
194 /***
195 * Method getRegion
196 */
197 public org.astrogrid.registry.beans.resource.dataservice.RegionType[] getRegion()
198 {
199 int size = _regionList.size();
200 org.astrogrid.registry.beans.resource.dataservice.RegionType[] mArray = new org.astrogrid.registry.beans.resource.dataservice.RegionType[size];
201 for (int index = 0; index < size; index++) {
202 mArray[index] = (org.astrogrid.registry.beans.resource.dataservice.RegionType) _regionList.get(index);
203 }
204 return mArray;
205 }
206
207 /***
208 * Method getRegionCount
209 */
210 public int getRegionCount()
211 {
212 return _regionList.size();
213 }
214
215 /***
216 * Returns the value of field 'regionOfRegard'. The field
217 * 'regionOfRegard' has the following description: The
218 * intrinsic size scale, given in arcseconds, associated
219 * with data items contained in a resource.
220 *
221 *
222 * @return the value of field 'regionOfRegard'.
223 */
224 public float getRegionOfRegard()
225 {
226 return this._regionOfRegard;
227 }
228
229 /***
230 * Returns the value of field 'spatialResolution'. The field
231 * 'spatialResolution' has the following description: The
232 * spatial (angular) resolution that is typical of the
233 * observations of interest, in decimal degrees.
234 *
235 *
236 * @return the value of field 'spatialResolution'.
237 */
238 public float getSpatialResolution()
239 {
240 return this._spatialResolution;
241 }
242
243 /***
244 * Method hasRegionOfRegard
245 */
246 public boolean hasRegionOfRegard()
247 {
248 return this._has_regionOfRegard;
249 }
250
251 /***
252 * Method hasSpatialResolution
253 */
254 public boolean hasSpatialResolution()
255 {
256 return this._has_spatialResolution;
257 }
258
259 /***
260 * Method isValid
261 */
262 public boolean isValid()
263 {
264 try {
265 validate();
266 }
267 catch (org.exolab.castor.xml.ValidationException vex) {
268 return false;
269 }
270 return true;
271 }
272
273 /***
274 * Method marshal
275 *
276 * @param out
277 */
278 public void marshal(java.io.Writer out)
279 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
280 {
281
282 Marshaller.marshal(this, out);
283 }
284
285 /***
286 * Method marshal
287 *
288 * @param handler
289 */
290 public void marshal(org.xml.sax.ContentHandler handler)
291 throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
292 {
293
294 Marshaller.marshal(this, handler);
295 }
296
297 /***
298 * Method removeRegion
299 *
300 * @param vRegion
301 */
302 public boolean removeRegion(org.astrogrid.registry.beans.resource.dataservice.RegionType vRegion)
303 {
304 boolean removed = _regionList.remove(vRegion);
305 return removed;
306 }
307
308 /***
309 * Method setRegion
310 *
311 * @param index
312 * @param vRegion
313 */
314 public void setRegion(int index, org.astrogrid.registry.beans.resource.dataservice.RegionType vRegion)
315 throws java.lang.IndexOutOfBoundsException
316 {
317
318 if ((index < 0) || (index > _regionList.size())) {
319 throw new IndexOutOfBoundsException();
320 }
321 _regionList.set(index, vRegion);
322 }
323
324 /***
325 * Method setRegion
326 *
327 * @param regionArray
328 */
329 public void setRegion(org.astrogrid.registry.beans.resource.dataservice.RegionType[] regionArray)
330 {
331
332 _regionList.clear();
333 for (int i = 0; i < regionArray.length; i++) {
334 _regionList.add(regionArray[i]);
335 }
336 }
337
338 /***
339 * Sets the value of field 'regionOfRegard'. The field
340 * 'regionOfRegard' has the following description: The
341 * intrinsic size scale, given in arcseconds, associated
342 * with data items contained in a resource.
343 *
344 *
345 * @param regionOfRegard the value of field 'regionOfRegard'.
346 */
347 public void setRegionOfRegard(float regionOfRegard)
348 {
349 this._regionOfRegard = regionOfRegard;
350 this._has_regionOfRegard = true;
351 }
352
353 /***
354 * Sets the value of field 'spatialResolution'. The field
355 * 'spatialResolution' has the following description: The
356 * spatial (angular) resolution that is typical of the
357 * observations of interest, in decimal degrees.
358 *
359 *
360 * @param spatialResolution the value of field
361 * 'spatialResolution'.
362 */
363 public void setSpatialResolution(float spatialResolution)
364 {
365 this._spatialResolution = spatialResolution;
366 this._has_spatialResolution = true;
367 }
368
369 /***
370 * Method unmarshalSpatialType
371 *
372 * @param reader
373 */
374 public static org.astrogrid.registry.beans.resource.dataservice.SpatialType unmarshalSpatialType(java.io.Reader reader)
375 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
376 {
377 return (org.astrogrid.registry.beans.resource.dataservice.SpatialType) Unmarshaller.unmarshal(org.astrogrid.registry.beans.resource.dataservice.SpatialType.class, reader);
378 }
379
380 /***
381 * Method validate
382 */
383 public void validate()
384 throws org.exolab.castor.xml.ValidationException
385 {
386 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
387 validator.validate(this);
388 }
389
390 }