Search in sources :

Example 1 with Recalculate

use of org.javarosa.core.model.condition.Recalculate in project javarosa by opendatakit.

the class FormDef method readExternal.

/**
 * Reads the form definition object from the supplied stream.
 * <p/>
 * Requires that the instance has been set to a prototype of the instance
 * that should be used for deserialization.
 *
 * @param dis - the stream to read from.
 * @throws IOException
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
@Override
public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOException, DeserializationException {
    setID(ExtUtil.readInt(dis));
    setName(ExtUtil.nullIfEmpty(ExtUtil.readString(dis)));
    setTitle((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
    setChildren((List<IFormElement>) ExtUtil.read(dis, new ExtWrapListPoly(), pf));
    setInstance((FormInstance) ExtUtil.read(dis, FormInstance.class, pf));
    setLocalizer((Localizer) ExtUtil.read(dis, new ExtWrapNullable(Localizer.class), pf));
    List<Condition> vcond = (List<Condition>) ExtUtil.read(dis, new ExtWrapList(Condition.class), pf);
    for (Condition condition : vcond) {
        addTriggerable(condition);
    }
    List<Recalculate> vcalc = (List<Recalculate>) ExtUtil.read(dis, new ExtWrapList(Recalculate.class), pf);
    for (Recalculate recalculate : vcalc) {
        addTriggerable(recalculate);
    }
    finalizeTriggerables();
    outputFragments = (List<IConditionExpr>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
    submissionProfiles = (HashMap<String, SubmissionProfile>) ExtUtil.read(dis, new ExtWrapMap(String.class, SubmissionProfile.class));
    formInstances = (HashMap<String, DataInstance>) ExtUtil.read(dis, new ExtWrapMap(String.class, new ExtWrapTagged()), pf);
    eventListeners = (HashMap<String, List<Action>>) ExtUtil.read(dis, new ExtWrapMap(String.class, new ExtWrapListPoly()), pf);
    extensions = (List<XFormExtension>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
    resetEvaluationContext();
}
Also used : Condition(org.javarosa.core.model.condition.Condition) IConditionExpr(org.javarosa.core.model.condition.IConditionExpr) DataInstance(org.javarosa.core.model.instance.DataInstance) Recalculate(org.javarosa.core.model.condition.Recalculate) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ExtWrapMap(org.javarosa.core.util.externalizable.ExtWrapMap) Localizer(org.javarosa.core.services.locale.Localizer) ExtWrapListPoly(org.javarosa.core.util.externalizable.ExtWrapListPoly) List(java.util.List) ArrayList(java.util.ArrayList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 2 with Recalculate

use of org.javarosa.core.model.condition.Recalculate in project javarosa by opendatakit.

the class StandardBindAttributesProcessor method createBinding.

DataBinding createBinding(IXFormParserFunctions parserFunctions, FormDef formDef, Collection<String> usedAttributes, Collection<String> passedThroughAttributes, Element element) {
    final DataBinding binding = new DataBinding();
    binding.setId(element.getAttributeValue("", ID_ATTR));
    final String nodeset = element.getAttributeValue(null, NODESET_ATTR);
    if (nodeset == null) {
        throw new XFormParseException("XForm Parse: <bind> without nodeset", element);
    }
    IDataReference ref;
    try {
        ref = new XPathReference(nodeset);
    } catch (XPathException xpe) {
        throw new XFormParseException(xpe.getMessage());
    }
    ref = parserFunctions.getAbsRef(ref, formDef);
    binding.setReference(ref);
    binding.setDataType(getDataType(element.getAttributeValue(null, "type")));
    String xpathRel = element.getAttributeValue(null, "relevant");
    if (xpathRel != null) {
        if ("true()".equals(xpathRel)) {
            binding.relevantAbsolute = true;
        } else if ("false()".equals(xpathRel)) {
            binding.relevantAbsolute = false;
        } else {
            Condition c = buildCondition(xpathRel, "relevant", ref);
            c = (Condition) formDef.addTriggerable(c);
            binding.relevancyCondition = c;
        }
    }
    String xpathReq = element.getAttributeValue(null, "required");
    if (xpathReq != null) {
        if ("true()".equals(xpathReq)) {
            binding.requiredAbsolute = true;
        } else if ("false()".equals(xpathReq)) {
            binding.requiredAbsolute = false;
        } else {
            Condition c = buildCondition(xpathReq, "required", ref);
            c = (Condition) formDef.addTriggerable(c);
            binding.requiredCondition = c;
        }
    }
    String xpathRO = element.getAttributeValue(null, "readonly");
    if (xpathRO != null) {
        if ("true()".equals(xpathRO)) {
            binding.readonlyAbsolute = true;
        } else if ("false()".equals(xpathRO)) {
            binding.readonlyAbsolute = false;
        } else {
            Condition c = buildCondition(xpathRO, "readonly", ref);
            c = (Condition) formDef.addTriggerable(c);
            binding.readonlyCondition = c;
        }
    }
    final String xpathConstr = element.getAttributeValue(null, "constraint");
    if (xpathConstr != null) {
        try {
            binding.constraint = new XPathConditional(xpathConstr);
        } catch (XPathSyntaxException xse) {
            throw new XFormParseException("bind for " + nodeset + " contains invalid constraint expression [" + xpathConstr + "] " + xse.getMessage());
        }
        binding.constraintMessage = element.getAttributeValue(NAMESPACE_JAVAROSA, "constraintMsg");
    }
    final String xpathCalc = element.getAttributeValue(null, "calculate");
    if (xpathCalc != null) {
        Recalculate r;
        try {
            r = buildCalculate(xpathCalc, ref);
        } catch (XPathSyntaxException xpse) {
            throw new XFormParseException("Invalid calculate for the bind attached to \"" + nodeset + "\" : " + xpse.getMessage() + " in expression " + xpathCalc);
        }
        r = (Recalculate) formDef.addTriggerable(r);
        binding.calculate = r;
    }
    binding.setPreload(element.getAttributeValue(NAMESPACE_JAVAROSA, "preload"));
    binding.setPreloadParams(element.getAttributeValue(NAMESPACE_JAVAROSA, "preloadParams"));
    saveUnusedAttributes(binding, element, usedAttributes, passedThroughAttributes);
    return binding;
}
Also used : Condition(org.javarosa.core.model.condition.Condition) XPathSyntaxException(org.javarosa.xpath.parser.XPathSyntaxException) Recalculate(org.javarosa.core.model.condition.Recalculate) XPathException(org.javarosa.xpath.XPathException) IDataReference(org.javarosa.core.model.IDataReference) DataBinding(org.javarosa.core.model.DataBinding) XPathConditional(org.javarosa.xpath.XPathConditional) XPathReference(org.javarosa.model.xform.XPathReference)

Example 3 with Recalculate

use of org.javarosa.core.model.condition.Recalculate in project javarosa by opendatakit.

the class FormDef method writeExternal.

/**
 * Writes the form definition object to the supplied stream.
 *
 * @param dos - the stream to write to.
 * @throws IOException
 */
@Override
public void writeExternal(DataOutputStream dos) throws IOException {
    ExtUtil.writeNumeric(dos, getID());
    ExtUtil.writeString(dos, ExtUtil.emptyIfNull(getName()));
    ExtUtil.write(dos, new ExtWrapNullable(getTitle()));
    ExtUtil.write(dos, new ExtWrapListPoly(getChildren()));
    ExtUtil.write(dos, getMainInstance());
    ExtUtil.write(dos, new ExtWrapNullable(localizer));
    List<Condition> conditions = dagImpl.getConditions();
    List<Recalculate> recalcs = dagImpl.getRecalculates();
    ExtUtil.write(dos, new ExtWrapList(conditions));
    ExtUtil.write(dos, new ExtWrapList(recalcs));
    ExtUtil.write(dos, new ExtWrapListPoly(outputFragments));
    ExtUtil.write(dos, new ExtWrapMap(submissionProfiles));
    // for support of multi-instance forms
    ExtUtil.write(dos, new ExtWrapMap(formInstances, new ExtWrapTagged()));
    ExtUtil.write(dos, new ExtWrapMap(eventListeners, new ExtWrapListPoly()));
    ExtUtil.write(dos, new ExtWrapListPoly(extensions));
}
Also used : Condition(org.javarosa.core.model.condition.Condition) ExtWrapListPoly(org.javarosa.core.util.externalizable.ExtWrapListPoly) Recalculate(org.javarosa.core.model.condition.Recalculate) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ExtWrapMap(org.javarosa.core.util.externalizable.ExtWrapMap) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Aggregations

Condition (org.javarosa.core.model.condition.Condition)3 Recalculate (org.javarosa.core.model.condition.Recalculate)3 ExtWrapList (org.javarosa.core.util.externalizable.ExtWrapList)2 ExtWrapListPoly (org.javarosa.core.util.externalizable.ExtWrapListPoly)2 ExtWrapMap (org.javarosa.core.util.externalizable.ExtWrapMap)2 ExtWrapNullable (org.javarosa.core.util.externalizable.ExtWrapNullable)2 ExtWrapTagged (org.javarosa.core.util.externalizable.ExtWrapTagged)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataBinding (org.javarosa.core.model.DataBinding)1 IDataReference (org.javarosa.core.model.IDataReference)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 DataInstance (org.javarosa.core.model.instance.DataInstance)1 Localizer (org.javarosa.core.services.locale.Localizer)1 XPathReference (org.javarosa.model.xform.XPathReference)1 XPathConditional (org.javarosa.xpath.XPathConditional)1 XPathException (org.javarosa.xpath.XPathException)1 XPathSyntaxException (org.javarosa.xpath.parser.XPathSyntaxException)1