List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationFunction.java
License:Open Source License
/** * Constructor/* ww w . j a va 2 s .co 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.OperationParameter.java
License:Open Source License
/** * Creates a new instance of OperationParameter *///from w ww . j a va 2 s. com public OperationParameter(Element root) throws Exception { super(root, XMLElementTextOnlyParser.instance()); this.resultantAttribute = root.attributeValue("name").trim(); this.operatorAttribute = root.attributeValue("operation"); if (null == this.operatorAttribute) { root.addAttribute("operation", "list.set"); this.operatorAttribute = root.attributeValue("operation"); } this.operatorAttribute = this.operatorAttribute.toLowerCase().trim(); this._key[1] = this.operatorAttribute; this.parameterOperator = ParameterOperatorRegistry.getPluggableComponent(this.operatorAttribute); this.parameterOperatorName = ParameterOperatorRegistry.getPluggableName(this.operatorAttribute); if (null == this.parameterOperator) { throw new ParsingException("Could not find any <parameter> operation named " + this.operatorAttribute); } }
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 www . j a v a 2 s . com*/ 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); }//w w w . j av a2 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); }/* w w w.j a v a 2s . c o 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 w ww . jav a 2 s.c om*/ 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 ww w .j a v a2 s .c o m*/ GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name, "/_value +=", value); } } }
From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java
License:Open Source License
private void handleReset(Runner runner, Element root) throws Exception { // read attributes String counterName = root.attributeValue("name"); // reset all stat counters if (counterName == null) { StatPool.getInstance().reset();// www . j a v a 2 s .c om return; } counterName = counterName.trim(); String path = root.attributeValue("path"); if (path == null) { path = "user>" + counterName; } path = path.trim(); if (path.charAt(0) == '>') { path = path.substring(1, path.length()); } String[] key = Utils.splitNoRegex(path, ">"); StatKey statKey = new StatKey(key); List<CounterReportTemplate> templates = StatCounterConfigManager.getInstance().getTemplateList(statKey); Iterator<CounterReportTemplate> iter = templates.iterator(); while (iter.hasNext()) { CounterReportTemplate template = iter.next(); // should replace LinkedList by LinkedHashMap if (counterName.equalsIgnoreCase(template.name)) { template.resetCounter(StatPool.getInstance(), statKey); } } }
From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java
License:Open Source License
private long getTimestamp(Element element) { long timestamp = -1; String millis = element.attributeValue("milliseconds"); String seconds = element.attributeValue("seconds"); if (null != millis) { timestamp = Long.parseLong(millis); } else if (null != seconds) { timestamp = (long) (Double.parseDouble(seconds) * 1000); }/*www. j a v a2 s .co m*/ return timestamp; }
From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationSwitch.java
License:Open Source License
/** * Constructor/*from w ww.java 2 s .co m*/ * * @param condition boolean variable which represents a condition of the if statment * @param operationsThen List of operations executed if the value of condition is true * @param operationsElse List of operations executed if the value of condition is false */ public OperationSwitch(Element root, Scenario scenario) throws Exception { super(root, null); this.scenario = scenario; this.parameter = root.attributeValue("parameter"); List<Element> list = root.elements("case"); equalsValues = new String[list.size()]; matchesValues = new String[list.size()]; operationSequences = new OperationSequence[list.size()]; int i = 0; for (Element element : list) { operationSequences[i] = new OperationSequence(element, scenario); equalsValues[i] = element.attributeValue("equals"); matchesValues[i] = element.attributeValue("matches"); boolean isEquals = null != equalsValues[i]; boolean isMatches = null != matchesValues[i]; if (!(isEquals ^ isMatches)) throw new ParsingException("case element cannot contain both matches and equals attributes"); i++; } Element defaultElement = root.element("default"); if (null != defaultElement) defaultOperationSequence = new OperationSequence(defaultElement, scenario); else defaultOperationSequence = null; }