public void setConfig(ConfigObject config) {
   this.config = config;
   if (config == null) {
     flatConfig = Collections.emptyMap();
   } else {
     flatConfig = config.flatten();
   }
 }
예제 #2
0
  /**
   * Converts this ConfigObject into a the java.util.Properties format, flattening the tree
   * structure beforehand
   *
   * @return A java.util.Properties instance
   */
  public Properties toProperties() {
    Properties props = new Properties();
    flatten(props);

    props = convertValuesToString(props);

    return props;
  }
예제 #3
0
  @SuppressWarnings("unchecked")
  void loadConfig(String location) {
    URL url = null;
    boolean throwException = false;
    try {
      url = new URL(location);
    } catch (MalformedURLException e) {
      File testConfigFile = new File(location);
      if (!testConfigFile.exists()) throwException = true;
      else {
        try {
          url = testConfigFile.toURI().toURL();
        } catch (MalformedURLException e1) {
          throwException = true;
        }
      }
    }

    if (throwException) {
      throw new RuntimeException(
          "Cannot load ["
              + location
              + "], it is not found or your location of the file "
              + "is incorrect. You have declared that your test ["
              + testClassName
              + "] requires "
              + "a configuration file, but the file cannot be loaded. Check the setting of the "
              + "org.rioproject.test.config system property");
    }
    ConfigObject config = new ConfigSlurper().parse(url);
    Map<String, Object> configMap = config.flatten();

    if (hasConfigurationFor(component, configMap)) {
      groups = getString(configMap.get(component + ".groups"));
      if (groups != null) System.setProperty(Constants.GROUPS_PROPERTY_NAME, groups);
      locators = getString(configMap.get(component + ".locators"));
      if (locators != null) System.setProperty(Constants.LOCATOR_PROPERTY_NAME, locators);
      numCybernodes = (Integer) configMap.get(component + ".numCybernodes");
      numMonitors = (Integer) configMap.get(component + ".numMonitors");
      numLookups = (Integer) configMap.get(component + ".numLookups");
      opString = getString(configMap.get(component + ".opstring"));
      Boolean b = (Boolean) configMap.get(component + ".autoDeploy");
      autoDeploy = b != null && b;
      testManager = (TestManager) configMap.get(component + ".testManager");
      b = (Boolean) configMap.get(component + ".harvest");
      runHarvester = b != null && b;
      String sTimeout = getString(configMap.get(component + ".timeout"));
      timeout = sTimeout == null ? 0 : Long.parseLong(sTimeout);
      loggingSystem = (LoggingSystem) configMap.get(component + ".loggingSystem");
      if (loggingSystem == null) {
        loggingSystem = LoggingSystem.LOGBACK;
      }
    }
  }
 public void configChanged() {
   ConfigObject co = getConfig();
   // not thread safe
   flatConfig = co.flatten();
   final ArtefactHandler[] handlers = getArtefactHandlers();
   for (ArtefactHandler handler : handlers) {
     if (handler instanceof GrailsConfigurationAware) {
       ((GrailsConfigurationAware) handler).setConfiguration(co);
     }
   }
 }
 @SuppressWarnings("unchecked")
 public static Object instantiateFromConfig(
     ConfigObject config, String configKey, String defaultClassName)
     throws InstantiationException, IllegalAccessException, ClassNotFoundException, LinkageError {
   return instantiateFromFlatConfig(config.flatten(), configKey, defaultClassName);
 }