Revision 29956 branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/PersistenceManager.java

View differences:

PersistenceManager.java
4 4
import java.util.Iterator;
5 5

  
6 6
import org.gvsig.tools.dynobject.DynStruct;
7
import org.gvsig.tools.persistence.validation.ValidationResult;
8 7

  
9 8
/**
10 9
 * <p>This interface contains the necessary methods to get a persistent representation
......
17 16
 */
18 17
public interface PersistenceManager {
19 18
	/**
20
	 * <p>Validation Mode -- MANDATORY: Validation is active, so 
19
	 * <p>Validation Mode -- MANDATORY: Validation is active, so
21 20
	 * {@link PersistenceManager#create(org.gvsig.tools.persistence.PersistentState)}
22 21
	 * and
23 22
	 * {@link PersistenceManager#getState(org.gvsig.tools.persistence.Persistent)}
......
42 41
	static public final int DISABLED = 0;
43 42

  
44 43
	/**
45
	 * <p>Creates a persistent state from an Persistent object.</p>
44
	 * <p>
45
	 * Creates a persistent state from an Persistent object.
46
	 * </p>
46 47
	 * 
47
	 * @param obj The Persistent object to be persisted
48
	 * @param obj
49
	 *            The Persistent object to be persisted
48 50
	 * 
49
	 * @return A PersistentState object, which stores the state of the
50
	 * provided Persistent Object.
51
	 * @return A PersistentState object, which stores the state of the provided
52
	 *         Persistent Object.
51 53
	 * @throws PersistenceException
54
	 * @throws PersistenceValidateExceptions
52 55
	 */
53
	public PersistentState getState(Persistent obj) throws PersistenceException;
56
	public PersistentState getState(Persistent obj)
57
			throws PersistenceException, PersistenceValidateExceptions;
54 58

  
55 59
	/**
56 60
	 * <p>Instantiates an object from a persistent state. The PersistentState object knows
57 61
	 * the class of the persisted object, and instantiates it by using introspection. The
58 62
	 * object must implement the Persistent interface so that it can understand the
59 63
	 * PersistentState.</p>
60
	 * 
64
	 *
61 65
	 * @param state The state of the object to be instantiated
62 66
	 * @return A new object whose state is the same as the provided <code>state</code> object.
63
	 * 
67
	 *
64 68
	 * @throws PersistenceException
65 69
	 */
66
	public Object create(PersistentState state) throws PersistenceException;
70
	public Persistent create(PersistentState state) throws PersistenceException;
67 71

  
68 72
	/**
69 73
	 * <p>Associates an alias with a class. This is similar to a symbolic link, which allows
70 74
	 * to access the class by means of its alias.</p>
71
	 * 
75
	 *
72 76
	 * <p>When an alias is defined, it replaces any
73 77
	 * class whose qualified name is equal to the alias. Therefore, this class will never
74 78
	 * be instantiated, and instead the class pointed by the the alias will be instantiated.</p>
75
	 * 
79
	 *
76 80
	 * <p>For example, if the following alias is defined:</p>
77 81
	 *
78 82
	 * <pre>Class aClass = org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol.class;
......
80 84
	 * </pre>
81 85
	 * <p>then, SimpleMarkerSymbol will be instantiated instead of ArrowMarkerSymbol from any
82 86
	 * PersistentState which references ArrowMarkerSymbol.</p>
83
	 * 
87
	 *
84 88
	 * <p>Aliases are useful to provided backward-compatibility paths (as old unexisting classes
85 89
	 * may be aliased to substitution classes), but are also useful to avoid limitations on
86 90
	 * ClassLoaders. As a Class object is provided, it will be possible to instantiate it even
......
95 99
	 * <p>Registers persistentClass as Persistent, and associates an attribute definition to that
96 100
	 * class. During a persistence process, the PersistenceManager will validate that a class
97 101
	 * only persists attributes which has been defined in its DynStruct definition.</p>
98
	 * 
102
	 *
99 103
	 * @param persistentClass The class to register
100 104
	 * @param definition The definition of the attributes allowed for the persistentClass
101 105
	 */
......
104 108
	/**
105 109
	 * <p>De-registers a class which has been previously registered using
106 110
	 *  <code>{@link #addDefinition(Class, DynStruct)}</code></p>
107
	 * 
111
	 *
108 112
	 * @param persistentClass
109 113
	 */
110 114
	public void removeDefinition(Class persistentClass);
111 115

  
112 116
	/**
113
	 * <p>Validates a persistent state by using the corresponding registered
117
	 * <p>
118
	 * Validates a persistent state by using the corresponding registered
114 119
	 * attribute definition. If there is no registered definition for the class
115
	 * represented by the PersistenteState, validation should fail.</p>
120
	 * represented by the PersistenteState, validation should fail.
121
	 * </p>
116 122
	 *
117
	 * <p>Some manager implementations may not support validation. In this case,
118
	 * they should always return a positive validation.</p>
123
	 * @param state
119 124
	 *
125
	 * @throws PersistenceValidateExceptions
126
	 *
127
	 */
128
	public void validate(PersistentState state)
129
			throws PersistenceValidateExceptions;
130

  
131
	/**
132
	 * <p>
133
	 * Validates a persistent state by using the corresponding registered
134
	 * attribute definition. <code>mode</code> specifies what to do when a
135
	 * definition of a state class is not registered.
136
	 * </p>
137
	 *
120 138
	 * @param state
121 139
	 *
122
	 * @return The validation result
140
	 * @throws PersistenceValidateExceptions
141
	 *
142
	 * @see {@link #setAutoValidation(int)}
143
	 * @set {@link #addDefinition(Class, DynStruct)}
144
	 *
123 145
	 */
124
	public ValidationResult validate(PersistentState state);
146
	public void validate(PersistentState state, int mode)
147
			throws PersistenceValidateExceptions;
125 148

  
126 149
	/**
127
	 * <p>If the provided persistent class has registered an attribute definition in
128
	 * this manager, then this method returns that definition. Otherwise, it returns
129
	 * null.</p>
150
	 * <p>
151
	 * If the provided persistent class has registered an attribute definition
152
	 * in this manager, then this method returns that definition. Otherwise, it
153
	 * returns null.
154
	 * </p>
130 155
	 *
131
	 * @param persistentClass The class whose corresponding attribute definition is
132
	 * to be retrieved.
156
	 * @param persistentClass
157
	 *            The class whose corresponding attribute definition is to be
158
	 *            retrieved.
133 159
	 *
134
	 * @return The attribute definition corresponding to the provided persistent class,
135
	 * or null otherwise.
160
	 * @return The attribute definition corresponding to the provided persistent
161
	 *         class, or null otherwise.
136 162
	 */
137 163
	public DynStruct getDefinition(Class persistentClass);
138 164

  
......
147 173
	 * <p>De-serializes an state from the data read from the provided
148 174
	 * <code>reader</code>. Depending on the implementation the serialized
149 175
	 * data may have different formats, such as XML or binary data.</p>
150
	 * 
176
	 *
151 177
	 * <p>Note that a particular implementation will only be able to
152 178
	 * de-serialize data which has been serialized by the same
153 179
	 * implementation.</p>
154
	 * 
180
	 *
155 181
	 * @param reader
156 182
	 * @return
157 183
	 */
158 184
	public PersistentState loadState(Reader reader) throws PersistenceException;
159
	
185

  
160 186
	/**
161 187
	 * <p>Sets the validation which will be applied in
162 188
	 * {@link #getState(Persistent)}, {@link #create(PersistentState)}
163 189
	 * methods. Validation ensures that persisted or de-persisted objects
164 190
	 * match the declared definition (which must have been previously
165 191
	 * registered by using {@link #addDefinition(Class, DynStruct)}).</p>
166
	 * 
192
	 *
167 193
	 * <p>When automatic validation is enabled (MANDATORY or
168 194
	 * MANDATORY_IF_DECLARED), a ValidationException will be thrown by
169 195
	 * {@link #getState(Persistent)}, {@link #create(PersistentState)}
170 196
	 * if a validation error is found.</p>
171
	 * 
197
	 *
172 198
	 * @param validationMode On of the following values:
173 199
	 * {@link #DISABLED}, {@link #MANDATORY}
174 200
	 * or {@link #MANDATORY_IF_DECLARED}
175 201

  
176 202
	 * @see #validate(PersistentState)
177 203
	 * @see #addDefinition(Class, DynStruct)
178
	 * 
204
	 *
179 205
	 * @throws PersistenceException If the mode is not supported by this manager
180 206
	 */
181 207
	public void setAutoValidation(int validationMode) throws PersistenceException;
182
	
208

  
183 209
	/**
184 210
	 * <p>Gets the validation which will be applied in
185 211
	 * {@link #getState(Persistent)}, {@link #create(PersistentState)} methods.
186 212
	 *
187 213
	 * @return The current mode for automatic validation: {@link #DISABLED},
188 214
	 * {@link #MANDATORY} or {@link #MANDATORY_IF_DECLARED}
189
	 * 
215
	 *
190 216
	 * @see #validate(PersistentState)
191 217
	 * @see #addDefinition(Class, DynStruct)
192 218
	 */

Also available in: Unified diff