示例#1
0
  /**
   * Loads properties from an array of property files. Be sure to call the loadProperties method
   * first to load the properties before invoking the getString, getBoolean and getInteger etc other
   * methods.
   *
   * @param name the property file names
   * @param required whether the property files are required
   * @return True if the specified property config loaded successfully
   */
  public static synchronized boolean loadProperties(String[] fileNames, boolean required)
      throws ConfigurationException {
    // Get the bootstrap property config class
    String propertyConfigClass = BootStrapProperties.getPropertyConfigClass();

    if (!StringUtil.goodString(propertyConfigClass)
        || propertyConfigClass.equals(
            "org.openhealthtools.openexchange.config.DefaultPropertyConfig")) {
      // Use the default property config
      if (log.isInfoEnabled()) {
        log.info("Loading properties from " + propertyConfigClass);
      }
      if (null == config) config = new DefaultPropertyConfig(fileNames, required);
      else ((DefaultPropertyConfig) config).load(fileNames, required);
    } else {
      try {
        Class clazz = Class.forName(propertyConfigClass);

        if (log.isInfoEnabled()) {
          log.info("Loading properties from " + propertyConfigClass);
        }
        config = (PropertyConfig) clazz.newInstance();
      } catch (Exception e) {
        String message = "Failed to load properties. Nested message is " + e.getMessage();
        log.fatal(message, e);
        throw new ConfigurationException(message, e);
      }
    }

    return true;
  }
示例#2
0
  /**
   * Loads the spring context to the spring container. This method has to called before invoking the
   * getApplicationContext method.
   *
   * @param configLocations the application context files
   * @return <code>true</code> if the spring config is loaded successfully.
   * @throws ConfigurationException when there is an error with configuration.
   */
  public static synchronized boolean loadSpringConfig(String[] configLocations)
      throws ConfigurationException {

    // Get the bootstrap property spring config class
    String springConfigClass = BootStrapProperties.getSpringConfigClass();

    if (!StringUtil.goodString(springConfigClass)
        || springConfigClass.equals(
            "org.openhealthtools.openexchange.config.DefaultSpringConfig")) {
      // Use the default property config
      if (log.isInfoEnabled()) {
        log.info("Loading Spring Context from " + springConfigClass);
      }
      config = new DefaultSpringConfig(configLocations);
    } else {
      try {
        Class clazz = Class.forName(springConfigClass);
        if (log.isInfoEnabled()) {
          log.info("Loading Spring Context from " + springConfigClass);
        }
        config = (SpringConfig) clazz.newInstance();
      } catch (Exception e) {
        String message =
            "Fail to load Spring application context. Nested message is " + e.getMessage();
        log.fatal(message + e.getMessage(), e);
        throw new ConfigurationException(message, e);
      }
    }
    return true;
  }
示例#3
0
  public static String getPropertyConfigClass() {
    String ret = properties.getProperty(PROPERTY_CONFIG_CLASS_PARAM);

    // Use the default property config class
    if (!StringUtil.goodString(ret)) {
      ret = DEFAULT_PROPERTY_CONFIG_CLASS;
    }
    return ret;
  }
示例#4
0
  public static String getConfigProcessorClass() {
    String ret = properties.getProperty(CONFIG_PROCESSOR_CLASS_PARAM);

    // Use the default spring config class
    if (!StringUtil.goodString(ret)) {
      ret = DEFAULT_CONFIG_PROCESSOR_CLASS;
    }
    return ret;
  }
示例#5
0
  public static String getSpringConfigClass() {
    String ret = properties.getProperty(SPRING_CONFIG_CLASS_PARAM);

    // Use the default spring config class
    if (!StringUtil.goodString(ret)) {
      ret = DEFAULT_SPRING_CONFIG_CLASS;
    }
    return ret;
  }
示例#6
0
  /**
   * Gets the property files to be loaded in the application.
   *
   * @param defaults the default array of property files
   * @return an array of property file names
   */
  public static String[] getPropertyFiles(String[] defaults) {
    String fileList = properties.getProperty(PROPERTY_FILES_PARAM);

    if (!StringUtil.goodString(fileList)) {
      return defaults;
    }

    String[] ret = fileList.split("\\s*[,:;]\\s*");
    return ret;
  }
示例#7
0
 /**
  * Checks to make sure the property name is a valid String.
  *
  * @param name the property name
  */
 private static void validateName(String name) {
   if (!StringUtil.goodString(name)) throw new IllegalArgumentException("Invalid Property Name");
 }