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

History | View | Annotate | Download (13.3 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

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

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

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

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

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

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

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

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

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

    
209
    public void remove(DynStruct dynClass);
210

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
332
    /**
333
     * Obtain the method for the indicated code of the dynObject.
334
     * 
335
     * @param dynObject
336
     * @param code
337
     *            code of the requeted method
338
     * @return the required DynMethod
339
     * 
340
     * @throws DynMethodException
341
     */
342
    public DynMethod getDynMethod(DynObject dynObject, int code)
343
        throws DynMethodException;
344

    
345
    public DynMethod getDynMethod(DynClass dynClass, int code)
346
        throws DynMethodException;
347

    
348
    public DynMethod getDynMethod(Object obj, int code)
349
        throws DynMethodException;
350

    
351
    public DynMethod getDynMethod(Class theClass, int code)
352
        throws DynMethodException;
353

    
354
    public DynMethod getDynMethod(int code) throws DynMethodException;
355

    
356
    /**
357
     * Invoke the method of the indicated code for the object self, with
358
     * parameters in context.
359
     * 
360
     * @param self
361
     *            object over the method is invoked
362
     * @param code
363
     *            code for the method to invoke
364
     * @param context
365
     *            paramters of method
366
     * @return return value for the method
367
     * @throws DynMethodException
368
     */
369
    public Object invokeDynMethod(Object self, int code, DynObject context)
370
        throws DynMethodException;
371

    
372
    void validate(DynObject object) throws DynObjectValidateException;
373

    
374
    /**
375
     * @deprecated use DataTypesManager.getDefaultClass
376
     */
377
    Class getDefaultClassOfType(int type);
378

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

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

    
411
    /**
412
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
413
     * name and its namespace.
414
     * 
415
     * @param namespace
416
     *            where the {@link DynClass} belongs to
417
     * @param name
418
     *            of the {@link DynClass}
419
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
420
     */
421
    DynClassName createDynClassName(String namespace, String name);
422

    
423
    /**
424
     * Creates a {@link org.gvsig.tools.dynobject.DynClassName} with a DynClass
425
     * name or fullname
426
     * 
427
     * @param name
428
     *            of the {@link DynClass}. It might be a simple name or a
429
     *            composed full name (namespace and name)
430
     * @return a new {@link org.gvsig.tools.dynobject.DynClassName}
431
     */
432
    DynClassName createDynClassName(String name);
433

    
434
    public Object getAttributeValue(Object obj, String name);
435

    
436
    public void setAttributeValue(Object obj, String name, Object value);
437
    
438
    public void copy(DynObject source, DynObject target);
439
    
440
    public void clear(DynObject obj);
441

    
442
}