KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > xml > ControllerParser


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Mathieu Peltier, Sara Bouchenak.
23  */

24
25 package org.objectweb.cjdbc.controller.xml;
26
27 import java.io.BufferedReader JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileReader JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.io.StringReader JavaDoc;
33 import java.net.InetAddress JavaDoc;
34 import java.net.URL JavaDoc;
35 import java.net.URLDecoder JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Locale JavaDoc;
38
39 import org.objectweb.cjdbc.common.i18n.Translate;
40 import org.objectweb.cjdbc.common.jmx.JmxConstants;
41 import org.objectweb.cjdbc.common.jmx.JmxException;
42 import org.objectweb.cjdbc.common.log.Trace;
43 import org.objectweb.cjdbc.common.net.SSLConfiguration;
44 import org.objectweb.cjdbc.common.xml.ControllerXmlTags;
45 import org.objectweb.cjdbc.common.xml.XmlValidator;
46 import org.objectweb.cjdbc.controller.core.Controller;
47 import org.objectweb.cjdbc.controller.core.ControllerConstants;
48 import org.objectweb.cjdbc.controller.core.ControllerFactory;
49 import org.objectweb.cjdbc.controller.core.ReportManager;
50 import org.objectweb.cjdbc.controller.core.security.ControllerSecurityManager;
51 import org.xml.sax.Attributes JavaDoc;
52 import org.xml.sax.InputSource JavaDoc;
53 import org.xml.sax.SAXException JavaDoc;
54 import org.xml.sax.SAXParseException JavaDoc;
55 import org.xml.sax.XMLReader JavaDoc;
56 import org.xml.sax.helpers.DefaultHandler JavaDoc;
57 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
58
59 /**
60  * Allows to parse an XML content containing the description of the controller
61  * confirming to C-JDBC-controller.dtd.
62  *
63  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
64  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
65  * @version 1.0
66  */

67 public class ControllerParser extends DefaultHandler JavaDoc
68 {
69   /** Logger instance. */
70   static Trace logger = Trace
71                                                     .getLogger(ControllerParser.class
72                                                         .getName());
73
74   /** XML parser. */
75   private XMLReader JavaDoc parser;
76
77   /** C-JDBC controller to setup. */
78   private ControllerFactory config;
79   private ControllerSecurityManager security;
80   private Controller controller;
81   private boolean parseAccept = false;
82   private SSLConfiguration ssl;
83   private String JavaDoc controllerIP;
84   private ReportManager manager;
85
86   /**
87    * Creates a new <code>ControllerParser</code> instance. This method
88    * Instanciates also a new <code>ControllerHandler</code>.
89    *
90    * @param configure a <code>ControllerFactory</code> object that contains
91    * the configuration to update with values from xml parsing
92    * @throws Exception if an error occurs
93    */

94   public ControllerParser(ControllerFactory configure) throws Exception JavaDoc
95   {
96     this.config = configure;
97     this.controller = configure.getController();
98
99     // Instantiate a new parser
100
parser = XMLReaderFactory.createXMLReader();
101
102     // Activate validation
103
parser.setFeature("http://xml.org/sax/features/validation", true);
104
105     // Install error handler
106
parser.setErrorHandler(this);
107
108     // Install document handler
109
parser.setContentHandler(this);
110
111     // Install local entity resolver
112
parser.setEntityResolver(this);
113   }
114
115   /**
116    * Parses an XML content according to C-JDBC-controller DTD.
117    *
118    * @param xml a <code>String</code> containing the XML content to parse
119    * @exception SAXException if an error occurs
120    * @exception IOException if an error occurs
121    */

122   public void readXML(String JavaDoc xml) throws IOException JavaDoc, SAXException JavaDoc
123   {
124     if (xml != null)
125     {
126       InputSource JavaDoc input = new InputSource JavaDoc(new StringReader JavaDoc(xml));
127       parser.parse(input);
128     }
129     else
130       throw new IOException JavaDoc("Input was null in input source.");
131   }
132
133   /**
134    * Parses an XML formatted string according to C-JDBC-controller DTD.
135    *
136    * @param xml a <code>String</code> reference to the xml to parse
137    * @param validateBeforeParsing if validation should be checked before parsing
138    * @exception SAXException if an error occurs
139    * @exception IOException if an error occurs
140    */

141   public void readXML(String JavaDoc xml, boolean validateBeforeParsing)
142       throws IOException JavaDoc, SAXException JavaDoc
143   {
144     if (validateBeforeParsing)
145     {
146       XmlValidator validator = new XmlValidator(
147           ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE, xml.toString());
148       if (logger.isDebugEnabled())
149       {
150         if (validator.isDtdValid())
151           logger.debug(Translate.get("controller.xml.dtd.validated"));
152         if (validator.isXmlValid())
153           logger.debug(Translate.get("controller.xml.document.validated"));
154       }
155
156       if (validator.getWarnings().size() > 0)
157       {
158         ArrayList JavaDoc warnings = validator.getWarnings();
159         for (int i = 0; i < warnings.size(); i++)
160           logger.warn(Translate.get("virtualdatabase.xml.parsing.warning",
161               warnings.get(i)));
162       }
163
164       if (!validator.isDtdValid())
165         logger.error(Translate.get("controller.xml.dtd.not.validated"));
166       if (!validator.isXmlValid())
167         logger.error(Translate.get("controller.xml.document.not.validated"));
168
169       ArrayList JavaDoc errors = validator.getExceptions();
170       for (int i = 0; i < errors.size(); i++)
171         logger.error(((Exception JavaDoc) errors.get(i)).getMessage());
172
173       if (!validator.isValid())
174         throw new SAXException JavaDoc(Translate
175             .get("controller.xml.document.not.valid"));
176     }
177     readXML(xml);
178   }
179
180   /**
181    * Parses an XML formatted file according to C-JDBC-controller DTD.
182    *
183    * @param fileReader a <code>FileReader</code> reference to the xml to parse
184    * @param validateBeforeParsing if validation should be checked before parsing
185    * @exception SAXException if an error occurs
186    * @exception IOException if an error occurs
187    */

188   public void readXML(FileReader JavaDoc fileReader, boolean validateBeforeParsing)
189       throws IOException JavaDoc, SAXException JavaDoc
190   {
191     if (fileReader != null)
192     {
193
194       // Read the file
195
BufferedReader JavaDoc in = new BufferedReader JavaDoc(fileReader);
196       StringBuffer JavaDoc xml = new StringBuffer JavaDoc();
197       String JavaDoc line;
198       do
199       {
200         line = in.readLine();
201         if (line != null)
202           xml.append(line.trim());
203       }
204       while (line != null);
205
206       readXML(xml.toString(), validateBeforeParsing);
207     }
208     else
209     {
210       throw new IOException JavaDoc("Input was null in input source.");
211     }
212   }
213
214   /**
215    * Handles notification of a non-recoverable parser error.
216    *
217    * @param e the warning information encoded as an exception.
218    * @exception SAXException any SAX exception, possibly wrapping another
219    * exception.
220    */

221   public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc
222   {
223     logger.error(Translate.get("controller.xml.parsing.fatal", new String JavaDoc[]{
224         e.getPublicId(), String.valueOf(e.getLineNumber()),
225         String.valueOf(e.getColumnNumber()), e.getMessage()}));
226     throw e;
227   }
228
229   /**
230    * Handles notification of a recoverable parser error.
231    *
232    * @param e the warning information encoded as an exception.
233    * @exception SAXException any SAX exception, possibly wrapping another
234    * exception
235    */

236   public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc
237   {
238     logger.error(Translate.get("controller.xml.parsing.error", new String JavaDoc[]{
239         e.getPublicId(), String.valueOf(e.getLineNumber()),
240         String.valueOf(e.getColumnNumber()), e.getMessage()}));
241     throw e;
242   }
243
244   /**
245    * Allows to parse the document with a local copy of the DTD whatever the
246    * original <code>DOCTYPE</code> found. Warning, this method is called only
247    * if the XML document contains a <code>DOCTYPE</code>.
248    *
249    * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String,
250    * java.lang.String)
251    */

252   public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
253       throws SAXException JavaDoc
254   {
255     logger.debug(Translate.get("controller.xml.dtd.using",
256         ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE));
257     InputStream JavaDoc stream = ControllerParser.class.getResourceAsStream("/"
258         + ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE);
259     if (stream == null)
260     {
261       throw new SAXException JavaDoc(Translate.get("controller.xml.dtd.not.found",
262           ControllerConstants.C_JDBC_CONTROLLER_DTD_FILE));
263     }
264
265     return new InputSource JavaDoc(stream);
266   }
267
268   /**
269    * Initializes parsing of a document.
270    *
271    * @exception SAXException unspecialized error
272    */

273   public void startDocument() throws SAXException JavaDoc
274   {
275     logger.debug(Translate.get("controller.xml.parsing.document"));
276   }
277
278   /**
279    * Finalizes parsing of a document.
280    *
281    * @exception SAXException unspecialized error
282    */

283   public void endDocument() throws SAXException JavaDoc
284   {
285     logger.info(Translate.get("controller.xml.done"));
286   }
287
288   /**
289    * Analyzes an element first line.
290    *
291    * @param uri name space URI
292    * @param localName local name
293    * @param name element raw name
294    * @param atts element attributes
295    * @exception SAXException if an error occurs
296    */

297   public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc name,
298       Attributes JavaDoc atts) throws SAXException JavaDoc
299   {
300     logger.debug(Translate.get("controller.xml.parsing.start", name));
301     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONTROLLER))
302       configureController(atts);
303     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_INTERNATIONALIZATION))
304     {
305       Locale.setDefault(new Locale JavaDoc(atts
306           .getValue(ControllerXmlTags.ATT_LANGUAGE), ""));
307     }
308     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_REPORT))
309       configureReport(atts);
310     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JMX))
311     {
312       config.put(ControllerFactory.JMX_ENABLE, "true");
313     }
314     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR))
315       configureHttpJmxAdaptor(atts);
316     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_RMI_JMX_ADAPTOR))
317       configureRmiJmxAdaptor(atts);
318     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SSL))
319       configureSSL(atts);
320     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_VIRTUAL_DATABASE))
321       configureVirtualDatabase(atts);
322     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SECURITY))
323     {
324       security = new ControllerSecurityManager();
325       boolean connect = new Boolean JavaDoc(atts
326           .getValue(ControllerXmlTags.ATT_DEFAULT_CONNECT)).booleanValue();
327       security.setDefaultConnect(connect);
328     }
329     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JAR))
330     {
331       boolean allow = new Boolean JavaDoc(atts
332           .getValue(ControllerXmlTags.ATT_JAR_ALLOW_DRIVER)).booleanValue();
333       security.setAllowAdditionalDriver(allow);
334     }
335     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CLIENT))
336       configureClient(atts);
337     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONSOLE))
338       configureConsole(atts);
339     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_ACCEPT))
340       parseAccept = true;
341     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_BLOCK))
342       parseAccept = false;
343     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_HOSTNAME))
344       security.addHostToSecureList(atts.getValue(ControllerXmlTags.ATT_VALUE),
345           parseAccept);
346     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_IPADDRESS))
347       security.addHostToSecureList(atts.getValue(ControllerXmlTags.ATT_VALUE),
348           parseAccept);
349     else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_IPRANGE))
350       configureIpRange(atts);
351   }
352
353   /**
354    * DatabasesParser for end of element.
355    *
356    * @param uri name space URI
357    * @param localName local name
358    * @param name element raw name
359    * @exception SAXException if an error occurs
360    */

361   public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc name)
362       throws SAXException JavaDoc
363   {
364     // We need information on what configuration are for jmx
365
if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JMX))
366     {
367       try
368       {
369         config.setUpJmx();
370       }
371       catch (JmxException jmxEx)
372       {
373         logger.error(Translate.get("controller.xml.jmx.setup.failed", jmxEx
374             .getMessage()), jmxEx);
375       }
376     }
377     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SECURITY))
378     {
379       security.setSslConfig(ssl);
380       ssl = null;
381       config.setUpSecurity(security);
382     }
383     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_RMI_JMX_ADAPTOR))
384     {
385       if (ssl != null)
386       {
387         config.put(JmxConstants.CONNECTOR_RMI_SSL, ssl);
388         ssl = null;
389       }
390     }
391     if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONTROLLER))
392     {
393       // Be sure no settings are used for report
394
if (manager == null)
395       {
396         manager = new ReportManager(controller);
397         manager.setSettings(null);
398         controller.setReport(manager);
399       }
400     }
401     logger.debug(Translate.get("controller.xml.parsing.end", name));
402   }
403
404   /**
405    * Configure a <code>ControllerXmlTags.ELT_CLIENT</code> element.
406    *
407    * @param atts the parser attributes
408    */

409   private void configureClient(Attributes JavaDoc atts)
410   {
411     boolean localhost = new Boolean JavaDoc(atts
412         .getValue(ControllerXmlTags.ATT_ONLY_LOCALHOST)).booleanValue();
413     boolean allow = new Boolean JavaDoc(atts.getValue(ControllerXmlTags.ATT_ALLOW))
414         .booleanValue();
415     security.setAllowClientShutdown(allow);
416     security.setAllowLocalClientOnly(localhost);
417   }
418
419   /**
420    * Configure a <code>ControllerXmlTags.ELT_CONSOLE</code> element.
421    *
422    * @param atts the parser attributes
423    */

424   private void configureConsole(Attributes JavaDoc atts)
425   {
426     boolean localhost = new Boolean JavaDoc(atts
427         .getValue(ControllerXmlTags.ATT_ONLY_LOCALHOST)).booleanValue();
428     boolean allow = new Boolean JavaDoc(atts.getValue(ControllerXmlTags.ATT_ALLOW))
429         .booleanValue();
430     security.setAllowConsoleShutdown(allow);
431     security.setAllowLocalConsoleOnly(localhost);
432   }
433
434   /**
435    * Configure a <code>ControllerXmlTags.ELT_CONTROLLER</code> element.
436    *
437    * @param atts the parser attributes
438    * @throws SAXException if an error occurs
439    */

440   private void configureController(Attributes JavaDoc atts) throws SAXException JavaDoc
441   {
442     try
443     {
444       String JavaDoc controllerPort = atts
445           .getValue(ControllerXmlTags.ATT_CONTROLLER_PORT);
446       if (controllerPort == null)
447         config.put(ControllerFactory.CONTROLLER_PORT, String
448             .valueOf(ControllerConstants.DEFAULT_PORT));
449       else
450         config.put(ControllerFactory.CONTROLLER_PORT, controllerPort);
451       config.getController().setPortNumber(
452           Integer.parseInt((String JavaDoc) config
453               .get(ControllerFactory.CONTROLLER_PORT)));
454
455       controllerIP = atts.getValue(ControllerXmlTags.ATT_CONTROLLER_IP);
456       if (controllerIP == null)
457       {
458         try
459         {
460           /**
461            * leaving "null" would be ok for
462            *
463            * @see org.objectweb.cjdbc.controller.core.ControllerServerThread#ControllerServerThread(Controller)
464            * but JMX/RMI naming scheme would not like it, so we use
465            * getLocalHost().getHostAddress() as a pseudo-empty/default
466            * value.
467            */

468           String JavaDoc localIP = InetAddress.getLocalHost().getHostAddress();
469           config.put(ControllerFactory.CONTROLLER_IP, localIP);
470         }
471         catch (RuntimeException JavaDoc e1)
472         {
473           logger
474               .warn("Unable to obtain IP address of controller, setting default address: "
475                   + ControllerConstants.DEFAULT_IP);
476           config.put(ControllerFactory.CONTROLLER_IP,
477               ControllerConstants.DEFAULT_IP);
478         }
479       }
480       else
481         config.put(ControllerFactory.CONTROLLER_IP, controllerIP);
482       config.getController().setIPAddress(
483           (String JavaDoc) config.get(ControllerFactory.CONTROLLER_IP));
484
485       String JavaDoc controllerBacklog = atts
486           .getValue(ControllerXmlTags.ATT_backlogSize);
487       if (controllerBacklog == null)
488         config.put(ControllerFactory.CONTROLLER_BACKLOG, String
489             .valueOf(ControllerConstants.DEFAULT_BACKLOG_SIZE));
490       else
491         config.put(ControllerFactory.CONTROLLER_BACKLOG, controllerBacklog);
492       config.getController().setBacklogSize(
493           Integer.parseInt((String JavaDoc) config
494               .get(ControllerFactory.CONTROLLER_BACKLOG)));
495     }
496     catch (Exception JavaDoc e)
497     {
498       throw new SAXException JavaDoc(e.getMessage());
499     }
500   }
501
502   /**
503    * Configure a <code>ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR</code> element.
504    *
505    * @param atts the parser attributes
506    */

507   private void configureHttpJmxAdaptor(Attributes JavaDoc atts)
508   {
509     String JavaDoc adaptorPort = atts.getValue(ControllerXmlTags.ATT_JMX_ADAPTOR_PORT);
510     if (config.get(JmxConstants.ADAPTOR_TYPE_HTTP) == null)
511       config.put(JmxConstants.ADAPTOR_TYPE_HTTP, String.valueOf(adaptorPort));
512   }
513
514   /**
515    * Configure a <code>ControllerXmlTags.ELT_IPRANGE</code> element.
516    *
517    * @param atts the parser attributes
518    */

519   private void configureIpRange(Attributes JavaDoc atts)
520   {
521     String JavaDoc iprange = atts.getValue(ControllerXmlTags.ATT_VALUE);
522     try
523     {
524       security.addToSecureList(iprange, parseAccept);
525     }
526     catch (Exception JavaDoc e)
527     {
528       logger.warn(Translate
529           .get("controller.configure.invalid.iprange", iprange));
530     }
531   }
532
533   /**
534    * Configure a <code>ControllerXmlTags.ELT_REPORT</code> element.
535    *
536    * @param atts the parser attributes
537    */

538   private void configureReport(Attributes JavaDoc atts)
539   {
540     config.put(ControllerXmlTags.ATT_REPORT_ENABLED, "true");
541     config.put(ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA, atts
542         .getValue(ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA));
543     config.put(ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN, atts
544         .getValue(ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN));
545     config.put(ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL, atts
546         .getValue(ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL));
547     config.put(ControllerXmlTags.ATT_REPORT_DELETE_ON_SHUTDOWN, atts
548         .getValue(ControllerXmlTags.ATT_REPORT_DELETE_ON_SHUTDOWN));
549     String JavaDoc reportLocation = atts
550         .getValue(ControllerXmlTags.ATT_REPORT_REPORT_LOCATION);
551     // Default to CJDBC_HOME/log
552
if ((reportLocation == null) || reportLocation.equals(""))
553     {
554       String JavaDoc defaultDir = System.getProperty("cjdbc.home");
555       if (defaultDir == null)
556       {
557         reportLocation = ".";
558       }
559       else
560       {
561         reportLocation = defaultDir + File.separator
562             + ControllerConstants.DEFAULT_LOG_DIR_NAME;
563       }
564     }
565     config.put(ControllerXmlTags.ATT_REPORT_REPORT_LOCATION, reportLocation);
566
567     config.put(ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING, atts
568         .getValue(ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING));
569     manager = new ReportManager(controller);
570     manager.setSettings(config);
571     controller.setReport(manager);
572   }
573
574   /**
575    * Configure a <code>ControllerXmlTags.ELT_RMI_JMX_ADAPTOR</code> element.
576    *
577    * @param atts the parser attributes
578    */

579   private void configureRmiJmxAdaptor(Attributes JavaDoc atts)
580   {
581     String JavaDoc adaptorPort = atts.getValue(ControllerXmlTags.ATT_JMX_ADAPTOR_PORT);
582     if (config.get(JmxConstants.ADAPTOR_TYPE_RMI) == null)
583       config.put(JmxConstants.ADAPTOR_TYPE_RMI, String.valueOf(adaptorPort));
584
585     String JavaDoc username = atts
586         .getValue(ControllerXmlTags.ATT_JMX_CONNECTOR_USERNAME);
587     String JavaDoc password = atts
588         .getValue(ControllerXmlTags.ATT_JMX_CONNECTOR_PASSWORD);
589     if (username != null)
590       config.put(JmxConstants.CONNECTOR_AUTH_USERNAME, username);
591     if (password != null)
592       config.put(JmxConstants.CONNECTOR_AUTH_PASSWORD, password);
593   }
594
595   /**
596    * Configure a <code>ControllerXmlTags.ELT_SSL</code> element.
597    *
598    * @param atts the parser attributes
599    */

600   private void configureSSL(Attributes JavaDoc atts)
601   {
602     ssl = new SSLConfiguration();
603     ssl
604         .setKeyStore(new File JavaDoc(atts.getValue(ControllerXmlTags.ATT_SSL_KEYSTORE)));
605     ssl.setKeyStorePassword(atts
606         .getValue(ControllerXmlTags.ATT_SSL_KEYSTORE_PASSWORD));
607     ssl.setKeyStoreKeyPassword(atts
608         .getValue(ControllerXmlTags.ATT_SSL_KEYSTORE_KEYPASSWORD));
609     ssl.setClientAuthenticationRequired("true".equals(atts
610         .getValue(ControllerXmlTags.ATT_SSL_NEED_CLIENT_AUTH)));
611     ssl.setTrustStore(new File JavaDoc(atts
612         .getValue(ControllerXmlTags.ATT_SSL_TRUSTSTORE)));
613     ssl.setTrustStorePassword(atts
614         .getValue(ControllerXmlTags.ATT_SSL_TRUSTSTORE_PASSWORD));
615   }
616
617   /**
618    * Configure a <code>ControllerXmlTags.ELT_VIRTUAL_DATABASE</code> element.
619    *
620    * @param atts the parser attributes
621    * @throws SAXException if an error occurs
622    */

623   private void configureVirtualDatabase(Attributes JavaDoc atts) throws SAXException JavaDoc
624   {
625     String JavaDoc checkPoint = atts
626         .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_CHECKPOINT);
627     String JavaDoc virtualName = atts
628         .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_NAME);
629     String JavaDoc file = atts.getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_FILE);
630
631     // Try to find the file on the path (usually config directory) if no file
632
// separator is found
633
if (file.indexOf(File.separator) == -1)
634     {
635       try
636       {
637         URL JavaDoc url = this.getClass().getResource("/" + file);
638         file = url.getFile();
639         logger.info(Translate.get("controller.configure.using", file));
640       }
641       catch (Exception JavaDoc e)
642       {
643         throw new SAXException JavaDoc(Translate.get(
644             "controller.configure.file.not.found", file));
645       }
646     }
647
648     file = URLDecoder.decode(file);
649
650     File JavaDoc checkExist = new File JavaDoc(file);
651     if (checkExist.exists() == false)
652       throw new SAXException JavaDoc(Translate.get(
653           "controller.configure.file.not.found", file));
654
655     int autoLoad = -1;
656     String JavaDoc autoLoadString = atts
657         .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_AUTO_ENABLE);
658
659     if (autoLoadString.equalsIgnoreCase(ControllerXmlTags.VAL_true))
660       autoLoad = ControllerConstants.AUTO_ENABLE_TRUE;
661     else if (autoLoadString.equalsIgnoreCase(ControllerXmlTags.VAL_force))
662       autoLoad = ControllerConstants.AUTO_ENABLE_FORCE;
663     else
664       autoLoad = ControllerConstants.AUTO_ENABLE_FALSE;
665
666     logger.info(Translate.get("controller.configure.setup", new String JavaDoc[]{
667         virtualName, String.valueOf(autoLoad), checkPoint}));
668     config.setUpVirtualDatabase(file, virtualName, autoLoad, checkPoint);
669   }
670
671 }
Popular Tags