Java ClassLoader loadProperties(final String configFile, final String chainProperty)

Here you can find the source of loadProperties(final String configFile, final String chainProperty)

Description

Loads in a property file and optionally searches for a contained property that contains the next file to load.

License

Open Source License

Parameter

Parameter Description
configFile The name of the property file to load. May be null, in which case nothing is loaded.
chainProperty The property name that contains the name of the next file to load.

Return

The loaded properties or an empty list if no file loaded.

Declaration

public static Properties loadProperties(final String configFile, final String chainProperty) 

Method Source Code


//package com.java2s;
/* ----------------------------------------------------------------------------
 * Copyright (C) 2013      European Space Agency
 *                         European Space Operations Centre
 *                         Darmstadt/*from w  w w .j ava2s  . c o  m*/
 *                         Germany
 * ----------------------------------------------------------------------------
 * System                : CCSDS MO MAL Java Implementation
 * ----------------------------------------------------------------------------
 * Licensed under the European Space Agency Public License, Version 2.0
 * You may not use this file except in compliance with the License.
 *
 * Except as expressly set forth in this License, the Software is provided to
 * You on an "as is" basis and without warranties of any kind, including without
 * limitation merchantability, fitness for a particular purpose, absence of
 * defects or errors, accuracy or non-infringement of intellectual property rights.
 * 
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 * ----------------------------------------------------------------------------
 */

import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
    private static final Set LOADED_PROPERTIES = new TreeSet();

    /**
     * Loads in a property file and optionally searches for a contained property that contains the next file to load.
     *
     * @param configFile The name of the property file to load. May be null, in which case nothing is loaded.
     * @param chainProperty The property name that contains the name of the next file to load.
     * @return The loaded properties or an empty list if no file loaded.
     */
    public static Properties loadProperties(final String configFile, final String chainProperty) {
        Properties topProps = new Properties();

        if (null != configFile) {
            final java.net.URL url = ClassLoader.getSystemClassLoader().getResource(configFile);
            if ((null != url) && (!LOADED_PROPERTIES.contains(url.toString()))) {
                LOADED_PROPERTIES.add(url.toString());

                try {
                    final Properties myProps = new Properties();
                    myProps.load(url.openStream());

                    final Properties subProps = loadProperties(myProps.getProperty(chainProperty), chainProperty);

                    Logger.getLogger("org.ccsds.moims.mo.mal.impl.util").log(Level.INFO,
                            "Loading properties from {0}", url.toString());
                    topProps.putAll(subProps);
                    topProps.putAll(myProps);
                } catch (Exception ex) {
                    Logger.getLogger("org.ccsds.moims.mo.mal.impl.util").log(Level.WARNING,
                            "Failed to load properties file {0} {1}", new Object[] { url, ex });
                }
            }
        }

        return topProps;
    }
}

Related

  1. loadAttachApi()
  2. loadCorrectedConfiguration(String configurationFilename)
  3. loadFile(String file)
  4. loadGuiConfiguration(String configurationFilename)
  5. loadProperties(File inFile)
  6. loadProperties(final String location)
  7. loadProperties(String propFile)
  8. loadPropertiesFromFile(File parent)
  9. loadTextFile(final String location)