Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / persistence / PersistentState.java @ 1861

History | View | Annotate | Download (22.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.persistence;
25

    
26
import java.io.File;
27
import java.io.Reader;
28
import java.net.URI;
29
import java.net.URL;
30
import java.util.Date;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Map;
34
import java.util.Set;
35

    
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.persistence.exception.PersistenceException;
38

    
39
public interface PersistentState {
40

    
41
    /**
42
     * Gets the name of the java class corresponding to this persistent state
43
     *
44
     * @return The class name of the java class represented by this state
45
     */
46
    public String getTheClassName();
47

    
48
    /**
49
     * Returns the struct definition associated to this state
50
     *
51
     * @return the DynStruct definition of the state.
52
     */
53
    public DynStruct getDefinition();
54

    
55
    public PersistentContext getContext();
56

    
57
    /**
58
     * Gets an <code>int</code> property.
59
     *
60
     * @param name The name of the property to get
61
     *
62
     * @return The <code>int</code> property associated to the provided name
63
     * @throws PersistenceException
64
     */
65
    public int getInt(String name) throws PersistenceException;
66

    
67
    public int getInt(String name, int defaultValue)
68
            throws PersistenceException;
69

    
70
    /**
71
     * Gets an <code>long</code> property.
72
     *
73
     * @param name The name of the property to get
74
     *
75
     * @return The <code>long</code> property associated to the provided name
76
     * @throws PersistenceException
77
     */
78
    public long getLong(String name) throws PersistenceException;
79

    
80
    public long getLong(String name, long defaultValue)
81
            throws PersistenceException;
82

    
83
    /**
84
     * Gets a <code>Date</code> property.
85
     *
86
     * @param name
87
     * @return The <code>Date</code> property associated to the provided name
88
     * @throws PersistenceException
89
     */
90
    public Date getDate(String name)
91
            throws PersistenceException;
92

    
93
    /**
94
     * Gets a <code>double</code> property.
95
     *
96
     * @param name The name of the property to get
97
     *
98
     * @return The <code>double</code> property associated to the provided name
99
     * @throws PersistenceException
100
     */
101
    public double getDouble(String name)
102
            throws PersistenceException;
103

    
104
    public double getDouble(String name, double defaultValue)
105
            throws PersistenceException;
106

    
107
    /**
108
     * Gets a <code>float</code> property.
109
     *
110
     * @param name The name of the property to get
111
     *
112
     * @return The <code>float</code> property associated to the provided name
113
     * @throws PersistenceException
114
     */
115
    public float getFloat(String name) throws PersistenceException;
116

    
117
    public float getFloat(String name, float defaultValue) throws PersistenceException;
118

    
119
    /**
120
     * Gets a <code>boolean</code> property.
121
     *
122
     * @param name The name of the property to get
123
     *
124
     * @return The <code>boolean</code> property associated to the provided name
125
     * @throws PersistenceException
126
     */
127
    public boolean getBoolean(String name) throws PersistenceException;
128

    
129
    public boolean getBoolean(String name, boolean defaultValue) throws PersistenceException;
130

    
131
    /**
132
     * Gets a <code>String</code> property.
133
     *
134
     * @param name The name of the property to get
135
     *
136
     * @return The <code>String</code> property associated to the provided name
137
     * @throws PersistenceException
138
     */
139
    public String getString(String name)
140
            throws PersistenceException;
141

    
142
    /**
143
     * Gets a {@link List} property.
144
     *
145
     * <strong>Don't use the returned List as it is, as it may not work as you
146
     * expect. Instead, choose you own implementation and do something
147
     * like:</strong> <code>
148
     * List myAttribute = new ArrayList(state.getList("prop"))
149
     * </code>
150
     *
151
     * @param name The name of the property to get
152
     *
153
     * @return The {@link List} property value associated to the provided name
154
     *
155
     * @throws PersistenceException if there is an error getting the property
156
     * value
157
     */
158
    public List getList(String name) throws PersistenceException;
159

    
160
    /**
161
     * Returns an array whose elements are of the class given. This is useful to
162
     * be able to cast the returned Object[] to the real class. To be able to
163
     * store and load a property as an array, the type of the property defined
164
     * in the {@link DynStruct} must be List.
165
     * <p>
166
     * Ex: <code>
167
     * Color[] colors = (Color[])state.getArray("colors", Color.class);
168
     * </code>
169
     * </p>
170
     *
171
     * @param name The name of the property to get
172
     * @param valueClass the class of the array elements
173
     * @return the array of elements
174
     * @throws PersistenceException if there is an error getting the property
175
     * value
176
     */
177
    public Object[] getArray(String name, Class valueClass)
178
            throws PersistenceException;
179

    
180
    /**
181
     * Returns an array whose elements are of boolean basic type. To be able to
182
     * store and load a property as an array, the type of the property defined
183
     * in the {@link DynStruct} must be List.
184
     *
185
     * @param name The name of the property to get
186
     * @return the array of elements
187
     * @throws PersistenceException if there is an error getting the property
188
     * value
189
     */
190
    public boolean[] getBooleanArray(String name) throws PersistenceException;
191

    
192
    /**
193
     * Returns an array whose elements are of int basic type. To be able to
194
     * store and load a property as an array, the type of the property defined
195
     * in the {@link DynStruct} must be List.
196
     *
197
     * @param name The name of the property to get
198
     * @return the array of elements
199
     * @throws PersistenceException if there is an error getting the property
200
     * value
201
     */
202
    public int[] getIntArray(String name) throws PersistenceException;
203

    
204
    /**
205
     * Returns an array whose elements are of long basic type. To be able to
206
     * store and load a property as an array, the type of the property defined
207
     * in the {@link DynStruct} must be List.
208
     *
209
     * @param name The name of the property to get
210
     * @return the array of elements
211
     * @throws PersistenceException if there is an error getting the property
212
     * value
213
     */
214
    public long[] getLongArray(String name) throws PersistenceException;
215

    
216
    /**
217
     * Returns an array whose elements are of float basic type. To be able to
218
     * store and load a property as an array, the type of the property defined
219
     * in the {@link DynStruct} must be List.
220
     *
221
     * @param name The name of the property to get
222
     * @return the array of elements
223
     * @throws PersistenceException if there is an error getting the property
224
     * value
225
     */
226
    public float[] getFloatArray(String name) throws PersistenceException;
227

    
228
    /**
229
     * Returns an array whose elements are of double basic type. To be able to
230
     * store and load a property as an array, the type of the property defined
231
     * in the {@link DynStruct} must be List.
232
     *
233
     * @param name The name of the property to get
234
     * @return the array of elements
235
     * @throws PersistenceException if there is an error getting the property
236
     * value
237
     */
238
    public double[] getDoubleArray(String name) throws PersistenceException;
239

    
240
    /**
241
     * Returns an array whose elements are of Date type.
242
     *
243
     * To be able to store and load a property as an array, the type of the
244
     * property defined in the {@link DynStruct} must be List.
245
     *
246
     * @param name
247
     * @return
248
     * @throws PersistenceException
249
     */
250
    public Date[] getDateArray(String name) throws PersistenceException;
251

    
252
    /**
253
     * Returns an array whose elements are of String type.
254
     *
255
     * To be able to store and load a property as an array, the type of the
256
     * property defined in the {@link DynStruct} must be List.
257
     *
258
     * @param name
259
     * @return
260
     * @throws PersistenceException
261
     */
262
    public String[] getStringArray(String name) throws PersistenceException;
263

    
264
    /**
265
     * Gets a {@link Map} property. <strong>Don't use the returned Map as is, as
266
     * it may not be a real usable Map implementation.</strong>
267
     *
268
     * <strong>Don't use the returned Map as it is, as it may not work as you
269
     * expect. Instead, choose you own implementation and do something
270
     * like:</strong> <code>
271
     * Map myAttribute = new HashMap(state.getSet("prop"))
272
     * </code>
273
     *
274
     * @param name The name of the property to get
275
     *
276
     * @return The {@link Map} property value associated to the provided name
277
     *
278
     * @throws PersistenceException if there is an error getting the property
279
     * value
280
     */
281
    public Map getMap(String name) throws PersistenceException;
282

    
283
    /**
284
     * Gets a {@link Set} property.
285
     *
286
     * <strong>Don't use the returned Set as it is, as it may not work as you
287
     * expect. Instead, choose you own implementation and do something
288
     * like:</strong> <code>
289
     * Set myAttribute = new HashSet(state.getSet("prop"))
290
     * </code>
291
     *
292
     * @param name The name of the property to get
293
     *
294
     * @return The {@link Set} property value associated to the provided name
295
     *
296
     * @throws PersistenceException if there is an error getting the property
297
     * value
298
     */
299
    public Set getSet(String name) throws PersistenceException;
300

    
301
    public URL getURL(String name) throws PersistenceException;
302

    
303
    public URI getURI(String name) throws PersistenceException;
304

    
305
    public File getFile(String name) throws PersistenceException;
306

    
307
    /**
308
     * Gets an <code>Object</code> property.
309
     *
310
     * @param name The name of the property to get
311
     *
312
     * @return The <code>Object</code> property associated to the provided name
313
     *
314
     * @throws PersistenceException
315
     */
316
    public Object get(String name) throws PersistenceException;
317

    
318
    public boolean isNull(String name);
319

    
320
    /**
321
     * <p>
322
     * Gets an <code>Iterator</code> over properties of types {@link List},
323
     * {@link Set} or {@link Map}.
324
     * </p>
325
     *
326
     * @param name The name of the property to get
327
     *
328
     * @return The <code>Iterator</code> associated to the property value of
329
     * provided name
330
     * @throws PersistenceException
331
     */
332
    public Iterator getIterator(String name) throws PersistenceException;
333

    
334
    /**
335
     * <p>
336
     * Sets a property of type String.
337
     * </p>
338
     *
339
     * @param name The name of the property to store <i>(must be a valid Java
340
     * identifier)</i>
341
     * @param value
342
     *
343
     * @throws PersistenceException
344
     */
345
    public void set(String name, String value) throws PersistenceException;
346

    
347
    public void set(String name, File value) throws PersistenceException;
348

    
349
    public void set(String name, URL value) throws PersistenceException;
350

    
351
    public void set(String name, URI value) throws PersistenceException;
352

    
353
    /**
354
     * <p>
355
     * Sets a property of type int.
356
     * </p>
357
     *
358
     * @param name The name of the property to store <i>(must be a valid Java
359
     * identifier)</i>
360
     * @param value
361
     *
362
     * @throws PersistenceException
363
     */
364
    public void set(String name, int value) throws PersistenceException;
365

    
366
    /**
367
     * <p>
368
     * Sets a property of type long.
369
     * </p>
370
     *
371
     * @param name The name of the property to store <i>(must be a valid Java
372
     * identifier)</i>
373
     * @param value
374
     *
375
     * @throws PersistenceException
376
     */
377
    public void set(String name, long value) throws PersistenceException;
378

    
379
    /**
380
     * <p>
381
     * Sets a property of type double.
382
     * </p>
383
     *
384
     * @param name The name of the property to store <i>(must be a valid Java
385
     * identifier)</i>
386
     * @param value
387
     *
388
     * @throws PersistenceException
389
     */
390
    public void set(String name, double value) throws PersistenceException;
391

    
392
    /**
393
     * <p>
394
     * Sets a property of type float.
395
     * </p>
396
     *
397
     * @param name The name of the property to store <i>(must be a valid Java
398
     * identifier)</i>
399
     * @param value
400
     *
401
     * @throws PersistenceException
402
     */
403
    public void set(String name, float value) throws PersistenceException;
404

    
405
    /**
406
     * <p>
407
     * Sets a property of type boolean.
408
     * </p>
409
     *
410
     * @param name The name of the property to store <i>(must be a valid Java
411
     * identifier)</i>
412
     * @param value
413
     *
414
     * @throws PersistenceException
415
     */
416
    public void set(String name, boolean value) throws PersistenceException;
417

    
418
    /**
419
     * <p>
420
     * Sets a property of type Persistent.
421
     * </p>
422
     *
423
     * @param name The name of the property to store <i>(must be a valid Java
424
     * identifier)</i>
425
     * @param obj The Persistent object to be stored in the state.
426
     *
427
     * @throws PersistenceException
428
     */
429
    public void set(String name, Persistent obj)
430
            throws PersistenceException;
431

    
432
    /**
433
     * <p>
434
     * Sets a property of type {@link List}.
435
     * </p>
436
     * <p>
437
     * The items of the list must be persistence supported types instance.
438
     * </p>
439
     * <p>
440
     * <i>{@link #get(String)} return an read only {@link List} instance after
441
     * {@link #load(Reader)}</i>
442
     * </p>
443
     *
444
     * @param name The name of the property to store <i>(must be a valid Java
445
     * identifier)</i>
446
     * @param value The {@link List} object to be stored in the state.
447
     *
448
     * @throws PersistenceException
449
     */
450
    public void set(String name, List value) throws PersistenceException;
451

    
452
    /**
453
     * Sets a property of type {@link List} with an array. To be able to store
454
     * and load a property as an array, the type of the property defined in the
455
     * {@link DynStruct} must be List.
456
     *
457
     * @param name The name of the property to set
458
     * @param value the value to set
459
     * @throws PersistenceException if there is an error setting the property
460
     * value
461
     */
462
    public void set(String name, Object[] value) throws PersistenceException;
463

    
464
    /**
465
     * Sets a property of type {@link List} with an array of int. To be able to
466
     * store and load a property as an array, the type of the property defined
467
     * in the {@link DynStruct} must be List.
468
     *
469
     * @param name The name of the property to set
470
     * @param value the value to set
471
     * @throws PersistenceException if there is an error setting the property
472
     * value
473
     */
474
    public void set(String name, int[] value) throws PersistenceException;
475

    
476
    /**
477
     * Sets a property of type {@link List} with an array of long. To be able to
478
     * store and load a property as an array, the type of the property defined
479
     * in the {@link DynStruct} must be List.
480
     *
481
     * @param name The name of the property to set
482
     * @param value the value to set
483
     * @throws PersistenceException if there is an error setting the property
484
     * value
485
     */
486
    public void set(String name, long[] value) throws PersistenceException;
487

    
488
    /**
489
     * Sets a property of type {@link List} with an array of float. To be able
490
     * to store and load a property as an array, the type of the property
491
     * defined in the {@link DynStruct} must be List.
492
     *
493
     * @param name The name of the property to set
494
     * @param value the value to set
495
     * @throws PersistenceException if there is an error setting the property
496
     * value
497
     */
498
    public void set(String name, float[] value) throws PersistenceException;
499

    
500
    /**
501
     * Sets a property of type {@link List} with an array of double. To be able
502
     * to store and load a property as an array, the type of the property
503
     * defined in the {@link DynStruct} must be List.
504
     *
505
     * @param name The name of the property to set
506
     * @param value the value to set
507
     * @throws PersistenceException if there is an error setting the property
508
     * value
509
     */
510
    public void set(String name, double[] value) throws PersistenceException;
511

    
512
    /**
513
     * Sets a property of type {@link List} with an array of Date.
514
     *
515
     * To be able to store and load a property as an array, the type of the
516
     * property defined in the {@link DynStruct} must be List.
517
     *
518
     * @param name
519
     * @param value the Date array to set.
520
     * @throws PersistenceException
521
     */
522
    public void set(String name, Date[] value) throws PersistenceException;
523

    
524
    /**
525
     * Sets a property of type {@link List} with an array of String.
526
     *
527
     * To be able to store and load a property as an array, the type of the
528
     * property defined in the {@link DynStruct} must be List.
529
     *
530
     * @param name
531
     * @param value
532
     * @throws PersistenceException
533
     */
534
    public void set(String name, String[] value) throws PersistenceException;
535

    
536
    /**
537
     * Sets a property of type {@link List} with an array of boolean. To be able
538
     * to store and load a property as an array, the type of the property
539
     * defined in the {@link DynStruct} must be List.
540
     *
541
     * @param name The name of the property to set
542
     * @param value the value to set
543
     * @throws PersistenceException if there is an error setting the property
544
     * value
545
     */
546
    public void set(String name, boolean[] value) throws PersistenceException;
547

    
548
    /**
549
     * <p>
550
     * Sets a property of type {@link Set}.
551
     * </p>
552
     * <p>
553
     * The items of the set must be persistence supported type instances.
554
     * </p>
555
     * <p>
556
     * <i>{@link #get(String)} return an read only {@link Set} instance after
557
     * {@link #load(Reader)}</i>
558
     * </p>
559
     *
560
     * @param name The name of the property to store <i>(must be a valid Java
561
     * identifier)</i>
562
     * @param value
563
     *
564
     * @throws PersistenceException
565
     */
566
    public void set(String name, Set value) throws PersistenceException;
567

    
568
    /**
569
     * <p>
570
     * Sets a property of type {@link Map}.
571
     * </p>
572
     * <p>
573
     * The values and keys of the map must be persistence supported type
574
     * instances.
575
     * </p>
576
     * <p><i>{@link #get(String)} return an read only {@link Map} instance after
577
     * {@link #load(Reader)}</i> </p>
578
     *
579
     * @param name The name of the property to store <i>(must be a valid Java
580
     * identifier)</i>
581
     * @param value
582
     *
583
     * @throws PersistenceException
584
     */
585
    public void set(String name, Map value) throws PersistenceException;
586

    
587
    /**
588
     * <p>
589
     * Sets a property of type {@link Boolean}.
590
     * </p>
591
     *
592
     * @param name The name of the property to store <i>(must be a valid Java
593
     * identifier)</i>
594
     * @param value
595
     *
596
     * @throws PersistenceException
597
     */
598
    public void set(String name, Boolean value) throws PersistenceException;
599

    
600
    /**
601
     * <p>
602
     * Sets a property of type {@link Date}.
603
     * </p>
604
     *
605
     * @param name The name of the property to store <i>(must be a valid Java
606
     * identifier)</i>
607
     * @param value
608
     *
609
     * @throws PersistenceException
610
     */
611
    public void set(String name, Date value) throws PersistenceException;
612

    
613
    /**
614
     * <p>
615
     * Sets a property of type {@link Integer}.
616
     * </p>
617
     *
618
     * @param name The name of the property to store <i>(must be a valid Java
619
     * identifier)</i>
620
     * @param value
621
     *
622
     * @throws PersistenceException
623
     */
624
    public void set(String name, Integer value) throws PersistenceException;
625

    
626
    /**
627
     * <p>
628
     * Sets a property of type {@link Long}.
629
     * </p>
630
     *
631
     * @param name The name of the property to store <i>(must be a valid Java
632
     * identifier)</i>
633
     * @param value
634
     *
635
     * @throws PersistenceException
636
     */
637
    public void set(String name, Long value) throws PersistenceException;
638

    
639
    /**
640
     * <p>
641
     * Sets a property of type {@link Float}.
642
     * </p>
643
     *
644
     * @param name The name of the property to store <i>(must be a valid Java
645
     * identifier)</i>
646
     * @param value
647
     *
648
     * @throws PersistenceException
649
     */
650
    public void set(String name, Float value) throws PersistenceException;
651

    
652
    /**
653
     * <p>
654
     * Sets a property of type {@link Double}.
655
     * </p>
656
     *
657
     * @param name The name of the property to store <i>(must be a valid Java
658
     * identifier)</i>
659
     * @param value
660
     *
661
     * @throws PersistenceException
662
     */
663
    public void set(String name, Double value) throws PersistenceException;
664

    
665
    /**
666
     * <p>
667
     * Sets a property of type {@link List} (<i>like do
668
     * {@link #set(String, List)} </i>) filled with the values provided by a
669
     * {@link Iterator}
670
     * </p>
671
     * <p>
672
     * The items of the iteration must be persistence supported types instance.
673
     * </p>
674
     *
675
     * @param name The name of the property to store <i>(must be a valid Java
676
     * identifier)</i>
677
     * @param it The iterator to get values to store in the list property.
678
     *
679
     * @throws PersistenceException
680
     * @see {@link #set(String, List)}
681
     */
682
    public void set(String name, Iterator it)
683
            throws PersistenceException;
684

    
685
    /**
686
     * <p>
687
     * Sets a property.
688
     * </p>
689
     * <p>
690
     * <code>value</code> must be a supported type or manager must have a
691
     * {@link PersistenceFactory} that know how persist it.
692
     * </p>
693
     *
694
     * @param name The name of the property to store <i>(must be a valid Java
695
     * identifier)</i>
696
     * @param value
697
     *
698
     * @throws PersistenceException
699
     */
700
    public void set(String name, Object value) throws PersistenceException;
701

    
702
    public void setNull(String name) throws PersistenceException;
703

    
704
    /**
705
     * <p>
706
     * Gets an iterator over the names of the properties contained in this
707
     * PersistentState.</p>
708
     *
709
     * @return An iterator which provides the name of all the properties
710
     * contained in this state.
711
     */
712
    public Iterator getNames();
713

    
714
    /**
715
     * Informs that a property is set or not.
716
     *
717
     * @param name
718
     * @return
719
     */
720
    public boolean hasValue(String name);
721

    
722
    /**
723
     * Make relatives all files, urls and uris that are in this state from the
724
     * folder specified.
725
     *
726
     * @param rootFolder
727
     */
728
    public void relativizeFiles(File rootFolder);
729

    
730
    /**
731
     * Make absolutes all files, urls and uris that are in this state from the
732
     * folder specified.
733
     *
734
     * @param rootFolder
735
     */
736
    public void derelativizeFiles(File rootFolder);
737

    
738
}