1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.instance.builder;
|
11
|
|
|
12
|
|
import java.util.ArrayList;
|
13
|
|
import java.util.HashMap;
|
14
|
|
import java.util.Iterator;
|
15
|
|
import java.util.List;
|
16
|
|
import java.util.Map;
|
17
|
|
|
18
|
|
import org.jbind.xml.base.IRef;
|
19
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
20
|
|
import org.jbind.xml.core.data.IDataContext;
|
21
|
|
import org.jbind.xml.core.data.IDataReference;
|
22
|
|
import org.jbind.xml.core.data.IDataStore;
|
23
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
24
|
|
|
25
|
|
public class DataContext implements IDataContext, IDataStore {
|
26
|
|
|
27
|
|
/**
|
28
|
|
* <i>(optional)</i>. Initialized on demand.
|
29
|
|
*/
|
30
|
|
private Map myIndexMaps = null;
|
31
|
|
|
32
|
|
/**
|
33
|
|
* <i>(optional)</i>. Initialized on demand.
|
34
|
|
*/
|
35
|
|
private List myReferences = null;
|
36
|
|
|
37
|
|
private boolean myIsShared;
|
38
|
|
|
39
|
222
|
public DataContext(boolean anIsShared) {
|
40
|
222
|
myIsShared = anIsShared;
|
41
|
|
}
|
42
|
|
|
43
|
113
|
private Map getIndexMap(IRef aRef) {
|
44
|
113
|
if (null == myIndexMaps) {
|
45
|
6
|
myIndexMaps = new HashMap(23);
|
46
|
|
}
|
47
|
113
|
Map res = (Map)myIndexMaps.get(aRef);
|
48
|
113
|
if (null == res) {
|
49
|
8
|
res = new HashMap();
|
50
|
8
|
myIndexMaps.put(aRef, res);
|
51
|
|
}
|
52
|
113
|
return res;
|
53
|
|
}
|
54
|
|
|
55
|
70
|
public void add(IDataReference anOpenReference) {
|
56
|
70
|
if (null == myReferences) {
|
57
|
6
|
myReferences = new ArrayList();
|
58
|
|
}
|
59
|
70
|
myReferences.add(anOpenReference);
|
60
|
|
}
|
61
|
|
|
62
|
93
|
public void resolveReferences(IConstraintViolations aViolations) {
|
63
|
93
|
if (null != myReferences) {
|
64
|
6
|
for (Iterator i = myReferences.iterator(); i.hasNext(); ) {
|
65
|
70
|
IDataReference reference = (IDataReference)i.next();
|
66
|
70
|
reference.resolve(this, aViolations);
|
67
|
|
}
|
68
|
6
|
myReferences = null;
|
69
|
|
}
|
70
|
93
|
if (!myIsShared) {
|
71
|
91
|
myIndexMaps = null;
|
72
|
|
}
|
73
|
|
}
|
74
|
|
|
75
|
70
|
public IAnyTypeData getIndexedData(IRef anIndexRef, Object aKey) {
|
76
|
70
|
return (IAnyTypeData)getIndexMap(anIndexRef).get(aKey);
|
77
|
|
}
|
78
|
|
|
79
|
43
|
public IAnyTypeData setIndexedData(IRef anIndexRef, Object aKey, IAnyTypeData aData) {
|
80
|
43
|
return (IAnyTypeData)getIndexMap(anIndexRef).put(aKey, aData);
|
81
|
|
}
|
82
|
|
|
83
|
0
|
public boolean isShared() {
|
84
|
0
|
return myIsShared;
|
85
|
|
}
|
86
|
|
}
|
87
|
|
|