@Override
 public void loadFromXML(Reader in) throws IOException {
   XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
   setStatusCodes(xml.getString("statusCodes", getStatusCodes()));
   setOutputDir(xml.getString("outputDir", getOutputDir()));
   setFileNamePrefix(xml.getString("fileNamePrefix", getFileNamePrefix()));
 }
Example #2
0
 private void addAccountSubcategories(XMLConfiguration config, COABO coa, String path) {
   for (COABO subcat : coa.getSubCategoryCOABOs()) {
     config.addProperty(path + "(-1)[@code]", subcat.getAssociatedGlcode().getGlcode());
     config.addProperty(path + "[@name]", subcat.getAccountName());
     addAccountSubcategories(config, subcat, path + GL_ACCOUNT_TAG);
   }
 }
  // @Test - TODO - disabled for now since the command is different on each platform
  public void embeddedServer() throws ConfigurationException, RserveException {
    final String xml =
        "<RConnectionPool><RConfiguration><RServer host=\"localhost\" port=\"6312\" embedded=\"true\" command=\"C:\\\\Program\\ Files\\\\R\\\\R-2.6.0\\\\library\\\\Rserve\\\\Rserve_d.exe\"/></RConfiguration></RConnectionPool>";
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(xml));
    pool = new RConnectionPool(configuration);

    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());

    final RConnection connection = pool.borrowConnection();
    assertNotNull(connection);
    assertTrue(connection.isConnected());

    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("The connections should be active", 1, pool.getNumberOfActiveConnections());
    assertEquals("The connections should not be idle", 0, pool.getNumberOfIdleConnections());

    final RConnection newConnection = pool.reEstablishConnection(connection);
    assertNotNull(newConnection);
    assertFalse(connection.isConnected());
    assertTrue(newConnection.isConnected());

    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("The connections should be active", 1, pool.getNumberOfActiveConnections());
    assertEquals("The connections should not be idle", 0, pool.getNumberOfIdleConnections());

    pool.returnConnection(newConnection);
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());
  }
 @Override
 public void loadFromXML(Reader in) {
   XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
   setRegex(xml.getString(""));
   super.loadFromXML(xml);
   setCaseSensitive(xml.getBoolean("[@caseSensitive]", false));
 }
  /**
   * Validates that a pool can be reopened after it has been closed.
   *
   * @throws ConfigurationException if there is a problem setting up the default test connection
   */
  @Test
  public void closeAndReopen() throws ConfigurationException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());

    pool.close();

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());
    assertTrue("The pool should be closed", pool.isClosed());

    pool.reopen();

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());
  }
  /**
   * Validates that the connections that have been invalidated are removed from the pool properly.
   *
   * @throws ConfigurationException if there is a problem setting up the default test connection
   * @throws RserveException if there is an issue connecting with an Rserver
   */
  @Test
  public void invalidateConnection() throws ConfigurationException, RserveException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);

    final RConnection connection = pool.borrowConnection();
    assertNotNull("Connection should not be null", connection);
    assertTrue("The connection should be connected to the server", connection.isConnected());

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("The connection should active", 1, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());

    pool.invalidateConnection(connection);

    // the connection should no longer be connected
    assertNotNull("Connection should not be null", connection);
    assertFalse("The connection should not be connected to the server", connection.isConnected());

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());
    assertTrue("The pool should be closed", pool.isClosed());
  }
 @Override
 public void updateConfig(XMLConfiguration config) {
   nsTableId = config.getInt("storage_table", 511);
   dataExpireTime = config.getInt("data_expiretime", 7 * 24 * 3600);
   topNum = config.getInt("top_num", 30);
   debug = config.getBoolean("debug", false);
 }
 /**
  * Validates that an attempt to return an invalid connection to the pool throws an error.
  *
  * @throws ConfigurationException if there is a problem setting up the default test connection
  */
 @Test(expected = NullPointerException.class)
 public void returnNullConnection() throws ConfigurationException {
   final XMLConfiguration configuration = new XMLConfiguration();
   configuration.load(new StringReader(POOL_CONFIGURATION_XML));
   pool = new RConnectionPool(configuration);
   pool.returnConnection(null);
 }
Example #9
0
 private void loadConfiguration(String url) {
   try {
     XMLConfiguration config = new XMLConfiguration(url);
     config.getString("webservice.port");
   } catch (ConfigurationException ex) {
     Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
 protected void loadStringTransformerFromXML(XMLConfiguration xml) throws IOException {
   setCaseSensitive(xml.getBoolean("[@caseSensitive]", false));
   setInclusive(xml.getBoolean("[@inclusive]", false));
   List<HierarchicalConfiguration> nodes = xml.configurationsAt("stripBetween");
   for (HierarchicalConfiguration node : nodes) {
     addStripEndpoints(node.getString("start", null), node.getString("end", null));
   }
 }
Example #11
0
  @PostConstruct
  public void init() {
    String genreFileName = PropertyTools.getProperty("yamj3.genre.fileName");
    if (StringUtils.isBlank(genreFileName)) {
      LOG.trace("No valid genre file name configured");
      return;
    }
    if (!StringUtils.endsWithIgnoreCase(genreFileName, "xml")) {
      LOG.warn("Invalid genre file name specified: {}", genreFileName);
      return;
    }

    File xmlFile;
    if (StringUtils.isBlank(FilenameUtils.getPrefix(genreFileName))) {
      // relative path given
      String path = System.getProperty("yamj3.home");
      if (StringUtils.isEmpty(path)) {
        path = ".";
      }
      xmlFile = new File(FilenameUtils.concat(path, genreFileName));
    } else {
      // absolute path given
      xmlFile = new File(genreFileName);
    }

    if (!xmlFile.exists() || !xmlFile.isFile()) {
      LOG.warn("Genres file does not exist: {}", xmlFile.getPath());
      return;
    }
    if (!xmlFile.canRead()) {
      LOG.warn("Genres file not readble: {}", xmlFile.getPath());
      return;
    }

    LOG.debug("Initialize genres from file: {}", xmlFile.getPath());

    try {
      XMLConfiguration c = new XMLConfiguration(xmlFile);

      List<HierarchicalConfiguration> genres = c.configurationsAt("genre");
      for (HierarchicalConfiguration genre : genres) {
        String masterGenre = genre.getString("[@name]");
        List<Object> subGenres = genre.getList("subgenre");
        for (Object subGenre : subGenres) {
          LOG.debug("New genre added to map: {} -> {}", subGenre, masterGenre);
          GENRES_MAP.put(((String) subGenre).toLowerCase(), masterGenre);
        }
      }

      try {
        this.commonStorageService.updateGenresXml(GENRES_MAP);
      } catch (Exception ex) {
        LOG.warn("Failed update genres xml in database", ex);
      }
    } catch (Exception ex) {
      LOG.error("Failed parsing genre input file: " + xmlFile.getPath(), ex);
    }
  }
Example #12
0
  public ToolBelt(String configFile) throws FitsConfigurationException {
    XMLConfiguration config = null;
    try {
      config = new XMLConfiguration(configFile);
    } catch (ConfigurationException e) {
      throw new FitsConfigurationException("Error reading " + configFile, e);
    }

    // Collect the tools-used elements
    List<ToolsUsedItem> toolsUsedList = processToolsUsed(config);

    tools = new ArrayList<Tool>();

    // get number of tools
    int size = config.getList("tools.tool[@class]").size();
    // for each tools get the class path and any excluded extensions
    for (int i = 0; i < size; i++) {
      String tClass = config.getString("tools.tool(" + i + ")[@class]");
      @SuppressWarnings("unchecked")
      List<String> excludes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@exclude-exts]");
      @SuppressWarnings("unchecked")
      List<String> includes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@include-exts]");
      Tool t = null;
      try {
        @SuppressWarnings("rawtypes")
        Class c = Class.forName(tClass);
        t = (Tool) c.newInstance();
      } catch (Exception e) {
        // Can't use this tool, but continue anyway.
        // throw new FitsConfigurationException("Error initializing "+tClass,e);
        logger.error(
            "Thread "
                + Thread.currentThread().getId()
                + " error initializing "
                + tClass
                + ": "
                + e.getClass().getName()
                + "  Message: "
                + e.getMessage());
        continue;
      }
      if (t != null) {
        t.setName(bareClassName(tClass));
        for (String ext : excludes) {
          t.addExcludedExtension(ext);
        }
        for (String ext : includes) {
          t.addIncludedExtension(ext);
        }
        // Modify included and excluded extensions by tools-used
        t.applyToolsUsed(toolsUsedList);
        tools.add(t);
      }
    }
  }
Example #13
0
  @Test
  public void testSaveModelSettings() throws ConfigurationException, IOException {
    PivotModel model = getPivotModel();
    model.setMdx(getTestQuery());
    model.initialize();

    model.setSorting(true);
    model.setTopBottomCount(3);
    model.setSortCriteria(SortCriteria.BOTTOMCOUNT);

    CellSet cellSet = model.getCellSet();
    CellSetAxis axis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal());

    model.sort(axis, axis.getPositions().get(0));

    String mdx = model.getCurrentMdx();

    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setDelimiterParsingDisabled(true);

    model.saveSettings(configuration);

    Logger logger = LoggerFactory.getLogger(getClass());
    if (logger.isDebugEnabled()) {
      StringWriter writer = new StringWriter();
      configuration.save(writer);
      writer.flush();
      writer.close();

      logger.debug("Loading report content :" + System.getProperty("line.separator"));
      logger.debug(writer.getBuffer().toString());
    }

    PivotModel newModel = new PivotModelImpl(getDataSource());
    newModel.restoreSettings(configuration);

    newModel.getCellSet();

    String newMdx = newModel.getCurrentMdx();
    if (newMdx != null) {
      // Currently the parser treats every number as double value.
      // It's inevitable now and does not impact the result.
      newMdx = newMdx.replaceAll("3\\.0", "3");
    }

    assertEquals("MDX has been changed after the state restoration", mdx, newMdx);
    assertTrue(
        "Property 'sorting' has been changed after the state restoration", newModel.isSorting());
    assertEquals(
        "Property 'topBottomCount' has been changed after the state restoration",
        3,
        newModel.getTopBottomCount());
    assertEquals(
        "Property 'sortMode' has been changed after the state restoration",
        SortCriteria.BOTTOMCOUNT,
        newModel.getSortCriteria());
  }
Example #14
0
  public void run() {
    String sourceDir = config.getString("source.path");
    String destDir = config.getString("destination.path");
    String sourceFilePath = file.toString();
    Xls2xmlStats.setThreadFileProcess(Thread.currentThread().getName(), sourceFilePath);
    if (isDebugging) {
      log.debug("Processing " + sourceFilePath);
    }
    // Destination file is same directory in output with xml
    String destFilePath = sourceFilePath.substring(sourceDir.length());
    if (destFilePath.startsWith(File.separator)) {
      destFilePath = destFilePath.substring(1);
    }
    // Add extensions with .xml
    destFilePath = destFilePath + ".xml";
    File destFile = new File(destDir, destFilePath);
    destFilePath = destFile.toString();
    try {
      if (ignoreExisting && destFile.exists() && (FileUtils.sizeOf(destFile) > 0)) {
        log.debug("Ignoring the recreation of file: " + destFilePath);
        log.debug("Filesize is: " + FileUtils.sizeOf(destFile));
      } else {
        FileUtils.touch(destFile);

        if (isDebugging) {
          log.debug("Created destination file: " + destFilePath);
        }
        // Put some XML in the file

        String processedXML = process2xml();

        BufferedWriter output = new BufferedWriter(new FileWriter(destFile));

        // Only write data to the file if there is data from the processing
        if (!processedXML.equals("")) {
          output.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
          output.newLine();
          String roottag = config.getString("conversion.tags.root");
          output.append("<" + roottag + ">");
          output.newLine();
          output.append(processedXML);
          output.append("</" + roottag + ">");
        }

        output.close();
      }
    } catch (IOException ioe) {
      log.error("Could not create destination file: " + destFilePath, ioe);
    }

    Xls2xmlStats.recordFileProcessed();
    Xls2xmlStats.setThreadFileProcess(Thread.currentThread().getName(), "");
    log.info("STATISTICS: " + Xls2xmlStats.status());
  }
Example #15
0
 /* Process the tools-used elements and return a list of
  * ... something */
 private List<ToolsUsedItem> processToolsUsed(XMLConfiguration config) {
   int size = config.getList("tools-used[@exts]").size();
   List<ToolsUsedItem> results = new ArrayList<ToolsUsedItem>(size);
   for (int i = 0; i < size; i++) {
     @SuppressWarnings("unchecked")
     List<String> exts = (List<String>) (List<?>) config.getList("tools-used(" + i + ")[@exts]");
     @SuppressWarnings("unchecked")
     List<String> tools = (List<String>) (List<?>) config.getList("tools-used(" + i + ")[@tools]");
     results.add(new ToolsUsedItem(exts, tools));
   }
   return results; // TODO stub
 }
Example #16
0
  /**
   * Load configuration
   *
   * @param config
   * @throws IllegalArgumentException if any required configuration element is invalid or missing
   * @throws IllegalStateException if authentication fails
   * @exception NumberFormatException if any required string property does not contain a parsable
   *     integer.
   */
  public void load(XMLConfiguration config) {
    this.config = config;
    final String url = config.getString("baseURL");
    // see http://commons.apache.org/configuration/userguide/howto_xml.html
    if (StringUtils.isBlank(url)) {
      // TODO: if any tests don't require baseURL then may this optional and have tests check and
      // mark status = SKIPPED
      throw new IllegalArgumentException("baseURL property must be defined");
    } else {
      try {
        baseURL = new URI(url);
        if (baseURL.getQuery() != null) {
          log.error("6.1.1 baseURL MUST NOT contain a query component, baseURL=" + baseURL);
        }
        baseUrlString = baseURL.toASCIIString();
        final String baseRawString = baseURL.toString();
        if (!baseUrlString.equals(baseRawString)) {
          log.warn(
              "baseURL appears to have non-ASCII characters and comparisons using URL may have problems");
          log.debug("baseURL ASCII String=" + baseUrlString);
          log.debug("baseURL raw String=" + baseRawString);
        }
        if (!baseUrlString.endsWith("/")) baseUrlString += '/'; // end the baseURL with slash
      } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
      }
    }

    // setup HTTP proxy if required
    String proxyHost = config.getString("proxy.host");
    String proxyPort = config.getString("proxy.port");
    if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) {
      proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort), "http");
    }

    // load optional HttpRequestChecker for HTTP request handling
    final String httpRequestCheckerClass = config.getString("HttpRequestChecker");
    if (StringUtils.isNotBlank(httpRequestCheckerClass)) {
      try {
        Class httpClass = Class.forName(httpRequestCheckerClass);
        httpRequestChecker = (HttpRequestChecker) httpClass.newInstance();
        httpRequestChecker.setup(this);
        if (httpRequestChecker.getCurrentUser(this) != null) currentUser = DEFAULT_USER;
      } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
      } catch (InstantiationException e) {
        throw new IllegalArgumentException(e);
      } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e);
      }
    }
  }
Example #17
0
  /**
   * @param context
   * @param in
   * @return
   * @throws ConfigurationException
   * @throws IOException
   */
  protected HierarchicalConfiguration readConfiguration(FacesContext context, InputStream in)
      throws ConfigurationException, IOException {
    ExpressionEvaluatorFactory factory = new FreeMarkerExpressionEvaluatorFactory();
    ExpressionEvaluator evaluator = factory.createEvaluator();

    String source = IOUtils.toString(in);
    source = (String) evaluator.evaluate(source, createELContext(context));

    XMLConfiguration config = new XMLConfiguration();
    config.load(new StringReader(source));

    return config;
  }
  private FilterConfiguration() {
    String url = getServerConfigFolder() + "tracplus2-index-filters.xml";
    try {
      configuration = new XMLConfiguration(url);
      configuration.setAutoSave(true);
      configuration.setReloadingStrategy(new FileChangedReloadingStrategy()); // 5 seconds

      logger.debug("Configuration file '{}' loaded", url);
    } catch (ConfigurationException e) {
      logger.error("Unable to load configuration file {}", e, url);
      configuration = new XMLConfiguration();
    }
  }
  /**
   * Validates that the connection pool will properly hand out a connection to an active Rserve
   * process. Note: this test assumes that a Rserve process is already running on localhost using
   * the default port.
   *
   * @throws ConfigurationException if there is a problem setting up the default test connection
   * @throws RserveException if there is a problem with the connection to the Rserve process
   */
  @Test
  public void validConnection() throws ConfigurationException, RserveException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);
    assertNotNull("Connection pool should never be null", pool);
    assertFalse("Everybody in - the pool should be open!", pool.isClosed());

    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connection should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections());

    // get a connection from the pool
    final RConnection connection = pool.borrowConnection();
    assertNotNull("Connection should not be null", connection);
    assertTrue("The connection should be connected to the server", connection.isConnected());

    // there should be no more connections available
    assertEquals("There should be one connections", 1, pool.getNumberOfConnections());
    assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections());
    assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections());

    // but try and get another
    final RConnection connection2 = pool.borrowConnection(100, TimeUnit.MILLISECONDS);
    assertNull("The first connection hasn't been returned - it should be null", connection2);

    // it didn't give us a connection, but make sure the counts didn't change
    assertEquals("There should be one connections", 1, pool.getNumberOfConnections());
    assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections());
    assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections());

    // return the connection to the pool
    pool.returnConnection(connection);

    // now there should be one available in the pool
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connection should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections());

    // make sure we can get another good connection after returning the previous one
    final RConnection connection3 = pool.borrowConnection(100, TimeUnit.MILLISECONDS);
    assertNotNull("Connection should not be null", connection3);
    assertTrue("The connection should be connected to the server", connection3.isConnected());

    // there should be no more connections available
    assertEquals("There should be one connections", 1, pool.getNumberOfConnections());
    assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections());
    assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections());

    pool.returnConnection(connection3);
  }
  @Test
  public void testParseCompleteWithTwoRoute() throws Exception {
    AddressFamilyRoutingConfiguration result =
        parser.parseConfiguration(config.configurationAt("AddressFamily(1)"));

    Assert.assertEquals(AddressFamily.IPv4, result.getKey().getAddressFamily());
    Assert.assertEquals(
        SubsequentAddressFamily.NLRI_UNICAST_FORWARDING,
        result.getKey().getSubsequentAddressFamily());

    Iterator<RouteConfiguration> it = result.getRoutes().iterator();

    Assert.assertTrue(it.hasNext());

    RouteConfiguration route = it.next();

    Assert.assertEquals(
        new NetworkLayerReachabilityInformation(
            24, new byte[] {(byte) 0xc0, (byte) 0xa8, (byte) 0x01}),
        route.getNlri());

    Assert.assertTrue(it.hasNext());
    route = it.next();

    Assert.assertEquals(
        new NetworkLayerReachabilityInformation(
            24, new byte[] {(byte) 0xc0, (byte) 0xa8, (byte) 0x02}),
        route.getNlri());

    Assert.assertFalse(it.hasNext());
  }
Example #21
0
 private void readProblemType(XMLConfiguration vrpProblem) {
   String fleetSize = vrpProblem.getString("problemType.fleetSize");
   if (fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE);
   else if (fleetSize.toUpperCase().equals(FleetSize.INFINITE.toString()))
     vrpBuilder.setFleetSize(FleetSize.INFINITE);
   else vrpBuilder.setFleetSize(FleetSize.FINITE);
 }
  @Test
  public void testTwoOutboundRouteFilteringConfiguration() throws Exception {
    Capabilities caps = parser.parseConfig(config.configurationAt("Capabilities(7)"));
    Iterator<Capability> capIt = caps.getRequiredCapabilities().iterator();

    Assert.assertTrue(capIt.hasNext());
    OutboundRouteFilteringCapability cap = (OutboundRouteFilteringCapability) capIt.next();
    Map<ORFType, ORFSendReceive> filters = cap.getFilters();
    Assert.assertEquals(AddressFamily.IPv4, cap.getAddressFamily());
    Assert.assertEquals(
        SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSubsequentAddressFamily());
    Assert.assertEquals(1, filters.size());
    Assert.assertTrue(filters.containsKey(ORFType.ADDRESS_PREFIX_BASED));
    Assert.assertEquals(ORFSendReceive.BOTH, filters.get(ORFType.ADDRESS_PREFIX_BASED));

    cap = (OutboundRouteFilteringCapability) capIt.next();
    filters = cap.getFilters();
    Assert.assertEquals(AddressFamily.IPv6, cap.getAddressFamily());
    Assert.assertEquals(
        SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, cap.getSubsequentAddressFamily());
    Assert.assertEquals(1, filters.size());
    Assert.assertTrue(filters.containsKey(ORFType.ADDRESS_PREFIX_BASED));
    Assert.assertEquals(ORFSendReceive.BOTH, filters.get(ORFType.ADDRESS_PREFIX_BASED));

    Assert.assertFalse(capIt.hasNext());
  }
Example #23
0
 /**
  * Dada una clave del fichero <b>XML</b> retorna el valor de dicha propiedad. En caso de no
  * existir la propiedad retorna el valor de <i>defaultValue</i>.
  *
  * @param key de la propiedad que se quiere obtener.
  * @param defaultValue valor a retornar en caso de no existir la propiedad
  * @return valor de la propiedad indicada o <b>defaultValue</b> si la propiedad no existe en el
  *     fichero
  * @throws ConfigUtilException si el fichero no existe
  */
 @Override
 public String getProperty(String key, String defaultValue) throws ConfigUtilException {
   try {
     return (String) configuration.getString(key, defaultValue);
   } catch (Exception e) {
     throw new ConfigUtilException(e.getMessage(), e);
   }
 }
  /**
   * Validates that the pool can be shut down properly and also that attempting to get a connection
   * after the pool has been shutdown throws an error.
   *
   * @throws ConfigurationException if there is a problem setting up the default test connection
   * @throws RserveException if there is an issue connecting with an Rserver
   */
  @Test(expected = IllegalStateException.class)
  public void borrowConnectionAfterShutdown() throws ConfigurationException, RserveException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);
    assertNotNull("Connection pool should never be null", pool);
    assertFalse("Everybody in - the pool should be open!", pool.isClosed());

    pool.close();
    assertNotNull("Connection pool should never be null", pool);
    assertTrue("Everybody out of the pool!", pool.isClosed());

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());

    pool.borrowConnection();
  }
Example #25
0
 @SuppressWarnings("unchecked")
 public void configDataSource(XMLConfiguration config, String section, String dataSourceName) {
   super.configDataSource(config, section, dataSourceName);
   Configuration dsConf = config.configurationAt(section);
   imdb.configDataSource(config, section + ".IMDb");
   if (dsConf.containsKey("users")) {
     usersList = dsConf.getList("users");
   }
   usersToLoad = Utils.getIntFromConfIfNotNull(dsConf, "usersToLoad", usersToLoad);
 }
Example #26
0
  public void loadConfig(String file) {
    try {
      xml = new XMLConfiguration();
      xml.load(file);

    } catch (ConfigurationException cex) {
      cex.printStackTrace();
      System.exit(1);
    }
  }
Example #27
0
 /**
  * Dado el nombre de un fichero <b>XML</b> genera una instancia del objeto que gestiona el fichero
  * mediante <i>Apache commons-configuration</i>.
  *
  * @param filename del fichero de propiedades <i>(p.e.: config.xml)</i>.
  * @throws ConfigUtilException si el fichero no existe
  */
 public ConfigXMLUtil(String filename) throws ConfigUtilException {
   try {
     configuration = new XMLConfiguration(filename);
     configuration.load();
   } catch (ConfigurationException ce) {
     throw new ConfigUtilException(ce.getMessage(), ce);
   } catch (Exception e) {
     throw new ConfigUtilException(e.getMessage(), e);
   }
 }
Example #28
0
 public static boolean loadConfig(String configFilePath) {
   String tmp = System.getProperty("os.name").toLowerCase();
   if (tmp.startsWith("windows")) {
     g.os = g.OS_WINDOWS;
   } else if (tmp.startsWith("linux")) {
     g.os = g.OS_LINUX;
   } else {
     g.os = g.OS_OTHER;
   }
   tmp = System.getProperty("sun.arch.data.model");
   if (tmp.equals("64")) {
     g.arch = g.ARCH_64;
   } else {
     g.arch = g.ARCH_32;
   }
   try {
     if (configFilePath == null) {
       config = new XMLConfiguration(configPath + "config.xml");
     } else {
       config = new XMLConfiguration(configFilePath);
     }
     dbConfig = config.getString("db", "").toLowerCase();
     siteUrl = config.getString("serverInfo.siteUrl");
     siteName = config.getString("serverInfo.siteName");
     uploadTemp = rootPath + config.getString("serverInfo.uploadTemp");
     uploadSizeMax = config.getLong("serverInfo.uploadSizeMax", 0);
     sessionExpiredTime = config.getInt("serverInfo.sessionExpiredTime", 0);
     sessionIdName = config.getString("serverInfo.sessionIdName", "ycsid");
     String _s = g.getConfig().getString("startup");
     if ("".equals(_s)) {
       startup = null;
     } else {
       _s = _s.replaceAll("\\s", "");
       startup = _s.split(";");
     }
     _s = null;
     // 加载全局参数
     List<HierarchicalConfiguration> fields = config.configurationsAt("globalVars.var");
     if (fields != null && fields.size() > 0) {
       vars = new String[fields.size()][2];
       HierarchicalConfiguration sub;
       for (int i = 0; i < fields.size(); i++) {
         sub = fields.get(i);
         vars[i][0] = sub.getString("[@name]");
         vars[i][1] = sub.getString("[@value]");
       }
       sub = null;
     }
     return true;
   } catch (ConfigurationException e) {
     return false;
   }
 }
Example #29
0
  public static Hashtable getMap(String config) throws FitsConfigurationException {
    Hashtable mappings = new Hashtable();
    XMLConfiguration conf = null;
    try {
      conf = new XMLConfiguration(config);
    } catch (ConfigurationException e) {
      throw new FitsConfigurationException("Error reading " + config + "fits.xml", e);
    }

    List fields = conf.configurationsAt("map");
    for (Iterator it = fields.iterator(); it.hasNext(); ) {
      HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
      // sub contains now all data about a single field
      String format = sub.getString("[@format]");
      String transform = sub.getString("[@transform]");
      mappings.put(format, transform);
    }
    return mappings;
  }
  @SuppressWarnings("unchecked")
  public BasicDataSource getDataSource(String dataSourceName, String dbName)
      throws SecurityException, ClassNotFoundException, IllegalArgumentException,
          InstantiationException, IllegalAccessException, InvocationTargetException {
    Configuration dbConf = confDbs.configurationAt(dbName);
    String dbClass = dbConf.getString("class");

    Constructor[] a = Class.forName(dbClass).getConstructors();
    BasicDataSource ds = (BasicDataSource) a[0].newInstance();
    ds.configDriver(confDbs, dbName);
    ds.configDataSource(confDatasources, dataSourceName);
    if (confDatasources.getProperty(dataSourceName + ".fillRandom") != null) {
      int fillRandomValues = confDatasources.getInt(dataSourceName + ".fillRandom");

      if (fillRandomValues == 1) ds.fillRandomValues();
    }
    ds.setName(dataSourceName + dbName);
    return ds;
  }