/**
* PropertyManager.java
* November 11, 2000
*
* Copyright (C) 2000 CoolServlets.com. All rights reserved.
*
* ===================================================================
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* CoolServlets.com (http://www.coolservlets.com)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Jive" and "CoolServlets.com" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please
* contact webmaster@coolservlets.com.
*
* 5. Products derived from this software may not be called "Jive",
* nor may "Jive" appear in their name, without prior written
* permission of CoolServlets.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of CoolServlets.com. For more information
* on CoolServlets.com, please see <http://www.coolservlets.com>.
*/
//package com.coolservlets.forum;
package com.rf.oas.database;
import java.util.*;
import java.io.*;
/**
* Manages properties for the entire Jive system. Properties are merely
* pieces of information that need to be saved in between server restarts. The
* class also reports the version of Jive.
* <p>
* At the moment, properties are stored in a Java Properties file. In a version
* of Jive coming soon, the properties file format will move to XML. XML
* properties will allow hierarchical property structures which may mean the
* API of this class will have to change.
* <p>
* Jive properties are only meant to be set and retrevied by core Jive classes.
* Therefore, skin writers should probably ignore this class.
* <p>
* This class is implemented as a singleton since many classloaders seem to
* take issue with doing classpath resource loading from a static context.
*/
public class PropertyManager {
/**
* The Major version number of Jive. i.e. 1.x.x
*/
private static final int MAJOR_VERSION = 1;
/**
* The Minor version number of Jive. i.e. x.1.x.
*/
private static final int MINOR_VERSION = 1;
/**
* The revision version number of Jive. i.e. x.x.1.
*/
private static final int REVISION_VERSION = 3;
private static PropertyManager manager = null;
private static Object managerLock = new Object();
//private static String propsName = "/jive.properties";
//private static String propsName = "/weberp.properties";
private static String propsName = "/db.properties";
/**
* Returns a Jive property.
*
* @param name the name of the property to return.
* @return the property value specified by name.
*/
public static String getProperty(String name) {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.getProp(name);
}
/**
* Sets a Jive property. If the property doesn't already exists, a new
* one will be created.
*
* @param name the name of the property being set.
* @param value the value of the property being set.
*/
public static void setProperty(String name, String value) {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
manager.setProp(name, value);
}
/**
* Deletes a Jive property. If the property doesn't exist, the method
* does nothing.
*
* @param name the name of the property to delete.
*/
public static void deleteProperty(String name) {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
manager.deleteProp(name);
}
/**
* Returns the names of the Jive properties.
*
* @return an Enumeration of the Jive property names.
*/
public static Enumeration propertyNames() {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propNames();
}
/**
* Returns true if the properties are readable. This method is mainly
* valuable at setup time to ensure that the properties file is setup
* correctly.
*/
public static boolean propertyFileIsReadable() {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propFileIsReadable();
}
/**
* Returns true if the properties are writable. This method is mainly
* valuable at setup time to ensure that the properties file is setup
* correctly.
*/
public static boolean propertyFileIsWritable() {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propFileIsWritable();
}
/**
* Returns true if the jive.properties file exists where the path property
* purports that it does.
*/
public static boolean propertyFileExists() {
if (manager == null) {
synchronized(managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propFileExists();
}
/**
* Returns the version number of Jive as a String. i.e. -- major.minor.revision
*/
public static String getJiveVersion() {
return MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
}