Source Code Cross Referenced for Config.java in  » Cache » OSCache » com » opensymphony » oscache » base » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2007 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.oscache.base;
006:
007:        import org.apache.commons.logging.Log;
008:        import org.apache.commons.logging.LogFactory;
009:
010:        import java.io.IOException;
011:        import java.io.InputStream;
012:        import java.net.URL;
013:
014:        import java.util.Properties;
015:
016:        /**
017:         * Responsible for holding the Cache configuration properties. If the default
018:         * constructor is used, this class will load the properties from the
019:         * <code>cache.configuration</code>.
020:         *
021:         * @author   <a href="mailto:fabian.crabus@gurulogic.de">Fabian Crabus</a>
022:         * @version  $Revision: 412 $
023:         */
024:        public class Config implements  java.io.Serializable {
025:
026:            private static final transient Log log = LogFactory
027:                    .getLog(Config.class);
028:
029:            /**
030:             * Name of the properties file.
031:             */
032:            private final static String PROPERTIES_FILENAME = "/oscache.properties";
033:
034:            /**
035:             * Properties map to hold the cache configuration.
036:             */
037:            private Properties properties = null;
038:
039:            /**
040:             * Create an OSCache Config that loads properties from oscache.properties.
041:             * The file must be present in the root of OSCache's classpath. If the file
042:             * cannot be loaded, an error will be logged and the configuration will
043:             * remain empty.
044:             */
045:            public Config() {
046:                this (null);
047:            }
048:
049:            /**
050:             * Create an OSCache configuration with the specified properties.
051:             * Note that it is the responsibility of the caller to provide valid
052:             * properties as no error checking is done to ensure that required
053:             * keys are present. If you're unsure of what keys should be present,
054:             * have a look at a sample oscache.properties file.
055:             *
056:             * @param p The properties to use for this configuration. If null,
057:             * then the default properties are loaded from the <code>oscache.properties</code>
058:             * file.
059:             */
060:            public Config(Properties p) {
061:                if (log.isDebugEnabled()) {
062:                    log.debug("OSCache: Config called");
063:                }
064:
065:                if (p == null) {
066:                    this .properties = loadProperties(PROPERTIES_FILENAME,
067:                            "the default configuration");
068:                } else {
069:                    this .properties = p;
070:                }
071:            }
072:
073:            /**
074:             * Retrieve the value of the named configuration property. If the property
075:             * cannot be found this method will return <code>null</code>.
076:             *
077:             * @param key The name of the property.
078:             * @return The property value, or <code>null</code> if the value could
079:             * not be found.
080:             *
081:             * @throws IllegalArgumentException if the supplied key is null.
082:             */
083:            public String getProperty(String key) {
084:                if (key == null) {
085:                    throw new IllegalArgumentException("key is null");
086:                }
087:
088:                if (properties == null) {
089:                    return null;
090:                }
091:
092:                return properties.getProperty(key);
093:            }
094:
095:            /**
096:             * Retrieves all of the configuration properties. This property set
097:             * should be treated as immutable.
098:             *
099:             * @return The configuration properties.
100:             */
101:            public Properties getProperties() {
102:                return properties;
103:            }
104:
105:            public Object get(Object key) {
106:                return properties.get(key);
107:            }
108:
109:            /**
110:             * Sets a configuration property.
111:             *
112:             * @param key   The unique name for this property.
113:             * @param value The value assigned to this property.
114:             *
115:             * @throws IllegalArgumentException if the supplied key is null.
116:             */
117:            public void set(Object key, Object value) {
118:                if (key == null) {
119:                    throw new IllegalArgumentException("key is null");
120:                }
121:
122:                if (value == null) {
123:                    return;
124:                }
125:
126:                if (properties == null) {
127:                    properties = new Properties();
128:                }
129:
130:                properties.put(key, value);
131:            }
132:
133:            /**
134:             * Load the properties from the specified URL.
135:             * @param url a non null value of the URL to the properties
136:             * @param info additional logger information if the properties can't be read
137:             * @return the loaded properties specified by the URL
138:             * @since 2.4
139:             */
140:            public static Properties loadProperties(URL url, String info) {
141:                log.info("OSCache: Getting properties from URL " + url
142:                        + " for " + info);
143:
144:                Properties properties = new Properties();
145:                InputStream in = null;
146:
147:                try {
148:                    in = url.openStream();
149:                    properties.load(in);
150:                    log.info("OSCache: Properties read " + properties);
151:                } catch (Exception e) {
152:                    log.error("OSCache: Error reading from " + url, e);
153:                    log.error("OSCache: Ensure the properties information in "
154:                            + url + " is readable and in your classpath.");
155:                } finally {
156:                    try {
157:                        in.close();
158:                    } catch (IOException e) {
159:                        log
160:                                .warn("OSCache: IOException while closing InputStream: "
161:                                        + e.getMessage());
162:                    }
163:                }
164:
165:                return properties;
166:            }
167:
168:            /**
169:             * Load the specified properties file from the classpath. If the file
170:             * cannot be found or loaded, an error will be logged and no
171:             * properties will be set.
172:             * @param filename the properties file with path
173:             * @param info additional logger information if file can't be read
174:             * @return the loaded properties specified by the filename
175:             * @since 2.4
176:             */
177:            public static Properties loadProperties(String filename, String info) {
178:                URL url = null;
179:
180:                ClassLoader threadContextClassLoader = Thread.currentThread()
181:                        .getContextClassLoader();
182:                if (threadContextClassLoader != null) {
183:                    url = threadContextClassLoader.getResource(filename);
184:                }
185:                if (url == null) {
186:                    url = Config.class.getResource(filename);
187:                    if (url == null) {
188:                        log
189:                                .warn("OSCache: No properties file found in the classpath by filename "
190:                                        + filename);
191:                        return new Properties();
192:                    }
193:                }
194:
195:                return loadProperties(url, info);
196:            }
197:
198:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.