Source Code Cross Referenced for Config.java in  » J2EE » Jaffa » org » jaffa » config » 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 » J2EE » Jaffa » org.jaffa.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ====================================================================
003:         * JAFFA - Java Application Framework For All
004:         *
005:         * Copyright (C) 2002 JAFFA Development Group
006:         *
007:         *     This library is free software; you can redistribute it and/or
008:         *     modify it under the terms of the GNU Lesser General Public
009:         *     License as published by the Free Software Foundation; either
010:         *     version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *     This library is distributed in the hope that it will be useful,
013:         *     but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *     Lesser General Public License for more details.
016:         *
017:         *     You should have received a copy of the GNU Lesser General Public
018:         *     License along with this library; if not, write to the Free Software
019:         *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         *
021:         * Redistribution and use of this software and associated documentation ("Software"),
022:         * with or without modification, are permitted provided that the following conditions are met:
023:         * 1.	Redistributions of source code must retain copyright statements and notices.
024:         *         Redistributions must also contain a copy of this document.
025:         * 2.	Redistributions in binary form must reproduce the above copyright notice,
026:         * 	this list of conditions and the following disclaimer in the documentation
027:         * 	and/or other materials provided with the distribution.
028:         * 3.	The name "JAFFA" must not be used to endorse or promote products derived from
029:         * 	this Software without prior written permission. For written permission,
030:         * 	please contact mail to: jaffagroup@yahoo.com.
031:         * 4.	Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032:         * 	appear in their names without prior written permission.
033:         * 5.	Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034:         *
035:         * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046:         * SUCH DAMAGE.
047:         * ====================================================================
048:         */
049:
050:        package org.jaffa.config;
051:
052:        import java.util.PropertyResourceBundle;
053:        import java.util.MissingResourceException;
054:        import java.util.HashMap;
055:        import org.apache.log4j.Logger;
056:        import org.apache.struts.util.MessageResources;
057:
058:        /** This class manages all the access to the frameworks configuration data
059:         * In addition it is used for all text string translation.
060:         *
061:         * This configuration object manages both static (read from a resource) and dynamic
062:         * (set by initilization params).
063:         *
064:         * Each configuration paramerter will have a static name associated with it. Only
065:         * the parameters flagged as dynamic will be accepted by the setProperty() method.
066:         *
067:         * By default the getters will return Ojects, but any property read from the resource
068:         * will be returned as string. The dynapic properties will return the same object that
069:         * was passed into it.
070:         *
071:         * NOTE: This has been modified to use the resource bundle libraries from Jakarta/Struts
072:         * NOTE: Changed Back to use normal resource bundles as Struts doesnt seem to work under J2EE
073:         *
074:         * @author  PaulE
075:         * @version 1.0
076:         */
077:        public class Config {
078:            private static Logger log = Logger
079:                    .getLogger(Config.class.getName());
080:
081:            /////////////////////////////////////////////////////////////////////////////
082:            // Define all the supported system properties here...
083:            /////////////////////////////////////////////////////////////////////////////
084:
085:            /////////////////////////////////////////////////////////////////////////////
086:            // Dynamic Properties (update setProperty() to support this method)
087:
088:            /** Dynamic, Returns java.lang.String : The physical path of where the web route is. Set in the initialization servlet. Example "C:\tomcat\webapps\Tools" */
089:            public static final String PROP_WEB_SERVER_ROOT = "framework.WebServerRoot";
090:
091:            /** Dynamic, Returns java.lang.String : The physical path of where the ApplicationResources.properties is. Set in the initialization servlet. Example "C:\tomcat\webapps\Tools\WEB-INF\classes\ApplicationResources.properties" */
092:            public static final String PROP_APPLICATION_RESOURCES_LOCATION = "framework.ApplicationResourcesLocation";
093:
094:            /** Dynamic, Returns java.lang.String : The physical path of where the ApplicationResources.default is. Set in the initialization servlet. Example "C:\tomcat\webapps\Tools\WEB-INF\classes\ApplicationResources.default" */
095:            public static final String PROP_APPLICATION_RESOURCES_DEFAULT_LOCATION = "framework.ApplicationResourcesDefaultLocation";
096:
097:            /** Dynamic, Returns java.lang.String : The physical path of where the ApplicationResources.override is. Set in the initialization servlet. Example "C:\ApplicationResources.override" */
098:            public static final String PROP_APPLICATION_RESOURCES_OVERRIDE_LOCATION = "framework.ApplicationResourcesOverrideLocation";
099:
100:            /////////////////////////////////////////////////////////////////////////////
101:            // Static Properties (should be defined and in-sync with the definition in the config.properties)
102:
103:            /** Static : This the the name of a file in the web servers route directory. It is used to get the WEB_SERVER_ROOT. '/index.html' is often a good value to use */
104:            public static final String PROP_WEB_SERVER_ROOT_FILE = "framework.WebServerRootFile";
105:            /** Static : Log4j Configuration To Use. 'none', 'default' or specified xml config file */
106:            public static final String PROP_LOG4J_CONFIG = "framework.Log4JConfig";
107:            /** Static : Location in the Web Application Tree of the Components.xml file */
108:            public static final String PROP_COMPONENTS_FILE = "framework.ComponentsFile";
109:            /** Static : The configuration file to be used when the JDBCEngine provider is used */
110:            public static final String PROP_JDBC_ENGINE_INIT = "framework.persistence.jdbcengine.init";
111:            /** Static : The no. of tiers being used */
112:            public static final String PROP_TIER = "framework.middleware.Tier";
113:            /** Static : The default html fragment used for guarded-buttons */
114:            public static final String PROP_PRESENTATION_DEFAULT_GUARDED_HTML_LOCATION = "framework.presentation.defaultGuardedHtml.location";
115:            /** Static : The invalidate or not to invalidate a Session, when redirecting to the FinalUrl */
116:            public static final String PROP_SECURITY_PORTLET_INVALIDATE_SESSION_BEFORE_REDIRECTING_TO_FINAL_URL = "framework.security.portlet.invalidateSessionBeforeRedirectingToFinalUrl";
117:
118:            /** Static : The URL location of the Role based security policy file */
119:            public static final String PROP_SECURITY_POLICY_URL = "framework.security.policy.url";
120:            /** Static : The URL location of the User based user grid settings file */
121:            public static final String PROP_USER_GRID_SETTINGS_URI = "framework.widgets.usergrid.user.url";
122:            /** Static : The URL location of the User based user grid settings file */
123:            public static final String PROP_DEFAULT_GRID_SETTINGS_URI = "framework.widgets.usergrid.default.url";
124:            /** Static : The URL location of the Menu list file */
125:            public static final String PROP_MENULIST_URL = "framework.menu.url";
126:
127:            /** Static : The frequency at which the Component Garbage Collector is run. */
128:            public static final String PROP_PRESENTATION_COMPONENT_GARBAGE_COLLECTION_FREQUENCY_IN_MINUTES = "framework.presentation.componentGarbageCollection.frequencyInMinutes";
129:            /** Static : This value is used to determine when a component is idle and should be garbage collected. */
130:            public static final String PROP_PRESENTATION_COMPONENT_GARBAGE_COLLECTION_TIME_OUT_IN_MINUTES = "framework.presentation.componentGarbageCollection.timeOutInMinutes";
131:
132:            /** Static : This property holds the url for the core-rules file used by the Dynamic Rules Engine. */
133:            public static final String PROP_RULES_ENGINE_CORE_RULES_URL = "framework.rules.core-rules.url";
134:            /** Static : This value is used to determine the directory in which the variations to the core-rules of the Dynamic-Rules-Engine are located. */
135:            public static final String PROP_RULES_ENGINE_VARIATIONS_DIR = "framework.rules.variations.directory";
136:            /** Static : This property holds the comma-separated list of the various validator.xml urls used by the Dynamic Rules Engine. */
137:            public static final String PROP_RULES_ENGINE_VALIDATORS_URL_LIST = "framework.rules.validators.url.list";
138:
139:            /** Static : The values to be displayed in the 'MaxRecords' dropdown of the Finder/Lookup criteria screens. */
140:            public static final String PROP_FINDER_MAX_RECORDS_DROP_DOWN_OPTIONS = "framework.finder.maxRecordsDropDownOptions";
141:
142:            /** Static : The TextTag uses this properties file to determine if a hyperlink to a Viewer component should be generated for a field. */
143:            public static final String PROP_DOMAIN_FIELD_VIEWER_COMPONENT_MAPPING_FILE = "framework.DomainFieldViewerComponentMappingFile";
144:
145:            /** Static : The TextTag uses this properties file to determine the key-field of a Viewer component for which it has generated a hyperlink. */
146:            public static final String PROP_KEY_FIELD_PER_VIEWER_COMPONENT_FILE = "framework.KeyFieldPerViewerComponentFile";
147:
148:            /** Static : The Jaffa exceptions typically contain error codes. Invoking the getLocalizedMessage() on a Jaffa exception will return an appropriate message by looking up the error-code in the specified ResourceBundle. No error is raised in case an invalid ResourceBundle is specified, or if no entry exists for the error-code. The ResourceBundle should refer to a properties file in the classpath. Eg. org/jaffa/resources/ApplicationResources */
149:            public static final String PROP_MESSAGE_RESOURCES_BUNDLE = "framework.messageResources.bundle";
150:
151:            /////////////////////////////////////////////////////////////////////////////
152:            // Static data to hold all the properties
153:            /////////////////////////////////////////////////////////////////////////////
154:            private static final String CONFIG_RESOURCE = "org.jaffa.config.framework";
155:            private static PropertyResourceBundle m_staticProperties;
156:
157:            /**
158:             * @associates Object
159:             */
160:            private static HashMap m_dynamicProperties = new HashMap();
161:
162:            /** Set Property. This is only valid on properties classifed as 'dynamic'
163:             * If an invalid property is set, an logging error is raised, and the
164:             * set opertaion is ignored.
165:             *
166:             * Each time a new dynamic property is added, this method must be updated to
167:             * accept it.
168:             * @param key the property name.
169:             * @param value the property value.
170:             */
171:            public static void setProperty(String key, Object value) {
172:                if (key.equals(PROP_WEB_SERVER_ROOT)
173:                        || key.equals(PROP_APPLICATION_RESOURCES_LOCATION)
174:                        || key
175:                                .equals(PROP_APPLICATION_RESOURCES_DEFAULT_LOCATION)
176:                        || key
177:                                .equals(PROP_APPLICATION_RESOURCES_OVERRIDE_LOCATION)) {
178:                    // Set the property
179:                    m_dynamicProperties.put(key, value);
180:                } else {
181:                    log.warn("Attempt to set property '" + key
182:                            + "' failed. This is not a dynamic property.");
183:                }
184:            }
185:
186:            /** Returns the value of a property.
187:             * @param key the name of the property.
188:             * @throws MissingResourceException if the property is not found
189:             * @return the value of a property.
190:             */
191:            public static Object getProperty(String key)
192:                    throws MissingResourceException {
193:                Object obj = null;
194:
195:                // Look at the dynapic ones first
196:                if (m_dynamicProperties != null
197:                        && m_dynamicProperties.containsKey(key)) {
198:                    return m_dynamicProperties.get(key);
199:                }
200:
201:                // Now look at the static ones...
202:                if (m_staticProperties == null)
203:                    initResources();
204:
205:                obj = m_staticProperties.getObject(key);
206:                //obj = m_staticProperties.getMessage(key);
207:
208:                // If nothing was returned, see it it was an undefiend key...
209:                if (obj == null /*&& !m_staticProperties.isPresent(key)*/) {
210:                    log.warn("Config Property '" + key
211:                            + "' Requested, but not found!");
212:                    throw new MissingResourceException("Not Found",
213:                            CONFIG_RESOURCE, key);
214:                }
215:
216:                if (obj != null)
217:                    return obj.toString();
218:                else
219:                    return null;
220:            }
221:
222:            /** Get a property, can be dynamic or static. Allows for a default value to be returned if the property is not found,
223:             * or if the property has an empty/null value.
224:             * @param key the name of the property.
225:             * @param defValue this value will be returned in case the property has a null value.
226:             * @return Either a string (for a static property) or the appropriate object (for a dynamic one)
227:             */
228:            public static Object getProperty(String key, Object defValue) {
229:                try {
230:                    Object obj = getProperty(key);
231:                    if (obj == null)
232:                        return defValue;
233:                    else
234:                        return obj;
235:                } catch (MissingResourceException e) {
236:                    return defValue;
237:                }
238:            }
239:
240:            /** Initialize the resources.
241:             * This looks for the configuration properties in package "org.jaffa.config" file "framework.properties"
242:             */
243:            private static void initResources() {
244:                if (m_staticProperties == null)
245:                    try {
246:                        m_staticProperties = (PropertyResourceBundle) PropertyResourceBundle
247:                                .getBundle(CONFIG_RESOURCE);
248:                        //m_staticProperties = MessageResources.getMessageResources(CONFIG_RESOURCE);
249:
250:                    } catch (MissingResourceException e) {
251:                        log.fatal("Can't Find Config File : " + CONFIG_RESOURCE
252:                                + ".properties", e);
253:                        // This is a mission critical thing to not find !!
254:                        throw new RuntimeException(
255:                                "Fatal Error: missing resource bundle: "
256:                                        + CONFIG_RESOURCE);
257:                    }
258:
259:            }
260:
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.