Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

In this page you can find the example usage for org.dom4j Element elements.

Prototype

List<Element> elements();

Source Link

Document

Returns the elements contained in this element.

Usage

From source file:com.devoteam.srit.xmlloader.asn1.XMLToASNParser.java

License:Open Source License

public void initField(String resultPath, ASNMessage message, Object objClass, Element element, Field field,
        String className) throws Exception {
    // si le champ est priv, pour y accder
    field.setAccessible(true);//from   w w w  .j  a v a 2  s.c  om
    //System.out.println(f);

    // pour ne pas traiter les static
    if (field.toGenericString().contains("static")) {
        return;
    } else if (field.getType().getCanonicalName().contains("Collection")) {
        // type DANS la collection

        // Rcuprer le type des lements de la collection
        Type[] elementParamTypeTab = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();

        // Exception si la collection n'a pas un seul argument
        if (elementParamTypeTab.length != 1) {
            throw new RuntimeException("Message d'erreur");
        }

        Class collectionElementType = (Class) elementParamTypeTab[0];

        // creer la collection
        ArrayList<Object> listInstance = new ArrayList<Object>();

        // parcourir les enfants <instance> de element
        List<Element> children = element.elements();
        for (Element elementInstance : children) {
            Object value = parseField(resultPath, message, elementInstance, null,
                    collectionElementType.getCanonicalName(), objClass, className);
            // pour chaque <instance>
            listInstance.add(value);
        }
        /*
        List<Element> children1 = element.elements("value");
        for (Element elementInstance : children1) 
        {
        // pour chaque <instance>
        listInstance.add(parseField(elementInstance, collectionElementType.getCanonicalName(), objClass, ClasseName));
        }
        */

        // set la collection dans le field
        field.set(objClass, listInstance);
    } else {
        // we add a embedded record in the list 
        Object value = parseField(resultPath, message, element, field, field.getType().getCanonicalName(),
                objClass, className);
        field.set(objClass, value);
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationFunction.java

License:Open Source License

/**
 * Constructor//from ww w.  ja  va2s  . c  o m
 */
public OperationFunction(Element root) throws Exception {
    super(root, null);
    String file = root.attributeValue("file");
    String name = root.attributeValue("name");

    if (file == null && name != null) {
        FunctionsRegistry.instance().register(name, root);
    } else if (file != null && name == null) {

        if (!root.elements().isEmpty()) {
            // TODO : should be zero, throw some error if not
        }

        importFile(file, URIRegistry.MTS_TEST_HOME);
    } else {
        throw new ParsingException(
                "<function> operation should have exactly one of the two attributes: file or name");
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationSequence.java

License:Open Source License

public OperationSequence(Element root, Scenario scenario) throws Exception {
    super(root, null);
    this.scenario = scenario;
    this.operations = new ArrayList<Operation>();
    HashSet<String> labelNames = new HashSet();
    if (null != root) {
        for (Element element : (List<Element>) root.elements()) {
            Operation operation = this.scenario.parseOperation(element);

            // check labels names unicity
            if (operation instanceof OperationLabel) {
                // only check unicity for labels that do not contain parameters in their names
                if (!Parameter.containsParameter(operation.getRootElement().attributeValue("name"))) {
                    if (labelNames.contains(operation.getRootElement().attributeValue("name"))) {
                        throw new Exception("Duplicated label name in operations sequence:\n" + this);
                    }//from  w  w  w  .ja va2  s .  c om
                    labelNames.add(operation.getRootElement().attributeValue("name"));
                }
            }

            this.operations.add(operation);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleCounter(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");
    StatKey statKey = new StatKey(StatPool.PREFIX_USER, "value", name, "_count");

    // create the corresponding template
    CounterReportTemplate template = new CounterReportTemplate("<counter>", statKey, null, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("increase")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, value);
            }/*from   w  w w.j  av  a  2 s . c  om*/
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =+", value);
        } else if (actionElementName.equals("decrease")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, -value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, -value);
            }
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =-", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleFlow(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");
    StatKey statKey = new StatKey(StatPool.PREFIX_USER, "value", name, "_count");

    // create the corresponding template
    CounterReportTemplate template = new CounterReportTemplate("<flow>", statKey, null, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("increase")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, value);
            }/*from ww  w  .  j av a  2 s .c  o  m*/
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =+", value);
        } else if (actionElementName.equals("decrease")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, -value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, -value);
            }
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =-", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleValue(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");

    // create the corresponding template 
    StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value");
    StatKey statKeyCount = new StatKey(StatPool.PREFIX_USER, "value", name, "_count");
    CounterReportTemplate template = new CounterReportTemplate("<value>", statKeyValue, statKeyCount, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("newValue")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyValue, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyValue, value);
            }//from   w  w  w. j  a va  2 s. co m
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_total +=", value);
            StatPool.getInstance().addValue(statKeyCount, 1);
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count +=", 1);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handlePercent(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");
    StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value");
    StatKey statKeyTotal = new StatKey(StatPool.PREFIX_USER, "value", name, "_total");

    // create the corresponding template
    CounterReportTemplate template = new CounterReportTemplate("<percent>", statKeyValue, statKeyTotal, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("incValue")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyValue, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyValue, value);
            }//from  ww  w  .  j a va  2  s .  co m
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_value =+", value);
        } else if (actionElementName.equals("incTotal")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyTotal, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyTotal, value);
            }
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_total =+", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleText(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");

    // create the corresponding template 
    StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value");
    CounterReportTemplate template = new CounterReportTemplate("<text>", statKeyValue, null, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("newValue")) {
            String value = (null != actionElement.attributeValue("value")
                    ? actionElement.attributeValue("value")
                    : actionElement.getText());
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyValue, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyValue, value);
            }/*from w ww  .j a v a 2 s. c  om*/
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_value +=", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationTestAnd.java

License:Open Source License

/**
 * Constructor//from  www  .ja v a2 s .c o m
 *
 * @param operationsTests list of tests
 */
public OperationTestAnd(Element root, Scenario scenario) throws Exception {
    super(root, null);
    this.scenario = scenario;
    this.operations = new ArrayList();
    for (Object object : root.elements()) {
        Element element = (Element) object;
        this.operations.add(scenario.parseOperation(element));
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationTestNot.java

License:Open Source License

/**
 * Constructor//from  ww w . j  a v a  2s.  co m
 *
 * @param operationsTests list of tests
 */
public OperationTestNot(Element root, Scenario scenario) throws Exception {
    super(root, null);
    this.scenario = scenario;
    if (root.elements().size() != 1) {
        throw new ParsingException("<not> operation should not contain more thant one operation");
    }

    this.operation = scenario.parseOperation((Element) root.elements().get(0));
}