|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Dictionary
java.util.Hashtable
java.util.Properties
wt.util.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:
Example applet init: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"); ... }
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 FormNested Class Summary |
Nested classes inherited from class java.util.Hashtable |
|
Field Summary | |
private boolean |
applet
|
private WTProperties |
appletProperties
|
private static String |
CLASSNAME
|
private static Hashtable |
codebaseMap
|
private Properties |
defaults
|
private Object |
key
|
private static Hashtable |
keyMap
|
private static String |
LINE_SEPARATOR
|
private static boolean |
localPropertiesOnly
|
private static WTProperties |
localProps
|
private static URL |
localPropsURL
|
private static Object |
lock
|
private static ClassLoader |
propClassLoader
|
private static String |
RESOURCE
|
static String |
RESOURCE_NAME
Name of the properties resource file. |
static String |
SERVER_CODEBASE_LOCATOR
Server codebase locator property name |
static String |
SERVER_CODEBASE_PROPERTY
Server codebase property name |
private static Object |
serverPropertiesKey
|
private URL |
url
|
private Hashtable |
valueCache
|
private static boolean |
verbose
|
private static Object |
writeLock
|
Fields inherited from class java.util.Properties |
|
Fields inherited from class java.util.Hashtable |
|
Constructor Summary | |
private |
WTProperties()
Private constructor to allow for empty WTProperties creation. |
|
WTProperties(Properties defaults)
Construct a new WTProperties object. |
Method Summary | |
private void |
appendPropertiesToFile(WTProperties prop,
String header,
String filepath)
This will open the specified wt.properties file and append a key/value pair to the end of the file. |
void |
appendPropertyToFile(String key,
String value,
String header)
This will open the current wt.properties file and append a key/value pair to the end of the file. |
void |
appendPropertyToFile(String key,
String value,
String header,
String filepath)
This will open the current wt.properties file and append a key/value pair to the end of the file. |
protected static void |
copyFile(String file1,
String file2,
boolean override)
Will copy a file to another. |
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. |
private WTProperties |
keepOnlyPropertyChanges(BufferedReader in)
This method will return a Properties object of ONLY the values that are NOT in the properties object. |
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. |
Enumeration |
propertyNames()
Returns an enumeration of all the keys in this property list, including the keys in the default property list. |
private static String |
readCodebaseFromLocator(URL url)
|
private String |
removeDoubleSlash(String text)
Method used to remove double slashes from properties that are being read by the parser above. |
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. |
void |
store()
This will store the wt.properties file according the the location which is set in the wt.codebase.location value. |
void |
store(String filename)
Will store the current preferences to a filename with a header stating the properties are coming from WTProperties and a time stamp in the Server Locale. |
void |
store(String filename,
String header)
This method will store the Properties into the filename specified along with a header outlining the new properties. |
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, save, setProperty, store |
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 |
Field Detail |
private static final String RESOURCE
private static final String CLASSNAME
public static final String RESOURCE_NAME
private static boolean verbose
public static final String SERVER_CODEBASE_PROPERTY
public static final String SERVER_CODEBASE_LOCATOR
private static WTProperties localProps
private static URL localPropsURL
private static final Object serverPropertiesKey
private static Hashtable codebaseMap
private static Hashtable keyMap
private static Object lock
private static boolean localPropertiesOnly
private static String LINE_SEPARATOR
private Object key
private static ClassLoader propClassLoader
private Properties defaults
private boolean applet
private WTProperties appletProperties
private URL url
private Hashtable valueCache
private static Object writeLock
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.
private WTProperties()
Method Detail |
private WTProperties keepOnlyPropertyChanges(BufferedReader in) throws IOException
in
- The reader to the properties stream
IOException
private String removeDoubleSlash(String text)
text
- The text to remove the slashes from
public void store() throws IOException
IOException
- If there is an error trying to locate wt.properties
Or there is an error writing to wt.properties. In
order to find wt.properties, the property wt.home
must be set.public void store(String filename) throws IOException
filename
- The filename of the file to update.
IOException
public void store(String filename, String header) throws IOException
NOTE: This should only be called from the server or server side
processes.
Supported API: false
filename
- The filename to updateheader
- The header to write to the file.
IOException
protected static void copyFile(String file1, String file2, boolean override) throws IOException
file1
- The first filefile2
- The second fileoverride
- Whether to override and attempt a forced copy.
IOException
public void appendPropertyToFile(String key, String value, String header) throws IOException
key
- The key to appendvalue
- The value to appendheader
- The header of who is editing the file.
IOException
- if the file could not be found or openedpublic void appendPropertyToFile(String key, String value, String header, String filepath) throws IOException
key
- The key to appendvalue
- The value to appendfilepath
- The file to append to.
IOException
- if the file could not be found or openedprivate void appendPropertiesToFile(WTProperties prop, String header, String filepath) throws IOException
prop
- The properties map of properties to add to the file.header
- The header to append to the file before appending the
propertiesfilepath
- The file to append to.
IOException
- if the file could not be found or openedpublic 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
private static String readCodebaseFromLocator(URL url) throws IOException
IOException
public static WTProperties getAppletProperties() throws IOException
WTProperties
object
IOException
public URL getURL()
WTProperties
object, null is returned.
WTProperties
objectpublic 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
IOException
public 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.
key
- the property key.
public int getProperty(String key, int default_value)
key
- the property key.
public boolean getProperty(String key, boolean default_value)
key
- the property key.
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 settingpublic void list(String prefix, PrintStream out)
prefix
- Optional prefix filter for property namesout
- a print streampublic Enumeration propertyNames()
Enumeration
,
Properties.defaults
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 |