use of org.jdom2.JDOMException in project scylla by bptlab.
the class SimulationConfigurationPane method open.
@Override
protected void open() throws JDOMException, IOException {
buttonClosefile.setEnabled(true);
try {
creator = SimulationConfigurationCreator.createFromFile(getFile().getPath());
} catch (NotAValidFileException e1) {
setFile(null);
e1.printStackTrace();
return;
}
if (gcc != null)
creator.setGCC(gcc);
Element modelRoot = null;
if (bpmnPath != null && !bpmnPath.isEmpty())
try {
Document doc;
SAXBuilder builder = new SAXBuilder();
doc = builder.build(bpmnPath);
modelRoot = doc.getRootElement();
creator.setModel(modelRoot, false);
} catch (JDOMException | IOException e) {
e.printStackTrace();
} catch (NoProcessSpecifiedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotAuthorizedToOverrideException e) {
int override = showModelOverrideConfirmationDialog(e);
if (override == 0)
try {
creator.setModel(modelRoot, true);
} catch (NoProcessSpecifiedException | NotAuthorizedToOverrideException e1) {
e1.printStackTrace();
}
else
clearBpmnPath();
e.printStackTrace();
}
setChangeFlag(true);
textfieldId.loadSavedValue();
if (creator.getRandomSeed() != null) {
textfieldSeed.setValue(creator.getRandomSeed());
}
if (creator.getProcessInstances() != null)
spinnerNOI.setValue(Integer.parseInt(creator.getProcessInstances()));
String startDt = creator.getStartDateTime();
if (startDt != null) {
startDateTime = ZonedDateTime.parse(startDt);
textfieldStartTime.setValue(startDateTime.toLocalTime());
textfieldStartDate.setValue(startDateTime.toLocalDate());
}
String endDt = creator.getEndDateTime();
if (endDt != null) {
checkboxUnlimited.setSelected(false);
endDateTime = ZonedDateTime.parse(endDt);
textfieldEndTime.setValue(endDateTime.toLocalTime());
textfieldEndDate.setValue(endDateTime.toLocalDate());
} else {
checkboxUnlimited.setSelected(true);
textfieldEndDate.getComponent().setEnabled(false);
textfieldEndTime.getComponent().setEnabled(false);
}
importCreatorElements();
setChangeFlag(false);
setEnabled(true);
}
use of org.jdom2.JDOMException in project scylla by bptlab.
the class SimulationConfigurationPane method be_openPM.
private void be_openPM() {
// Choose file to be opened
ScalingFileChooser chooser = new ScalingFileChooser(ScyllaGUI.DEFAULTFILEPATH);
chooser.setDialogTitle("Open Process Model File");
int c = chooser.showDialog(SimulationConfigurationPane.this, "Open");
// if the process is canceled, nothing happens
if (c == ScalingFileChooser.APPROVE_OPTION) {
if (chooser.getSelectedFile() != null) {
try {
boolean success = true;
bpmnPath = chooser.getSelectedFile().getPath();
if (creator != null)
success = updateModel();
if (!success) {
clearBpmnPath();
} else {
labelRefPMshow.setText(bpmnPath);
}
} catch (JDOMException | IOException e1) {
e1.printStackTrace();
}
ScyllaGUI.DEFAULTFILEPATH = chooser.getSelectedFile().getPath();
} else {
System.err.println("Could not open file");
}
}
}
use of org.jdom2.JDOMException in project scylla by bptlab.
the class SimulationManager method run.
/**
* parses input, runs DesmoJ simulation experiment, writes BPS output logs
*/
public String run() {
try {
SAXBuilder builder = new SAXBuilder();
if (globalConfigurationFilename == null || globalConfigurationFilename.isEmpty()) {
throw new ScyllaValidationException("No global configuration provided.");
} else {
// parse global configuration XML
Document gcDoc = builder.build(globalConfigurationFilename);
Element gcRootElement = gcDoc.getRootElement();
GlobalConfigurationParser globalConfigurationParser = new GlobalConfigurationParser(this);
globalConfiguration = globalConfigurationParser.parse(gcDoc.getRootElement());
String fileNameWithoutExtension = // filename.lastIndexOf("\\") +
globalConfigurationFilename.substring(// 1,
globalConfigurationFilename.lastIndexOf(Scylla.FILEDELIM) + 1, globalConfigurationFilename.lastIndexOf(".xml"));
globalConfiguration.setFileNameWithoutExtension(fileNameWithoutExtension);
// plugins to parse global configuration
GlobalConfigurationParserPluggable.runPlugins(this, globalConfiguration, gcRootElement);
DateTimeUtils.setZoneId(globalConfiguration.getZoneId());
}
CommonProcessElementsParser cpeParser = new CommonProcessElementsParser(this);
for (String filename : processModelFilenames) {
Document pmDoc = builder.build(filename);
Element pmRootElement = pmDoc.getRootElement();
// parse common process elements from XML (BPMN)
CommonProcessElements commonProcessElementsFromFile = cpeParser.parse(pmRootElement);
String fileNameWithoutExtension = // filename.lastIndexOf("\\") + 1,
filename.substring(filename.lastIndexOf(Scylla.FILEDELIM) + 1, filename.lastIndexOf(".bpmn"));
commonProcessElementsFromFile.setBpmnFileNameWithoutExtension(fileNameWithoutExtension);
// plugins to parse common process elements
CommonProcessElementsParserPluggable.runPlugins(this, commonProcessElementsFromFile, pmRootElement);
// parse process model(s) from XML (BPMN)
ProcessModelParser pmParser = new ProcessModelParser(this);
pmParser.setCommonProcessElements(commonProcessElementsFromFile);
ProcessModel processModelFromFile = pmParser.parse(pmDoc.getRootElement());
String processId = processModelFromFile.getId();
if (processModels.containsKey(processId)) {
throw new ScyllaValidationException("Duplicate process model with id " + processId + ".");
}
// plugins to parse process model(s)
ProcessModelParserPluggable.runPlugins(this, processModelFromFile, pmRootElement);
processModels.put(processId, processModelFromFile);
commonProcessElements.put(processId, commonProcessElementsFromFile);
}
SimulationConfigurationParser simParser = new SimulationConfigurationParser(this);
// parse each simulation configuration XML
for (String filename : simulationConfigurationFilenames) {
Document scDoc = builder.build(filename);
SimulationConfiguration simulationConfigurationFromFile = simParser.parse(scDoc.getRootElement());
String processId = simulationConfigurationFromFile.getProcessModel().getId();
if (simulationConfigurations.containsKey(processId)) {
throw new ScyllaValidationException("Multiple simulation configurations for process with id " + processId + ".");
}
// plugins to parse simulation configuration
SimulationConfigurationParserPluggable.runPlugins(this, simulationConfigurationFromFile, scDoc);
simulationConfigurations.put(processId, simulationConfigurationFromFile);
}
} catch (JDOMException | IOException | ScyllaValidationException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
}
// TODO validate resources in process models (i.e. check if they are all covered in resource data)
TimeUnit epsilon = TimeUnit.SECONDS;
DateTimeUtils.setReferenceTimeUnit(epsilon);
String experimentName = Long.toString((new Date()).getTime());
Experiment.setEpsilon(epsilon);
Experiment exp = new Experiment(experimentName, experimentOutputFolder);
exp.setShowProgressBar(false);
// XXX each simulation configuration may have its own seed
Long randomSeed = globalConfiguration.getRandomSeed();
if (randomSeed != null) {
exp.setSeedGenerator(randomSeed);
} else {
exp.setSeedGenerator((new Random()).nextLong());
}
SimulationModel sm = new SimulationModel(null, globalConfiguration, commonProcessElements, processModels, simulationConfigurations, enableBpsLogging, enableDesLogging);
sm.connectToExperiment(exp);
int lambda = 1;
if (sm.getEndDateTime() != null) {
// have to use time which is slightly after intended end time (epsilon)
// otherwise the AbortProcessSimulationEvent(s) may not fire
long simulationDuration = DateTimeUtils.getDuration(sm.getStartDateTime(), sm.getEndDateTime());
TimeInstant simulationTimeInstant = new TimeInstant(simulationDuration + lambda, epsilon);
exp.stop(simulationTimeInstant);
exp.tracePeriod(new TimeInstant(0), simulationTimeInstant);
exp.debugPeriod(new TimeInstant(0), simulationTimeInstant);
} else {
exp.traceOn(new TimeInstant(0));
exp.debugOn(new TimeInstant(0));
}
if (!enableDesLogging) {
exp.debugOff(new TimeInstant(0));
exp.traceOff(new TimeInstant(0));
}
exp.start();
exp.report();
exp.finish();
try {
// log process execution
// log resources, process, tasks
StringBuilder strb = new StringBuilder(globalConfigurationFilename.substring(0, globalConfigurationFilename.lastIndexOf(Scylla.FILEDELIM) + 1));
outputPath = strb.substring(0, strb.lastIndexOf(Scylla.FILEDELIM) + 1) + "output_" + new SimpleDateFormat("yy_MM_dd_HH_mm_ss").format(new Date()) + Scylla.FILEDELIM;
File outputPathFolder = new File(outputPath);
if (!outputPathFolder.exists())
outputPathFolder.mkdir();
OutputLoggerPluggable.runPlugins(sm, outputPath);
} catch (IOException e) {
e.printStackTrace();
}
return outputPath;
}
use of org.jdom2.JDOMException in project scylla by bptlab.
the class SimulationConfigurationCreator method createFromFile.
/**
* Creates a new SCCreator from an existing SC xml file
* @param scPath to xml file
* @return new SCCreator
* @throws JDOMException when errors occur in parsing
* @throws IOException when an I/O error prevents a document from being fully parsed
* @throws NotAValidFileException a) when the file has no simulation configuration root element
*/
public static SimulationConfigurationCreator createFromFile(String scPath) throws JDOMException, IOException, NotAValidFileException {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(scPath);
Element r = doc.getRootElement();
if (r.getChild("simulationConfiguration", stdNsp) == null)
throw new NotAValidFileException("Cannot open simulation configuration with path " + scPath + " : root element not found");
SimulationConfigurationCreator sc = new SimulationConfigurationCreator(r, doc);
return sc;
}
use of org.jdom2.JDOMException in project jPOS by jpos.
the class UI method configure.
protected void configure(Element ui) throws JDOMException {
setLookAndFeel(ui);
createMappings(ui);
createObjects(ui, "object");
createObjects(ui, "action");
if (!"ui".equals(ui.getName())) {
ui = ui.getChild("ui");
}
if (ui != null) {
JFrame frame = initFrame(ui);
Element mb = ui.getChild("menubar");
if (mb != null)
frame.setJMenuBar(buildMenuBar(mb));
frame.setContentPane(createComponent(ui.getChild("components")));
if ("true".equals(ui.getAttributeValue("full-screen"))) {
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
frame.setUndecorated("true".equals(ui.getAttributeValue("undecorated")));
device.setFullScreenWindow(frame);
} else {
frame.show();
}
}
}
Aggregations