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 @ 307

History | View | Annotate | Download (12.5 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 iterator();
247

    
248
    /**
249
     * Return an iterator over all registered DynClass with the same namespace.
250
     * 
251
     * @return the iterator.
252
     */
253
    public Iterator iterator(String namespace);
254

    
255
    /**
256
     * Return the list of names of all registered DynClass.
257
     * 
258
     * @return list of DynClass names.
259
     */
260
    public List getNames();
261

    
262
    /**
263
     * Create a new DynObject associated to the DynStruct or DynClass
264
     * passed as parameter.
265
     * 
266
     * @param dynStruct
267
     *            or dynClass to use for create the dynObject
268
     * @return the new DynObject
269
     */
270
    public DynObject createDynObject(DynStruct dynStruct);
271

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

    
281
    /**
282
     * Crea un nuevo objeto asociandole como clase base la indicada que tiene el
283
     * nombre indicado.
284
     * 
285
     * @param dynClassName
286
     * @return el nuevo DynObject
287
     */
288
    public DynObject createDynObject(String namespace, String classname);
289

    
290
    /**
291
     * Actualiza todas las DynClasses registradas para reflejar la
292
     * herencia de forma adecuada.
293
     */
294
    public void consolide();
295

    
296
    /**
297
     * Register the method in the dynClass.
298
     * 
299
     * @param dynClass
300
     *            class over the method is registred
301
     * @param dynMethod
302
     *            method to registry
303
     * @return unique code of method
304
     */
305
    public int registerDynMethod(DynClass dynClass, DynMethod dynMethod);
306

    
307
    /**
308
     * Register the method in the class.
309
     * 
310
     * @param theClass
311
     *            class over the method is registred
312
     * @param dynMethod
313
     *            method to registry
314
     * @return unique code of method
315
     */
316
    public int registerDynMethod(Class theClass, DynMethod dynMethod);
317

    
318
    /**
319
     * Obtain the method for the indicated code of the dynObject.
320
     * 
321
     * @param dynObject
322
     * @param code
323
     *            code of the requeted method
324
     * @return the required DynMethod
325
     * 
326
     * @throws DynMethodException
327
     */
328
    public DynMethod getDynMethod(DynObject dynObject, int code)
329
        throws DynMethodException;
330

    
331
    public DynMethod getDynMethod(DynClass dynClass, int code)
332
        throws DynMethodException;
333

    
334
    public DynMethod getDynMethod(Object obj, int code)
335
        throws DynMethodException;
336

    
337
    public DynMethod getDynMethod(Class theClass, int code)
338
        throws DynMethodException;
339

    
340
    public DynMethod getDynMethod(int code) throws DynMethodException;
341

    
342
    /**
343
     * Invoke the method of the indicated code for the object self, with
344
     * parameters in context.
345
     * 
346
     * @param self
347
     *            object over the method is invoked
348
     * @param code
349
     *            code for the method to invoke
350
     * @param context
351
     *            paramters of method
352
     * @return return value for the method
353
     * @throws DynMethodException
354
     */
355
    public Object invokeDynMethod(Object self, int code, DynObject context)
356
        throws DynMethodException;
357

    
358
    void validate(DynObject object) throws DynObjectValidateException;
359

    
360
    /**
361
     * @deprecated use DataTypesManager.getDefaultClass
362
     */
363
    Class getDefaultClassOfType(int type);
364

    
365
    /**
366
     * Creates a new {@link DynObjectPagingHelper} to page the data of a
367
     * {@link DynObjectSet}.
368
     * 
369
     * @param set
370
     *            to page the data of
371
     * @return a {@link DynObjectPagingHelper}
372
     * @throws BaseException
373
     *             if there is an error creating the paging helper, usually
374
     *             because of an error getting the data of the
375
     *             {@link DynObjectSet}
376
     */
377
    DynObjectPagingHelper createDynObjectPagingHelper(DynObjectSet set)
378
        throws BaseException;
379

    
380
    /**
381
     * Creates a new {@link DynObjectPagingHelper} to page the data of a
382
     * {@link DynObjectSet}.
383
     * 
384
     * @param set
385
     *            to page the data of
386
     * @param pageSize
387
     *            the size of the page to load using the helper
388
     * @return a {@link DynObjectPagingHelper}
389
     * @throws BaseException
390
     *             if there is an error creating the paging helper, usually
391
     *             because of an error getting the data of the
392
     *             {@link DynObjectSet}
393
     */
394
    DynObjectPagingHelper createDynObjectPagingHelper(DynObjectSet set,
395
        int pageSize) throws BaseException;
396

    
397
    /**
398
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
399
     * name and its namespace.
400
     * 
401
     * @param namespace
402
     *            where the {@link DynClass} belongs to
403
     * @param name
404
     *            of the {@link DynClass}
405
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
406
     */
407
    DynClassName createDynClassName(String namespace, String name);
408

    
409
    /**
410
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
411
     * name or fullname
412
     * 
413
     * @param name
414
     *            of the {@link DynClass}. It might be a simple name or a
415
     *            composed full name (namespace and name)
416
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
417
     */
418
    DynClassName createDynClassName(String name);
419
}