|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Dictionary<K,V>
java.util.Hashtable<Object,Object>
java.util.Properties
wt.util.WTProperties
public class WTProperties
Windchill configuration properties.
This is a convenience class providing static access to the following property sources:
- System Properties
- Properties supplied by the Java runtime system.
- Configuration File
- Properties loaded from a resource file named wt.properties. This is loaded just like a class file, and therefore it represents the properties associated with the software installation from which classes are being loaded. The file is loaded as a class resource of the WTProperties class. If the WTProperties class is loaded from the local class path, then this file will be loaded from the local class path. If the WTProperties class is loaded remotely, then this file may be loaded from either the local class path or remotely.
- Application Arguments
- Command line arguments to a Java application. The argument strings are parsed and any of the form name=value are made available as properties.
- Server's Configuration File
- Properties loaded from the server's properites file. These properties are loaded via a URL connection to wt.properties relative to the server's codebase URL. For applets, the codebase is the applet's codebase unless an applet parameter named wt.server.codebase indicates otherwise. For applications, it is the wt.server.codebase property as defined by any of the previous property sources.
- Applet Parameters
- Parameters of the current applet.
Access is provided at three levels with each level inheriting the lower levels as default values.
In all cases, the properties objects returned support a form of macro substitution in the property values so that values can be constructed from other property values. Values are parsed for expressions of the form
getLocalProperties ()- Properties defined by the application arguments, configuration file, and system properties. These properties are global to the Java Virtual Machine and the Java class files that are loaded.This level should be used for properties accessed by static class initializers.
getServerProperties- Properties defined in the server's configuration file. This interface is intended to allow a client to view the properties being used by the server, however, this object will only reflect the server's configuration file, not any additional system properties and command line parameters that may have been used.
getAppletProperties- The highest level where all properties defined in the above sources are visible, including applet parameters. Note, however, that applet parameters will not appear in enumerations of the properties since the list of available parameters is not exposed by the Applet class.
$(name) and the value of the property name
is substituted into the resulting property value. The expression
$DATE(format) is a builtin SimpleDateFormat
macro where format is a pattern expression such as MMddyy. It can be used to construct
date/time based values such as log file names. The expression
$LIB(key) is a builtin macro which lists the contents
of the directory pointed at by key separated by File.pathSeparator.
The methods for accessing properties are static, making it very convenient
for classes to access properties without the benefit of any other context.
However, the server and applet properties are not static relative to
this class. If this class was loaded from the local class path, it
may be shared by multiple applets that may be communicating with multiple
servers. Therefore, a simple convention is used to correctly associate
the calling thread to the appropriate server and applet properties. This
class uses the WTContext class to map the calling thread to
appropriate server and applet properties objects. It is important that applications
and applets call the WTContext.init method at startup. Applets should
also call the destroy method when they are destoyed to remove this mapping and
allow the timely garbage collection of the Applet object.
Example application main:
public static void main (String args)
{
// Initialize WTContext with command line arguments
WTContext.init(args);
// Replace system properties with WTProperties
Properties props = WTProperties.getLocalProperties();
System.setProperties(props);
// Get our wt.foo.bar property
String bar = props.getProperty("wt.foo.bar");
...
}
Example applet init:
public void init ()
{
// Initialize WTContext for this applet
WTContext.init(this);
// Get the wt.foo.bar property from applet parameters, server
// configuration properties, local configuration properties,
// or system properties.
Properties props = WTProperties.getAppletProperties();
String bar = props.getProperty("wt.foo.bar");
...
}
public void destroy ()
{
// Destroy WTContext for this applet
WTContext.getContext().destroy(this);
}
WTContext,
Serialized Form| Constructor Summary | |
|---|---|
WTProperties(Properties defaults)
Construct a new WTProperties object. |
|
| Method Summary | |
|---|---|
static WTProperties |
getAppletProperties()
Get a properties object for the current thread that includes applet parameters (if any), server configuration file properties, and local properties. |
static WTProperties |
getLocalProperties()
Get a properties object that includes application arguments, properties from the resource file wt.properties in the local codebase, and Java system properties. |
String |
getProperty(String key)
Searches for the property with the specified key in this property list. |
boolean |
getProperty(String key,
boolean default_value)
Convenience method to get a boolean property string and convert it to a boolean value. |
int |
getProperty(String key,
int default_value)
Convenience method to get an integer property string and convert it to an int value. |
static URL |
getServerCodebase()
Convenience method to retrieve server codebase URL for the current thread. |
static URL |
getServerCodebase(Applet applet,
Properties props)
Get server codebase URL as determined from applet codebase or property value. |
static WTProperties |
getServerProperties()
Get a properties object for the current thread that includes properties from the server's wt.properties configuration file in addition to local properties. |
static WTProperties |
getServerProperties(URL codebase)
Get a properties object for the given server codebase that includes server configuration file properties and local properties. |
URL |
getURL()
Gets the URL from which the corresponding local or server properties where loaded. |
void |
list(String prefix,
PrintStream out)
Prints this property list out to the specified output stream. |
static void |
main(String[] args)
Simple tester. |
void |
parseArgs(String[] args)
Parse name=value pairs from a string array into this properties object. |
static void |
reset()
Reset the WTProperties class to its initial state. |
static void |
setLocalPropertiesOnly(boolean local_only)
Sets to allow only local properties to be loaded. |
static void |
setVerbose(boolean verbose)
Set verbose mode for debugging. |
String |
substitute(String str)
Substitutes expressions of the form $(name) in strings with property
values from this properties object. |
| Methods inherited from class java.util.Properties |
|---|
getProperty, list, list, load, loadFromXML, save, store, storeToXML, storeToXML |
| Methods inherited from class java.util.Hashtable |
|---|
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public WTProperties(Properties defaults)
WTProperties object.
Normally, references to the standard properties objects are returned by static
methods of this class. This constructor exists for applications that wish to load
their own private properties files and take advantage of the extra utility functions
or macro substitution.
| Method Detail |
|---|
public static WTProperties getLocalProperties()
throws IOException
WTProperties object
IOException
public static WTProperties getServerProperties()
throws IOException
WTProperties object
IOException
public static WTProperties getServerProperties(URL codebase)
throws IOException
codebase argument is null, the properties for
the default server are returned.
codebase - the server codebase to load properties from
WTProperties object
IOException
public static URL getServerCodebase()
throws IOException
wt.server.codebase. If called from an
application, it will return the URL for the local wt.server.codebase
property.
IOException
public static URL getServerCodebase(Applet applet,
Properties props)
throws IOException
wt.server.codebase. If the codebase is not
available from the applet, it will return the URL for the wt.server.codebase
property in the given property object. If wt.server.codebase is not specified,
but wt.server.codebase.locator is specified, the given URL will be opened and
used to read the server codebase URL as the first line of the response body.
applet - the Applet objectprops - the Properties object
IOException
public static WTProperties getAppletProperties()
throws IOException
WTProperties object
IOExceptionpublic URL getURL()
WTProperties object, null is returned.
WTProperties object
public static void reset()
throws IOException
WTProperties class to its initial state.
This discards any current property objects, causing reloading
when they are next accessed. It is used to force reloading
of property values from their original sources.
If the local properties object was set as the system property object, it is reloaded immediately and set to be the system property object again.
This method may be necessary to build very long lived applets or applications that need to recover from exceptions due to property changes that take place during their lifetimes. For example, a long lived client that needs to recover even if its server host or port number is changed while it is active.
Note that resetting the WTProperties will not affect static class
initialization performed in existing classes. Often, classes will use local properties
to initialize static final values that cannot be reset later.
Supported API: true
IOExceptionpublic static void setLocalPropertiesOnly(boolean local_only)
Classes that load and execute in both client and server processes may
request the server properties. Server applications can use this method
to bypass attempts to load server properties which will ultimately be
identical to the local properties already loaded.
Supported API: true
local_only - the setting.public void parseArgs(String[] args)
args - string arraypublic String getProperty(String key)
null if the property is not found. Expresions of the form
$(name) are substituted with the value of the named property
if it is found, otherwise they are replaced by an empty string. If the
entire value is a substitution and the named property does not exist, null
is returned instead. Substitution is only performed for properties
contained in this object. Properties found in the default property list
are returned unchanged. The expression $DATE(format) is a builtin
SimpleDateFormat macro where format is a pattern expression such as
MMddyy. It can be used to construct date/time based values such as log file names.
The expression $LIB(key) is a builtin macro which lists the contents
of the directory pointed at by key separated by File.pathSeparator.
Once a substitution has been performed, the substituted value is cached and
will continue to be returned for consistency.
getProperty in class Propertieskey - the property key.
public int getProperty(String key,
int default_value)
key - the property key.default - value returned if named property does not exist
public boolean getProperty(String key,
boolean default_value)
key - the property key.default - value returned if named property does not exist
public String substitute(String str)
$(name) in strings with property
values from this properties object. If the entire value is a substitution and the
named property is not found, null is returned instead of an empty string. The expression
$DATE(format) is a builtin SimpleDateFormat macro where format is
a pattern expression such as MMddyy. It can be used to construct date/time based values such
as log file names.
The expression $LIB(key) is a builtin macro which lists the contents
of the directory pointed at by key separated by File.pathSeparator.
This is used internally to the WTProperties.getProperty
method. It is exposed as a public method to allow the same substitutions
to be applied against arbitrary strings.
Supported API: true
str - the string to be parsed for substitutions
public static void setVerbose(boolean verbose)
verbose - the verbose setting
public void list(String prefix,
PrintStream out)
prefix - Optional prefix filter for property namesout - a print stream
public static void main(String[] args)
throws IOException
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||