svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / persistence / impl / AbstractPersistenceManager.java @ 30619
History | View | Annotate | Download (17.5 KB)
1 |
package org.gvsig.tools.persistence.impl; |
---|---|
2 |
|
3 |
import java.util.Collections; |
4 |
import java.util.HashMap; |
5 |
import java.util.Iterator; |
6 |
import java.util.List; |
7 |
import java.util.Map; |
8 |
import java.util.Set; |
9 |
import java.util.TreeSet; |
10 |
import java.util.Map.Entry; |
11 |
import java.util.regex.Pattern; |
12 |
|
13 |
import org.gvsig.tools.dynobject.DynClass; |
14 |
import org.gvsig.tools.dynobject.DynObject; |
15 |
import org.gvsig.tools.dynobject.DynStruct; |
16 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
17 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
18 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
19 |
import org.gvsig.tools.persistence.PersistenceClassNotRegistered; |
20 |
import org.gvsig.tools.persistence.PersistenceCreateException; |
21 |
import org.gvsig.tools.persistence.PersistenceException; |
22 |
import org.gvsig.tools.persistence.PersistenceFactory; |
23 |
import org.gvsig.tools.persistence.PersistenceManager; |
24 |
import org.gvsig.tools.persistence.PersistenceRuntimeException; |
25 |
import org.gvsig.tools.persistence.PersistenceTypeNotSupportedException; |
26 |
import org.gvsig.tools.persistence.PersistenceValidateExceptions; |
27 |
import org.gvsig.tools.persistence.Persistent; |
28 |
import org.gvsig.tools.persistence.PersistentState; |
29 |
import org.gvsig.tools.persistence.impl.exception.PersistenceInvalidValidateModeException; |
30 |
import org.gvsig.tools.persistence.impl.exception.PersistenceValidateMissingDefinitionException; |
31 |
|
32 |
public abstract class AbstractPersistenceManager implements |
33 |
ImplementationPersistenceManager { |
34 |
public static final String DEFAULT_DOMAIN_URL = "http://www.gvsig.org"; |
35 |
public static final String DEFAULT_DOMAIN_NAME = "gvSIG"; |
36 |
|
37 |
public static final Pattern VALID_DOMAIN_NAME_PATTERN = Pattern |
38 |
.compile("[\\w][\\d\\w_]*");
|
39 |
protected Map classes; |
40 |
protected Map domainsURL; |
41 |
protected int autoValidationMode = PersistenceManager.DISABLED; |
42 |
|
43 |
|
44 |
private class ClassInfo { |
45 |
public DynStruct definition = null; |
46 |
public String domainName = null; |
47 |
public Object theClass = null; |
48 |
} |
49 |
|
50 |
|
51 |
protected AbstractPersistenceManager() {
|
52 |
classes = new HashMap(); |
53 |
domainsURL = new HashMap(); |
54 |
} |
55 |
|
56 |
public void addAlias(String name, Class aClass) |
57 |
throws PersistenceClassNotRegistered {
|
58 |
ClassInfo info = (ClassInfo) classes.get(aClass.getName()); |
59 |
if (info == null) { |
60 |
throw new PersistenceClassNotRegistered(aClass.getName()); |
61 |
} |
62 |
classes.put(name, info); |
63 |
} |
64 |
|
65 |
/* (non-Javadoc)
|
66 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createInstaceOfObject(org.gvsig.tools.persistence.PersistentState)
|
67 |
*/
|
68 |
public Object createInstaceOfObject(PersistentState state, Class classOfState, PersistenceFactory factory) |
69 |
throws PersistenceException, PersistenceCreateException,
|
70 |
PersistenceClassNotRegistered { |
71 |
// TODO IMPLEMENTAR FACTORY
|
72 |
String className = state.getTheClassName();
|
73 |
if (className == null) { |
74 |
throw new PersistenceException("The class name is not stored in the state."); |
75 |
} |
76 |
try {
|
77 |
Class theClass;
|
78 |
|
79 |
ClassInfo info = (ClassInfo) classes.get(className); |
80 |
|
81 |
if (info == null) { |
82 |
throw new PersistenceClassNotRegistered(className); |
83 |
} |
84 |
|
85 |
Object x = info.theClass;
|
86 |
|
87 |
|
88 |
if (x instanceof Class) { |
89 |
theClass = (Class) x;
|
90 |
} else if (x instanceof String) { |
91 |
theClass = Class.forName((String) x); |
92 |
} else { // x is null |
93 |
theClass = Class.forName(className);
|
94 |
} |
95 |
return theClass.newInstance();
|
96 |
} catch (ClassNotFoundException e) { |
97 |
throw new PersistenceCreateException(state, e); |
98 |
} catch (InstantiationException e) { |
99 |
throw new PersistenceCreateException(state, e); |
100 |
} catch (IllegalAccessException e) { |
101 |
throw new PersistenceCreateException(state, e); |
102 |
} |
103 |
} |
104 |
|
105 |
|
106 |
public Object create(PersistentState state) throws PersistenceException { |
107 |
String className = state.getTheClassName();
|
108 |
if (className == null) { |
109 |
throw new PersistenceException("The class name is not stored in the state."); |
110 |
} |
111 |
ImplementationPersistentState iState =(ImplementationPersistentState) state; |
112 |
PersistentContext context = iState.getContext(); |
113 |
context.clearInstances(); |
114 |
|
115 |
Class classOfObj = getClassOf(state);
|
116 |
PersistenceFactory factory = getFactoryFor(state); |
117 |
Object obj = createInstaceOfObject(state, classOfObj, factory);
|
118 |
|
119 |
this.loadFromState(obj, state, factory);
|
120 |
|
121 |
context.setObject(iState.getId(), obj); |
122 |
|
123 |
return obj;
|
124 |
|
125 |
} |
126 |
|
127 |
public void registerClass(Class persistentClass, DynStruct definition) { |
128 |
registerClass(persistentClass, definition, null);
|
129 |
} |
130 |
|
131 |
public DynStruct getDefinition(Class persistentClass) { |
132 |
return getDefinition(persistentClass.getName());
|
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#getDefinition(java.lang.String)
|
137 |
*/
|
138 |
public DynStruct getDefinition(String persistentClassName) { |
139 |
ClassInfo info = (ClassInfo) classes.get(persistentClassName); |
140 |
if (info == null) { |
141 |
return null; |
142 |
} |
143 |
return info.definition;
|
144 |
} |
145 |
|
146 |
|
147 |
public Iterator getPersistentClasses() { |
148 |
Iterator iter = classes.values().iterator();
|
149 |
Set classesSet = new TreeSet(); |
150 |
ClassInfo info; |
151 |
while (iter.hasNext()) {
|
152 |
info = (ClassInfo) iter.next(); |
153 |
classesSet.add(info.theClass); |
154 |
} |
155 |
return classesSet.iterator();
|
156 |
} |
157 |
|
158 |
|
159 |
/*
|
160 |
* (non-Javadoc)
|
161 |
*
|
162 |
* @see
|
163 |
* org.gvsig.tools.persistence.PersistenceManager#validate(org.gvsig.tools
|
164 |
* .persistence.PersistentState)
|
165 |
*/
|
166 |
public void validateAll(PersistentState state) |
167 |
throws PersistenceValidateExceptions {
|
168 |
validateAll(state, this.autoValidationMode);
|
169 |
} |
170 |
|
171 |
public void validate(PersistentState state) |
172 |
throws PersistenceValidateExceptions {
|
173 |
PersistenceValidateExceptions exceptionList = new PersistenceValidateExceptions();
|
174 |
DynStruct curDefinition; |
175 |
DynObjectToPersistentStateAdapter dynAdapter = new DynObjectToPersistentStateAdapter();
|
176 |
|
177 |
curDefinition = this.getDefinition(state.getTheClassName());
|
178 |
if (curDefinition == null) { |
179 |
exceptionList |
180 |
.add(new PersistenceValidateMissingDefinitionException(
|
181 |
state.getTheClassName())); |
182 |
} |
183 |
dynAdapter.setData(state, curDefinition); |
184 |
try {
|
185 |
curDefinition.validate(dynAdapter); |
186 |
} catch (DynObjectValidateException e) {
|
187 |
exceptionList.add(e); |
188 |
} |
189 |
if (exceptionList.size() > 0) { |
190 |
throw exceptionList;
|
191 |
} |
192 |
} |
193 |
|
194 |
|
195 |
public void validateAll(PersistentState state, int mode) |
196 |
throws PersistenceValidateExceptions {
|
197 |
|
198 |
if (mode == PersistenceManager.DISABLED){
|
199 |
return;
|
200 |
} |
201 |
|
202 |
PersistenceValidateExceptions exceptionList = new PersistenceValidateExceptions();
|
203 |
|
204 |
PersistentContext context = ((ImplementationPersistentState) state) |
205 |
.getContext(); |
206 |
|
207 |
Iterator statesIter = context.statesIterator();
|
208 |
ImplementationPersistentState curState; |
209 |
DynStruct curDefinition; |
210 |
DynObjectToPersistentStateAdapter dynAdapter = new DynObjectToPersistentStateAdapter();
|
211 |
|
212 |
|
213 |
while (statesIter.hasNext()) {
|
214 |
curState = (ImplementationPersistentState) statesIter.next(); |
215 |
curDefinition = this.getDefinition(curState.getTheClassName());
|
216 |
if (curDefinition == null){ |
217 |
if (mode == PersistenceManager.MANDATORY){
|
218 |
exceptionList |
219 |
.add(new PersistenceValidateMissingDefinitionException(
|
220 |
curState.getTheClassName())); |
221 |
} |
222 |
continue;
|
223 |
} |
224 |
dynAdapter.setData(curState, curDefinition); |
225 |
try {
|
226 |
curDefinition.validate(dynAdapter); |
227 |
} catch (DynObjectValidateException e) {
|
228 |
exceptionList.add(e); |
229 |
} |
230 |
} |
231 |
|
232 |
if (exceptionList.size() > 0) { |
233 |
throw exceptionList;
|
234 |
} |
235 |
} |
236 |
|
237 |
private class DynObjectToPersistentStateAdapter implements DynObject { |
238 |
private PersistentState state;
|
239 |
private DynStruct struct;
|
240 |
|
241 |
public void setData(PersistentState state, DynStruct struct) { |
242 |
this.state = state;
|
243 |
this.struct = struct;
|
244 |
} |
245 |
|
246 |
public void delegate(DynObject dynObject) { |
247 |
// Nothing to do
|
248 |
|
249 |
} |
250 |
|
251 |
public DynClass getDynClass() {
|
252 |
// Nothing to do
|
253 |
return null; |
254 |
} |
255 |
|
256 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
257 |
try {
|
258 |
return state.get(name);
|
259 |
} catch (PersistenceException e) {
|
260 |
throw new DynFieldNotFoundException(name, struct.getName()); |
261 |
} |
262 |
} |
263 |
|
264 |
public boolean hasDynValue(String name) { |
265 |
return state.hasValue(name);
|
266 |
} |
267 |
|
268 |
public void implement(DynClass dynClass) { |
269 |
// Nothing to do
|
270 |
|
271 |
} |
272 |
|
273 |
public Object invokeDynMethod(String name, DynObject context) |
274 |
throws DynMethodException {
|
275 |
// Nothing to do
|
276 |
return null; |
277 |
} |
278 |
|
279 |
public Object invokeDynMethod(int code, DynObject context) |
280 |
throws DynMethodException {
|
281 |
// Nothing to do
|
282 |
return null; |
283 |
} |
284 |
|
285 |
public void setDynValue(String name, Object value) |
286 |
throws DynFieldNotFoundException {
|
287 |
// Nothing to do
|
288 |
} |
289 |
|
290 |
} |
291 |
|
292 |
public int getAutoValidation() { |
293 |
return autoValidationMode;
|
294 |
} |
295 |
|
296 |
public void setAutoValidation(int validationMode) throws PersistenceException { |
297 |
switch (validationMode) {
|
298 |
case DISABLED:
|
299 |
case MANDATORY:
|
300 |
case MANDATORY_IF_DECLARED:
|
301 |
autoValidationMode = validationMode; |
302 |
break;
|
303 |
default:
|
304 |
throw new PersistenceInvalidValidateModeException(validationMode); |
305 |
} |
306 |
} |
307 |
|
308 |
public PersistentState getState(Object obj) |
309 |
throws PersistenceException, PersistenceValidateExceptions, PersistenceTypeNotSupportedException {
|
310 |
PersistentContext context = new DefaultPersistentContext(this); |
311 |
ImplementationPersistentState state = createState(obj, context); |
312 |
context.setRoot(state.getId()); |
313 |
this.validateAll(state, this.autoValidationMode); |
314 |
return state;
|
315 |
} |
316 |
|
317 |
/* (non-Javadoc)
|
318 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createState(org.gvsig.tools.persistence.Persistent, org.gvsig.tools.persistence.impl.PersistentContext)
|
319 |
*/
|
320 |
public ImplementationPersistentState createState(Object theOriginal, |
321 |
PersistentContext context) |
322 |
throws PersistenceException,
|
323 |
PersistenceClassNotRegistered, PersistenceTypeNotSupportedException { |
324 |
|
325 |
ImplementationPersistentState state = createPersistentStateInstance(context); |
326 |
String theClass = theOriginal.getClass().getName();
|
327 |
state.setTheClassName(theClass); |
328 |
if (!classes.containsKey(theClass)) {
|
329 |
throw new PersistenceClassNotRegistered(theClass); |
330 |
} |
331 |
context.addReference(theOriginal, state); |
332 |
PersistenceFactory factory = getFactoryFor(theOriginal); |
333 |
if (factory != null) { |
334 |
factory.saveToState(state, theOriginal); |
335 |
|
336 |
} else {
|
337 |
if (theOriginal instanceof Persistent) { |
338 |
((Persistent) theOriginal).saveToState(state); |
339 |
} else {
|
340 |
throw new PersistenceTypeNotSupportedException(theOriginal |
341 |
.getClass()); |
342 |
} |
343 |
} |
344 |
return state;
|
345 |
} |
346 |
|
347 |
/* (non-Javadoc)
|
348 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createPersistentStateInstance(org.gvsig.tools.persistence.impl.PersistentContext)
|
349 |
*/
|
350 |
public abstract ImplementationPersistentState createPersistentStateInstance( |
351 |
PersistentContext context); |
352 |
|
353 |
/*
|
354 |
* (non-Javadoc)
|
355 |
*
|
356 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
357 |
* createPersistentContext()
|
358 |
*/
|
359 |
public PersistentContext createPersistentContext() {
|
360 |
return new DefaultPersistentContext(this); |
361 |
} |
362 |
|
363 |
/*
|
364 |
* (non-Javadoc)
|
365 |
*
|
366 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
367 |
* createrObjectReference(java.lang.Integer)
|
368 |
*/
|
369 |
public ObjectReference createrObjectReference(Integer id) { |
370 |
return new DefaultObjectReference(id); |
371 |
} |
372 |
|
373 |
/*
|
374 |
* (non-Javadoc)
|
375 |
*
|
376 |
* @see
|
377 |
* org.gvsig.tools.persistence.PersistenceManager#registerClass(java.lang
|
378 |
* .Class)
|
379 |
*/
|
380 |
public void registerClass(Class persistentClass) { |
381 |
registerClass(persistentClass, null, null, null); |
382 |
} |
383 |
|
384 |
/*
|
385 |
* (non-Javadoc)
|
386 |
*
|
387 |
* @see
|
388 |
* org.gvsig.tools.persistence.PersistenceManager#unregisterClass(java.lang
|
389 |
* .Class)
|
390 |
*/
|
391 |
public void unregisterClass(Class persistentClass) { |
392 |
classes.remove(persistentClass.getName()); |
393 |
} |
394 |
|
395 |
/*
|
396 |
* (non-Javadoc)
|
397 |
*
|
398 |
* @see
|
399 |
* org.gvsig.tools.persistence.PersistenceManager#unregisterClass(java.lang
|
400 |
* .String)
|
401 |
*/
|
402 |
public void unregisterClass(String className) { |
403 |
classes.remove(className); |
404 |
} |
405 |
|
406 |
/*
|
407 |
* (non-Javadoc)
|
408 |
*
|
409 |
* @see
|
410 |
* org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createList
|
411 |
* (java.util.List, org.gvsig.tools.persistence.impl.PersistentContext)
|
412 |
*/
|
413 |
public List createList(List list, PersistentContext context) { |
414 |
return new DelegatedList(list, this, context); |
415 |
} |
416 |
|
417 |
/*
|
418 |
* (non-Javadoc)
|
419 |
*
|
420 |
* @see
|
421 |
* org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createMap
|
422 |
* (java.util.Map, org.gvsig.tools.persistence.impl.PersistentContext)
|
423 |
*/
|
424 |
public Map createMap(Map map, PersistentContext context) { |
425 |
return new DelegatedMap(map, this, context); |
426 |
} |
427 |
|
428 |
/*
|
429 |
* (non-Javadoc)
|
430 |
*
|
431 |
* @see
|
432 |
* org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createSet
|
433 |
* (java.util.Set, org.gvsig.tools.persistence.impl.PersistentContext)
|
434 |
*/
|
435 |
public Set createSet(Set set, PersistentContext context) { |
436 |
return new DelegatedSet(set, this, context); |
437 |
} |
438 |
|
439 |
/*
|
440 |
* (non-Javadoc)
|
441 |
*
|
442 |
* @see
|
443 |
* org.gvsig.tools.persistence.PersistenceManager#registerClass(java.lang
|
444 |
* .Class, org.gvsig.tools.dynobject.DynStruct, java.lang.String)
|
445 |
*/
|
446 |
public void registerClass(Class persistentClass, DynStruct definition, |
447 |
String domainName) {
|
448 |
|
449 |
registerClass(persistentClass, definition, domainName, null);
|
450 |
|
451 |
} |
452 |
|
453 |
/*
|
454 |
* (non-Javadoc)
|
455 |
*
|
456 |
* @see
|
457 |
* org.gvsig.tools.persistence.PersistenceManager#registerClass(java.lang
|
458 |
* .Class, org.gvsig.tools.dynobject.DynStruct, java.lang.String)
|
459 |
*/
|
460 |
public void registerClass(Class persistentClass, DynStruct definition, |
461 |
String domainName, String domainURL) { |
462 |
|
463 |
String domainURLStored = (String) domainsURL.get(domainName); |
464 |
String domainURLToUse;
|
465 |
ClassInfo info = new ClassInfo();
|
466 |
info.definition = definition; |
467 |
info.theClass = persistentClass; |
468 |
if (domainName == null) { |
469 |
info.domainName = DEFAULT_DOMAIN_NAME; |
470 |
domainURLToUse = DEFAULT_DOMAIN_URL; |
471 |
} else {
|
472 |
if (!VALID_DOMAIN_NAME_PATTERN.matcher(domainName).matches()) {
|
473 |
throw new PersistenceRuntimeException( |
474 |
"invalid domain name identifier: '" + domainName + "'"); |
475 |
} |
476 |
info.domainName = domainName; |
477 |
if (domainURL == null) { |
478 |
if (domainURLStored == null) { |
479 |
domainURLToUse = DEFAULT_DOMAIN_URL; |
480 |
} else {
|
481 |
domainURLToUse = domainURLStored; |
482 |
} |
483 |
} else {
|
484 |
domainURLToUse = domainURL; |
485 |
} |
486 |
} |
487 |
|
488 |
if (domainURLStored == null) { |
489 |
domainsURL.put(info.domainName, domainURLToUse); |
490 |
} else if (!domainURLStored.equals(domainURLToUse)){ |
491 |
throw new PersistenceRuntimeException("Domain URL conflict in " |
492 |
+ info.domainName + ": " + domainURLStored + " " |
493 |
+ domainURLToUse); |
494 |
} |
495 |
|
496 |
classes.put(persistentClass.getName(), info); |
497 |
|
498 |
|
499 |
} |
500 |
|
501 |
|
502 |
/*
|
503 |
* (non-Javadoc)
|
504 |
*
|
505 |
* @see
|
506 |
* org.gvsig.tools.persistence.PersistenceManager#registerFactory(org.gvsig
|
507 |
* .tools.persistence.PersistenceFactory)
|
508 |
*/
|
509 |
public void registerFactory(PersistenceFactory factory) { |
510 |
// TODO Auto-generated method stub
|
511 |
|
512 |
} |
513 |
|
514 |
/*
|
515 |
* (non-Javadoc)
|
516 |
*
|
517 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
518 |
* getFactoryFor(java.lang.Object)
|
519 |
*/
|
520 |
public PersistenceFactory getFactoryFor(Object object) { |
521 |
// TODO Auto-generated method stub
|
522 |
return null; |
523 |
} |
524 |
|
525 |
/*
|
526 |
* (non-Javadoc)
|
527 |
*
|
528 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
529 |
* getFactoryFor(org.gvsig.tools.persistence.PersistentState)
|
530 |
*/
|
531 |
public PersistenceFactory getFactoryFor(PersistentState state) {
|
532 |
// TODO Auto-generated method stub
|
533 |
return null; |
534 |
} |
535 |
|
536 |
/*
|
537 |
* (non-Javadoc)
|
538 |
*
|
539 |
* @see
|
540 |
* org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#getClassOf
|
541 |
* (org.gvsig.tools.persistence.PersistentState)
|
542 |
*/
|
543 |
public Class getClassOf(PersistentState state) { |
544 |
// TODO Auto-generated method stub
|
545 |
return null; |
546 |
} |
547 |
|
548 |
/*
|
549 |
* (non-Javadoc)
|
550 |
*
|
551 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
552 |
* getFactoryFor(java.lang.Class)
|
553 |
*/
|
554 |
public PersistenceFactory getFactoryFor(Class klass) { |
555 |
// TODO Auto-generated method stub
|
556 |
return null; |
557 |
} |
558 |
|
559 |
/*
|
560 |
* (non-Javadoc)
|
561 |
*
|
562 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
563 |
* loadFromState(java.lang.Object,
|
564 |
* org.gvsig.tools.persistence.PersistentState,
|
565 |
* org.gvsig.tools.persistence.PersistenceFactory)
|
566 |
*/
|
567 |
public void loadFromState(Object obj, PersistentState state, |
568 |
PersistenceFactory factory) throws PersistenceException {
|
569 |
if (factory != null) { |
570 |
factory.loadFromState(state, obj); |
571 |
return;
|
572 |
} else if (obj instanceof Persistent) { |
573 |
((Persistent) obj).loadFromState(state); |
574 |
|
575 |
} else {
|
576 |
throw new PersistenceTypeNotSupportedException(obj.getClass()); |
577 |
} |
578 |
|
579 |
} |
580 |
|
581 |
/*
|
582 |
* (non-Javadoc)
|
583 |
*
|
584 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
585 |
* getDomainName(java.lang.String)
|
586 |
*/
|
587 |
public String getDomainName(String theClassName) |
588 |
throws PersistenceClassNotRegistered {
|
589 |
ClassInfo info = (ClassInfo) classes.get(theClassName); |
590 |
if (info == null) { |
591 |
throw new PersistenceClassNotRegistered(theClassName); |
592 |
} |
593 |
return info.domainName;
|
594 |
} |
595 |
|
596 |
/*
|
597 |
* (non-Javadoc)
|
598 |
*
|
599 |
* @see
|
600 |
* org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#getDomains
|
601 |
* ()
|
602 |
*/
|
603 |
public Map getDomains() { |
604 |
return Collections.unmodifiableMap(domainsURL); |
605 |
} |
606 |
|
607 |
/*
|
608 |
* (non-Javadoc)
|
609 |
*
|
610 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
611 |
* getDomainURL(java.lang.String)
|
612 |
*/
|
613 |
public String getDomainURL(String domainName) { |
614 |
return (String) domainsURL.get(domainName); |
615 |
} |
616 |
|
617 |
/*
|
618 |
* (non-Javadoc)
|
619 |
*
|
620 |
* @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
|
621 |
* getDomainDefinitions(java.lang.String)
|
622 |
*/
|
623 |
public Map getDomainDefinitions(String domainName) { |
624 |
if (!domainsURL.containsKey(domainName)) {
|
625 |
throw new PersistenceRuntimeException("Domain not registered"); |
626 |
} |
627 |
Map definitions = new HashMap(); |
628 |
Entry entry; |
629 |
ClassInfo info; |
630 |
Iterator iter = classes.entrySet().iterator();
|
631 |
while (iter.hasNext()) {
|
632 |
entry = (Entry) iter.next(); |
633 |
info = (ClassInfo) entry.getValue(); |
634 |
if (domainName.equals(info.domainName)) {
|
635 |
definitions.put(entry.getKey(), info.definition); |
636 |
} |
637 |
} |
638 |
return definitions;
|
639 |
} |
640 |
} |