1 45 package org.openejb.alt.assembler.classic.xml; 46 47 import java.io.IOException ; 48 import java.util.Properties ; 49 50 import org.apache.xerces.parsers.DOMParser; 51 import org.openejb.EnvProps; 52 import org.openejb.OpenEJBException; 53 import org.openejb.alt.assembler.classic.OpenEjbConfiguration; 54 import org.openejb.alt.assembler.classic.OpenEjbConfigurationFactory; 55 import org.openejb.util.OpenEJBErrorHandler; 56 import org.openejb.util.SafeProperties; 57 import org.openejb.util.SafeToolkit; 58 import org.w3c.dom.Document ; 59 import org.xml.sax.ErrorHandler ; 60 import org.xml.sax.SAXException ; 61 import org.xml.sax.SAXNotRecognizedException ; 62 import org.xml.sax.SAXNotSupportedException ; 63 import org.xml.sax.SAXParseException ; 64 65 66 103 public class DomOpenEjbConfigurationFactory implements OpenEjbConfigurationFactory{ 104 105 private SafeToolkit toolkit = SafeToolkit.getToolkit("DomConfig"); 106 private XmlOpenEJBConfiguration config; 107 private String configXml; 108 109 120 public void init(Properties props) throws OpenEJBException { 121 SafeProperties safeProps = toolkit.getSafeProperties(props); 122 configXml = safeProps.getProperty(EnvProps.CONFIGURATION); 123 new java.io.File (configXml); 124 } 125 126 public OpenEjbConfiguration getOpenEjbConfiguration() throws OpenEJBException { 127 try { 128 if (config == null) { 129 config = new XmlOpenEJBConfiguration(); 130 DOMParser parser = new DOMParser(); 131 132 parser.setErrorHandler(new XMLErrorHandler()); 133 parser.setFeature("http://xml.org/sax/features/validation", true); 134 parser.setFeature("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", true); 135 parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); 136 parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false); 137 parser.parse(configXml); 138 139 Document document = parser.getDocument(); 140 config.initializeFromDOM(document); 141 } 142 143 return config; 144 } catch (IOException e) { 145 throw new OpenEJBException("Problem creating the OpenEjbConfiguration structure from file "+configXml, e); 146 } catch (SAXNotSupportedException e) { 147 throw new OpenEJBException("Problem creating the OpenEjbConfiguration structure from file "+configXml, e); 148 } catch (SAXNotRecognizedException e) { 149 throw new OpenEJBException("Problem creating the OpenEjbConfiguration structure from file "+configXml, e); 150 } catch (SAXException e) { 151 throw new OpenEJBException("Problem creating the OpenEjbConfiguration structure from file "+configXml, e); 152 } 153 } 154 155 } 156 157 class XMLErrorHandler implements ErrorHandler{ 158 159 public void warning (SAXParseException exception) throws SAXException { 160 handleError("warning",exception); 161 } 162 163 public void error (SAXParseException exception) throws SAXException { 164 handleError("error",exception); 165 } 166 167 public void fatalError (SAXParseException exception) throws SAXException { 168 handleError("fatal error",exception); 169 } 170 171 private void handleError(String errorType, SAXParseException e) { 172 OpenEJBErrorHandler.configurationParsingError(errorType, e.getLocalizedMessage(), e.getLineNumber()+"", e.getColumnNumber()+""); 173 } 174 } 175 176 177 | Popular Tags |