Source Code Cross Referenced for ConfigurationInitializer.java in  » Testing » jakarta-cactus » org » apache » cactus » internal » configuration » 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 » Testing » jakarta cactus » org.apache.cactus.internal.configuration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003-2004 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.internal.configuration;
021:
022:        import java.io.FileInputStream;
023:        import java.io.IOException;
024:
025:        import java.util.Enumeration;
026:        import java.util.MissingResourceException;
027:        import java.util.PropertyResourceBundle;
028:        import java.util.ResourceBundle;
029:
030:        import org.apache.cactus.internal.util.ClassLoaderUtils;
031:        import org.apache.cactus.util.ChainedRuntimeException;
032:
033:        /**
034:         * Read Cactus configuration files and set the properties found as
035:         * System properties.
036:         *
037:         * @version $Id: ConfigurationInitializer.java 239016 2004-06-27 15:23:30Z vmassol $
038:         */
039:        public class ConfigurationInitializer {
040:            /**
041:             * Name of the Cactus configuration file if cactus is to look for it in
042:             * the classpath.
043:             */
044:            private static final String DEFAULT_CONFIG_NAME = "cactus";
045:
046:            /**
047:             * Name of the java property for specifying the location of the cactus
048:             * configuration file. This overrides any cactus configuration file that is
049:             * put in the classpath.
050:             */
051:            private static final String CACTUS_CONFIG_PROPERTY = "cactus.config";
052:
053:            /**
054:             * Name of the Cactus property that points to a properties file
055:             * containing logging configuration.
056:             */
057:            private static final String CACTUS_LOGGING_CONFIG_PROPERTY = "cactus.logging.config";
058:
059:            /**
060:             * Have the Cactus configuration files been initialized?
061:             */
062:            private static boolean isInitialized;
063:
064:            /**
065:             * Read Cactus configuration files.
066:             * 
067:             * @param isReinitialization if true then force a re-read of the Cactus 
068:             *        configuration files
069:             */
070:            public static synchronized void initialize(
071:                    boolean isReinitialization) {
072:                if (!isInitialized) {
073:                    initializeConfig(isReinitialization);
074:                    initializeLoggingConfig(isReinitialization);
075:                    isInitialized = true;
076:                }
077:            }
078:
079:            /**
080:             * Read Cactus configuration files.
081:             */
082:            public static synchronized void initialize() {
083:                initialize(false);
084:            }
085:
086:            /**
087:             * Initialize general cactus configuration. Read the cactus configuration 
088:             * file from the java property defined on the command line 
089:             * (named CACTUS_CONFIG_PROPERTY) and if none has been defined tries to 
090:             * read the DEFAULT_CONFIG_NAME file from the classpath. All properties 
091:             * found are exported as java system properties.
092:             * 
093:             * @param isReinitialization if true then force a re-read of the Cactus 
094:             *        configuration files
095:             */
096:            private static void initializeConfig(boolean isReinitialization) {
097:                ResourceBundle config;
098:
099:                // Has the user passed the location of the cactus configuration
100:                // file as a java property
101:                String configOverride = System
102:                        .getProperty(CACTUS_CONFIG_PROPERTY);
103:
104:                if (configOverride == null) {
105:                    // Try to read the default cactus configuration file from the
106:                    // classpath
107:                    try {
108:                        config = ClassLoaderUtils.loadPropertyResourceBundle(
109:                                DEFAULT_CONFIG_NAME,
110:                                ConfigurationInitializer.class);
111:                    } catch (MissingResourceException e) {
112:                        // Cannot find cactus properties file. Do nothing.
113:                        return;
114:                    }
115:                } else {
116:                    // Try to read from specified properties file
117:                    try {
118:                        config = new PropertyResourceBundle(
119:                                new FileInputStream(configOverride));
120:                    } catch (IOException e) {
121:                        throw new ChainedRuntimeException(
122:                                "Cannot read cactus configuration file ["
123:                                        + configOverride + "]", e);
124:                    }
125:                }
126:
127:                addSystemProperties(config, isReinitialization);
128:            }
129:
130:            /**
131:             * Initialize logging configuration.
132:             * 
133:             * @param isReinitialization if true then force a re-read of the Cactus 
134:             *        configuration files
135:             */
136:            private static void initializeLoggingConfig(
137:                    boolean isReinitialization) {
138:                String logConfig = System
139:                        .getProperty(CACTUS_LOGGING_CONFIG_PROPERTY);
140:                if (logConfig != null) {
141:                    ResourceBundle bundle;
142:                    try {
143:                        bundle = new PropertyResourceBundle(
144:                                new FileInputStream(logConfig));
145:                    } catch (IOException e) {
146:                        throw new ChainedRuntimeException(
147:                                "Failed to load logging "
148:                                        + "configuration file [" + logConfig
149:                                        + "]");
150:                    }
151:                    addSystemProperties(bundle, isReinitialization);
152:                }
153:            }
154:
155:            /**
156:             * Add all properties found in the resource bundle as system
157:             * properties.
158:             *
159:             * @param theBundle the resource bundle containing the properties to
160:             *        set as system properties
161:             * @param isReinitialization if true then force a re-read of the Cactus 
162:             *        configuration files
163:             */
164:            private static void addSystemProperties(ResourceBundle theBundle,
165:                    boolean isReinitialization) {
166:                Enumeration keys = theBundle.getKeys();
167:
168:                while (keys.hasMoreElements()) {
169:                    String key = (String) keys.nextElement();
170:
171:                    // Only set the system property if it does not already exist.
172:                    // This allows system properties defined on the command line
173:                    // override Cactus properties located in the Cactus configuration
174:                    // files.
175:                    if ((System.getProperty(key) == null) || isReinitialization) {
176:                        System.setProperty(key, theBundle.getString(key));
177:                    }
178:                }
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.