Example usage for org.jdom2 Element clone

List of usage examples for org.jdom2 Element clone

Introduction

In this page you can find the example usage for org.jdom2 Element clone.

Prototype

@Override
public Element clone() 

Source Link

Document

This returns a deep clone of this element.

Usage

From source file:org.yawlfoundation.yawl.elements.YTask.java

License:Open Source License

protected Element performExternalDataExtraction(String expression, YParameter inputParam)
        throws YStateException, YDataStateException {
    Element result = null;
    if (ExternalDBGatewayFactory.isExternalDBMappingExpression(expression)) {
        AbstractExternalDBGateway extractor = ExternalDBGatewayFactory.getInstance(expression);
        if (extractor != null) {
            Element netData = _net.getInternalDataDocument().getRootElement();
            result = extractor.populateTaskParameter(this, inputParam, netData);
        }/*from  w  w  w  . ja va 2s. c  o m*/
    }
    if (result != null) {
        if (_net.getSpecification().getSchemaVersion().isSchemaValidating()) {
            if (!skipOutboundSchemaChecks()) {

                // remove any dynamic attributes for schema checking
                Element resultSansAttributes = JDOMUtil.stripAttributes((Element) result.clone());
                performSchemaValidationOverExtractionResult(expression, inputParam, resultSansAttributes);
            }
        }
    } else {
        throw new YStateException("External data pull failure.");
    }
    return result;
}

From source file:org.yawlfoundation.yawl.elements.YTask.java

License:Open Source License

protected void performSchemaValidationOverExtractionResult(String expression, YParameter param, Element result)
        throws YDataStateException {
    Element tempRoot = new Element(_decompositionPrototype.getID());
    try {/*from   ww w .j  a va  2  s.co m*/
        tempRoot.addContent(result.clone());
        _net.getSpecification().getDataValidator().validate(param, tempRoot, getID());
    } catch (YDataValidationException e) {
        YDataStateException f = new YDataStateException(expression,
                _net.getInternalDataDocument().getRootElement(),
                _net.getSpecification().getDataValidator().getSchema(), tempRoot, e.getErrors(), getID(),
                "BAD PROCESS DEFINITION. " + "Data extraction failed schema validation at task starting.");
        f.setStackTrace(e.getStackTrace());
        throw f;
    }
}

From source file:org.yawlfoundation.yawl.engine.interfce.Marshaller.java

License:Open Source License

public static String getMergedOutputData(Element inputData, Element outputData) {
    try {//w w  w .  j a v  a  2s .  c  om
        Element merged = inputData.clone();
        JDOMUtil.stripAttributes(merged);
        JDOMUtil.stripAttributes(outputData);

        List<Element> children = outputData.getChildren();

        // iterate through the output vars and add them to the merged doc.
        for (int i = children.size() - 1; i >= 0; i--) {
            Element child = children.get(i);

            // the input data will be removed from the merged doc and
            // the output data will be added.
            merged.removeChild(child.getName());
            merged.addContent(child.detach());
        }
        return JDOMUtil.elementToString(merged);
    } catch (Exception e) {
        return "";
    }
}

From source file:org.yawlfoundation.yawl.engine.interfce.Marshaller.java

License:Open Source License

public static String filterDataAgainstOutputParams(String mergedOutputData, List<YParameter> outputParams)
        throws JDOMException, IOException {

    //set up output document
    Element outputData = JDOMUtil.stringToElement(mergedOutputData);
    Element filteredData = new Element(outputData.getName());

    Collections.sort(outputParams);
    for (YParameter parameter : outputParams) {
        Element child = outputData.getChild(parameter.getPreferredName());
        if (null != child) {
            filteredData.addContent(child.clone());
        }// ww  w .jav  a  2s  .  c o  m
    }
    return JDOMUtil.elementToString(filteredData);
}

From source file:org.yawlfoundation.yawl.engine.YEngine.java

License:Open Source License

/** updates the case data with the data passed after completion of an exception handler */
public boolean updateCaseData(String idStr, String data) throws YPersistenceException {
    YNetRunner runner = _netRunnerRepository.get(idStr);
    if (runner != null && data != null) {
        synchronized (_pmgr) {
            startTransaction();/* ww  w  . ja v a  2  s.co m*/
            try {
                YNet net = runner.getNet();
                Element updatedVars = JDOMUtil.stringToElement(data);
                for (Element eVar : updatedVars.getChildren()) {
                    net.assignData(_pmgr, eVar.clone());
                }
                commitTransaction();
                return true;
            } catch (Exception e) {
                rollbackTransaction();
                _logger.error("Problem updating Case Data for case " + idStr, e);
            }
        }
    }
    return false;
}

From source file:org.yawlfoundation.yawl.engine.YEngine.java

License:Open Source License

private String mapOutputDataForSkippedWorkItem(YWorkItem workItem, String data) throws YStateException {

    // get input and output params for task
    YSpecificationID specID = workItem.getSpecificationID();
    String taskID = workItem.getTaskID();
    YTask task = getTaskDefinition(specID, taskID);

    Map<String, YParameter> inputs = task.getDecompositionPrototype().getInputParameters();
    Map<String, YParameter> outputs = task.getDecompositionPrototype().getOutputParameters();

    if (outputs.isEmpty()) { // no output data to map
        return StringUtil.wrap("", taskID);
    }/*from  w  ww .ja  va  2  s  . com*/

    // map data values to params
    Element itemData = JDOMUtil.stringToElement(data);
    Element outputData = itemData != null ? itemData.clone() : new Element(taskID);

    // remove the input-only params from output data
    for (String name : inputs.keySet())
        if (outputs.get(name) == null)
            outputData.removeChild(name);

    // for each output param:
    //   1. if matching output Element, do nothing
    //   2. else if matching input param, use its value
    //   3. else if default value specified, use its value
    //   4. else use default value for the param's data type
    List<YParameter> outParamList = new ArrayList<YParameter>(outputs.values());
    Collections.sort(outParamList); // get in right order
    for (YParameter outParam : outParamList) {
        String name = outParam.getName();
        if (outputData.getChild(name) != null)
            continue; // matching I/O element

        // the output param has no corresponding input param, so add an element
        String defaultValue = outParam.getDefaultValue();
        if (defaultValue == null) {
            String typeName = outParam.getDataTypeName();
            if (!XSDType.isBuiltInType(typeName)) {
                throw new YStateException(
                        String.format("Could not skip work item [%s]: Output-Only parameter [%s]"
                                + " requires a default value.", workItem.getIDString(), name));
            }
            defaultValue = JDOMUtil.getDefaultValueForType(typeName);
        }
        Element outData = new Element(name);
        outData.setText(defaultValue);
        outputData.addContent(outData);
    }

    return JDOMUtil.elementToStringDump(outputData);
}

From source file:org.yawlfoundation.yawl.procletService.state.Performatives.java

License:Open Source License

public static String calculateContent(List<EntityID> eids, WorkItemRecord wir) {
    myLog.debug("CALCULATECONTENT");
    myLog.debug("eids:" + eids);
    Element dataList = wir.getDataList();
    if (dataList != null) {
        dataList = dataList.clone();
        myLog.debug("dataList:" + JDOMUtil.elementToString(dataList));
        Element eidData = dataList.getChild("entities");
        List<Element> eltsRemove = new ArrayList<Element>();
        if (eidData != null) {
            myLog.debug("have entities");
            List<Element> children = eidData.getChildren("entity");
            for (Element child : children) {
                myLog.debug("have entity");
                Element emid = child.getChild("entity_id");
                String value = emid.getValue().trim();
                myLog.debug("value:" + value);
                // check if this one occurs in eids
                boolean match = false;
                for (EntityID eid : eids) {
                    if (eid.getEmid().getValue().equals(value)) {
                        // match
                        myLog.debug("found match");
                        match = true;/*from  w w  w  . j  av  a  2 s.  c o m*/
                        break;
                    }
                }
                if (!match) {
                    eltsRemove.add(child);
                }
            }
        }
        // remove what is not needed
        myLog.debug("eltsRemove:" + eltsRemove.toString());
        Element eidData2 = dataList.getChild("entities");
        if (eidData != null) {
            myLog.debug("have entities");
            for (Element eltSave : eltsRemove) {
                eidData2.removeContent(eltSave);
            }
        }
        //      // create output
        //      Element output = new Element("entities");
        //      for (Element elt : eltsSave) {
        //         output.addContent(elt);
        //      }
        String outputStr = JDOMUtil.elementToString(eidData2);
        myLog.debug("outputStr:" + outputStr);
        return outputStr;
    } else {
        // get from the graphs which entities it concerns
        List<EntityMID> emids = new ArrayList<EntityMID>();
        myLog.debug("wir:" + wir);
        List<InteractionGraph> graphs = InteractionGraphs.getInstance().getGraphs();
        for (InteractionGraph graph : graphs) {
            if (!graph.getEntityMID().getValue().contains("TEMP")) {
                for (InteractionArc arc : graph.getArcs()) {
                    myLog.debug("arc:" + arc);
                    // check the tail
                    if (arc.getTail().getClassID().equals(wir.getSpecURI())
                            && arc.getTail().getProcletID().equals(wir.getCaseID())
                            && arc.getTail().getBlockID().equals(wir.getTaskID())) {
                        myLog.debug("in loop");
                        EntityMID emid = arc.getEntityID().getEmid();
                        // check if not already in emids
                        boolean check = false;
                        for (EntityMID emidC : emids) {
                            if (emidC.getValue().equals(emid.getValue())) {
                                check = true;
                            }
                        }
                        if (!check) {
                            emids.add(emid);
                            myLog.debug("emid added:" + emid);
                        }
                    }
                }
            }
        }
        // have the relevant emids
        Element newEntsElt = new Element("entities");
        for (EntityMID emid : emids) {
            Element newEntElt = new Element("entity");
            Element newEidElt = new Element("entity_id");
            newEidElt.setText(emid.getValue());
            newEntElt.addContent(newEidElt);
            newEntsElt.addContent(newEntElt);
        }
        String outputStr = JDOMUtil.elementToString(newEntsElt);
        myLog.debug("outputStr:" + outputStr);
        return outputStr;
    }
}

From source file:org.yawlfoundation.yawl.resourcing.codelets.XQueryEvaluator.java

License:Open Source License

public Element execute(Element inData, List<YParameter> inParams, List<YParameter> outParams)
        throws CodeletExecutionException {

    if (outParams == null) {
        String msg = "Cannot perform evaluation: Missing or empty output parameter list.";
        throw new CodeletExecutionException(msg);
    }//from w ww . j  a v  a  2s  . c  o m

    this.setInputs(inData, inParams, outParams);

    // convert input vars to a Doc
    Document dataDoc = new Document(inData.clone());

    String query = (String) getParameterValue("query");
    String output = evaluateQuery(query, dataDoc);

    setParameterValue("result", output);
    return getOutputData();
}

From source file:org.yawlfoundation.yawl.resourcing.jsf.dynform.DynFormFieldAssembler.java

License:Open Source License

private Element getIteratedContent(Element data, int index, String name) {
    Element result = null;// w  w  w .  j  a va2 s. c o m
    if ((data != null) && (index < data.getContentSize())) {
        List<Element> relevantChildren = data.getChildren(name);
        result = new Element(data.getName());
        Element iteratedContent = relevantChildren.get(index);
        result.addContent(iteratedContent.clone());
    }
    return result;
}

From source file:org.yawlfoundation.yawl.resourcing.ResourceManager.java

License:Open Source License

/**
 * updates the input datalist with the changed data in the output datalist
 *
 * @param in  - the JDOM Element containing the input params
 * @param out - the JDOM Element containing the output params
 * @return a JDOM Element with the data updated
 *//*from  w w  w  .j a v a 2 s  .  c  om*/
private Element updateOutputDataList(Element in, Element out) {

    // get a copy of the 'in' list
    Element result = in.clone();

    // for each child in 'out' list, get its value and copy to 'in' list
    for (Element e : out.getChildren()) {

        // if there's a matching 'in' data item, update its value
        Element resData = result.getChild(e.getName());
        if (resData != null) {
            if (resData.getContentSize() > 0)
                resData.setContent(e.cloneContent());
            else
                resData.setText(e.getText());
        } else {
            result.addContent(e.clone());
        }
    }

    return result;
}