use of org.jdom2.Namespace in project JMRI by JMRI.
the class ConnectionConfigManager method savePreferences.
private synchronized void savePreferences(Profile profile, boolean shared) {
Element element = new Element(CONNECTIONS, NAMESPACE);
connections.stream().forEach((o) -> {
log.debug("Saving connection {} ({})...", o.getConnectionName(), shared);
Element e = ConfigXmlManager.elementFromObject(o, shared);
if (e != null) {
element.addContent(e);
}
});
// save connections, or save an empty connections element if user removed all connections
try {
ProfileUtils.getAuxiliaryConfiguration(profile).putConfigurationFragment(JDOMUtil.toW3CElement(element), shared);
} catch (JDOMException ex) {
log.error("Unable to create create XML", ex);
}
}
use of org.jdom2.Namespace in project jPOS by jpos.
the class BSHMethodTest method testInitInterpreterThrowsEvalError.
@Test
public void testInitInterpreterThrowsEvalError() throws Throwable {
Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
e.addContent("testBSHMethod\rStr");
e.setAttributes(new ArrayList());
BSHMethod bshMethod = BSHMethod.createBshMethod(e);
try {
bshMethod.initInterpreter(arguments);
fail("Expected EvalError to be thrown");
} catch (EvalError ex) {
assertEquals("ex.getMessage()", "Sourced file: inline evaluation of: ``testBSHMethod Str;'' : Typed variable declaration : Class: testBSHMethod not found in namespace", ex.getMessage());
assertEquals("ex.getMessage()", "Sourced file: inline evaluation of: ``testBSHMethod Str;'' : Typed variable declaration : Class: testBSHMethod not found in namespace", ex.getMessage());
assertEquals("(HashMap) arguments.size()", 0, arguments.size());
}
}
use of org.jdom2.Namespace in project scylla by bptlab.
the class DataObjectSCParserPlugin method parse.
@Override
public /* pasrses the datobjects and creates the distWrapper*/
Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
Map<Integer, Map<String, DataObjectField>> dataObjects = new HashMap<Integer, Map<String, DataObjectField>>();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("dataObject") || elementName.equals("dataInput")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
Map<String, DataObjectField> dataObjectFields = new HashMap<String, DataObjectField>();
for (Element field : el.getChildren("field", simNamespace)) {
String fieldName = field.getAttributeValue("name");
String fieldType = field.getAttributeValue("type");
DataDistributionType dataDistributionType = DataDistributionType.getEnum(fieldType);
DataDistributionWrapper distWrapper = new DataDistributionWrapper(dataDistributionType);
for (Element fieldElement : field.getChildren()) {
if (fieldElement.getName().endsWith("Distribution")) {
Distribution distribution = SimulationConfigurationParser.getDistribution(field, simNamespace, fieldType);
distWrapper.setDistribution(distribution);
}
/*else if (fieldElement.getName().equals("range")) {
try{
double min = Double.parseDouble(fieldElement.getAttributeValue("min"));
distWrapper.setMin(min);
} catch (NumberFormatException e) {
// do nothing: min was not set and is automatically -Double.MAX_VALUE
}
try{
double max = Double.parseDouble(fieldElement.getAttributeValue("max"));
distWrapper.setMax(max);
} catch (NumberFormatException e) {
// do nothing: max was not set and is automatically Double.MAX_VALUE
}
Distribution distribution = new UniformDistribution(distWrapper.getMin(), distWrapper.getMax());
distWrapper.setDistribution(distribution);
}*/
}
dataObjectFields.put(fieldName, new DataObjectField(distWrapper, nodeId, fieldName, fieldType));
}
dataObjects.put(nodeId, dataObjectFields);
}
}
// System.out.println(processModel.getDataObjectsGraph().print());
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("dataObjects", dataObjects);
return extensionAttributes;
}
use of org.jdom2.Namespace in project scylla by bptlab.
the class ExclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("exclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
Double probabilitySum = 0d;
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.parseDouble(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Exclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
probabilitySum += branchingProbability;
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
if (probabilitySum <= 0) {
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", where the sum of probabilities is negative or zero.");
}
if (probabilitySum > 1) {
// XXX imprecision by IEEE 754 floating point representation
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", exceeding 1 in total.");
}
// complete probabilities with the default flow probability
if (probabilitySum > 0 && probabilitySum <= 1) {
Map<String, String> gatewayAttributes = processModel.getNodeAttributes().get(nodeId);
String defaultFlowIdentifier = gatewayAttributes.get("default");
if (defaultFlowIdentifier != null) {
double probabilityOfDefaultFlow = 1 - probabilitySum;
int defaultFlowNodeId = processModel.getIdentifiersToNodeIds().get(defaultFlowIdentifier);
if (!branchingProbabilities.containsKey(defaultFlowNodeId)) {
branchingProbabilities.put(defaultFlowNodeId, probabilityOfDefaultFlow);
} else {
branchingProbabilities.put(defaultFlowNodeId, branchingProbabilities.get(defaultFlowNodeId) + probabilityOfDefaultFlow);
}
;
}
}
try {
if (branchingProbabilities.keySet().size() != processModel.getIdsOfNextNodes(nodeId).size()) {
throw new ScyllaValidationException("Number of branching probabilities defined in simulation configuration " + "does not match to number of outgoing flows of exclusive gateway " + identifier + ".");
}
} catch (NodeNotFoundException e) {
throw new ScyllaValidationException("Node not found: " + e.getMessage());
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
use of org.jdom2.Namespace in project scylla by bptlab.
the class InclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("inclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.valueOf(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Inclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
Aggregations