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.schema.cmp;
|
11
|
|
|
12
|
|
import java.util.HashMap;
|
13
|
|
import java.util.Map;
|
14
|
|
|
15
|
|
import org.jbind.xml.base.INamespaces;
|
16
|
|
import org.jbind.xml.base.IRef;
|
17
|
|
import org.jbind.xml.core.cmp.IComponent;
|
18
|
|
import org.jbind.xml.core.cmp.ISchema;
|
19
|
|
import org.jbind.xml.core.cmp.ISchemas;
|
20
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
21
|
|
|
22
|
|
/**
|
23
|
|
* Singleton that provides access to schema components.
|
24
|
|
*/
|
25
|
|
public class Schemas implements ISchemas {
|
26
|
|
|
27
|
|
private static ISchemas ourInstance = new Schemas();
|
28
|
|
|
29
|
9694
|
public static ISchemas getInstance() {
|
30
|
9694
|
return ourInstance;
|
31
|
|
}
|
32
|
|
|
33
|
|
|
34
|
|
/**
|
35
|
|
* Maps strings of namespaces uris to {@link
|
36
|
|
* org.jbind.xml.schema.commponent.ISchema ISchema}s.
|
37
|
|
*/
|
38
|
|
private Map mySchemas = new HashMap();
|
39
|
|
|
40
|
|
/**
|
41
|
|
* Maps FqTypeNames to maps of their enumeration options.
|
42
|
|
* Each containted map maps strings to IAnyTypeData.
|
43
|
|
*/
|
44
|
|
private Map myOptionsMaps = new HashMap();
|
45
|
|
|
46
|
3
|
private Schemas() {
|
47
|
3
|
resetSchemas();
|
48
|
|
}
|
49
|
|
|
50
|
199
|
private void resetSchemas() {
|
51
|
199
|
mySchemas.clear();
|
52
|
199
|
mySchemas.put(INamespaces.XML_SCHEMA, W3CTypes.schema);
|
53
|
|
}
|
54
|
|
|
55
|
9193
|
public ISchema getSchema(String aNamespace) {
|
56
|
9193
|
return (ISchema)mySchemas.get(aNamespace);
|
57
|
|
}
|
58
|
|
|
59
|
|
|
60
|
4900
|
public IComponent getComponent(IRef aGlobalRef) {
|
61
|
4900
|
IComponent res = null;
|
62
|
4900
|
ISchema schema = getSchema(aGlobalRef.getNamespace());
|
63
|
4900
|
if (null != schema) {
|
64
|
4639
|
res = schema.getComponent(aGlobalRef);
|
65
|
|
}
|
66
|
4900
|
return res;
|
67
|
|
}
|
68
|
|
|
69
|
|
|
70
|
130
|
public void setSchema(ISchema aSchema) {
|
71
|
130
|
mySchemas.put(aSchema.getNamespace(), aSchema);
|
72
|
|
}
|
73
|
|
|
74
|
175
|
private Map getOptions(String aFqTypeName) {
|
75
|
175
|
Map res = (Map)myOptionsMaps.get(aFqTypeName);
|
76
|
175
|
if (null == res) {
|
77
|
68
|
res = new HashMap(31);
|
78
|
68
|
myOptionsMaps.put(aFqTypeName, res);
|
79
|
|
}
|
80
|
175
|
return res;
|
81
|
|
}
|
82
|
|
|
83
|
171
|
public void addEnumerationOption(String aFqTypeName, String anOptionName, IAnyTypeData aData) {
|
84
|
171
|
Map m = getOptions(aFqTypeName);
|
85
|
171
|
m.put(anOptionName, aData);
|
86
|
|
}
|
87
|
|
|
88
|
4
|
public IAnyTypeData getEnumerationOption(String aFqTypeName, String anOptionName) {
|
89
|
4
|
Map m = getOptions(aFqTypeName);
|
90
|
4
|
IAnyTypeData res = (IAnyTypeData)m.get(anOptionName);
|
91
|
|
assert null != res :
|
92
|
|
"missing enumeration option '" + anOptionName + "' for type '" + aFqTypeName + "'. The schema containing this type must have been loaded in advance.";
|
93
|
4
|
return res;
|
94
|
|
}
|
95
|
|
|
96
|
196
|
public void reset() {
|
97
|
196
|
resetSchemas();
|
98
|
196
|
myOptionsMaps.clear();
|
99
|
|
}
|
100
|
|
}
|
101
|
|
|