PropertyWrapperpublic class PropertyWrapper extends Object implements Serializable $Source: /cvs/glassfish/appserv-commons/src/java/com/sun/enterprise/util/PropertyWrapper.java,v $ |
Fields Summary |
---|
static Logger | _logger | protected boolean | bTryDefaultFileOnEnvFailuretry a defauly property file if env name fails? | private boolean | bLoadedmaintains a flag to know if the properties were loaded successfully | protected boolean | bDebugdebug flag | protected String | properties_file_nameThe name of the properties file. | protected Properties | propsThe bucket to hold the properties. |
Constructors Summary |
---|
public PropertyWrapper(String propertiesFileName, String envPropName, boolean bTryDefaultFileOnEnvFailure)The constructor loads the properties from a file. The name of the file
can be specified in two ways. If an environment property name exists,
it would be the first to be given a shot. if the properties are not
loaded and flag 'bTryDefaultFileOnEnvFailure' is true, a default filename
in the propertiesFileName parameter will be given a shot.
// First try to see if you can load properties vai the env variable
try
{
if(null!=envPropName)
{
SecurityManager sm = System.getSecurityManager();
if(null!=sm)
sm.checkPropertyAccess(envPropName);
String envPropFile = System.getProperty(envPropName);
//if(bDebug) System.out.println("envname=" + envPropName + ",envPropName=" + envPropFile);
//Bug 4677074 begin
//if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"envname=" + envPropName + ",envPropName=" + envPropFile);
//Bug 4677074 end
if(null!=envPropFile)
{
properties_file_name = envPropFile;
try
{
loadProperties();
}catch(IOException ioe)
{
if(com.sun.enterprise.util.logging.Debug.enabled)
//Bug 4677074 System.err.println("PropertyWrapper::PropertyWrapper() > " + ioe);
//Bug 4677074 begin
_logger.log(Level.SEVERE,"enterprise_util.dbgcntl_ioexception",ioe);
//Bug 4677074 end
}
}
}
} catch(SecurityException se)
{
//Bug 4677074 System.out.println("PropertyWrapper::PropertyWrapper() don not have security access to " + properties_file_name + " > " + se);
//Bug 4677074 begin
_logger.log(Level.SEVERE,"iplanet_util.security_exception",new Object[]{properties_file_name,se});
//Bug 4677074 end
}
// Try to load from a property file specified checking the 'bTryDefaultFileOnEnvFailure' flag
if( !bLoaded && bTryDefaultFileOnEnvFailure && (null!=propertiesFileName) )
{
try
{
properties_file_name = propertiesFileName;
loadProperties();
}catch(IOException ioe)
{
if(com.sun.enterprise.util.logging.Debug.enabled)
//Bug 4677074 System.err.println("PropertyWrapper::PropertyWrapper() > " + ioe);
//Bug 4677074 begin
_logger.log(Level.SEVERE,"enterprise_util.dbgcntl_ioexception",ioe);
//Bug 4677074 end
}
}
if(bLoaded && bDebug)
//Bug 4677074 System.out.println("PropertyWrapper using " + properties_file_name);
//Bug 4677074 begin
_logger.log(Level.FINE,"PropertyWrapper using " + properties_file_name);
//Bug 4677074 end
else if (!bLoaded && bDebug)
//Bug 4677074 System.out.println("PropertyWrapper reports properties could not be loaded for env=" + envPropName + " or filename=" + propertiesFileName);
//Bug 4677074 begin
_logger.log(Level.FINE,"PropertyWrapper reports properties could not be loaded for env=" + envPropName + " or filename=" + propertiesFileName);
//Bug 4677074 end
| public PropertyWrapper(String propertiesFileName, String envPropName)The constructor loads the properties from a file. The name of the file
can be specified in two ways. If an environment property name exists,
it would be the first to be given a shot, if the properties are not
loaded, a default filename in the propertiesFileName parameter will be
given a shot.
this(propertiesFileName, envPropName, true);
| public PropertyWrapper(String propertiesFileName)The constructor loads the properties from a file from the classpath.
this(propertiesFileName, null, true);
| public PropertyWrapper(Properties props)The constructor to initialize the object with a set of properties.
this.props=props;
|
Methods Summary |
---|
protected boolean | getBooleanProperty(java.lang.String key, boolean defaultVal)Read the string property [true | false] and convert it into a boolean.
String str = getProperty(key);
if(null==str)
return defaultVal;
if(str.toLowerCase().startsWith("true"))
return true;
if(str.toLowerCase().startsWith("false"))
return false;
return defaultVal;
| protected int | getIntProperty(java.lang.String key, int defaultVal)Read the string property and convert it to an int.
String str = getProperty(key);
if(null==str)
return defaultVal;
try
{
return Integer.parseInt(str);
}catch(NumberFormatException nfe)
{
return -1;
}
| protected int | getIntProperty(java.lang.String key)Read the string property and convert it to an int.
String str = getProperty(key);
if(null==str)
return -1;
try
{
return Integer.parseInt(str);
}catch(NumberFormatException nfe)
{
return -1;
}
| protected long | getLongProperty(java.lang.String key)Read the string property and convert it to an long.
String str = getProperty(key);
if (str == null)
return -1;
try {
return Long.parseLong(str);
} catch(NumberFormatException nfe) {
return -1;
}
| protected long | getLongProperty(java.lang.String key, long defaultVal)Read the string property and convert it to an long.
String str = getProperty(key);
if (str == null)
return defaultVal;
try {
return Long.parseLong(str);
} catch(NumberFormatException nfe) {
return -1;
}
| public java.lang.String | getPropertiesFile()Return the filename of the properties file.
return properties_file_name;
| protected java.lang.String | getProperty(java.lang.String key)This method returns the value for a particular name of a property.
return getProperty(key, null);
| protected java.lang.String | getProperty(java.lang.String key, java.lang.String defaultVal)This method returns the value for a particular name of a property with a default
value supplied along.
return props.getProperty(key, defaultVal);
| protected void | loadProperties()This method allows to load properties into the instance object, from the filename
specified in the parameter of the constructor. Set flag bLoaded to true if the
properties are loaded and are non empty.
props = new Properties();
try
{
InputStream is = ClassLoader.getSystemResourceAsStream(properties_file_name);
props.load(is);
if(!props.isEmpty())
bLoaded = true;
}catch(IOException e)
{
throw e;
}
|
|