Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dynobject / DynObjectManager.java @ 301

History | View | Annotate | Download (12.3 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22
package org.gvsig.tools.dynobject;
23

    
24
import java.io.IOException;
25
import java.io.InputStream;
26
import java.util.Iterator;
27
import java.util.List;
28
import java.util.Map;
29

    
30
import org.xmlpull.v1.XmlPullParser;
31
import org.xmlpull.v1.XmlPullParserException;
32

    
33
import org.gvsig.tools.dynobject.exception.DuplicateDynClassException;
34
import org.gvsig.tools.dynobject.exception.DynMethodException;
35
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
36
import org.gvsig.tools.exception.BaseException;
37

    
38
/**
39
 * Manager for the DynObject tools library. This is the main entry point to the
40
 * tools dynobjects API.
41
 * 
42
 * @author gvSIG Team
43
 * @version $Id$
44
 */
45
public interface DynObjectManager {
46

    
47
    /**
48
     * Null value for method id.
49
     * 
50
     * This value not is a value valid for a code of method.
51
     */
52
    public int NULLCODE = -1;
53

    
54
    /**
55
     * Create a instance of DynClass with the name and description
56
     * Indicated as parameters.
57
     * 
58
     * @param name
59
     *            , the name used for DynClass name.
60
     * @param description
61
     *            , the description associated to the
62
     *            new DynClass.
63
     * 
64
     * @return the DynClass created.
65
     */
66
    public DynClass createDynClass(String name, String description);
67

    
68
    /**
69
     * Create a instance of DynClass with the name and description
70
     * Indicated as parameters.
71
     * 
72
     * @param namespace
73
     *            , the namespace used for the new DynClass.
74
     * 
75
     * @param name
76
     *            , the name used for the new DynClass.
77
     * 
78
     * @param description
79
     *            , the description associated to the
80
     *            new DynClass.
81
     * 
82
     * @return the DynClass created.
83
     * 
84
     */
85
    public DynClass createDynClass(String namespace, String name,
86
        String description);
87

    
88
    /**
89
     * Load the classes defined in the resource and return a Map
90
     * with its.
91
     * The classes do not be registered in the manager.
92
     * 
93
     * @param resource
94
     *            , XML with the definition of dynamic
95
     *            classes.
96
     * 
97
     * @param loader
98
     *            , loader used to load classes used in
99
     *            "classOfValue" in the resource.
100
     * 
101
     * @param defaultNamespace
102
     *            , namespace used in classes that do not
103
     *            specify a namespace in the resource.
104
     * 
105
     * @return The Map of loaded dynamic classes
106
     * 
107
     * @throws XmlPullParserException
108
     * @throws IOException
109
     */
110
    public Map importDynClassDefinitions(InputStream resource,
111
        ClassLoader loader, String defaultNamespace)
112
        throws XmlPullParserException, IOException;
113

    
114
    /**
115
     * Load the classes defined in the resource.
116
     * When the class do not specify a namespace this is set
117
     * to null.
118
     * 
119
     * The classes do not be registered in the manager.
120
     * 
121
     * @param resource
122
     *            , XML with the definition of dynamic
123
     *            classes.
124
     * 
125
     * @param loader
126
     *            , loader used to load classes used in
127
     *            "classOfValue" in the resource.
128
     * 
129
     * @return The Map of loaded dynamic classes
130
     * 
131
     * @throws XmlPullParserException
132
     * @throws IOException
133
     */
134
    public Map importDynClassDefinitions(InputStream resource,
135
        ClassLoader loader) throws XmlPullParserException, IOException;
136

    
137
    /**
138
     * Load the classes defined in the resource.
139
     * When the class do not specify a namespace this is set
140
     * to null.
141
     * 
142
     * The classes do not be registered in the manager.
143
     * 
144
     * @param parser
145
     *            , XML parser used in the definition of dynamic
146
     *            classes.
147
     * 
148
     * @param loader
149
     *            , loader used to load classes used in
150
     *            "classOfValue" in the resource.
151
     * 
152
     * @param defaultNamespace
153
     *            , namespace used in classes that do not
154
     *            specify a namespace in the resource.
155
     * 
156
     * @return The Map of loaded dynamic classes
157
     * 
158
     * @throws XmlPullParserException
159
     * @throws IOException
160
     */
161
    public Map importDynClassDefinitions(XmlPullParser parser,
162
        ClassLoader loader, String defaultNamespace)
163
        throws XmlPullParserException, IOException;
164

    
165
    /**
166
     * A?ade la dynClass a la lista de clases registradas.
167
     * Falla lanzando una excepcion si ya existe una clase registrada con ese
168
     * nombre en ese namespace.
169
     * 
170
     * @param dynClass
171
     * @throws DuplicateDynClassException
172
     */
173
    public void add(DynClass dynClass) throws DuplicateDynClassException;
174

    
175
    /**
176
     * Create and add to the manager a class with the name
177
     * passed as parameter in the default namespace.
178
     * 
179
     * @param name
180
     * @param description
181
     * @return the new class created.
182
     */
183
    public DynClass add(String name, String description);
184

    
185
    /**
186
     * Create and add to the manager a class with the name
187
     * passed as parameter in the default namespace.
188
     * 
189
     * @param name
190
     * @param description
191
     * @return the new class created.
192
     */
193
    public DynClass add(String name);
194

    
195
    public void remove(DynStruct dynClass);
196

    
197
    /**
198
     * Obtiene la clase asociado al nombre indicado.
199
     * 
200
     * Si se indica un nombre con namespace la buscara en
201
     * ese namespace. if not se usara el namespace por
202
     * defecto.
203
     * 
204
     * @param name
205
     *            , nombre de la clase que queremos obtener.
206
     * @return la clase requerida.
207
     */
208
    public DynClass get(String name);
209

    
210
    /**
211
     * Obtiene el la clase asociado al nombre indicado dentro del
212
     * namespace pedido.
213
     * 
214
     * @param name
215
     *            , nombre de la clase que queremos obtener.
216
     * @return la clase requerida.
217
     */
218
    public DynClass get(String namespace, String name);
219

    
220
    /**
221
     * Comprueba si esta registrada una clase.
222
     * 
223
     * @return true si la clase "name" esta registrada, false si no.
224
     */
225
    public boolean has(String name);
226

    
227
    /**
228
     * Comprueba si esta registrada una clase.
229
     * 
230
     * @return true si la clase "name" esta registrada, false si no.
231
     */
232
    public boolean has(String namespace, String name);
233

    
234
    /**
235
     * Return the count of registered DynClass.
236
     * 
237
     * @return count of DynClass
238
     */
239
    public int getCount();
240

    
241
    /**
242
     * Return an iterator over all registered DynClass.
243
     * 
244
     * @return the iterator.
245
     */
246
    public Iterator interator();
247

    
248
    /**
249
     * Return the list of names of all registered DynClass.
250
     * 
251
     * @return list of DynClass names.
252
     */
253
    public List getNames();
254

    
255
    /**
256
     * Create a new DynObject associated to the DynStruct or DynClass
257
     * passed as parameter.
258
     * 
259
     * @param dynStruct
260
     *            or dynClass to use for create the dynObject
261
     * @return the new DynObject
262
     */
263
    public DynObject createDynObject(DynStruct dynStruct);
264

    
265
    /**
266
     * Crea un nuevo objeto asociandole como clase base la indicada que tiene el
267
     * nombre indicado.
268
     * 
269
     * @param dynClassName
270
     * @return el nuevo DynObject
271
     */
272
    public DynObject createDynObject(String classname);
273

    
274
    /**
275
     * Crea un nuevo objeto asociandole como clase base la indicada que tiene el
276
     * nombre indicado.
277
     * 
278
     * @param dynClassName
279
     * @return el nuevo DynObject
280
     */
281
    public DynObject createDynObject(String namespace, String classname);
282

    
283
    /**
284
     * Actualiza todas las DynClasses registradas para reflejar la
285
     * herencia de forma adecuada.
286
     */
287
    public void consolide();
288

    
289
    /**
290
     * Register the method in the dynClass.
291
     * 
292
     * @param dynClass
293
     *            class over the method is registred
294
     * @param dynMethod
295
     *            method to registry
296
     * @return unique code of method
297
     */
298
    public int registerDynMethod(DynClass dynClass, DynMethod dynMethod);
299

    
300
    /**
301
     * Register the method in the class.
302
     * 
303
     * @param theClass
304
     *            class over the method is registred
305
     * @param dynMethod
306
     *            method to registry
307
     * @return unique code of method
308
     */
309
    public int registerDynMethod(Class theClass, DynMethod dynMethod);
310

    
311
    /**
312
     * Obtain the method for the indicated code of the dynObject.
313
     * 
314
     * @param dynObject
315
     * @param code
316
     *            code of the requeted method
317
     * @return the required DynMethod
318
     * 
319
     * @throws DynMethodException
320
     */
321
    public DynMethod getDynMethod(DynObject dynObject, int code)
322
        throws DynMethodException;
323

    
324
    public DynMethod getDynMethod(DynClass dynClass, int code)
325
        throws DynMethodException;
326

    
327
    public DynMethod getDynMethod(Object obj, int code)
328
        throws DynMethodException;
329

    
330
    public DynMethod getDynMethod(Class theClass, int code)
331
        throws DynMethodException;
332

    
333
    public DynMethod getDynMethod(int code) throws DynMethodException;
334

    
335
    /**
336
     * Invoke the method of the indicated code for the object self, with
337
     * parameters in context.
338
     * 
339
     * @param self
340
     *            object over the method is invoked
341
     * @param code
342
     *            code for the method to invoke
343
     * @param context
344
     *            paramters of method
345
     * @return return value for the method
346
     * @throws DynMethodException
347
     */
348
    public Object invokeDynMethod(Object self, int code, DynObject context)
349
        throws DynMethodException;
350

    
351
    void validate(DynObject object) throws DynObjectValidateException;
352

    
353
    /**
354
     * @deprecated use DataTypesManager.getDefaultClass
355
     */
356
    Class getDefaultClassOfType(int type);
357

    
358
    /**
359
     * Creates a new {@link DynObjectPagingHelper} to page the data of a
360
     * {@link DynObjectSet}.
361
     * 
362
     * @param set
363
     *            to page the data of
364
     * @return a {@link DynObjectPagingHelper}
365
     * @throws BaseException
366
     *             if there is an error creating the paging helper, usually
367
     *             because of an error getting the data of the
368
     *             {@link DynObjectSet}
369
     */
370
    DynObjectPagingHelper createDynObjectPagingHelper(DynObjectSet set)
371
        throws BaseException;
372

    
373
    /**
374
     * Creates a new {@link DynObjectPagingHelper} to page the data of a
375
     * {@link DynObjectSet}.
376
     * 
377
     * @param set
378
     *            to page the data of
379
     * @param pageSize
380
     *            the size of the page to load using the helper
381
     * @return a {@link DynObjectPagingHelper}
382
     * @throws BaseException
383
     *             if there is an error creating the paging helper, usually
384
     *             because of an error getting the data of the
385
     *             {@link DynObjectSet}
386
     */
387
    DynObjectPagingHelper createDynObjectPagingHelper(DynObjectSet set,
388
        int pageSize) throws BaseException;
389

    
390
    /**
391
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
392
     * name and its namespace.
393
     * 
394
     * @param namespace
395
     *            where the {@link DynClass} belongs to
396
     * @param name
397
     *            of the {@link DynClass}
398
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
399
     */
400
    DynClassName createDynClassName(String namespace, String name);
401

    
402
    /**
403
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
404
     * name or fullname
405
     * 
406
     * @param name
407
     *            of the {@link DynClass}. It might be a simple name or a
408
     *            composed full name (namespace and name)
409
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
410
     */
411
    DynClassName createDynClassName(String name);
412
}