Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.controller.xml.ControllerParser Class Reference

List of all members.

Public Member Functions

 ControllerParser (ControllerFactory configure) throws Exception
void readXML (String xml) throws IOException, SAXException
void readXML (String xml, boolean validateBeforeParsing) throws IOException, SAXException
void readXML (FileReader fileReader, boolean validateBeforeParsing) throws IOException, SAXException
void fatalError (SAXParseException e) throws SAXException
void error (SAXParseException e) throws SAXException
InputSource resolveEntity (String publicId, String systemId) throws SAXException
void startDocument () throws SAXException
void endDocument () throws SAXException
void startElement (String uri, String localName, String name, Attributes atts) throws SAXException
void endElement (String uri, String localName, String name) throws SAXException

Static Package Attributes

Trace logger

Detailed Description

Allows to parse an XML content containing the description of the controller confirming to C-JDBC-controller.dtd.

Author:
Emmanuel Cecchet

Nicolas Modrzyk

Version:
1.0

Definition at line 67 of file ControllerParser.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.xml.ControllerParser.ControllerParser ControllerFactory  configure  )  throws Exception
 

Creates a new ControllerParser instance. This method Instanciates also a new ControllerHandler.

Parameters:
configure a ControllerFactory object that contains the configuration to update with values from xml parsing
Exceptions:
Exception if an error occurs

Definition at line 94 of file ControllerParser.java.

00095   {
00096     this.config = configure;
00097     this.controller = configure.getController();
00098 
00099     // Instantiate a new parser
00100     parser = XMLReaderFactory.createXMLReader();
00101 
00102     // Activate validation
00103     parser.setFeature("http://xml.org/sax/features/validation", true);
00104 
00105     // Install error handler
00106     parser.setErrorHandler(this);
00107 
00108     // Install document handler
00109     parser.setContentHandler(this);
00110 
00111     // Install local entity resolver
00112     parser.setEntityResolver(this);
00113   }


Member Function Documentation

void org.objectweb.cjdbc.controller.xml.ControllerParser.endDocument  )  throws SAXException
 

Finalizes parsing of a document.

Exceptions:
SAXException unspecialized error

Definition at line 282 of file ControllerParser.java.

00283   {
00284     logger.info(Translate.get("controller.xml.done"));
00285   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.endElement String  uri,
String  localName,
String  name
throws SAXException
 

DatabasesParser for end of element.

Parameters:
uri name space URI
localName local name
name element raw name
Exceptions:
SAXException if an error occurs

Definition at line 360 of file ControllerParser.java.

References org.objectweb.cjdbc.common.xml.XmlValidator.error().

00362   {
00363     // We need information on what configuration are for jmx
00364     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JMX))
00365     {
00366       try
00367       {
00368         config.setUpJmx();
00369       }
00370       catch (JmxException jmxEx)
00371       {
00372         logger.error(Translate.get("controller.xml.jmx.setup.failed", jmxEx
00373             .getMessage()), jmxEx);
00374       }
00375     }
00376     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SECURITY))
00377     {
00378       security.setSslConfig(ssl);
00379       ssl = null;
00380       config.setUpSecurity(security);
00381     }
00382     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_RMI_JMX_ADAPTOR))
00383     {
00384       if (ssl != null)
00385       {
00386         config.put(JmxConstants.CONNECTOR_RMI_SSL, ssl);
00387         ssl = null;
00388       }
00389     }
00390     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONTROLLER))
00391     {
00392       // Be sure no settings are used for report
00393       if (manager == null)
00394       {
00395         manager = new ReportManager(controller);
00396         manager.setSettings(null);
00397         controller.setReport(manager);
00398       }
00399     }
00400     logger.debug(Translate.get("controller.xml.parsing.end", name));
00401   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.error SAXParseException  e  )  throws SAXException
 

Handles notification of a recoverable parser error.

Parameters:
e the warning information encoded as an exception.
Exceptions:
SAXException any SAX exception, possibly wrapping another exception

Definition at line 235 of file ControllerParser.java.

References org.objectweb.cjdbc.common.xml.XmlValidator.error().

00236   {
00237     logger.error(Translate.get("controller.xml.parsing.error", new String[]{
00238         e.getPublicId(), String.valueOf(e.getLineNumber()),
00239         String.valueOf(e.getColumnNumber()), e.getMessage()}));
00240     throw e;
00241   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.fatalError SAXParseException  e  )  throws SAXException
 

Handles notification of a non-recoverable parser error.

Parameters:
e the warning information encoded as an exception.
Exceptions:
SAXException any SAX exception, possibly wrapping another exception.

Definition at line 220 of file ControllerParser.java.

References org.objectweb.cjdbc.common.xml.XmlValidator.error(), and org.objectweb.cjdbc.controller.xml.ControllerParser.logger.

00221   {
00222     logger.error(Translate.get("controller.xml.parsing.fatal", new String[]{
00223         e.getPublicId(), String.valueOf(e.getLineNumber()),
00224         String.valueOf(e.getColumnNumber()), e.getMessage()}));
00225     throw e;
00226   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.readXML FileReader  fileReader,
boolean  validateBeforeParsing
throws IOException, SAXException
 

Parses an XML formatted file according to C-JDBC-controller DTD.

Parameters:
fileReader a FileReader reference to the xml to parse
validateBeforeParsing if validation should be checked before parsing
Exceptions:
SAXException if an error occurs
IOException if an error occurs

Definition at line 187 of file ControllerParser.java.

References org.objectweb.cjdbc.controller.xml.ControllerParser.readXML().

00189   {
00190     if (fileReader != null)
00191     {
00192 
00193       // Read the file
00194       BufferedReader in = new BufferedReader(fileReader);
00195       StringBuffer xml = new StringBuffer();
00196       String line;
00197       do
00198       {
00199         line = in.readLine();
00200         if (line != null)
00201           xml.append(line.trim());
00202       }
00203       while (line != null);
00204 
00205       readXML(xml.toString(), validateBeforeParsing);
00206     }
00207     else
00208     {
00209       throw new IOException("Input was null in input source.");
00210     }
00211   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.readXML String  xml,
boolean  validateBeforeParsing
throws IOException, SAXException
 

Parses an XML formatted string according to C-JDBC-controller DTD.

Parameters:
xml a String reference to the xml to parse
validateBeforeParsing if validation should be checked before parsing
Exceptions:
SAXException if an error occurs
IOException if an error occurs

Definition at line 141 of file ControllerParser.java.

References org.objectweb.cjdbc.common.xml.XmlValidator.error(), org.objectweb.cjdbc.common.xml.XmlValidator.getExceptions(), org.objectweb.cjdbc.common.xml.XmlValidator.getWarnings(), org.objectweb.cjdbc.common.xml.XmlValidator.isDtdValid, org.objectweb.cjdbc.common.xml.XmlValidator.isValid(), org.objectweb.cjdbc.common.xml.XmlValidator.isXmlValid, org.objectweb.cjdbc.controller.xml.ControllerParser.logger, and org.objectweb.cjdbc.controller.xml.ControllerParser.readXML().

00143   {
00144     if (validateBeforeParsing)
00145     {
00146       XmlValidator validator = new XmlValidator(
00147           ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE, xml.toString());
00148       if (logger.isDebugEnabled())
00149       {
00150         if (validator.isDtdValid())
00151           logger.debug(Translate.get("controller.xml.dtd.validated"));
00152         if (validator.isXmlValid())
00153           logger.debug(Translate.get("controller.xml.document.validated"));
00154       }
00155 
00156       if (validator.getWarnings().size() > 0)
00157       {
00158         ArrayList warnings = validator.getWarnings();
00159         for (int i = 0; i < warnings.size(); i++)
00160           logger.warn(Translate.get("virtualdatabase.xml.parsing.warning",
00161               warnings.get(i)));
00162       }
00163 
00164       if (!validator.isDtdValid())
00165         logger.error(Translate.get("controller.xml.dtd.not.validated"));
00166       if (!validator.isXmlValid())
00167         logger.error(Translate.get("controller.xml.document.not.validated"));
00168 
00169       ArrayList errors = validator.getExceptions();
00170       for (int i = 0; i < errors.size(); i++)
00171         logger.error(((Exception) errors.get(i)).getMessage());
00172 
00173       if (!validator.isValid())
00174         throw new SAXException(ExceptionTypes.XML_DOCUMENT_INVALID);
00175     }
00176     readXML(xml);
00177   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.readXML String  xml  )  throws IOException, SAXException
 

Parses an XML content according to C-JDBC-controller DTD.

Parameters:
xml a String containing the XML content to parse
Exceptions:
SAXException if an error occurs
IOException if an error occurs

Definition at line 122 of file ControllerParser.java.

Referenced by org.objectweb.cjdbc.controller.xml.ControllerParser.readXML(), and org.objectweb.cjdbc.controller.core.ControllerFactory.setUpByXml().

00123   {
00124     if (xml != null)
00125     {
00126       InputSource input = new InputSource(new StringReader(xml));
00127       parser.parse(input);
00128     }
00129     else
00130       throw new IOException("Input was null in input source.");
00131   }

InputSource org.objectweb.cjdbc.controller.xml.ControllerParser.resolveEntity String  publicId,
String  systemId
throws SAXException
 

Allows to parse the document with a local copy of the DTD whatever the original DOCTYPE found. Warning, this method is called only if the XML document contains a DOCTYPE.

See also:
org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)

Definition at line 251 of file ControllerParser.java.

00253   {
00254     logger.debug(Translate.get("controller.xml.dtd.using",
00255         ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE));
00256     InputStream stream = ControllerParser.class.getResourceAsStream("/"
00257         + ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE);
00258     if (stream == null)
00259     {
00260       throw new SAXException(Translate.get("controller.xml.dtd.not.found",
00261           ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE));
00262     }
00263 
00264     return new InputSource(stream);
00265   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.startDocument  )  throws SAXException
 

Initializes parsing of a document.

Exceptions:
SAXException unspecialized error

Definition at line 272 of file ControllerParser.java.

00273   {
00274     logger.debug(Translate.get("controller.xml.parsing.document"));
00275   }

void org.objectweb.cjdbc.controller.xml.ControllerParser.startElement String  uri,
String  localName,
String  name,
Attributes  atts
throws SAXException
 

Analyzes an element first line.

Parameters:
uri name space URI
localName local name
name element raw name
atts element attributes
Exceptions:
SAXException if an error occurs

Definition at line 296 of file ControllerParser.java.

00298   {
00299     logger.debug(Translate.get("controller.xml.parsing.start", name));
00300     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONTROLLER))
00301       configureController(atts);
00302     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_INTERNATIONALIZATION))
00303     {
00304       Locale.setDefault(new Locale(atts
00305           .getValue(ControllerXmlTags.ATT_LANGUAGE), ""));
00306     }
00307     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_REPORT))
00308       configureReport(atts);
00309     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JMX))
00310     {
00311       config.put(ControllerFactory.JMX_ENABLE, "true");
00312     }
00313     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR))
00314       configureHttpJmxAdaptor(atts);
00315     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_RMI_JMX_ADAPTOR))
00316       configureRmiJmxAdaptor(atts);
00317     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SSL))
00318       configureSSL(atts);
00319     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_VIRTUAL_DATABASE))
00320       configureVirtualDatabase(atts);
00321     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SECURITY))
00322     {
00323       security = new ControllerSecurityManager();
00324       boolean connect = new Boolean(atts
00325           .getValue(ControllerXmlTags.ATT_DEFAULT_CONNECT)).booleanValue();
00326       security.setDefaultConnect(connect);
00327     }
00328     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JAR))
00329     {
00330       boolean allow = new Boolean(atts
00331           .getValue(ControllerXmlTags.ATT_JAR_ALLOW_DRIVER)).booleanValue();
00332       security.setAllowAdditionalDriver(allow);
00333     }
00334     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CLIENT))
00335       configureClient(atts);
00336     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONSOLE))
00337       configureConsole(atts);
00338     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_ACCEPT))
00339       parseAccept = true;
00340     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_BLOCK))
00341       parseAccept = false;
00342     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_HOSTNAME))
00343       security.addHostToSecureList(atts.getValue(ControllerXmlTags.ATT_VALUE),
00344           parseAccept);
00345     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_IPADDRESS))
00346       security.addHostToSecureList(atts.getValue(ControllerXmlTags.ATT_VALUE),
00347           parseAccept);
00348     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_IPRANGE))
00349       configureIpRange(atts);
00350   }


Member Data Documentation

Trace org.objectweb.cjdbc.controller.xml.ControllerParser.logger [static, package]
 

Initial value:

 Trace
                                                    .getLogger(ControllerParser.class
                                                        .getName())
Logger instance.

Definition at line 70 of file ControllerParser.java.

Referenced by org.objectweb.cjdbc.controller.xml.ControllerParser.fatalError(), and org.objectweb.cjdbc.controller.xml.ControllerParser.readXML().


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:04:50 2005 for C-JDBC by  doxygen 1.3.9.1