Search in sources :

Example 96 with Document

use of org.geotoolkit.sml.xml.v100.Document in project jPOS by jpos.

the class Q2 method persist.

private long persist(File f, ObjectName name) {
    long deployed = f.lastModified();
    try {
        Element e = (Element) server.getAttribute(name, "Persist");
        if (e != null) {
            XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
            Document doc = new Document();
            e.detach();
            doc.setRootElement(e);
            File tmp = new File(f.getAbsolutePath() + ".tmp");
            Writer writer = new BufferedWriter(new FileWriter(tmp));
            try {
                out.output(doc, writer);
            } finally {
                writer.close();
            }
            f.delete();
            tmp.renameTo(f);
            deployed = f.lastModified();
        }
    } catch (Exception ex) {
        log.warn("persist", ex);
    }
    return deployed;
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeneralSecurityException(java.security.GeneralSecurityException) BundleException(org.osgi.framework.BundleException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) SAXException(org.xml.sax.SAXException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ISOException(org.jpos.iso.ISOException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 97 with Document

use of org.geotoolkit.sml.xml.v100.Document in project jPOS by jpos.

the class Q2 method deploy.

private boolean deploy(File f) {
    LogEvent evt = log != null ? log.createInfo() : null;
    try {
        QEntry qentry = dirMap.get(f);
        SAXBuilder builder = createSAXBuilder();
        Document doc;
        if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
            doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
        } else {
            doc = decrypt(builder.build(f));
        }
        Element rootElement = doc.getRootElement();
        String iuuid = rootElement.getAttributeValue("instance");
        if (iuuid != null) {
            UUID uuid = UUID.fromString(iuuid);
            if (!uuid.equals(getInstanceId())) {
                deleteFile(f, iuuid);
                return false;
            }
        }
        if (QFactory.isEnabled(rootElement)) {
            if (evt != null)
                evt.addMessage("deploy: " + f.getCanonicalPath());
            Object obj = factory.instantiate(this, rootElement);
            qentry.setObject(obj);
            ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
            qentry.setInstance(instance);
        } else if (evt != null) {
            evt.addMessage("deploy ignored (enabled='" + QFactory.getEnabledAttribute(rootElement) + "'): " + f.getCanonicalPath());
        }
    } catch (InstanceAlreadyExistsException e) {
        /*
            * Ok, the file we tried to deploy, holds an object
            *  that already has been deployed.
            *  
            * Rename it out of the way.
            * 
            */
        tidyFileAway(f, DUPLICATE_EXTENSION);
        if (evt != null)
            evt.addMessage(e);
        return false;
    } catch (Exception e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ERROR_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } catch (Error e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ENV_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } finally {
        if (evt != null)
            Logger.log(evt);
    }
    return true;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LogEvent(org.jpos.util.LogEvent) Element(org.jdom2.Element) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeneralSecurityException(java.security.GeneralSecurityException) BundleException(org.osgi.framework.BundleException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) SAXException(org.xml.sax.SAXException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ISOException(org.jpos.iso.ISOException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 98 with Document

use of org.geotoolkit.sml.xml.v100.Document in project jPOS by jpos.

the class QThreadPoolExecutorTest method setQBeanConfig.

protected void setQBeanConfig(byte[] config) {
    ByteArrayInputStream bis = new ByteArrayInputStream(config);
    Document doc = getDocument(bis);
    qbean.setPersist(doc.getRootElement());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.jdom2.Document)

Example 99 with Document

use of org.geotoolkit.sml.xml.v100.Document in project scylla by bptlab.

the class SimulationConfigurationPane method updateModel.

private boolean updateModel() throws JDOMException, IOException {
    Document doc;
    SAXBuilder builder = new SAXBuilder();
    doc = builder.build(bpmnPath);
    Element modelRoot = doc.getRootElement();
    try {
        creator.setModel(modelRoot, false);
    } catch (NoProcessSpecifiedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotAuthorizedToOverrideException e) {
        if (showModelOverrideConfirmationDialog(e) == 0) {
            try {
                creator.setModel(modelRoot, true);
            } catch (NoProcessSpecifiedException | NotAuthorizedToOverrideException e1) {
                e1.printStackTrace();
            }
        } else
            return false;
    }
    // Reimport updated creator elements
    startEventPanel.setStartEvent(creator.getStartEvent());
    taskPanel.clear();
    gatewayPanel.clear();
    importCreatorElements();
    button_openPM.setEnabled(false);
    panelStarteventExpand.setContent(startEventPanel);
    panelTasksExpand.setContent(taskPanel);
    panelGatewaysExpand.setContent(gatewayPanel);
    gatewayPanel.forAll((gateway) -> {
        if (gateway instanceof ExclusiveGatewayPanel) {
            ((ExclusiveGatewayPanel) gateway).initBranches();
        }
    });
    return true;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) NotAuthorizedToOverrideException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NotAuthorizedToOverrideException) Element(org.jdom2.Element) Document(org.jdom2.Document) NoProcessSpecifiedException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NoProcessSpecifiedException)

Example 100 with Document

use of org.geotoolkit.sml.xml.v100.Document in project scylla by bptlab.

the class JDomTestClass method createEmpty.

public static void createEmpty() {
    FileWriter writer;
    // Namespace nsp = Namespace.getNamespace("bsim","http://bsim.hpi.uni-potsdam.de/scylla/simModel");
    // 
    // Element root = new Element("globalConfiguration",nsp);
    // Document d = new Document(root);
    // root.setAttribute("targetNamespace", "http://www.hpi.de");
    // Element rAO = new Element("resourceAssignmentOrder",nsp);
    // rAO.setText("priority,simulationTime,");
    // root.addContent(rAO);
    GlobalConfigurationCreator c = new GlobalConfigurationCreator();
    c.setId("This is an ID");
    c.addReferencedResourceAssignmentOrder("priority");
    c.addReferencedResourceAssignmentOrder("simulationTime");
    c.removeReferencedResourceAssignmentOrder("simulationTime");
    c.setSeed(1337);
    c.setTimeOffset(ZoneOffset.ofHoursMinutesSeconds(13, 37, 42));
    c.createTimetable("Hero");
    Timetable lazy = c.createTimetable("Lazy");
    c.deleteTimetable("Hero");
    c.deleteTimetable("Hero");
    TimetableItem item = lazy.addItem(DayOfWeek.MONDAY, DayOfWeek.FRIDAY, LocalTime.parse("13:37"), LocalTime.parse("20:35:37"));
    item.setFrom(DayOfWeek.THURSDAY);
    c.addResourceType("Student");
    c.addResourceType("Professor");
    // Nothing should happen
    c.addResourceType("Student");
    c.removeResourceType("Student");
    ResourceType student = c.addResourceType("Student");
    student.setName("True Hero");
    student.setDefaultTimeUnit(TimeUnit.MINUTES);
    student.setDefaultQuantity(100);
    student.setDefaultCost(12.50);
    student.addInstance("Anton");
    student.addInstance("Bert");
    student.getInstance("Anton").setCost(50);
    student.removeInstance("Bert");
    ResourceType prof = c.getResourceType("Professor");
    prof.setDefaultQuantity(1);
    prof.setDefaultCost(41.14);
    prof.setDefaultTimeUnit(TimeUnit.HOURS);
    c.validate();
    // 
    try {
        writer = new FileWriter("testFile.xml");
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(c.getDoc(), writer);
        outputter.output(c.getDoc(), System.out);
    // writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Element r = null;
    try {
        Document doc;
        SAXBuilder builder = new SAXBuilder();
        doc = builder.build("./samples/p2_normal.bpmn");
        r = doc.getRootElement();
    } catch (JDOMException | IOException e1) {
        e1.printStackTrace();
    }
    SimulationConfigurationCreator s = new SimulationConfigurationCreator();
    s.setId("This is the id");
    // s.setProcessRef("Process_2");
    s.setProcessInstances(10);
    s.setStartDateTime(ZonedDateTime.parse("2017-07-06T09:00:00.000+02:00"));
    s.setEndDateTime(ZonedDateTime.parse("2017-07-12T09:00:00.000+02:00"));
    s.setRandomSeed(1337);
    try {
        s.setModel(r, false);
    } catch (NoProcessSpecifiedException | NotAuthorizedToOverrideException e1) {
        e1.printStackTrace();
    }
    Distribution testDistribution = Distribution.create(DistributionType.BINOMIAL);
    testDistribution.setAttribute("amount", 5);
    testDistribution.setAttribute(0, 0.2);
    s.getStartEvent().setArrivalRateDistribution(testDistribution);
    Task t = (Task) s.getElement("Task_1tvvo6w");
    t.setDurationDistribution(Distribution.create(DistributionType.CONSTANT));
    t.getDurationDistribution().setAttribute("constantValue", 100);
    t.assignResource(student).setAmount(5);
    t.assignResource(prof).setAmount(5);
    t.getResource("Student").setAmount(13);
    t.deassignResource(prof.getId());
    t.getResource(student.getId()).setAssignmentPriority(5);
    t.assignResource(prof).setAmount(5);
    t.getResource("Professor").setAssignmentPriority(0);
    t.getResource(prof.getId()).removeAssignmentDefinition();
    t.deassignResource(prof.getId());
    for (ElementLink element : s.getElements()) {
        if (!(element instanceof Task))
            continue;
        Task task = (Task) element;
        Distribution d = Distribution.create(DistributionType.TRIANGULAR);
        d.setAttribute(0, 11);
        d.setAttribute(2, 33);
        d.setAttribute("peak", 22);
        task.setDurationDistribution(d);
        task.assignResource(prof).setAmount(3);
    }
    ExclusiveGateway g = null;
    for (ElementLink element : s.getElements()) {
        if (element instanceof ExclusiveGateway) {
            g = (ExclusiveGateway) element;
            break;
        }
    }
    g.setBranchingProbability("SequenceFlow_1237oxj", 1);
    for (String branch : g.getBranches()) {
        System.err.println(s.getFlowTarget(branch).el.getAttributeValue("name"));
    }
    try {
        writer = new FileWriter("testFile2.xml");
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(s.getDoc(), writer);
        outputter.output(s.getDoc(), System.out);
    // writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Timetable(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator.Timetable) XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) Task(de.hpi.bpt.scylla.creation.SimulationConfiguration.Task) FileWriter(java.io.FileWriter) Element(org.jdom2.Element) SimulationConfigurationCreator(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator) ResourceType(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator.ResourceType) GlobalConfigurationCreator(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) NoProcessSpecifiedException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NoProcessSpecifiedException) ExclusiveGateway(de.hpi.bpt.scylla.creation.SimulationConfiguration.ExclusiveGateway) NotAuthorizedToOverrideException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NotAuthorizedToOverrideException) Distribution(de.hpi.bpt.scylla.creation.SimulationConfiguration.Distribution) TimetableItem(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator.Timetable.TimetableItem)

Aggregations

Document (org.jdom2.Document)882 Element (org.jdom2.Element)491 Test (org.junit.Test)320 IOException (java.io.IOException)211 SAXBuilder (org.jdom2.input.SAXBuilder)207 XMLOutputter (org.jdom2.output.XMLOutputter)144 File (java.io.File)131 JDOMException (org.jdom2.JDOMException)120 InputStream (java.io.InputStream)61 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 ArrayList (java.util.ArrayList)52 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Path (java.nio.file.Path)46 HashMap (java.util.HashMap)46 List (java.util.List)36 Attribute (org.jdom2.Attribute)35 Document (com.google.cloud.language.v1.Document)34 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)34