01: /*
02: * Created on Dec 23, 2004
03: */
04: package uk.org.ponder.saxalizer.mapping;
05:
06: import java.io.InputStream;
07: import java.util.List;
08:
09: import uk.org.ponder.saxalizer.SAXalizerMappingContext;
10: import uk.org.ponder.saxalizer.XMLProvider;
11: import uk.org.ponder.util.UniversalRuntimeException;
12:
13: /**
14: * @author Antranig Basman (antranig@caret.cam.ac.uk)
15: *
16: */
17: public class MappingLoadManager {
18: private MappableXMLProvider xmlprovider;
19: private SAXalizerMappingContext mappingcontext;
20: private ContainerTypeRegistry ctr;
21:
22: public void setMappableXMLProvider(MappableXMLProvider xmlprovider) {
23: this .xmlprovider = xmlprovider;
24: }
25:
26: public void setSAXalizerMappingContext(
27: SAXalizerMappingContext mappingcontext) {
28: this .mappingcontext = mappingcontext;
29: }
30:
31: public SAXalizerMappingContext getSAXalizerMappingContext() {
32: return mappingcontext;
33: }
34:
35: public void setContainerTypeRegistry(ContainerTypeRegistry ctr) {
36: this .ctr = ctr;
37: }
38:
39: public void setMappingLoaders(List mappingloaders) {
40: for (int i = 0; i < mappingloaders.size(); ++i) {
41: MappingLoader mappingloader = (MappingLoader) mappingloaders
42: .get(i);
43: mappingloader.loadExtendedMappings(mappingcontext);
44: mappingloader.loadStandardMappings(xmlprovider);
45: mappingloader.registerContainerTypes(ctr);
46: }
47: }
48:
49: public ClassNameManager getClassNameManager() {
50: return mappingcontext.classnamemanager;
51: }
52:
53: public XMLProvider getXMLProvider() {
54: return xmlprovider;
55: }
56:
57: public MappableXMLProvider getMappableXMLProvider() {
58: return xmlprovider;
59: }
60:
61: public static void loadClasspathMapping(
62: MappableXMLProvider xmlprovider, String path) {
63: try {
64: InputStream is = xmlprovider.getClass().getClassLoader()
65: .getResourceAsStream(path);
66: if (is == null) {
67: throw new UniversalRuntimeException(
68: "Classpath resource for path " + path
69: + " not found");
70: }
71: xmlprovider.loadMapping(is);
72: } catch (Throwable t) {
73: throw UniversalRuntimeException.accumulate(t,
74: "Failed to load mapping for " + path);
75: }
76: }
77: }
|