1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springmodules.validation.bean.conf.loader.xml;
18
19 import java.io.IOException;
20 import java.util.Map;
21
22 import javax.xml.parsers.DocumentBuilder;
23 import javax.xml.parsers.DocumentBuilderFactory;
24 import javax.xml.parsers.ParserConfigurationException;
25
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.core.io.Resource;
29 import org.springmodules.validation.bean.conf.ResourceConfigurationLoadingException;
30 import org.w3c.dom.Document;
31 import org.xml.sax.SAXException;
32
33 /**
34 * An {@link AbstractResourceBasedBeanValidationConfigurationLoader} implementation that serves as a base class
35 * for all xml baed bean validation configuration loaders.
36 *
37 * @author Uri Boness
38 */
39 public abstract class AbstractXmlBeanValidationConfigurationLoader extends AbstractResourceBasedBeanValidationConfigurationLoader {
40
41 private final Logger logger = LoggerFactory.getLogger(AbstractXmlBeanValidationConfigurationLoader.class);
42
43 /**
44 * todo: document
45 *
46 * @see org.springmodules.validation.bean.conf.loader.xml.AbstractResourceBasedBeanValidationConfigurationLoader#loadConfigurations(org.springframework.core.io.Resource)
47 */
48 protected final Map loadConfigurations(Resource resource) {
49 try {
50 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
51 builderFactory.setNamespaceAware(true);
52 DocumentBuilder builder = builderFactory.newDocumentBuilder();
53 Document document = builder.parse(resource.getInputStream());
54 return loadConfigurations(document, resource.getDescription());
55 } catch (IOException ioe) {
56 logger.error("Could not read resource '" + resource.getDescription() + "'", ioe);
57 throw new ResourceConfigurationLoadingException(resource, ioe);
58 } catch (ParserConfigurationException pce) {
59 logger.error("Could not parse xml resource '" + resource.getDescription() + "'", pce);
60 throw new ResourceConfigurationLoadingException(resource, pce);
61 } catch (SAXException se) {
62 logger.error("Could not parse xml resource '" + resource.getDescription() + "'", se);
63 throw new ResourceConfigurationLoadingException(resource, se);
64 } catch (Throwable t) {
65 logger.error("Could not parse xml resource '" + resource.getDescription() + "'", t);
66 throw new ResourceConfigurationLoadingException(resource, t);
67 }
68 }
69
70 /**
71 * todo: document
72 */
73 protected abstract Map loadConfigurations(Document document, String resourceName);
74
75
76 }