|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bbn.openmap.MapHandlerChild com.bbn.openmap.PropertyHandler
public class PropertyHandler
The PropertyHandler object is the organizer of properties, looking for settings on how to configure OpenMap components. It is designed to look through a series of locations to find properties files, loading them in order. If there is a name conflict for a property, the last version of the property set is the one that gets used. This object isn't really interested in hooking up with other objects. It's assumed that many objects will want to contact this object, and find the properties that apply to them. There is one exception this: When components start implementing the PropertyProvider interface, and the PropertyHandler becomes capable of creating an properties file, then the PropertyHandler will be able to use the BeanContext to query PropertyProviders to get their properties to put in the properties file.
The PropertyHandler looks in several places for an openmap.properties file:
Also significant, the PropertyHandler can be given a BeanContext to load components. For this, the openmap.components property contains a marker name list for openmap objects. Each member of the list is then used to look for another property (markername.class) which specifies which class names are to be instantiated and added to the BeanContext. Intelligent components are smart enough to wire themselves together. Order does matter for the openmap.components property, especially for components that get added to lists and menus. Place the components in the list in the order that you want components added to the MapHandler.
If the debug.showprogress environment variable is set, the PropertyHandler will display a progress bar when it is creating components. If the debug.properties file is set, the steps that the PropertyHandler takes in looking for property files will be displayed.
If the PropertyHandler is created with an empty constructor or with a null Properties object, it will do the search for an openmap.properties file. If you don't want it to do that search, create it with an empty Properties object.
Nested Class Summary | |
---|---|
static class |
PropertyHandler.Builder
This Builder class lets you have more control over how a PropertyHandler is constructed. |
Field Summary | |
---|---|
static java.lang.String |
componentProperty
The property name used to hold a list of marker names. |
static java.lang.String |
configDirProperty
The name of the system directory containing a properties file. |
protected boolean |
DEBUG
|
protected I18n |
i18n
All components can have access to an I18n object, which is provided by the Environment. |
static java.lang.String |
includeProperty
The property name used to hold a list of marker names. |
static java.lang.String |
localizedProperty
The property name used to hold a file, resource or URL of a file to use containing localized properties, like layer names. |
static java.util.logging.Logger |
logger
|
protected java.util.Hashtable |
prefixLibrarian
A hashtable to keep track of property prefixes and the objects that were created for them. |
protected ProgressSupport |
progressSupport
|
protected java.util.Properties |
properties
Final openmap properties object. |
protected java.lang.String |
propertyPrefix
The propertyPrefix can be set to reflect a particular set of properties, or for an application. |
static java.lang.String |
propsFileName
The appendix for the name of the properties file to read. |
protected boolean |
updateProgress
Flag to set whether the PropertyHandler should provide status updates to any progress listeners, when it is building components. |
protected java.util.Set |
usedPrefixes
Container to hold prefixes for components that have been created, in order to determine if duplicates might have been made. |
Fields inherited from class com.bbn.openmap.MapHandlerChild |
---|
beanContextChildSupport, isolated |
Constructor Summary | |
---|---|
PropertyHandler()
Create a PropertyHandler object that checks in the default order for openmap.properties files. |
|
PropertyHandler(boolean provideProgressUpdates)
Create a PropertyHandler object that checks in the default order for openmap.properties files. |
|
PropertyHandler(java.util.Properties props)
Constructor to take Properties for configuration, using the default "openmap" property prefix for configuration. |
|
PropertyHandler(PropertyHandler.Builder builder)
|
|
PropertyHandler(java.lang.String urlString)
Constructor to take resource name, file path or URL string as argument, to create context for a particular map. |
|
PropertyHandler(java.net.URL url)
Constructor to take path (URL) as argument, to create context for a particular map. |
Method Summary | |
---|---|
void |
addProgressListener(ProgressListener list)
Add a ProgressListener that will display build progress. |
void |
addProperties(java.util.Properties p)
Add in the properties from the given Properties object. |
void |
addProperties(java.lang.String propFile)
Add in the properties from the given source, which can be a resource, file or URL. |
void |
addProperties(java.net.URL urlToProperties)
Add in the properties from the given URL. |
void |
addProperty(java.lang.String property,
java.lang.String value)
Add (or overwrite) a property to the current properties |
boolean |
addUsedPrefix(java.lang.String prefix)
Changes ' ' characters to '_', and then tries to add it to the used prefix list. |
void |
appendProperty(java.lang.String property,
java.util.Properties src)
Append the given property into the current properties |
void |
appendProperty(java.lang.String property,
java.lang.String value)
Append the given property into the current properties |
void |
clearProgressListeners()
Clear all progress listeners. |
void |
createComponents(MapHandler mapHandler)
Given a BeanContext (actually a MapHandler, to handle SoloMapComponents), look for the openmap.components property in the current properties, and parse the list given as that property. |
static java.util.Properties |
createOpenMapProperties(MapHandler mapHandler,
java.io.PrintStream ps)
Creates a Properties object containing the current settings as defined by OpenMap components held by the MapHandler. |
void |
dispose()
|
static java.util.Properties |
fetchProperties(java.net.URL propsURL)
Load a Properties object from the classpath. |
void |
findAndInit(java.lang.Object obj)
All the PropertyHandler does with the MapHandler is look for PropertyConsumers and register their prefixes with the prefixLibarian. |
void |
findAndUndo(java.lang.Object obj)
The childrenRemoved has been changed to go through its iterator to call this method with every object. |
protected void |
fireProgressUpdate(int type,
java.lang.String task,
int frameNumber,
int totalFrames)
Fire an build update to progress listeners. |
java.lang.Object |
get(java.lang.String markername)
Given a property prefix, or markername, from the properties file, get the object that was created for it. |
java.lang.String |
getDefaultPropertyFileName()
Provides this class with the default properties file name to look for. |
protected java.util.Properties |
getIncludeProperties(java.lang.String markerList,
java.util.Properties props)
Take a marker name list (space separated names), and open the properties files listed in the property with keys of marker.URL. |
protected java.util.Properties |
getLocalizedProperties(java.lang.String localizedPropertyFile,
java.lang.String userHomeDirectory)
Load the localized properties that will take precedence over all other properties. |
java.util.Hashtable |
getPrefixLibrarian()
Get the Hashtable being held that matches property prefix strings with components. |
protected ProgressSupport |
getProgressSupport()
Get progress support if needed. |
java.util.Properties |
getProperties()
Get the current properties set within this handler. |
java.util.Properties |
getProperties(java.lang.String prefix)
Get a properties object containing all the properties with the given prefix. |
java.lang.String |
getPropertyPrefix()
|
java.lang.String |
getUniquePrefix(java.lang.String prefix)
If you are creating a new object, it's important to get a unique prefix for its properties. |
boolean |
getUpdateProgress()
|
protected void |
init(java.util.Properties props,
java.lang.String howString)
Initialize internal properties from Properties object. |
void |
loadProjectionAndLayers(MapHandler mapHandler,
java.util.Properties props)
Given a MapHandler and a Java Properties object, the LayerHandler will be cleared of it's current layers, and reloaded with the layers in the properties. |
protected void |
merge(java.util.Properties from)
Take the from properties, copy them into the internal PropertyHandler properties. |
protected void |
merge(java.util.Properties from,
java.util.Properties to)
Take the from properties, copy them into the to properties. |
protected void |
merge(java.util.Properties from,
java.util.Properties to,
java.lang.String what,
java.lang.String where)
Take the from properties, copy them into the to properties. |
protected void |
merge(java.util.Properties from,
java.lang.String what,
java.lang.String where)
Take the from properties, copy them into the internal PropertyHandler properties. |
void |
prependProperty(java.lang.String property,
java.util.Properties src)
Prepend the given property into the current properties |
void |
prependProperty(java.lang.String property,
java.lang.String value)
Prepend the given property into the current properties |
protected static void |
printComponentProperties(java.util.Vector components,
PropertyHandler ph,
java.io.PrintStream ps,
java.util.Properties createdProperties)
A helper function to createOpenMapProperties that gets the current properties of the given components and prints them out to the PrintStream and the provided Properties object. |
protected static void |
printLayerProperties(LayerHandler layerHandler,
PropertyHandler ph,
java.io.PrintStream ps,
java.util.Properties createdProperties)
A helper function to createOpenMapProperties that gets the current properties of the layers in the LayerHandler and prints them out to the PrintStream and the provided Properties object. |
protected static void |
printMapProperties(MapBean mapBean,
java.io.PrintStream ps,
java.util.Properties createdProperties)
A helper function to createOpenMapProperties that gets the current properties of the MapBean and prints them out to the PrintStream and the provided Properties object. |
protected static void |
printProperties(java.lang.String key,
java.lang.String value,
java.io.PrintStream ps,
java.util.Properties createdProperties)
A simple helper method that writes key-value pairs to a print stream or Properties, whatever is not null. |
void |
put(java.lang.String markername,
java.lang.Object obj)
Register an object with the prefix librarian against a specific marker name. |
java.lang.Object |
remove(java.lang.String markername)
Remove an object from the prefix librarian register, returning that object if it has been found. |
void |
removeMarker(java.lang.String property,
java.lang.String marker)
remove a marker from a space delimited set of properties. |
void |
removeProgressListener(ProgressListener list)
Remove a ProgressListener that displayed build progress. |
boolean |
removeProperty(java.lang.String property)
Remove an existing property if it exists. |
boolean |
removeUsedPrefix(java.lang.String prefix)
Changes ' ' characters to '_', and then tries to remove it to the used prefix list. |
protected void |
searchForAndLoadProperties()
Look for an openmap.properties file in the classpath, configDirectory and user home directory, in that order. |
protected void |
searchForAndLoadProperties(java.lang.String propsFileName)
Look for a properties file as a resource in the classpath, in the config directory, and in the user's home directory, in that order. |
void |
setProperties(java.util.Properties props)
Merges the properties to the overall properties held by the PropertyHandler. |
void |
setPropertyPrefix(java.lang.String propertyPrefix)
|
void |
setUpdateProgress(boolean set)
Set a flag that will trigger the PropertyHandler to fire progress events when it is going through the creation process. |
Methods inherited from class com.bbn.openmap.MapHandlerChild |
---|
addPropertyChangeListener, addVetoableChangeListener, childrenAdded, childrenRemoved, findAndInit, firePropertyChange, fireVetoableChange, getBeanContext, isIsolated, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext, setIsolated |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.util.logging.Logger logger
protected transient I18n i18n
protected java.lang.String propertyPrefix
public static final java.lang.String propsFileName
public static final java.lang.String configDirProperty
public static final java.lang.String componentProperty
# if 'openmap' is the PropertyHandler property prefix... openmap.components=name1 name2 name3 name1.class=com.bbn.openmap.InformationDelegator name2.class=com.bbn.openmap.MouseDelegator name3.class=com.bbn.openmap.LayerHandler
public static final java.lang.String includeProperty
openmap.include=name1 name2 name1.URL=http://openmap.bbn.com/props/link.properties name2.URL=file:///usr/local/openmap/props/shape.properties
public static final java.lang.String localizedProperty
protected java.util.Properties properties
protected java.util.Set usedPrefixes
protected ProgressSupport progressSupport
protected boolean updateProgress
protected java.util.Hashtable prefixLibrarian
protected boolean DEBUG
Constructor Detail |
---|
public PropertyHandler()
public PropertyHandler(boolean provideProgressUpdates)
provideProgressUpdates
- if true, a progress bar will be displayed
to show the progress of building components.public PropertyHandler(java.lang.String urlString) throws java.net.MalformedURLException, java.io.IOException
java.net.MalformedURLException
java.io.IOException
public PropertyHandler(java.net.URL url) throws java.io.IOException
java.io.IOException
public PropertyHandler(java.util.Properties props)
props
- public PropertyHandler(PropertyHandler.Builder builder)
Method Detail |
---|
public java.lang.String getDefaultPropertyFileName()
protected void searchForAndLoadProperties()
protected void searchForAndLoadProperties(java.lang.String propsFileName)
propsFileName
- to search forprotected java.util.Properties getLocalizedProperties(java.lang.String localizedPropertyFile, java.lang.String userHomeDirectory)
protected void init(java.util.Properties props, java.lang.String howString)
props
- the properties to merge into the properties held by the
PropertyHandler.howString
- a string describing where the properties come from. Just
used for debugging purposes, so passing in a null value is no big
deal.protected java.util.Properties getIncludeProperties(java.lang.String markerList, java.util.Properties props)
markerList
- space separated marker names in a single string that
needs to be parsed.props
- the properties that the markerList comes from, in order to
get the marker.URL properties.
protected void merge(java.util.Properties from)
from
- the source properties.protected void merge(java.util.Properties from, java.util.Properties to)
from
- the source properties.to
- the destination properties.protected void merge(java.util.Properties from, java.lang.String what, java.lang.String where)
from
- the source properties.what
- a description of what the from properties represent.where
- a description of where the properties were read from.protected void merge(java.util.Properties from, java.util.Properties to, java.lang.String what, java.lang.String where)
from
- the source properties.to
- the destination properties.what
- a description of what the from properties represent.where
- a description of where the properties were read from.public void setProperties(java.util.Properties props)
public java.util.Properties getProperties()
public java.lang.Object get(java.lang.String markername)
public java.util.Properties getProperties(java.lang.String prefix)
public void put(java.lang.String markername, java.lang.Object obj)
public java.lang.Object remove(java.lang.String markername)
public java.util.Hashtable getPrefixLibrarian()
public void createComponents(MapHandler mapHandler)
mapHandler
- BeanContext.public java.lang.String getPropertyPrefix()
public void setPropertyPrefix(java.lang.String propertyPrefix)
public static java.util.Properties createOpenMapProperties(MapHandler mapHandler, java.io.PrintStream ps)
mapHandler
- MapHandler containing components to use for Properties.ps
- PrintStream to write properties to, may be null if you just
want the Properties object that is returned.
protected static void printProperties(java.lang.String key, java.lang.String value, java.io.PrintStream ps, java.util.Properties createdProperties)
protected static void printMapProperties(MapBean mapBean, java.io.PrintStream ps, java.util.Properties createdProperties)
mapBean
- MapBean to get parameters from.ps
- PrintStream to write properties to, may be null.createdProperties
- Properties object to store properties in, may be
null.protected static void printComponentProperties(java.util.Vector components, PropertyHandler ph, java.io.PrintStream ps, java.util.Properties createdProperties)
components
- Vector of components to get parameters from.ph
- PropertyHandler that may have properties to use as a foundation
for the properties for the components. If the component can't
provide properties reflecting its settings, the property handler
will be consulted for properties it knows about for that
component.ps
- PrintStream to write properties to, may be null.createdProperties
- Properties object to store properties in, may be
null.protected static void printLayerProperties(LayerHandler layerHandler, PropertyHandler ph, java.io.PrintStream ps, java.util.Properties createdProperties)
layerHandler
- LayerHandler to get layers from.ph
- PropertyHandler that may have properties to use as a foundation
for the properties for the components. If the component can't
provide properties reflecting its settings, the property handler
will be consulted for properties it knows about for that
component.ps
- PrintStream to write properties to, may be null.createdProperties
- Properties object to store properties in, may be
null.public void loadProjectionAndLayers(MapHandler mapHandler, java.util.Properties props)
public java.lang.String getUniquePrefix(java.lang.String prefix)
public boolean addUsedPrefix(java.lang.String prefix)
public boolean removeUsedPrefix(java.lang.String prefix)
public void addProgressListener(ProgressListener list)
public void removeProgressListener(ProgressListener list)
public void clearProgressListeners()
protected ProgressSupport getProgressSupport()
protected void fireProgressUpdate(int type, java.lang.String task, int frameNumber, int totalFrames)
frameNumber
- the current frame counttotalFrames
- the total number of frames.public void setUpdateProgress(boolean set)
public boolean getUpdateProgress()
public boolean removeProperty(java.lang.String property)
public void addProperty(java.lang.String property, java.lang.String value)
public void addProperties(java.net.URL urlToProperties)
public void addProperties(java.lang.String propFile) throws java.net.MalformedURLException
java.net.MalformedURLException
- if propFile doesn't resolve properly.public void addProperties(java.util.Properties p)
public void removeMarker(java.lang.String property, java.lang.String marker)
public void appendProperty(java.lang.String property, java.util.Properties src)
public void appendProperty(java.lang.String property, java.lang.String value)
public void prependProperty(java.lang.String property, java.util.Properties src)
public void prependProperty(java.lang.String property, java.lang.String value)
public static java.util.Properties fetchProperties(java.net.URL propsURL)
Properties
object. If there was an error loading the
properties from propsURL
, an empty Properties
object is returned.
propsURL
- the URL of the properties to be loaded
public void findAndInit(java.lang.Object obj)
findAndInit
in interface LightMapHandlerChild
findAndInit
in class MapHandlerChild
public void findAndUndo(java.lang.Object obj)
MapHandlerChild
findAndUndo
in interface LightMapHandlerChild
findAndUndo
in class MapHandlerChild
public void dispose()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |