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

History | View | Annotate | Download (14.2 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
import org.gvsig.tools.util.UnmodifiableBasicMap;
44

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

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

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

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

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

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

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

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

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

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

    
212
    public void remove(DynStruct dynClass);
213

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
392
    void validate(DynObject object) throws DynObjectValidateException;
393

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

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

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

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

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

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

    
456
    public void setAttributeValue(Object obj, String name, Object value);
457
    
458
    public void copy(DynObject source, DynObject target);
459

    
460
    public boolean equals(DynObject obj1, DynObject obj2);
461
    
462
    public int hashCode(DynObject obj);
463
    
464
    public void clear(DynObject obj);
465
    
466
    public DynField createDynField(String name);
467
    
468
    public void registerTag(String name, String description);
469
    
470
    public UnmodifiableBasicMap<String,String> getTags();
471

    
472
}