Example usage for org.apache.commons.configuration.tree ConfigurationNode getName

List of usage examples for org.apache.commons.configuration.tree ConfigurationNode getName

Introduction

In this page you can find the example usage for org.apache.commons.configuration.tree ConfigurationNode getName.

Prototype

String getName();

Source Link

Document

Returns the name of this node.

Usage

From source file:com.photon.phresco.plugins.xcode.Instrumentation.java

private void generateXMLReport(String location) {

    try {//from w ww.  j  av  a 2  s . co m
        String startTime = "";
        int total, pass, fail;
        total = pass = fail = 0;
        config = new XMLPropertyListConfiguration(location);
        ArrayList list = (ArrayList) config.getRoot().getChild(0).getValue();
        String key;

        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        Document doc = docBuilder.newDocument();

        Element root = doc.createElement(XMLConstants.TESTSUITES_NAME);
        doc.appendChild(root);
        Element testSuite = doc.createElement(XMLConstants.TESTSUITE_NAME);
        testSuite.setAttribute(XMLConstants.NAME, "FunctionalTestSuite");
        root.appendChild(testSuite);

        for (Object object : list) {

            XMLPropertyListConfiguration config = (XMLPropertyListConfiguration) object;

            startTime = config.getRoot().getChild(2).getValue().toString();

            break;
        }

        for (Object object : list) {

            XMLPropertyListConfiguration config = (XMLPropertyListConfiguration) object;

            ConfigurationNode con = config.getRoot().getChild(0);
            key = con.getName();

            if (key.equals(XMLConstants.LOGTYPE) && con.getValue().equals(XMLConstants.PASS)) {
                pass++;
                total++;
                Element child1 = doc.createElement(XMLConstants.TESTCASE_NAME);
                child1.setAttribute(XMLConstants.NAME, (String) config.getRoot().getChild(1).getValue());
                child1.setAttribute(XMLConstants.RESULT, (String) con.getValue());

                String endTime = config.getRoot().getChild(2).getValue().toString();

                long differ = getTimeDiff(startTime, endTime);
                startTime = endTime;
                child1.setAttribute(XMLConstants.TIME, differ + "");
                testSuite.appendChild(child1);
            } else if (key.equals(XMLConstants.LOGTYPE) && con.getValue().equals(XMLConstants.ERROR)) {
                fail++;
                total++;
                Element child1 = doc.createElement(XMLConstants.TESTCASE_NAME);
                child1.setAttribute(XMLConstants.NAME, (String) config.getRoot().getChild(1).getValue());
                child1.setAttribute(XMLConstants.RESULT, (String) con.getValue());

                String endTime = config.getRoot().getChild(2).getValue().toString();

                long differ = getTimeDiff(startTime, endTime);
                startTime = endTime;
                child1.setAttribute(XMLConstants.TIME, differ + "");
                testSuite.appendChild(child1);
            }

        }

        testSuite.setAttribute(XMLConstants.TESTS, String.valueOf(total));
        testSuite.setAttribute(XMLConstants.SUCCESS, String.valueOf(pass));
        testSuite.setAttribute(XMLConstants.FAILURES, String.valueOf(fail));

        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.INDENT, "yes");

        File file = new File(project.getBasedir().getAbsolutePath() + File.separator + xmlResult);
        Writer bw = new BufferedWriter(new FileWriter(file));
        StreamResult result = new StreamResult(bw);
        DOMSource source = new DOMSource(doc);
        trans.transform(source, result);

    } catch (Exception e) {
        getLog().error("Interrupted while generating XML file");
    }
}

From source file:nz.co.senanque.madura.configuration.ConstructorBeanFactory.java

public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception {
    Map m = decl.getBeanProperties();
    XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl;
    ConfigurationNode n = xmlDecl.getNode();
    String nodeName = n.getName();
    n = n.getParentNode();//from w ww.  j  a va 2s  . co m
    while (n != null) {

        if (n.getName() != null)
            nodeName = n.getName() + "/" + nodeName;
        n = n.getParentNode();
    }

    Object bean = beans.get(nodeName);
    if (bean != null) {
        // Yes, there is already an instance
        return bean;
    } else {
        // No, create it now (done by the super class)
        List<Class> constructorClasses = new ArrayList<Class>();
        List<Object> constructorArguments = new ArrayList<Object>();
        Object o = m.get("constructor-arg");
        if (o != null) {
            constructorClasses.add(o.getClass());
            constructorArguments.add(o);
        }
        o = m.get("constructor-arg0");
        if (o != null) {
            constructorClasses.add(o.getClass());
            constructorArguments.add(o);
        }
        for (int i = 1; i < 10; i++) {
            o = m.get("constructor-arg" + i);
            if (o == null)
                break;
            constructorClasses.add(o.getClass());
            constructorArguments.add(o);
        }
        Constructor constructor = beanClass
                .getDeclaredConstructor(constructorClasses.toArray(new Class[constructorClasses.size()]));
        bean = constructor.newInstance(constructorArguments.toArray(new Object[constructorArguments.size()]));
        // Store it in map
        beans.put(nodeName, bean);
        return bean;
    }
}

From source file:nz.co.senanque.madura.configuration.ListBeanFactory.java

public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception {
    XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl;
    ConfigurationNode n = xmlDecl.getNode();
    String nodeName = n.getName();
    n = n.getParentNode();/*from   w  w  w  .  j  av a 2 s  . co m*/
    while (n != null) {
        if (n.getName() != null)
            nodeName = n.getName() + "/" + nodeName;
        n = n.getParentNode();
    }
    Object bean = beans.get(nodeName);
    if (bean != null) {
        // Yes, there is already an instance
        return bean;
    }
    final List<String> list = new ArrayList<String>();
    n = xmlDecl.getNode();
    List<ConfigurationNode> children = n.getChildren();
    for (ConfigurationNode node : children) {
        list.add(node.getValue().toString());
    }
    // Store it in map
    bean = list;
    beans.put(nodeName, bean);
    return bean;
}

From source file:nz.co.senanque.madura.configuration.SetterBeanFactory.java

public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception {
    Map<String, String> m = decl.getBeanProperties();
    XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl;
    ConfigurationNode n = xmlDecl.getNode();
    String nodeName = n.getName();
    n = n.getParentNode();//from   ww w  .j  av  a2 s .  c o  m
    while (n != null) {

        if (n.getName() != null)
            nodeName = n.getName() + "/" + nodeName;
        n = n.getParentNode();
    }

    Object bean = beans.get(nodeName);
    if (bean != null) {
        // Yes, there is already an instance
        return bean;
    } else {
        // create the bean and use the rest of the attributes as properties
        bean = beanClass.newInstance();
        for (Map.Entry entry : m.entrySet()) {
            String key = (String) entry.getKey();
            if (key.equals("config-class"))
                continue;
            org.apache.commons.beanutils.BeanUtils.setProperty(bean, key, entry.getValue());
        }
        // Store it in map
        beans.put(nodeName, bean);
        return bean;
    }
}

From source file:nz.co.senanque.madura.configuration.XMLBeanFactory.java

public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception {
    Map m = decl.getBeanProperties();
    XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl;
    ConfigurationNode n = xmlDecl.getNode();
    String nodeName = n.getName();
    n = n.getParentNode();//from   ww  w.j  av  a2s  . c om
    while (n != null) {
        if (n.getName() != null)
            nodeName = n.getName() + "/" + nodeName;
        n = n.getParentNode();
    }
    Object bean = beans.get(nodeName);
    if (bean != null) {
        // Yes, there is already an instance
        return bean;
    }
    String fileLocation = (String) m.get("fileLocation");
    Document doc = null;
    SAXBuilder sax = new SAXBuilder();
    if (fileLocation == null) {
        // build the doc from the children
        ConfigurationNode node = xmlDecl.getNode();
        doc = new Document();
        doc.addContent(makeElement(node));
    } else {
        InputStream in = new FileInputStream(fileLocation);
        doc = sax.build(in);
    }
    bean = doc;
    // Store it in map
    beans.put(nodeName, bean);
    return bean;
}

From source file:nz.co.senanque.madura.configuration.XMLBeanFactory.java

private Element makeElement(ConfigurationNode node) {
    Element element = new Element(node.getName());
    Object value = node.getValue();
    if (value != null)
        element.setText(value.toString());
    List<ConfigurationNode> attributes = node.getAttributes();
    for (ConfigurationNode attribute : attributes) {
        element.setAttribute(new Attribute(attribute.getName(), attribute.getValue().toString()));
    }//from w w w  .j  a v a  2s.  c o  m
    List<ConfigurationNode> children = node.getChildren();
    for (ConfigurationNode child : children) {
        element.addContent(makeElement(child));
    }
    return element;
}

From source file:org.apache.james.fetchmail.FetchMail.java

/**
 * Method configure parses and validates the Configuration data and creates
 * a new <code>ParsedConfiguration</code>, an <code>Account</code> for each
 * configured static account and a//ww w  .  j a  v a2  s  .  co  m
 * <code>ParsedDynamicAccountParameters</code> for each dynamic account.
 *
 * @see org.apache.james.lifecycle.api.Configurable#configure(HierarchicalConfiguration)
 */
public void configure(HierarchicalConfiguration configuration) throws ConfigurationException {
    // Set any Session parameters passed in the Configuration
    setSessionParameters(configuration);

    // Create the ParsedConfiguration used in the delegation chain
    ParsedConfiguration parsedConfiguration = new ParsedConfiguration(configuration, logger, getLocalUsers(),
            getDNSService(), getDomainList(), getMailQueue());

    setParsedConfiguration(parsedConfiguration);

    // Setup the Accounts
    List<HierarchicalConfiguration> allAccounts = configuration.configurationsAt("accounts");
    if (allAccounts.size() < 1)
        throw new ConfigurationException("Missing <accounts> section.");
    if (allAccounts.size() > 1)
        throw new ConfigurationException("Too many <accounts> sections, there must be exactly one");
    HierarchicalConfiguration accounts = allAccounts.get(0);

    if (!accounts.getKeys().hasNext())
        throw new ConfigurationException("Missing <account> section.");

    int i = 0;
    // Create an Account for every configured account
    for (ConfigurationNode accountsChild : accounts.getRoot().getChildren()) {

        String accountsChildName = accountsChild.getName();

        List<HierarchicalConfiguration> accountsChildConfig = accounts.configurationsAt(accountsChildName);
        HierarchicalConfiguration conf = accountsChildConfig.get(i);

        if ("alllocal".equals(accountsChildName)) {
            // <allLocal> is dynamic, save the parameters for accounts to
            // be created when the task is triggered
            getParsedDynamicAccountParameters().add(new ParsedDynamicAccountParameters(i, conf));
            continue;
        }

        if ("account".equals(accountsChildName)) {
            // Create an Account for the named user and
            // add it to the list of static accounts
            getStaticAccounts().add(new Account(i, parsedConfiguration, conf.getString("[@user]"),
                    conf.getString("[@password]"), conf.getString("[@recipient]"),
                    conf.getBoolean("[@ignorercpt-header]"), conf.getString("[@customrcpt-header]", ""),
                    getSession()));
            continue;
        }

        throw new ConfigurationException("Illegal token: <" + accountsChildName + "> in <accounts>");
    }
    i++;
}

From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java

protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) {
    final String parentName = parentNode.getName();
    if (obj instanceof Map<?, ?>) {
        for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) {
            final Node childNode = new Node(entry.getKey());

            // if parent node is look like "tableS", "userS" or "groupS"
            if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) {
                //this is done to have "users.user[@name='smith'] instead of "users.smith"
                childNode.setName(parentName.substring(0, parentName.length() - 1));
                childNode.addAttribute(new Node("name", entry.getKey()));
            }//from   w ww  .ja  v  a2s .c  o m

            childNode.setReference(entry);
            loadHierarchy(childNode, entry.getValue());
            parentNode.addChild(childNode);
        }
    } else if (obj instanceof Collection) {
        for (Object child : (Collection) obj) {
            final Node childNode = new Node("item");
            childNode.setReference(child);
            loadHierarchy(childNode, child);
            parentNode.addChild(childNode);
        }
    }

    parentNode.setValue(obj);
}

From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java

protected Object saveHierarchy(final ConfigurationNode parentNode) {
    if (parentNode.getChildrenCount() == 0)
        return parentNode.getValue();

    if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) {
        return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList());
    } else {/*from   w ww.  j  av a2s .  c o m*/
        final Map<String, Object> map = new LinkedHashMap<>();
        for (ConfigurationNode childNode : parentNode.getChildren()) {
            String nodeName = childNode.getName();
            if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0)
                nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue());

            map.put(nodeName, saveHierarchy(childNode));
        }

        return map;
    }
}

From source file:org.kepler.configuration.CommonsConfigurationReader.java

/**
 * add the structure of root to prop//from   w w w  . j  a  v a2 s.  c o  m
 */
private ConfigurationProperty getConfiguration(ConfigurationNode root, Module m,
        ConfigurationNamespace namespace) throws Exception {
    String originMod;
    boolean originOk = true;
    ConfigurationProperty cp = new ConfigurationProperty(m, root.getName());
    cp.setNamespace(namespace);
    String value = (String) root.getValue();
    boolean mutable = true;
    if (value != null && !value.equals("")) {
        cp.setValue(value);
    }

    if (root.getChildrenCount() != 0) {
        Iterator it = root.getChildren().iterator();
        while (it.hasNext()) {
            ConfigurationNode child = (ConfigurationNode) it.next();
            ConfigurationProperty nextProp = getConfiguration(child, m, namespace);
            if (nextProp == null) {
                if (_isDebugging) {
                    _log.debug("not loading property " + child.getName()
                            + " because it was added from an inactive module.");
                }
                continue;
            }

            if (nextProp.getName().equals("mutable")) {
                if (nextProp.getValue() != null && nextProp.getValue().equals("false")) {
                    cp.setMutable(false);
                }
            } else if (nextProp.getName().equals("originModule")) {
                if (nextProp.getValue() != null && !nextProp.getValue().equals("")) {
                    originMod = nextProp.getValue();
                    if (!ModuleTree.instance().contains(originMod)) {
                        originOk = false;
                    } else {
                        cp.setOriginModule(ConfigurationManager.getModule(originMod));
                    }
                }
            }

            cp.addProperty(nextProp, true);
        }
    }

    if (originOk) {
        return cp;
    } else {
        return null;
    }
}