📄 jrfproperties.java
字号:
/*
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is jRelationalFramework.
*
* The Initial Developer of the Original Code is is.com.
* Portions created by is.com are Copyright (C) 2000 is.com.
* All Rights Reserved.
*
* Contributor(s): Jonathan Carlson (joncrlsn@users.sf.net)
* Contributor(s): ____________________________________
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License (the "GPL") or the GNU Lesser General
* Public license (the "LGPL"), in which case the provisions of the GPL or
* LGPL are applicable instead of those above. If you wish to allow use of
* your version of this file only under the terms of either the GPL or LGPL
* and not to allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by either the GPL or LGPL
* License. If you do not delete the provisions above, a recipient may use
* your version of this file under either the MPL or GPL or LGPL License.
*
*/
package com.is.jrf;
import com.is.jrf.DatabasePolicy;
import com.is.jrf.InstantDBDatabasePolicy;
import com.is.jrf.OracleDatabasePolicy;
import com.is.jrf.SQLServerSybaseDatabasePolicy;
import com.is.jrf.HypersonicDatabasePolicy;
import com.is.util.PropertiesHelper;
import java.util.Properties;
import org.apache.log4j.Category;
/**
* Use of this class or it's properties file is <i>not</i> required. This
* class is used only when the AbstractDomain subclass has not set a
* DatabasePolicy or JDBCHelper information.
*
* <p> This class manages the properties file for the jRelationalFramework.
*
* <p> The location of the properties file can be set with the
* <code>-DjrfPropertiesFile=</code> JVM argument. Otherwise, the default
* is assumed to be <code>jrf.properties</jrf> somewhere in the root of one
* of the directories (or jars) in the classpath.
*
*/
public class JRFProperties
{
private static Properties s_properties = null;
private static DatabasePolicy s_databasePolicy = null;
/** See java.util.ResourceBundle */
private static final String DEFAULT_BUNDLE_NAME = "jrf";
private static boolean s_bundleNotFound = false;
private static final Category LOG =
Category.getInstance(JRFProperties.class.getName());
/**
* Check the jrfPropertiesFile system property (set with a jvm argument of
* <code>-DjrfPropertiesFile=abc</code> -- The ".properties" file suffix is
* assumed). If there is no property with that name, we assume the
* properties file is named <code>jrf.properties</code> and is in the root
* of one of the directories (or jars) in the classpath.
*/
public static void initialize()
{
String bundleName = System.getProperty("jrfPropertiesFile");
if (bundleName != null)
{
int index = bundleName.indexOf(".properties");
if (index > 0)
{
bundleName = bundleName.substring(0, index);
}
}
else
{
bundleName = DEFAULT_BUNDLE_NAME;
}
JRFProperties.initialize(bundleName);
} // initialize()
/**
* To use this method, there must be a <i>bundleName</i>.properties file
* somewhere in the classpath. Note that understanding how
* java.util.ResourceBundle works will help in understanding how this
* works.
*
* @param bundleName a value of type 'String'. See java.util.ResourceBundle
*/
public static synchronized void initialize(String bundleName)
{
// if we've alrady been here and not found the properties file bundle,
// then don't look for it again.
if (s_bundleNotFound)
{
return;
}
s_properties = PropertiesHelper.getPropertiesForBundle(bundleName);
if (s_properties == null)
{
s_bundleNotFound = true;
LOG.warn(
"com.is.jrf.JRFProperties could not find the "
+ bundleName + ".properties file. This may be by design.");
return;
}
else
{
LOG.info(
"JRFProperties initialized with resource bundle named '"
+ bundleName + "'");
}
// Set the static s_databasePolicy field.
JRFProperties.assignDatabasePolicy();
} // initialize(aString)
public static synchronized void initialize(Properties properties)
{
s_properties = properties;
} // initialize(aProperties)
/**
* If the first time, then read the properties file. Return the value of
* the specified property.
*
* @param aString a value of type 'String'
* @return a value of type 'String'
*/
public static String getProperty(String aString)
{
if (s_properties == null)
{
JRFProperties.initialize();
}
if (s_properties == null)
{
return null;
}
return s_properties.getProperty(aString);
}
/**
* Return true if the property exists and it's value is "true" or "yes".
* The default is false if the property does not exist.
*
* @return a value of type 'boolean'
*/
public static boolean propertyIsTrue(String aString)
{
String value = JRFProperties.getProperty(aString);
boolean returnValue = false;
if (value != null &&
(value.equalsIgnoreCase("true") ||
value.equalsIgnoreCase("yes")))
{
returnValue = true;
}
return returnValue;
}
/**
* Return the DatabasePolicy instance. Be warned that if this database
* policy object has instance variables and you are in a multi-threaded
* environment, that this instance may need to be synchronized or else
* this will need to return a clone of the database policy.
*
* @return a value of type 'DatabasePolicy'
*/
public static DatabasePolicy getDatabasePolicy()
{
if (s_properties == null)
{
JRFProperties.initialize();
}
return s_databasePolicy;
} // getDatabasePolicy()
/**
* Depending upon the databasePolicy value in the properties file, create
* an instance of a subclass of DatabasePolicy and assign it to its'
* static field.
*/
private static void assignDatabasePolicy()
{
String policyClass = JRFProperties.getProperty("databasePolicy");
if (policyClass == null)
{
return;
}
try
{
s_databasePolicy =
(DatabasePolicy) Class.forName(policyClass).newInstance();
}
catch (Exception e)
{
throw new ConfigurationException(e);
}
} // assignDatabasePolicy()
} // JRFProperties
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -