Source Code Cross Referenced for ControllerParser.java in  » Database-JDBC-Connection-Pool » sequoia-2.10.9 » org » continuent » sequoia » controller » xml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » sequoia 2.10.9 » org.continuent.sequoia.controller.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Sequoia: Database clustering technology.
003:         * Copyright (C) 2002-2004 French National Institute For Research In Computer
004:         * Science And Control (INRIA).
005:         * Contact: sequoia@continuent.org
006:         * 
007:         * Licensed under the Apache License, Version 2.0 (the "License");
008:         * you may not use this file except in compliance with the License.
009:         * You may obtain a copy of the License at
010:         * 
011:         * http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License. 
018:         *
019:         * Initial developer(s): Emmanuel Cecchet.
020:         * Contributor(s): Mathieu Peltier, Sara Bouchenak.
021:         */package org.continuent.sequoia.controller.xml;
022:
023:        import java.io.BufferedReader;
024:        import java.io.File;
025:        import java.io.FileReader;
026:        import java.io.IOException;
027:        import java.io.InputStream;
028:        import java.io.StringReader;
029:        import java.net.InetAddress;
030:        import java.net.URL;
031:        import java.net.URLDecoder;
032:        import java.util.ArrayList;
033:        import java.util.Locale;
034:
035:        import org.continuent.sequoia.common.i18n.Translate;
036:        import org.continuent.sequoia.common.jmx.JmxConstants;
037:        import org.continuent.sequoia.common.jmx.JmxException;
038:        import org.continuent.sequoia.common.log.Trace;
039:        import org.continuent.sequoia.common.net.SSLConfiguration;
040:        import org.continuent.sequoia.common.xml.ControllerXmlTags;
041:        import org.continuent.sequoia.common.xml.XmlValidator;
042:        import org.continuent.sequoia.controller.core.Controller;
043:        import org.continuent.sequoia.controller.core.ControllerConfiguration;
044:        import org.continuent.sequoia.controller.core.ControllerConstants;
045:        import org.continuent.sequoia.controller.core.ReportManager;
046:        import org.continuent.sequoia.controller.core.security.ControllerSecurityManager;
047:        import org.xml.sax.Attributes;
048:        import org.xml.sax.InputSource;
049:        import org.xml.sax.SAXException;
050:        import org.xml.sax.SAXParseException;
051:        import org.xml.sax.XMLReader;
052:        import org.xml.sax.helpers.DefaultHandler;
053:        import org.xml.sax.helpers.XMLReaderFactory;
054:
055:        /**
056:         * Allows to parse an XML content containing the description of the controller
057:         * confirming to sequoia-controller.dtd.
058:         * 
059:         * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
060:         * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
061:         * @version 1.0
062:         */
063:        public class ControllerParser extends DefaultHandler {
064:            /** Logger instance. */
065:            static Trace logger = Trace.getLogger(ControllerParser.class
066:                    .getName());
067:            static Trace endUserLogger = Trace
068:                    .getLogger("org.continuent.sequoia.enduser");
069:
070:            /** XML parser. */
071:            private XMLReader parser;
072:
073:            /** Sequoia controller to setup. */
074:            private ControllerConfiguration config;
075:            private ControllerSecurityManager security;
076:            private Controller controller;
077:            private boolean parseAccept = false;
078:            private SSLConfiguration ssl;
079:            private String controllerIP;
080:            private ReportManager manager;
081:
082:            /**
083:             * Creates a new <code>ControllerParser</code> instance. This method
084:             * Instanciates also a new <code>ControllerHandler</code>.
085:             * 
086:             * @param configure a <code>ControllerConfiguration</code> object that
087:             *          contains the configuration to update with values from xml parsing
088:             * @throws Exception i private String doctype; f an error occurs
089:             */
090:            public ControllerParser(ControllerConfiguration configure)
091:                    throws Exception {
092:                this .config = configure;
093:                this .controller = configure.getController();
094:
095:                // Instantiate a new parser
096:                parser = XMLReaderFactory.createXMLReader();
097:
098:                // Activate validation
099:                parser.setFeature("http://xml.org/sax/features/validation",
100:                        true);
101:
102:                // Install error handler
103:                parser.setErrorHandler(this );
104:
105:                // Install document handler
106:                parser.setContentHandler(this );
107:
108:                // Install local entity resolver
109:                parser.setEntityResolver(this );
110:            }
111:
112:            /**
113:             * Parses an XML content according to SEQUOIA-CONTROLLER DTD.
114:             * 
115:             * @param xml a <code>String</code> containing the XML content to parse
116:             * @exception SAXException if an error occurs
117:             * @exception IOException if an error occurs
118:             */
119:            public void readXML(String xml) throws IOException, SAXException {
120:                if (xml != null) {
121:                    InputSource input = new InputSource(new StringReader(xml));
122:                    parser.parse(input);
123:                } else
124:                    throw new IOException("Input was null in input source.");
125:            }
126:
127:            /**
128:             * Parses an XML formatted string according to SEQUOIA-CONTROLLER DTD.
129:             * 
130:             * @param xml a <code>String</code> reference to the xml to parse
131:             * @param validateBeforeParsing if validation should be checked before parsing
132:             * @exception SAXException if an error occurs
133:             * @exception IOException if an error occurs
134:             */
135:            public void readXML(String xml, boolean validateBeforeParsing)
136:                    throws IOException, SAXException {
137:                if (validateBeforeParsing) {
138:                    XmlValidator validator = new XmlValidator(
139:                            ControllerConstants.SEQUOIA_CONTROLLER_DTD_FILE,
140:                            xml.toString());
141:                    if (logger.isDebugEnabled()) {
142:                        if (validator.isDtdValid())
143:                            logger.debug(Translate
144:                                    .get("controller.xml.dtd.validated"));
145:                        if (validator.isXmlValid())
146:                            logger.debug(Translate
147:                                    .get("controller.xml.document.validated"));
148:                    }
149:
150:                    if (validator.getWarnings().size() > 0) {
151:                        ArrayList warnings = validator.getWarnings();
152:                        for (int i = 0; i < warnings.size(); i++)
153:                            logger.warn(Translate.get(
154:                                    "virtualdatabase.xml.parsing.warning",
155:                                    warnings.get(i)));
156:                    }
157:
158:                    if (!validator.isDtdValid())
159:                        logger.error(Translate
160:                                .get("controller.xml.dtd.not.validated"));
161:                    if (!validator.isXmlValid())
162:                        logger.error(Translate
163:                                .get("controller.xml.document.not.validated"));
164:
165:                    ArrayList errors = validator.getExceptions();
166:                    for (int i = 0; i < errors.size(); i++)
167:                        logger.error(((Exception) errors.get(i)).getMessage());
168:
169:                    if (!validator.isValid())
170:                        throw new SAXException(Translate
171:                                .get("controller.xml.document.not.valid"));
172:                }
173:                readXML(xml);
174:            }
175:
176:            /**
177:             * Parses an XML formatted file according to SEQUOIA-CONTROLLER DTD.
178:             * 
179:             * @param fileReader a <code>FileReader</code> reference to the xml to parse
180:             * @param validateBeforeParsing if validation should be checked before parsing
181:             * @exception SAXException if an error occurs
182:             * @exception IOException if an error occurs
183:             */
184:            public void readXML(FileReader fileReader,
185:                    boolean validateBeforeParsing) throws IOException,
186:                    SAXException {
187:                if (fileReader != null) {
188:
189:                    // Read the file
190:                    BufferedReader in = new BufferedReader(fileReader);
191:                    StringBuffer xml = new StringBuffer();
192:                    String line;
193:                    do {
194:                        line = in.readLine();
195:                        if (line != null)
196:                            xml.append(line);
197:                    } while (line != null);
198:
199:                    readXML(xml.toString(), validateBeforeParsing);
200:                } else {
201:                    throw new IOException("Input was null in input source.");
202:                }
203:            }
204:
205:            /**
206:             * Handles notification of a non-recoverable parser error.
207:             * 
208:             * @param e the warning information encoded as an exception.
209:             * @exception SAXException any SAX exception, possibly wrapping another
210:             *              exception.
211:             */
212:            public void fatalError(SAXParseException e) throws SAXException {
213:                String msg = Translate.get("controller.xml.parsing.fatal",
214:                        new String[] { e.getPublicId(),
215:                                String.valueOf(e.getLineNumber()),
216:                                String.valueOf(e.getColumnNumber()),
217:                                e.getMessage() });
218:                logger.error(msg);
219:                endUserLogger.fatal(msg);
220:                throw e;
221:            }
222:
223:            /**
224:             * Handles notification of a recoverable parser error.
225:             * 
226:             * @param e the warning information encoded as an exception.
227:             * @exception SAXException any SAX exception, possibly wrapping another
228:             *              exception
229:             */
230:            public void error(SAXParseException e) throws SAXException {
231:                logger.error(Translate.get("controller.xml.parsing.error",
232:                        new String[] { e.getPublicId(),
233:                                String.valueOf(e.getLineNumber()),
234:                                String.valueOf(e.getColumnNumber()),
235:                                e.getMessage() }));
236:                throw e;
237:            }
238:
239:            /**
240:             * Allows to parse the document with a local copy of the DTD whatever the
241:             * original <code>DOCTYPE</code> found. Warning, this method is called only
242:             * if the XML document contains a <code>DOCTYPE</code>.
243:             * 
244:             * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String,
245:             *      java.lang.String)
246:             */
247:            public InputSource resolveEntity(String publicId, String systemId)
248:                    throws SAXException {
249:                logger.debug(Translate.get("controller.xml.dtd.using",
250:                        ControllerConstants.SEQUOIA_CONTROLLER_DTD_FILE));
251:                InputStream stream = ControllerParser.class
252:                        .getResourceAsStream("/"
253:                                + ControllerConstants.SEQUOIA_CONTROLLER_DTD_FILE);
254:                if (stream == null) {
255:                    throw new SAXException(Translate.get(
256:                            "controller.xml.dtd.not.found",
257:                            ControllerConstants.PRODUCT_NAME,
258:                            ControllerConstants.SEQUOIA_CONTROLLER_DTD_FILE));
259:                }
260:
261:                return new InputSource(stream);
262:            }
263:
264:            /**
265:             * Initializes parsing of a document.
266:             * 
267:             * @exception SAXException unspecialized error
268:             */
269:            public void startDocument() throws SAXException {
270:                logger.debug(Translate.get("controller.xml.parsing.document"));
271:            }
272:
273:            /**
274:             * Finalizes parsing of a document.
275:             * 
276:             * @exception SAXException unspecialized error
277:             */
278:            public void endDocument() throws SAXException {
279:                logger.info(Translate.get("controller.xml.done"));
280:            }
281:
282:            /**
283:             * Analyzes an element first line.
284:             * 
285:             * @param uri name space URI
286:             * @param localName local name
287:             * @param name element raw name
288:             * @param atts element attributes
289:             * @exception SAXException if an error occurs
290:             */
291:            public void startElement(String uri, String localName, String name,
292:                    Attributes atts) throws SAXException {
293:                logger.debug(Translate
294:                        .get("controller.xml.parsing.start", name));
295:                if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONTROLLER))
296:                    configureController(atts);
297:                else if (name
298:                        .equalsIgnoreCase(ControllerXmlTags.ELT_INTERNATIONALIZATION)) {
299:                    Locale.setDefault(new Locale(atts
300:                            .getValue(ControllerXmlTags.ATT_LANGUAGE), ""));
301:                } else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_REPORT))
302:                    configureReport(atts);
303:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JMX)) {
304:                    config.put(ControllerConfiguration.JMX_ENABLE, "true");
305:                } else if (name
306:                        .equalsIgnoreCase(ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR))
307:                    configureHttpJmxAdaptor(atts);
308:                else if (name
309:                        .equalsIgnoreCase(ControllerXmlTags.ELT_RMI_JMX_ADAPTOR))
310:                    configureRmiJmxAdaptor(atts);
311:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SSL))
312:                    configureSSL(atts);
313:                else if (name
314:                        .equalsIgnoreCase(ControllerXmlTags.ELT_VIRTUAL_DATABASE))
315:                    configureVirtualDatabase(atts);
316:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SECURITY)) {
317:                    security = new ControllerSecurityManager();
318:                    boolean connect = new Boolean(atts
319:                            .getValue(ControllerXmlTags.ATT_DEFAULT_CONNECT))
320:                            .booleanValue();
321:                    security.setDefaultConnect(connect);
322:                } else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JAR)) {
323:                    boolean allow = new Boolean(atts
324:                            .getValue(ControllerXmlTags.ATT_JAR_ALLOW_DRIVER))
325:                            .booleanValue();
326:                    security.setAllowAdditionalDriver(allow);
327:                } else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_ACCEPT))
328:                    parseAccept = true;
329:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_BLOCK))
330:                    parseAccept = false;
331:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_HOSTNAME))
332:                    security
333:                            .addHostToSecureList(atts
334:                                    .getValue(ControllerXmlTags.ATT_VALUE),
335:                                    parseAccept);
336:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_IPADDRESS))
337:                    security
338:                            .addHostToSecureList(atts
339:                                    .getValue(ControllerXmlTags.ATT_VALUE),
340:                                    parseAccept);
341:                else if (name.equalsIgnoreCase(ControllerXmlTags.ELT_IPRANGE))
342:                    configureIpRange(atts);
343:            }
344:
345:            /**
346:             * DatabasesParser for end of element.
347:             * 
348:             * @param uri name space URI
349:             * @param localName local name
350:             * @param name element raw name
351:             * @exception SAXException if an error occurs
352:             */
353:            public void endElement(String uri, String localName, String name)
354:                    throws SAXException {
355:                // We need information on what configuration are for jmx
356:                if (name.equalsIgnoreCase(ControllerXmlTags.ELT_JMX)) {
357:                    try {
358:                        config.setUpJmx();
359:                    } catch (JmxException jmxEx) {
360:                        logger.error(Translate.get(
361:                                "controller.xml.jmx.setup.failed", jmxEx
362:                                        .getMessage()), jmxEx);
363:                    }
364:                }
365:                if (name.equalsIgnoreCase(ControllerXmlTags.ELT_SECURITY)) {
366:                    security.setSslConfig(ssl);
367:                    ssl = null;
368:                    config.setUpSecurity(security);
369:                }
370:                if (name
371:                        .equalsIgnoreCase(ControllerXmlTags.ELT_RMI_JMX_ADAPTOR)) {
372:                    if (ssl != null) {
373:                        config.put(JmxConstants.CONNECTOR_RMI_SSL, ssl);
374:                        ssl = null;
375:                    }
376:                }
377:                if (name.equalsIgnoreCase(ControllerXmlTags.ELT_CONTROLLER)) {
378:                    // Be sure no settings are used for report
379:                    if (manager == null) {
380:                        manager = new ReportManager(controller);
381:                        manager.setSettings(null);
382:                        controller.setReport(manager);
383:                    }
384:                }
385:                logger.debug(Translate.get("controller.xml.parsing.end", name));
386:            }
387:
388:            /**
389:             * Configure a <code>ControllerXmlTags.ELT_CONTROLLER</code> element.
390:             * 
391:             * @param atts the parser attributes
392:             * @throws SAXException if an error occurs
393:             */
394:            private void configureController(Attributes atts)
395:                    throws SAXException {
396:                try {
397:                    String controllerPort = atts
398:                            .getValue(ControllerXmlTags.ATT_CONTROLLER_PORT);
399:                    if (controllerPort == null)
400:                        config
401:                                .put(
402:                                        ControllerConfiguration.CONTROLLER_PORT,
403:                                        String
404:                                                .valueOf(ControllerConstants.DEFAULT_PORT));
405:                    else
406:                        config.put(ControllerConfiguration.CONTROLLER_PORT,
407:                                controllerPort);
408:                    config
409:                            .getController()
410:                            .setPortNumber(
411:                                    Integer
412:                                            .parseInt((String) config
413:                                                    .get(ControllerConfiguration.CONTROLLER_PORT)));
414:
415:                    controllerIP = atts
416:                            .getValue(ControllerXmlTags.ATT_CONTROLLER_IP);
417:                    if (controllerIP == null) {
418:                        try {
419:                            /**
420:                             * leaving "null" would be ok for
421:                             * 
422:                             * @see org.continuent.sequoia.controller.core.ControllerServerThread#ControllerServerThread(Controller)
423:                             *      but JMX/RMI naming scheme would not like it, so we use
424:                             *      getLocalHost().getHostAddress() as a pseudo-empty/default
425:                             *      value.
426:                             */
427:                            String localIP = InetAddress.getLocalHost()
428:                                    .getHostAddress();
429:                            config.put(ControllerConfiguration.CONTROLLER_IP,
430:                                    localIP);
431:                        } catch (RuntimeException e1) {
432:                            logger
433:                                    .warn("Unable to obtain IP address of controller, setting default address: "
434:                                            + ControllerConstants.DEFAULT_IP);
435:                            config.put(ControllerConfiguration.CONTROLLER_IP,
436:                                    ControllerConstants.DEFAULT_IP);
437:                        }
438:                    } else
439:                        config.put(ControllerConfiguration.CONTROLLER_IP,
440:                                controllerIP);
441:                    config
442:                            .getController()
443:                            .setIPAddress(
444:                                    (String) config
445:                                            .get(ControllerConfiguration.CONTROLLER_IP));
446:
447:                    String controllerBacklog = atts
448:                            .getValue(ControllerXmlTags.ATT_backlogSize);
449:                    if (controllerBacklog == null)
450:                        config
451:                                .put(
452:                                        ControllerConfiguration.CONTROLLER_BACKLOG,
453:                                        String
454:                                                .valueOf(ControllerConstants.DEFAULT_BACKLOG_SIZE));
455:                    else
456:                        config.put(ControllerConfiguration.CONTROLLER_BACKLOG,
457:                                controllerBacklog);
458:                    config
459:                            .getController()
460:                            .setBacklogSize(
461:                                    Integer
462:                                            .parseInt((String) config
463:                                                    .get(ControllerConfiguration.CONTROLLER_BACKLOG)));
464:                } catch (Exception e) {
465:                    logger.warn("Error while configuring controller", e);
466:                    throw new SAXException(e.getMessage());
467:                }
468:            }
469:
470:            /**
471:             * Configure a <code>ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR</code> element.
472:             * 
473:             * @param atts the parser attributes
474:             */
475:            private void configureHttpJmxAdaptor(Attributes atts) {
476:                String adaptorPort = atts
477:                        .getValue(ControllerXmlTags.ATT_JMX_ADAPTOR_PORT);
478:                if (config.get(JmxConstants.ADAPTOR_TYPE_HTTP) == null)
479:                    config.put(JmxConstants.ADAPTOR_TYPE_HTTP, String
480:                            .valueOf(adaptorPort));
481:            }
482:
483:            /**
484:             * Configure a <code>ControllerXmlTags.ELT_IPRANGE</code> element.
485:             * 
486:             * @param atts the parser attributes
487:             */
488:            private void configureIpRange(Attributes atts) {
489:                String iprange = atts.getValue(ControllerXmlTags.ATT_VALUE);
490:                try {
491:                    security.addToSecureList(iprange, parseAccept);
492:                } catch (Exception e) {
493:                    logger.warn(Translate.get(
494:                            "controller.configure.invalid.iprange", iprange));
495:                }
496:            }
497:
498:            /**
499:             * Configure a <code>ControllerXmlTags.ELT_REPORT</code> element.
500:             * 
501:             * @param atts the parser attributes
502:             */
503:            private void configureReport(Attributes atts) {
504:                config.put(ControllerXmlTags.ATT_REPORT_ENABLED, "true");
505:                config
506:                        .put(
507:                                ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA,
508:                                atts
509:                                        .getValue(ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA));
510:                config
511:                        .put(
512:                                ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN,
513:                                atts
514:                                        .getValue(ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN));
515:                config
516:                        .put(
517:                                ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL,
518:                                atts
519:                                        .getValue(ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL));
520:                config
521:                        .put(
522:                                ControllerXmlTags.ATT_REPORT_DELETE_ON_SHUTDOWN,
523:                                atts
524:                                        .getValue(ControllerXmlTags.ATT_REPORT_DELETE_ON_SHUTDOWN));
525:                String reportLocation = atts
526:                        .getValue(ControllerXmlTags.ATT_REPORT_REPORT_LOCATION);
527:
528:                if ((reportLocation == null) || reportLocation.equals("")) {
529:                    reportLocation = System.getProperty("sequoia.log");
530:                    if (reportLocation == null)
531:                        reportLocation = ".";
532:                }
533:                config.put(ControllerXmlTags.ATT_REPORT_REPORT_LOCATION,
534:                        reportLocation);
535:
536:                config
537:                        .put(
538:                                ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING,
539:                                atts
540:                                        .getValue(ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING));
541:                manager = new ReportManager(controller);
542:                manager.setSettings(config);
543:                controller.setReport(manager);
544:            }
545:
546:            /**
547:             * Configure a <code>ControllerXmlTags.ELT_RMI_JMX_ADAPTOR</code> element.
548:             * 
549:             * @param atts the parser attributes
550:             */
551:            private void configureRmiJmxAdaptor(Attributes atts) {
552:                String adaptorPort = atts
553:                        .getValue(ControllerXmlTags.ATT_JMX_ADAPTOR_PORT);
554:                if (config.get(JmxConstants.ADAPTOR_TYPE_RMI) == null)
555:                    config.put(JmxConstants.ADAPTOR_TYPE_RMI, String
556:                            .valueOf(adaptorPort));
557:
558:                String username = atts
559:                        .getValue(ControllerXmlTags.ATT_JMX_CONNECTOR_USERNAME);
560:                String password = atts
561:                        .getValue(ControllerXmlTags.ATT_JMX_CONNECTOR_PASSWORD);
562:                if (username != null)
563:                    config.put(JmxConstants.CONNECTOR_AUTH_USERNAME, username);
564:                if (password != null)
565:                    config.put(JmxConstants.CONNECTOR_AUTH_PASSWORD, password);
566:            }
567:
568:            /**
569:             * Configure a <code>ControllerXmlTags.ELT_SSL</code> element.
570:             * 
571:             * @param atts the parser attributes
572:             */
573:            private void configureSSL(Attributes atts) {
574:                ssl = new SSLConfiguration();
575:                String keyStore = atts
576:                        .getValue(ControllerXmlTags.ATT_SSL_KEYSTORE);
577:                String keyStorePassword = atts
578:                        .getValue(ControllerXmlTags.ATT_SSL_KEYSTORE_PASSWORD);
579:                String keyStoreKeyPassword = atts
580:                        .getValue(ControllerXmlTags.ATT_SSL_KEYSTORE_KEYPASSWORD);
581:                String trustStore = atts
582:                        .getValue(ControllerXmlTags.ATT_SSL_TRUSTSTORE);
583:                String trustStorePassword = atts
584:                        .getValue(ControllerXmlTags.ATT_SSL_TRUSTSTORE_PASSWORD);
585:                ssl.setKeyStore(new File(keyStore));
586:
587:                // Sanity checks, default to SSL_KEYSTORE values
588:                if (keyStoreKeyPassword == null)
589:                    keyStoreKeyPassword = keyStorePassword;
590:                if (trustStore == null)
591:                    trustStore = keyStore;
592:                if (trustStorePassword == null)
593:                    trustStorePassword = keyStorePassword;
594:
595:                ssl.setKeyStorePassword(keyStorePassword);
596:                ssl.setKeyStoreKeyPassword(keyStoreKeyPassword);
597:                ssl.setClientAuthenticationRequired("true".equals(atts
598:                        .getValue(ControllerXmlTags.ATT_SSL_NEED_CLIENT_AUTH)));
599:                ssl.setTrustStore(new File(trustStore));
600:                ssl.setTrustStorePassword(trustStorePassword);
601:            }
602:
603:            /**
604:             * Configure a <code>ControllerXmlTags.ELT_VIRTUAL_DATABASE</code> element.
605:             * 
606:             * @param atts the parser attributes
607:             * @throws SAXException if an error occurs
608:             */
609:            private void configureVirtualDatabase(Attributes atts)
610:                    throws SAXException {
611:                String checkPoint = atts
612:                        .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_CHECKPOINT);
613:                String virtualName = atts
614:                        .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_NAME);
615:                String file = atts
616:                        .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_FILE);
617:
618:                // Try to find the file on the path (usually config directory) if no file
619:                // separator is found
620:                if (file.indexOf(File.separator) == -1) {
621:                    try {
622:                        URL url = this .getClass().getResource("/" + file);
623:                        file = url.getFile();
624:                        logger.info(Translate.get("controller.configure.using",
625:                                file));
626:                    } catch (Exception e) {
627:                        throw new SAXException(Translate.get(
628:                                "controller.configure.file.not.found", file));
629:                    }
630:                }
631:
632:                file = URLDecoder.decode(file);
633:
634:                File checkExist = new File(file);
635:                if (checkExist.exists() == false)
636:                    throw new SAXException(Translate.get(
637:                            "controller.configure.file.not.found", file));
638:
639:                int autoLoad = -1;
640:                String autoLoadString = atts
641:                        .getValue(ControllerXmlTags.ATT_VIRTUAL_DATABASE_AUTO_ENABLE);
642:
643:                if (autoLoadString.equalsIgnoreCase(ControllerXmlTags.VAL_true))
644:                    autoLoad = ControllerConstants.AUTO_ENABLE_TRUE;
645:                else if (autoLoadString
646:                        .equalsIgnoreCase(ControllerXmlTags.VAL_force))
647:                    autoLoad = ControllerConstants.AUTO_ENABLE_FORCE;
648:                else
649:                    autoLoad = ControllerConstants.AUTO_ENABLE_FALSE;
650:
651:                logger.info(Translate.get("controller.configure.setup",
652:                        new String[] { virtualName, String.valueOf(autoLoad),
653:                                checkPoint }));
654:                config.setUpVirtualDatabase(file, virtualName, autoLoad,
655:                        checkPoint);
656:            }
657:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.