Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / persistence / PersistentState.java @ 29956

History | View | Annotate | Download (7.18 KB)

1
package org.gvsig.tools.persistence;
2

    
3
import java.io.Reader;
4
import java.io.Writer;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.Iterator;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.Set;
12

    
13
public interface PersistentState {
14
        /**
15
         * Gets the name of the class corresponding to this persistent state
16
         *
17
         * @return The class name of the class represented by this state
18
         */
19
        public String getTheClassName();
20

    
21
        /**
22
         * Gets an <code>int</code> property.
23
         *
24
         * @param name
25
         *            The name of the property to get
26
         *
27
         * @return The <code>int</code> property associated to the provided name
28
         * @throws PersistenceException
29
         */
30
        public int getInt(String name) throws PersistenceException;
31

    
32
        /**
33
         * Gets an <code>long</code> property.
34
         *
35
         * @param name
36
         *            The name of the property to get
37
         *
38
         * @return The <code>long</code> property associated to the provided name
39
         * @throws PersistenceException
40
         */
41
        public long getLong(String name) throws PersistenceException;
42

    
43
        /**
44
         * Gets a <code>double</code> property.
45
         *
46
         * @param name
47
         *            The name of the property to get
48
         *
49
         * @return The <code>double</code> property associated to the provided name
50
         * @throws PersistenceException
51
         */
52
        public double getDouble(String name)
53
                        throws PersistenceException;
54

    
55
        /**
56
         * Gets a <code>float</code> property.
57
         *
58
         * @param name
59
         *            The name of the property to get
60
         *
61
         * @return The <code>float</code> property associated to the provided name
62
         * @throws PersistenceException
63
         */
64
        public float getFloat(String name) throws PersistenceException;
65

    
66
        /**
67
         * Gets a <code>boolean</code> property.
68
         *
69
         * @param name
70
         *            The name of the property to get
71
         *
72
         * @return The <code>boolean</code> property associated to the provided name
73
         * @throws PersistenceException
74
         */
75
        public boolean getBoolean(String name)
76
                        throws PersistenceException;
77

    
78
        /**
79
         * Gets a <code>String</code> property.
80
         *
81
         * @param name
82
         *            The name of the property to get
83
         *
84
         * @return The <code>String</code> property associated to the provided name
85
         * @throws PersistenceException
86
         */
87
        public String getString(String name)
88
                        throws PersistenceException;
89

    
90
        /**
91
         * Gets an <code>Object</code> property.
92
         *
93
         * @param name
94
         *            The name of the property to get
95
         *
96
         * @return The <code>Object</code> property associated to the provided name
97
         *
98
         * @throws PersistenceException
99
         */
100
        public Object get(String name) throws PersistenceException;
101

    
102
        /**
103
         * <p>
104
         * Gets an <code>Iterator</code> over properties of types {@link List},
105
         * {@link Set} or {@link Map}.
106
         * </p>
107
         *
108
         * @param name
109
         *            The name of the property to get
110
         *
111
         * @return The <code>Iterator</code> associated to the property value of
112
         *         provided name
113
         * @throws PersistenceException
114
         */
115
        public Iterator getIterator(String name) throws PersistenceException;
116

    
117
        /**
118
         * <p>Sets a property of type String.</p>
119
         *
120
         * @param name The name of the property to store
121
         * @param it The String object to be stored in the state.
122
         *
123
         * @throws PersistenceException
124
         */
125
        public void set(String name, String value) throws PersistenceException;
126

    
127
        /**
128
         * <p>Sets a property of type int.</p>
129
         *
130
         * @param name The name of the property to store
131
         * @param it The int value to be stored in the state.
132
         *
133
         * @throws PersistenceException
134
         */
135
        public void set(String name, int value) throws PersistenceException;
136

    
137
        /**
138
         * <p>Sets a property of type long.</p>
139
         *
140
         * @param name The name of the property to store
141
         * @param it The long value to be stored in the state.
142
         *
143
         * @throws PersistenceException
144
         */
145
        public void set(String name, long value) throws PersistenceException;
146

    
147
        /**
148
         * <p>Sets a property of type double.</p>
149
         *
150
         * @param name The name of the property to store
151
         * @param it The double value to be stored in the state.
152
         *
153
         * @throws PersistenceException
154
         */
155
        public void set(String name, double value) throws PersistenceException;
156

    
157
        /**
158
         * <p>Sets a property of type float.</p>
159
         *
160
         * @param name The name of the property to store
161
         * @param it The float value to be stored in the state.
162
         *
163
         * @throws PersistenceException
164
         */
165
        public void set(String name, float value) throws PersistenceException;
166

    
167
        /**
168
         * <p>Sets a property of type boolean.</p>
169
         *
170
         * @param name The name of the property to store
171
         * @param it The boolean value to be stored in the state.
172
         *
173
         * @throws PersistenceException
174
         */
175
        public void set(String name, boolean value) throws PersistenceException;
176

    
177
        /**
178
         * <p>Sets a property of type Persistent.</p>
179
         *
180
         * @param name The name of the property to store
181
         * @param it The Persistent object to be stored in the state.
182
         *
183
         * @throws PersistenceException
184
         */
185
        public void set(String name, Persistent obj)
186
                        throws PersistenceException;
187

    
188
        /**
189
         * Sets a property of type Object. Only the following types can be stored:
190
         * <ul>
191
         * <li> {@link Persistent}</li>
192
         * <li> {@link Boolean}</li>
193
         * <li> {@link Integer}</li>
194
         * <li> {@link Long}</li>
195
         * <li> {@link Float}</li>
196
         * <li> {@link Double}</li>
197
         * <li> {@link String}</li>
198
         * <li> {@link List} <i>({@link #get(String)} return an {@link ArrayList}
199
         * instance after {@link #load(Reader)}) </i></li>
200
         * <li> {@link Set} <i>({@link #get(String)} return a {@link HashSet}
201
         * instance after {@link #load(Reader)}) </i></li>
202
         * <li> {@link Map} <i>({@link #get(String)} return a {@link HashMap}
203
         * instance after {@link #load(Reader)}) </i></li>
204
         *
205
         * @param name
206
         *            The name of the property to store
207
         * @param obj
208
         *            The object to be stored in the state.
209
         *
210
         * @throws PersistenceException
211
         */
212
        public void set(String name, Object obj)
213
                        throws PersistenceException;
214

    
215
        /**
216
         * <p>
217
         * Sets a property of type {@link List} filled with the values provided by a
218
         * {@link Iterator}
219
         * </p>
220
         *
221
         * @param name
222
         *            The name of the property to store
223
         * @param it
224
         *            The iterator to get values to store in the list property.
225
         *
226
         * @throws PersistenceException
227
         */
228
        public void set(String name, Iterator it)
229
                        throws PersistenceException;
230

    
231
        /**
232
         * <p>Gets an iterator over the names of the properties contained
233
         * in this PersistentState.</p>
234
         *
235
         * @return An iterator which provides the name of all the
236
         * properties contained in this state.
237
         */
238
        public Iterator getNames();
239

    
240
        /**
241
         * <p>Serializes this state and writes the serialized data
242
         * in the provided <code>writer</code>. Depending on the implementation
243
         * the serialized data may have different formats, such as XML or
244
         * binary data.</p>
245
         *
246
         * @param writer
247
         */
248
        public void save(Writer writer) throws PersistenceException;
249

    
250
        /**
251
         * <p>De-serializes the data read from the provided <code>reader</code>. Depending
252
         * on the implementation the serialized data may have different formats, such as XML or
253
         * binary data.</p>
254
         *
255
         * <p>Note that a particular implementation will only be able to
256
         * de-serialize data which has been serialized by the same
257
         * implementation.</p>
258
         *
259
         * @param reader
260
         */
261
        public void load(Reader reader) throws PersistenceException;
262

    
263
        /**
264
         * Informs that a property is set or not.
265
         * 
266
         * @param name
267
         * @return
268
         */
269
        public boolean hasValue(String name);
270
}