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

History | View | Annotate | Download (13.9 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.dynobject;
25

    
26
import java.io.File;
27
import java.io.FileNotFoundException;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.io.OutputStream;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Map;
34

    
35
import org.xmlpull.v1.XmlPullParser;
36
import org.xmlpull.v1.XmlPullParserException;
37
import org.gvsig.tools.dynobject.exception.DuplicateDynClassException;
38
import org.gvsig.tools.dynobject.exception.DynMethodException;
39
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
40
import org.gvsig.tools.dynobject.impl.DefaultDynField;
41
import org.gvsig.tools.dynobject.impl.DynClassExportHelper;
42
import org.gvsig.tools.exception.BaseException;
43

    
44
/**
45
 * Manager for the DynObject tools library. This is the main entry point to the
46
 * tools dynobjects API.
47
 * 
48
 * @author gvSIG Team
49
 * @version $Id$
50
 */
51
public interface DynObjectManager {
52
    public static final String DYNCLASS_NAME_SEPARATOR = ":";
53

    
54
    /**
55
     * Null value for method id.
56
     * 
57
     * This value not is a value valid for a code of method.
58
     */
59
    public int NULLCODE = -1;
60

    
61
    public DynClass createCopy(DynClass source);
62
    /**
63
     * Create a instance of DynClass with the name and description
64
     * Indicated as parameters.
65
     * 
66
     * @param name
67
     *            , the name used for DynClass name.
68
     * @param description
69
     *            , the description associated to the
70
     *            new DynClass.
71
     * 
72
     * @return the DynClass created.
73
     */
74
    public DynClass createDynClass(String name, String description);
75

    
76
    public DynObjectEncoder createSimpleDynObjectEncoder();
77
    
78
    /**
79
     * Create a instance of DynClass with the name and description
80
     * Indicated as parameters.
81
     * 
82
     * @param namespace
83
     *            , the namespace used for the new DynClass.
84
     * 
85
     * @param name
86
     *            , the name used for the new DynClass.
87
     * 
88
     * @param description
89
     *            , the description associated to the
90
     *            new DynClass.
91
     * 
92
     * @return the DynClass created.
93
     * 
94
     */
95
    public DynClass createDynClass(String namespace, String name,
96
        String description);
97

    
98
    public String exportSimpleDynClassDefinitions(DynClass dynClass);
99
    
100
    public void exportSimpleDynClassDefinitions(File out, DynClass dynClass) throws FileNotFoundException ;
101
    
102
    public void exportSimpleDynClassDefinitions(OutputStream out, DynClass dynClass);
103
    
104
    /**
105
     * Load the classes defined in the resource and return a Map
106
     * with its.
107
     * The classes do not be registered in the manager.
108
     * 
109
     * @param resource
110
     *            , XML with the definition of dynamic
111
     *            classes.
112
     * 
113
     * @param loader
114
     *            , loader used to load classes used in
115
     *            "classOfValue" in the resource.
116
     * 
117
     * @param defaultNamespace
118
     *            , namespace used in classes that do not
119
     *            specify a namespace in the resource.
120
     * 
121
     * @return The Map of loaded dynamic classes
122
     * 
123
     * @throws XmlPullParserException
124
     * @throws IOException
125
     */
126
    public Map importDynClassDefinitions(InputStream resource,
127
        ClassLoader loader, String defaultNamespace)
128
        throws XmlPullParserException, IOException;
129

    
130
    /**
131
     * Load the classes defined in the resource.
132
     * When the class do not specify a namespace this is set
133
     * to null.
134
     * 
135
     * The classes do not be registered in the manager.
136
     * 
137
     * @param resource
138
     *            , XML with the definition of dynamic
139
     *            classes.
140
     * 
141
     * @param loader
142
     *            , loader used to load classes used in
143
     *            "classOfValue" in the resource.
144
     * 
145
     * @return The Map of loaded dynamic classes
146
     * 
147
     * @throws XmlPullParserException
148
     * @throws IOException
149
     */
150
    public Map importDynClassDefinitions(InputStream resource,
151
        ClassLoader loader) throws XmlPullParserException, IOException;
152

    
153
    /**
154
     * Load the classes defined in the resource.
155
     * When the class do not specify a namespace this is set
156
     * to null.
157
     * 
158
     * The classes do not be registered in the manager.
159
     * 
160
     * @param parser
161
     *            , XML parser used in the definition of dynamic
162
     *            classes.
163
     * 
164
     * @param loader
165
     *            , loader used to load classes used in
166
     *            "classOfValue" in the resource.
167
     * 
168
     * @param defaultNamespace
169
     *            , namespace used in classes that do not
170
     *            specify a namespace in the resource.
171
     * 
172
     * @return The Map of loaded dynamic classes
173
     * 
174
     * @throws XmlPullParserException
175
     * @throws IOException
176
     */
177
    public Map importDynClassDefinitions(XmlPullParser parser,
178
        ClassLoader loader, String defaultNamespace)
179
        throws XmlPullParserException, IOException;
180

    
181
    /**
182
     * A?ade la dynClass a la lista de clases registradas.
183
     * Falla lanzando una excepcion si ya existe una clase registrada con ese
184
     * nombre en ese namespace.
185
     * 
186
     * @param dynClass
187
     * @throws DuplicateDynClassException
188
     */
189
    public void add(DynClass dynClass) throws DuplicateDynClassException;
190

    
191
    /**
192
     * Create and add to the manager a class with the name
193
     * passed as parameter in the default namespace.
194
     * 
195
     * @param name
196
     * @param description
197
     * @return the new class created.
198
     */
199
    public DynClass add(String name, String description);
200

    
201
    /**
202
     * Create and add to the manager a class with the name
203
     * passed as parameter in the default namespace.
204
     * 
205
     * @param name
206
     * @param description
207
     * @return the new class created.
208
     */
209
    public DynClass add(String name);
210

    
211
    public void remove(DynStruct dynClass);
212

    
213
    /**
214
     * Obtiene la clase asociado al nombre indicado.
215
     * 
216
     * Si se indica un nombre con namespace la buscara en
217
     * ese namespace. if not se usara el namespace por
218
     * defecto.
219
     * 
220
     * @param name
221
     *            , nombre de la clase que queremos obtener.
222
     * @return la clase requerida.
223
     */
224
    public DynClass get(String name);
225

    
226
    /**
227
     * Obtiene el la clase asociado al nombre indicado dentro del
228
     * namespace pedido.
229
     * 
230
     * @param name
231
     *            , nombre de la clase que queremos obtener.
232
     * @return la clase requerida.
233
     */
234
    public DynClass get(String namespace, String name);
235

    
236
    /**
237
     * Comprueba si esta registrada una clase.
238
     * 
239
     * @return true si la clase "name" esta registrada, false si no.
240
     */
241
    public boolean has(String name);
242

    
243
    /**
244
     * Comprueba si esta registrada una clase.
245
     * 
246
     * @return true si la clase "name" esta registrada, false si no.
247
     */
248
    public boolean has(String namespace, String name);
249

    
250
    /**
251
     * Return the count of registered DynClass.
252
     * 
253
     * @return count of DynClass
254
     */
255
    public int getCount();
256

    
257
    /**
258
     * Return an iterator over all registered DynClass.
259
     * 
260
     * @return the iterator.
261
     */
262
    public Iterator iterator();
263

    
264
    /**
265
     * Return an iterator over all registered DynClass with the same namespace.
266
     * 
267
     * @return the iterator.
268
     */
269
    public Iterator iterator(String namespace);
270

    
271
    /**
272
     * Return the list of names of all registered DynClass.
273
     * 
274
     * @return list of DynClass names.
275
     */
276
    public List getNames();
277

    
278
    /**
279
     * Create a new DynObject associated to the DynStruct or DynClass
280
     * passed as parameter.
281
     * 
282
     * @param dynStruct
283
     *            or dynClass to use for create the dynObject
284
     * @return the new DynObject
285
     */
286
    public DynObject createDynObject(DynStruct dynStruct);
287

    
288
    /**
289
     * Crea un nuevo objeto asociandole como clase base la indicada que tiene el
290
     * nombre indicado.
291
     * 
292
     * @param dynClassName
293
     * @return el nuevo DynObject
294
     */
295
    public DynObject createDynObject(String classname);
296

    
297
    /**
298
     * Crea un nuevo objeto asociandole como clase base la indicada que tiene el
299
     * nombre indicado.
300
     * 
301
     * @param dynClassName
302
     * @return el nuevo DynObject
303
     */
304
    public DynObject createDynObject(String namespace, String classname);
305

    
306
    /**
307
     * Actualiza todas las DynClasses registradas para reflejar la
308
     * herencia de forma adecuada.
309
     */
310
    public void consolide();
311

    
312
    /**
313
     * Register the method in the dynClass.
314
     * 
315
     * @param dynClass
316
     *            class over the method is registred
317
     * @param dynMethod
318
     *            method to registry
319
     * @return unique code of method
320
     */
321
    public int registerDynMethod(DynClass dynClass, DynMethod dynMethod);
322

    
323
    /**
324
     * Register the method in the class.
325
     * 
326
     * @param theClass
327
     *            class over the method is registred
328
     * @param dynMethod
329
     *            method to registry
330
     * @return unique code of method
331
     */
332
    public int registerDynMethod(Class theClass, DynMethod dynMethod);
333

    
334
    /**
335
     * Register an anonimous method.
336
     * 
337
     * @param dynMethod method to registry
338
     * @return unique code of method
339
     */
340
    public int registerDynMethod(DynMethod dynMethod);
341
    
342
    /**
343
     * Obtain the method for the indicated code of the dynObject.
344
     * 
345
     * @param dynObject
346
     * @param code
347
     *            code of the requeted method
348
     * @return the required DynMethod
349
     * 
350
     * @throws DynMethodException
351
     */
352
    public DynMethod getDynMethod(DynObject dynObject, int code)
353
        throws DynMethodException;
354

    
355
    public DynMethod getDynMethod(DynClass dynClass, int code)
356
        throws DynMethodException;
357

    
358
    public DynMethod getDynMethod(Object obj, int code)
359
        throws DynMethodException;
360

    
361
    public DynMethod getDynMethod(Class theClass, int code)
362
        throws DynMethodException;
363

    
364
    public DynMethod getDynMethod(int code) throws DynMethodException;
365

    
366
    /**
367
     * Retrieve an anonimous method registered in the manager.
368
     * 
369
     * @param methodName name of the requeted method
370
     * @return the required DynMethod
371
     * @throws DynMethodException 
372
     */
373
    public DynMethod getDynMethod(String methodName) throws DynMethodException;
374
    
375
    /**
376
     * Invoke the method of the indicated code for the object self, with
377
     * parameters in context.
378
     * 
379
     * @param self
380
     *            object over the method is invoked
381
     * @param code
382
     *            code for the method to invoke
383
     * @param context
384
     *            paramters of method
385
     * @return return value for the method
386
     * @throws DynMethodException
387
     */
388
    public Object invokeDynMethod(Object self, int code, DynObject context)
389
        throws DynMethodException;
390

    
391
    void validate(DynObject object) throws DynObjectValidateException;
392

    
393
    /**
394
     * @deprecated use DataTypesManager.getDefaultClass
395
     */
396
    Class getDefaultClassOfType(int type);
397

    
398
    /**
399
     * Creates a new {@link DynObjectPagingHelper} to page the data of a
400
     * {@link DynObjectSet}.
401
     * 
402
     * @param set
403
     *            to page the data of
404
     * @return a {@link DynObjectPagingHelper}
405
     * @throws BaseException
406
     *             if there is an error creating the paging helper, usually
407
     *             because of an error getting the data of the
408
     *             {@link DynObjectSet}
409
     */
410
    DynObjectPagingHelper createDynObjectPagingHelper(DynObjectSet set)
411
        throws BaseException;
412

    
413
    /**
414
     * Creates a new {@link DynObjectPagingHelper} to page the data of a
415
     * {@link DynObjectSet}.
416
     * 
417
     * @param set
418
     *            to page the data of
419
     * @param pageSize
420
     *            the size of the page to load using the helper
421
     * @return a {@link DynObjectPagingHelper}
422
     * @throws BaseException
423
     *             if there is an error creating the paging helper, usually
424
     *             because of an error getting the data of the
425
     *             {@link DynObjectSet}
426
     */
427
    DynObjectPagingHelper createDynObjectPagingHelper(DynObjectSet set,
428
        int pageSize) throws BaseException;
429

    
430
    /**
431
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
432
     * name and its namespace.
433
     * 
434
     * @param namespace
435
     *            where the {@link DynClass} belongs to
436
     * @param name
437
     *            of the {@link DynClass}
438
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
439
     */
440
    DynClassName createDynClassName(String namespace, String name);
441

    
442
    /**
443
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
444
     * name or fullname
445
     * 
446
     * @param name
447
     *            of the {@link DynClass}. It might be a simple name or a
448
     *            composed full name (namespace and name)
449
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
450
     */
451
    DynClassName createDynClassName(String name);
452

    
453
    public Object getAttributeValue(Object obj, String name);
454

    
455
    public void setAttributeValue(Object obj, String name, Object value);
456
    
457
    public void copy(DynObject source, DynObject target);
458
    
459
    public void clear(DynObject obj);
460
    
461
    public DynField createDynField(String name);
462

    
463
}