Package com.clarkparsia.empire.config.io.impl

Examples of com.clarkparsia.empire.config.io.impl.PropertiesConfigReader


  public static EmpireConfiguration readConfiguration() {
    InputStream aConfigStream = null;

    // the default configuration reader
    ConfigReader aReader = new PropertiesConfigReader();

    try {
      // not ideal, really we want just a single standard config file name with the system property which can override
      // that.  but since we don't have a standard yet, we'll check a bunch of them.
      if (System.getProperty("empire.configuration.file") != null && new File(System.getProperty("empire.configuration.file")).exists()) {
        aConfigStream = new FileInputStream(System.getProperty("empire.configuration.file"));
      }
      // check inside the jar to see if the config file is there
      else if (DefaultEmpireModule.class.getResourceAsStream("/empire.configuration") != null) {
        aConfigStream = DefaultEmpireModule.class.getResourceAsStream("/empire.configuration");
      }
      // this is the default non-jar location
      else if (new File("empire.configuration").exists()) {
        aConfigStream = new FileInputStream("empire.configuration");
        aReader = new PropertiesConfigReader();
      }

      // these locations are @deprecated in 0.7, to be removed in 0.9
      else if (new File("empire.config").exists()) {
        aConfigStream = new FileInputStream("empire.config");
        aReader = new PropertiesConfigReader();
      }
      else if (new File("empire.properties").exists()) {
        aConfigStream = new FileInputStream("empire.properties");
        aReader = new PropertiesConfigReader();
      }
      else if (new File("empire.config.properties").exists()) {
        aConfigStream = new FileInputStream("empire.config.properties");
        aReader = new PropertiesConfigReader();
      }
      else if (new File("empire.xml").exists()) {
        aConfigStream = new FileInputStream("empire.xml");
        aReader = new XmlConfigReader();
      }
      else if (new File("empire.config.xml").exists()) {
        aConfigStream = new FileInputStream("empire.config.xml");
        aReader = new XmlConfigReader();
      }
    }
    catch (FileNotFoundException e) {
      LOGGER.error("Count not find config file: " + e.getMessage());
    }

    EmpireConfiguration aConfig = null;

    if (aConfigStream == null) {
      LOGGER.warn("No configuration found or specified, Empire may not start or function correctly.");
      return null;
    }
    else {
      // TODO: need a more sophisticated method of selection which reader to use =)
      if (System.getProperty("empire.config.reader") != null) {
        try {
          @SuppressWarnings("unchecked") // it's ok if this throws a cast exception, we handle that
          Class<ConfigReader> aClass = (Class<ConfigReader>) BeanReflectUtil.loadClass(System.getProperty("empire.config.reader"));

          aReader =  Empire.get().instance(aClass);
        }
        catch (Exception e) {
          LOGGER.error("Unable to find or create specified configuration reader class: " + System.getProperty("empire.config.reader"), e);
        }
      }
    }

    if (aConfigStream != null && aReader != null) {
      try {
        aConfig = aReader.read(aConfigStream);
      }
      catch (IOException e) {
        LOGGER.error("Error while reading default Empire configuration file from the path", e);
      }
      catch (EmpireException e) {
View Full Code Here


  }

  @Parameterized.Parameters
  public static Collection configurations() {
    return Arrays.asList(new Object[][] {
        { new PropertiesConfigReader(), getProperiesFormatConfig() },
        { new XmlConfigReader(), getXmlFormatConfig() }
    });
  }
View Full Code Here

TOP

Related Classes of com.clarkparsia.empire.config.io.impl.PropertiesConfigReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.