Example usage for org.jdom2 Element getContentSize

List of usage examples for org.jdom2 Element getContentSize

Introduction

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

Prototype

@Override
    public int getContentSize() 

Source Link

Usage

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

License:Open Source License

private void addDefaultValuesAsRequired(Document dataDoc) {
    if (dataDoc == null)
        return;/*from   w ww . j  a  va2  s . co m*/
    Element dataElem = dataDoc.getRootElement();
    for (YParameter param : _decompositionPrototype.getOutputParameters().values()) {
        String defaultValue = param.getDefaultValue();
        if (!StringUtil.isNullOrEmpty(defaultValue)) {
            Element paramData = dataElem.getChild(param.getPreferredName());

            // if there's an element, but no value, add the default
            if (paramData != null) {
                if (StringUtil.isNullOrEmpty(paramData.getText())) {
                    paramData.setText(defaultValue);
                }
            }

            // else if there's no element at all, add it with the default value
            else {
                Element defElem = JDOMUtil
                        .stringToElement(StringUtil.wrap(defaultValue, param.getPreferredName()));
                defElem.setNamespace(dataElem.getNamespace());
                dataElem.addContent(Math.min(dataElem.getContentSize(), param.getOrdering()), defElem.detach());
            }
        }
    }
}

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

License:Open Source License

protected Element performDataExtraction(String expression, YParameter inputParam)
        throws YDataStateException, YQueryException {

    Element result = evaluateTreeQuery(expression, _net.getInternalDataDocument());

    // if the param id of empty complex type flag type, don't return the query result
    // as input data if the flag is not currently set
    if (inputParam.isEmptyTyped()) {
        if (!isPopulatedEmptyTypeFlag(expression))
            return null;
    }// www.ja  va  2 s  . c om

    // else if we have an empty element and the element is not mandatory, don't pass
    // the element out to the task as input data.
    else if ((!inputParam.isRequired()) && (result.getChildren().size() == 0)
            && (result.getContentSize() == 0)) {
        return null;
    }

    /**
     * AJH: Allow option to inhibit schema validation for outbound data.
     *      Ideally need to support this at task level.
     */
    if (_net.getSpecification().getSchemaVersion().isSchemaValidating() && (!skipOutboundSchemaChecks())) {
        performSchemaValidationOverExtractionResult(expression, inputParam, result);
    }
    return result;
}

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

License:Open Source License

public static WorkItemRecord unmarshalWorkItem(Element workItemElement) {
    if (workItemElement == null)
        return null;

    WorkItemRecord wir;/*from   www  . j  a v a  2s  .c o  m*/
    String status = workItemElement.getChildText("status");
    String caseID = workItemElement.getChildText("caseid");
    String taskID = workItemElement.getChildText("taskid");
    String specURI = workItemElement.getChildText("specuri");
    String enablementTime = workItemElement.getChildText("enablementTime");
    if (caseID != null && taskID != null && specURI != null && enablementTime != null && status != null) {

        wir = new WorkItemRecord(caseID, taskID, specURI, enablementTime, status);

        wir.setExtendedAttributes(unmarshalWorkItemAttributes(workItemElement));
        wir.setUniqueID(workItemElement.getChildText("uniqueid"));
        wir.setTaskName(workItemElement.getChildText("taskname"));
        wir.setDocumentation(workItemElement.getChildText("documentation"));
        wir.setAllowsDynamicCreation(workItemElement.getChildText("allowsdynamiccreation"));
        wir.setRequiresManualResourcing(workItemElement.getChildText("requiresmanualresourcing"));
        wir.setCodelet(workItemElement.getChildText("codelet"));
        wir.setDeferredChoiceGroupID(workItemElement.getChildText("deferredChoiceGroupID"));
        wir.setSpecVersion(workItemElement.getChildText("specversion"));
        wir.setFiringTime(workItemElement.getChildText("firingTime"));
        wir.setStartTime(workItemElement.getChildText("startTime"));
        wir.setCompletionTimeMs(workItemElement.getChildText("completionTime"));
        wir.setEnablementTimeMs(workItemElement.getChildText("enablementTimeMs"));
        wir.setFiringTimeMs(workItemElement.getChildText("firingTimeMs"));
        wir.setStartTimeMs(workItemElement.getChildText("startTimeMs"));
        wir.setCompletionTimeMs(workItemElement.getChildText("completionTimeMs"));
        wir.setTimerTrigger(workItemElement.getChildText("timertrigger"));
        wir.setTimerExpiry(workItemElement.getChildText("timerexpiry"));
        wir.setStartedBy(workItemElement.getChildText("startedBy"));
        wir.setTag(workItemElement.getChildText("tag"));
        wir.setCustomFormURL(workItemElement.getChildText("customform"));

        String specid = workItemElement.getChildText("specidentifier");
        if (specid != null)
            wir.setSpecIdentifier(specid);

        String resStatus = workItemElement.getChildText("resourceStatus");
        if (resStatus != null)
            wir.setResourceStatus(resStatus);

        Element data = workItemElement.getChild("data");
        if ((null != data) && (data.getContentSize() > 0))
            wir.setDataList((Element) data.getContent(0));

        Element updateddata = workItemElement.getChild("updateddata");
        if ((null != updateddata) && (updateddata.getContentSize() > 0))
            wir.setUpdatedData((Element) updateddata.getContent(0));

        Element logPredicate = workItemElement.getChild("logPredicate");
        if (logPredicate != null) {
            wir.setLogPredicateStarted(logPredicate.getChildText("start"));
            wir.setLogPredicateCompletion(logPredicate.getChildText("completion"));
        }

        return wir;
    }
    throw new IllegalArgumentException("Input element could not be parsed.");
}

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

License:Open Source License

private YLogDataItemList assembleLogDataItemList(Element data, boolean input) {
    YLogDataItemList result = new YLogDataItemList();
    if (data != null) {
        Map<String, YParameter> params = _engine.getParameters(_specID, getTaskID(), input);
        String descriptor = (input ? "Input" : "Output") + "VarAssignment";
        for (Element child : data.getChildren()) {
            String name = child.getName();
            String value = child.getValue();
            YParameter param = params.get(name);
            if (param != null) {
                String dataType = param.getDataTypeNameUnprefixed();

                // if a complex type, store the structure with the value
                if (child.getContentSize() > 1) {
                    value = JDOMUtil.elementToString(child);
                }//from  w  w  w .  ja v a 2 s  .  com
                result.add(new YLogDataItem(descriptor, name, value, dataType));

                // add any configurable logging predicates for this parameter
                YLogDataItem dataItem = getDataLogPredicate(param, input);
                if (dataItem != null)
                    result.add(dataItem);
            }
        }
    }
    return result;
}

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

License:Open Source License

/**
 *
 * @param eField/*  ww w  .j  av a2 s  .c o  m*/
 * @param data
 * @param ns
 * @param level
 * @return a list of 'DynFormField'
 */
private List<DynFormField> createField(Element eField, Element data, Namespace ns, int level)
        throws DynFormException {
    DynFormField field;
    List<DynFormField> result = new ArrayList<DynFormField>();

    // get eField element's attributes
    String minOccurs = eField.getAttributeValue("minOccurs");
    String maxOccurs = eField.getAttributeValue("maxOccurs");
    String name = eField.getAttributeValue("name");
    String type = getElementDataType(eField, ns);

    if (level == 0)
        _currentParam = _params.get(name);

    if (type == null) {

        // check for a simpleType definition
        Element simple = eField.getChild("simpleType", ns);
        if (simple != null) {
            field = addField(name, null, data, minOccurs, maxOccurs, level);
            applySimpleTypeFacets(simple, ns, field);
            result.add(field);
        } else {
            // check for empty complex type (flag defn)
            Element complex = eField.getChild("complexType", ns);
            if ((complex != null) && complex.getContentSize() == 0) {
                field = addField(name, null, data, minOccurs, maxOccurs, level);
                field.setEmptyComplexTypeFlag(true);
                if ((data != null) && (data.getChild(name) != null)) {
                    field.setValue("true");
                }
                result.add(field);
            } else {
                // new populated complex type - recurse in a new field list
                String groupID = getNextGroupID();
                List<Element> dataList = (data != null) ? data.getChildren(name) : null;
                if ((dataList != null) && (!dataList.isEmpty())) {
                    for (Element var : dataList) {
                        field = addGroupField(name, eField, ns, var, minOccurs, maxOccurs, level);
                        field.setGroupID(groupID);
                        result.add(field);
                    }
                } else {
                    field = addGroupField(name, eField, ns, null, minOccurs, maxOccurs, level);
                    field.setGroupID(groupID);
                    result.add(field);
                }
            }
        }
    } else {
        // a plain element
        result.addAll(addElementField(name, type, data, minOccurs, maxOccurs, level));
    }

    return result;
}

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

License:Open Source License

private int getInitialInstanceCount(String min, Element data, String dataName) {
    int dataCount = 1;
    int minOccurs = Math.max(SubPanelController.convertOccurs(min), 1);
    if ((data != null) && (data.getContentSize() > 1)) {
        dataCount = data.getChildren(dataName).size();
    }/*w ww  .  j a  v a 2 s  . com*/
    return Math.max(minOccurs, dataCount);
}

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 av a2 s  . co 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

public Map<String, FormParameter> getWorkItemParamsInfo(WorkItemRecord wir) throws IOException, JDOMException {
    Map<String, FormParameter> inputs, outputs;
    TaskInformation taskInfo = getTaskInformation(wir);
    // map the params
    inputs = mapParamList(taskInfo.getParamSchema().getInputParams());
    outputs = mapParamList(taskInfo.getParamSchema().getOutputParams());

    // if param is only in input list, mark it as input-only
    for (String name : inputs.keySet()) {
        if (!outputs.containsKey(name)) {
            inputs.get(name).setInputOnly(true);
        }//ww  w  .ja  v a  2  s  . co m
    }

    // combine the two maps
    if (outputs != null)
        outputs.putAll(inputs);
    else
        outputs = inputs;

    // now map data values to params
    Element itemData;
    if (wir.isEdited()) {
        wir = _workItemCache.get(wir.getID()); // refresh data list if required
        itemData = wir.getUpdatedData();
    } else
        itemData = JDOMUtil.stringToElement(wir.getDataListString());

    for (String name : outputs.keySet()) {
        Element data = itemData.getChild(name);
        if (data != null) {
            if (data.getContentSize() > 0) // complex type
                outputs.get(name).setValue(JDOMUtil.elementToStringDump(data));
            else // simple type
                outputs.get(name).setValue(itemData.getText());
        }
    }

    return outputs;
}

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   ww w.  j a v  a  2  s.  co  m*/
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;
}

From source file:org.yawlfoundation.yawl.worklet.WorkletService.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 ww. ja v a  2  s.  co  m
public Element updateDataList(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 {
            // if the item is not in the 'in' list, add it.
            result.getChildren().add(e.clone());
        }
    }

    return result;
}