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

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
    /**
62
     * Create a instance of DynClass with the name and description
63
     * Indicated as parameters.
64
     * 
65
     * @param name
66
     *            , the name used for DynClass name.
67
     * @param description
68
     *            , the description associated to the
69
     *            new DynClass.
70
     * 
71
     * @return the DynClass created.
72
     */
73
    public DynClass createDynClass(String name, String description);
74

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

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

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

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

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

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

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

    
210
    public void remove(DynStruct dynClass);
211

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
390
    void validate(DynObject object) throws DynObjectValidateException;
391

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

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

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

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

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

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

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

    
462
}