Package com.adahas.tools.jmxeval.exception

Examples of com.adahas.tools.jmxeval.exception.ConfigurationException


   */
  public ElementBuilder() throws ConfigurationException {
    try {
      mappings.load(ElementBuilder.class.getResourceAsStream("/mapping.properties"));
    } catch (IOException e) {
      throw new ConfigurationException("Error reading mapping.properties", e);
    }
  }
View Full Code Here


   
    final String xmlFileName = context.getConfigValue(Context.CONFIG_FILENAME);
    final File xmlFile = new File(xmlFileName);
   
    if (!xmlFile.exists() || !xmlFile.canRead()) {
      throw new ConfigurationException("Error: Can not read configuration file: " + xmlFile.getAbsolutePath());
    }
   
    final boolean validate = Boolean.valueOf(context.getConfigValue(Context.CONFIG_VALIDATE));
   
    // Read the XML document and validate
    final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);
    builderFactory.setValidating(validate);
   
    builderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

    // Schema validation
    if (validate) {
      final URL schemaURL = ElementBuilder.class.getResource("/schema/jmxeval-" + context.getConfigValue(Context.CONFIG_SCHEMA) + ".xsd");
      builderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaURL.toString());
    }

    try {
      final DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
     
      // set error handler to throw any exceptions out
      documentBuilder.setErrorHandler(new ConfigurationErrorHandler());
     
      final Document document = documentBuilder.parse(xmlFile);
 
      // process the configuration
      return build(document.getDocumentElement(), null);
     
    } catch (ParserConfigurationException e) {
      throw new ConfigurationException("XML Parser configuration error: " + e.getMessage(), e);
    } catch (SAXException e) {
      throw new ConfigurationException("Exception while parsing configuration file: " + e.getMessage(), e);
    } catch (IOException e) {
      throw new ConfigurationException("Error reading configuration file: " + e.getMessage(), e);
    }
  }
View Full Code Here

   */
  protected Element build(final Node node, final Element parentElement) throws ConfigurationException {
    final String className = (String) mappings.get(node.getNodeName());
   
    if (className == null) {
      throw new ConfigurationException("Can not find mapping for element: " + node.getNodeName());
    }
   
    final Element elem = createElementInstance(className, node, parentElement);
   
    // build child elements
View Full Code Here

    try {
      final Constructor<?> constructor = Class.forName(className).getConstructor(Node.class, Element.class);
      return (Element) constructor.newInstance(node, parentElement);
     
    } catch (ClassNotFoundException e) {
      throw new ConfigurationException("Can not find class: " + className, e);
    } catch (NoSuchMethodException e) {
      throw new ConfigurationException("Non compaible class: " + className, e);
    } catch (InstantiationException e) {
      throw new ConfigurationException("Can not instanciate: " + className, e);
    } catch (IllegalAccessException e) {
      throw new ConfigurationException("Can access constructor on class: " + className, e);
    } catch (InvocationTargetException e) {
      throw new ConfigurationException("Can not invoke constructor on class: " + className, e);
    }
  }
View Full Code Here

TOP

Related Classes of com.adahas.tools.jmxeval.exception.ConfigurationException

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.