⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertyhandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/PropertyHandler.java,v $// $RCSfile: PropertyHandler.java,v $// $Revision: 1.20.2.5 $// $Date: 2005/07/29 14:43:14 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.PrintStream;import java.net.MalformedURLException;import java.net.URL;import java.net.URLClassLoader;import java.util.Collections;import java.util.Enumeration;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.Properties;import java.util.Set;import java.util.TreeMap;import java.util.Vector;import com.bbn.openmap.event.ProgressEvent;import com.bbn.openmap.event.ProgressListener;import com.bbn.openmap.event.ProgressSupport;import com.bbn.openmap.gui.ProgressListenerGauge;import com.bbn.openmap.plugin.PlugIn;import com.bbn.openmap.proj.ProjectionFactory;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.Environment;/** * 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 openmap.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. * <P> *  * The PropertyHandler looks in several places for an * openmap.properties file: * <UL> * <LI>as a resource in the code base. * <LI>in the configDir set as a system property at runtime. * <LI>in the user's home directory. * </UL> *  * For each openmap.properties file, a check is performed to look * within for an openmap.include property containing a marker name * list. That list is parsed, and each item is checked * (markerName.URL) for an URL to another properties file. * <P> *  * 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. * <P> *  * 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. * <P> *  * 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. */public class PropertyHandler extends MapHandlerChild implements        SoloMapComponent {    /**     * The name of the properties file to read. (openmap.properties is     * default)     */    public final static String propsFileName = "openmap.properties";    /**     * The name of the system directory containing a properties file.     * (openmap.configDir)     */    public final static String configDirProperty = "openmap.configDir";    /**     * The property name used to hold a list of marker names. Each     * marker name is used to create another property to look for to     * create a component to add to a BeanContext. For example:     * <P>     *      * <PRE>     *      * openmap.components=name1 name2 name3     * name1.class=com.bbn.openmap.InformationDelegator     * name2.class=com.bbn.openmap.MouseDelegator     * name3.class=com.bbn.openmap.LayerHandler     *      * </PRE>     */    public final static String componentProperty = "openmap.components";    /**     * The property name used to hold a list of marker names. Each     * marker name is used to create another property to look for to     * connect to a URL to load a properties file. For example:     * <P>     *      * <PRE>     *      * openmap.include=name1 name2     * name1.URL=http://openmap.bbn.com/props/link.properties     * name2.URL=file:///usr/local/openmap/props/shape.properties     *      * </PRE>     */    public final static String includeProperty = "openmap.include";    /**     * The property name used to hold a file, resorce or URL of a file     * to use containing localized properties, like layer names. This     * is optional, if it's not in the openmap.properties file or the     * properties file being read in, an openmap_&ltlocalization     * string&gt.properties file will be searched for in the classpath     * (i.e. openmap.localized=openmap_en_US.properties).     */    public final static String localizedProperty = "openmap.localized";    /** Final openmap properties object. */    protected Properties properties = new Properties();    /**     * Container to hold prefixes for components that have been     * created, in order to determine if duplicates might have been     * made. Important if properties are going to be written out, so     * that property scoping can occur properly. This collection holds     * prefixes of objects that have been created by this     * PropertyHandler, and also prefixes that have been given out on     * request.     */    protected Set usedPrefixes = Collections.synchronizedSet(new HashSet());    protected ProgressSupport progressSupport;    /**     * Flag to set whether the PropertyHandler should provide status     * updates to any progress listeners, when it is building     * components.     */    protected boolean updateProgress = false;    /**     * A hashtable to keep track of property prefixes and the objects     * that were created for them.     */    protected Hashtable prefixLibrarian = new Hashtable();    protected boolean DEBUG = false;    /**     * Create a PropertyHandler object that checks in the default     * order for openmap.properties files. It checks for the     * openmap.properties file as a resource, in the configDir if     * specified as a system property, and lastly, in the user's home     * directory. If you want an empty PropertyHandler that doesn't do     * the search, use the constructor that takes a     * java.util.Properties object and provide it with empty     * Properties.     */    public PropertyHandler() {        this(false);    }    /**     * Create a PropertyHandler object that checks in the default     * order for openmap.properties files. It checks for the     * openmap.properties file as a resource, in the configDir if     * specified as a system property, and lastly, in the user's home     * directory.     *      * @param provideProgressUpdates if true, a progress bar will be     *        displayed to show the progress of building components.     */    public PropertyHandler(boolean provideProgressUpdates) {        DEBUG = Debug.debugging("properties");        updateProgress = provideProgressUpdates;        searchForAndLoadProperties();    }    /**     * Constructor to take resource name, file path or URL string as     * argument, to create context for a particular map.     */    public PropertyHandler(String urlString) throws MalformedURLException,            IOException {        this(PropUtils.getResourceOrFileOrURL(urlString));    }    /**     * Constructor to take path (URL) as argument, to create context     * for a particular map.     */    public PropertyHandler(URL url) throws IOException {        DEBUG = Debug.debugging("properties");        InputStream is = null;        if (url != null) {            // Open URL to read in properties            is = url.openStream();        }        Properties tmpProperties = new Properties();        if (is != null) {            tmpProperties.load(is);        }        init(tmpProperties, "URL");        Environment.init(getProperties());    }    /**     * Constructor to take Properties object as argument, to create     * context for a particular map.     */    public PropertyHandler(Properties props) {        DEBUG = Debug.debugging("properties");        init(props, null);        Environment.init(getProperties());    }    /**     * Look for openmap.properties files as a resource in the     * classpath, in the config directory, and in the user's home     * directory, in that order. If any property is duplicated in any     * version, last one wins.     */    protected void searchForAndLoadProperties() {        Properties tmpProperties = new Properties();        Properties includeProperties;        Properties localizedProperties;        boolean foundProperties = false;        boolean showDebugMessages = false;        if (Debug.debugging("locale")) {            java.util.Locale.setDefault(new java.util.Locale("pl", "PL"));        }        if (DEBUG) {            showDebugMessages = true;        }        if (Debug.debugging("showprogress")) {            updateProgress = true;        }        if (showDebugMessages) {            Debug.output("***** Searching for properties ****");        }        // look for openmap.properties file in jar archive(of course        // only in same package as this class) or wherever this        // object's class file lives.        if (showDebugMessages) {            Debug.output("PropertyHandler: Looking for " + propsFileName                    + " in Resources");        }        InputStream propsIn = getClass().getResourceAsStream(propsFileName);        // Look in the codebase for applets...        if (propsIn == null && Environment.isApplet()) {            URL[] cba = new URL[1];            cba[0] = Environment.getApplet().getCodeBase();            URLClassLoader ucl = URLClassLoader.newInstance(cba);            propsIn = ucl.getResourceAsStream(propsFileName);        }        if (propsIn == null) {            propsIn = ClassLoader.getSystemResourceAsStream(propsFileName);            if (propsIn != null && showDebugMessages) {                Debug.output("Loading properties from System Resources: "                        + propsFileName);            }        } else {            if (showDebugMessages) {                Debug.output("Loading properties from file " + propsFileName                        + " from package of class " + getClass());            }        }        if (propsIn != null) {            foundProperties = PropUtils.loadProperties(tmpProperties, propsIn);            init(tmpProperties, "resources");            tmpProperties.clear();        }        if (!foundProperties && (Environment.isApplet() || showDebugMessages)) {            Debug.output("PropertyHandler: Unable to locate as resource: "                    + propsFileName);        }        // Seems like we can kick out here in event of Applet...        if (Environment.isApplet()) {            Environment.init(getProperties());            return;        }        Properties systemProperties;        try {            systemProperties = System.getProperties();        } catch (java.security.AccessControlException ace) {            systemProperties = new Properties();        }        String openmapConfigDirectory = systemProperties.getProperty(configDirProperty);        if (openmapConfigDirectory == null) {            Vector cps = Environment.getClasspathDirs();            String defaultExtraDir = "share";            for (int searchCount = 0; searchCount < cps.size(); searchCount++) {                File shareDir = new File((String) cps.elementAt(searchCount), defaultExtraDir);                if (shareDir.exists()) {                    // Debug.output("Found share directory: " +                    // shareDir.getPath());                    openmapConfigDirectory = shareDir.getPath();                    break;                    // } else {                    // Debug.output("No share directory in: " +                    // shareDir.getPath());                }            }        }        Environment.addPathToClasspaths(openmapConfigDirectory);        // in OpenMap config directory        if (showDebugMessages) {            Debug.output("PropertyHandler: Looking for "                    + propsFileName                    + " in configuration directory: "                    + (openmapConfigDirectory == null ? "not set"                            : openmapConfigDirectory));        }        // We want foundProperties to reflect if properties have ever        // been found.        foundProperties |= PropUtils.loadProperties(tmpProperties,                openmapConfigDirectory,                propsFileName);        // Include properties from config file properties.        includeProperties = getIncludeProperties(tmpProperties.getProperty(includeProperty),                tmpProperties);        merge(includeProperties,                "include file properties",                openmapConfigDirectory);        // OK, now merge the config file properties into the main        // properties        merge(tmpProperties, propsFileName, openmapConfigDirectory);        // Clear out the tmp        tmpProperties.clear();        // Let system properties take precidence over resource and

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -