Search in sources :

Example 16 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class ItemsetBinding method writeExternal.

public void writeExternal(DataOutputStream out) throws IOException {
    ExtUtil.write(out, new ExtWrapTagged(nodesetExpr));
    ExtUtil.write(out, contextRef);
    ExtUtil.write(out, new ExtWrapTagged(labelExpr));
    ExtUtil.write(out, new ExtWrapNullable(valueExpr == null ? null : new ExtWrapTagged(valueExpr)));
    ExtUtil.write(out, new ExtWrapNullable(copyExpr == null ? null : new ExtWrapTagged(copyExpr)));
    ExtUtil.writeBool(out, labelIsItext);
    ExtUtil.writeBool(out, copyMode);
}
Also used : ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 17 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class QuestionDef method readExternal.

@Override
public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOException, DeserializationException {
    try {
        setID(ExtUtil.readInt(dis));
        binding = (IDataReference) ExtUtil.read(dis, new ExtWrapNullable(new ExtWrapTagged()), pf);
        setAppearanceAttr((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
        setTextID((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
        setLabelInnerText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
        setHelpText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
        setHelpTextID((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
        setHelpInnerText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
        setControlType(ExtUtil.readInt(dis));
        additionalAttributes = ExtUtil.readAttributes(dis, null);
        choices = (List<SelectChoice>) ExtUtil.nullIfEmpty((List<SelectChoice>) ExtUtil.read(dis, new ExtWrapList(SelectChoice.class), pf));
        for (int i = 0; i < getNumChoices(); i++) {
            choices.get(i).setIndex(i);
        }
        setDynamicChoices((ItemsetBinding) ExtUtil.read(dis, new ExtWrapNullable(ItemsetBinding.class)));
        osmTags = (List<OSMTag>) ExtUtil.nullIfEmpty((List<OSMTag>) ExtUtil.read(dis, new ExtWrapList(OSMTag.class), pf));
    } catch (OutOfMemoryError e) {
        throw new DeserializationException("serialization format change caused misalignment and out-of-memory error");
    }
}
Also used : OSMTag(org.javarosa.core.model.osm.OSMTag) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) DeserializationException(org.javarosa.core.util.externalizable.DeserializationException) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 18 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class TreeElement method readExternal.

/* ==== SERIALIZATION ==== */
/*
     * TODO:
     *
     * this new serialization scheme is kind of lame. ideally, we shouldn't have
     * to sub-class TreeElement at all; we should have an API that can
     * seamlessly represent complex data model objects (like weight history or
     * immunizations) as if they were explicity XML subtrees underneath the
     * parent TreeElement
     *
     * failing that, we should wrap this scheme in an ExternalizableWrapper
     */
@Override
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
    name = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    multiplicity = ExtUtil.readInt(in);
    flags = ExtUtil.readInt(in);
    value = (IAnswerData) ExtUtil.read(in, new ExtWrapNullable(new ExtWrapTagged()), pf);
    // child
    if (!ExtUtil.readBool(in)) {
        // 1.
        // todo is this needed?
        children.clear();
    } else {
        // 2.
        int numChildren = (int) ExtUtil.readNumeric(in);
        children.clear();
        // 3.
        List<TreeElement> newChildren = new ArrayList<>(numChildren);
        for (int i = 0; i < numChildren; ++i) {
            boolean normal = ExtUtil.readBool(in);
            TreeElement child;
            if (normal) {
                // 3.1
                child = new TreeElement();
                child.readExternal(in, pf);
            } else {
                // 3.2
                child = (TreeElement) ExtUtil.read(in, new ExtWrapTagged(), pf);
            }
            child.setParent(this);
            newChildren.add(child);
        }
        children.addAll(newChildren);
    }
    // end Jan 22, 2009
    dataType = ExtUtil.readInt(in);
    instanceName = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    constraint = (Constraint) ExtUtil.read(in, new ExtWrapNullable(Constraint.class), pf);
    preloadHandler = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    preloadParams = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    namespace = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    bindAttributes = ExtUtil.readAttributes(in, this);
    attributes = ExtUtil.readAttributes(in, this);
}
Also used : Constraint(org.javarosa.core.model.condition.Constraint) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ArrayList(java.util.ArrayList) Constraint(org.javarosa.core.model.condition.Constraint) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 19 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class CompactInstanceWrapper method writeExternal.

/**
 * serialize a compact instance
 */
public void writeExternal(DataOutputStream out) throws IOException {
    if (instance == null) {
        throw new RuntimeException("instance has not yet been set via setData()");
    }
    ExtUtil.writeNumeric(out, instance.getFormId());
    ExtUtil.writeNumeric(out, instance.getID());
    ExtUtil.write(out, new ExtWrapNullable(instance.getDateSaved()));
    writeTreeElement(out, instance.getRoot());
}
Also used : ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 20 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class DataBinding method writeExternal.

/* (non-Javadoc)
     * @see org.javarosa.core.services.storage.utilities.Externalizable#writeExternal(java.io.DataOutputStream)
     */
public void writeExternal(DataOutputStream out) throws IOException {
    ExtUtil.write(out, new ExtWrapNullable(getId()));
    ExtUtil.writeNumeric(out, getDataType());
    ExtUtil.write(out, new ExtWrapNullable(getPreload()));
    ExtUtil.write(out, new ExtWrapNullable(getPreloadParams()));
    ExtUtil.write(out, new ExtWrapTagged(ref));
// don't bother writing relevancy/required/readonly/constraint/calculate/additionalAttrs right now; they're only used during parse anyway
}
Also used : ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Aggregations

ExtWrapNullable (org.javarosa.core.util.externalizable.ExtWrapNullable)27 ExtWrapTagged (org.javarosa.core.util.externalizable.ExtWrapTagged)13 ExtWrapListPoly (org.javarosa.core.util.externalizable.ExtWrapListPoly)9 ExtWrapList (org.javarosa.core.util.externalizable.ExtWrapList)7 ExtWrapMap (org.javarosa.core.util.externalizable.ExtWrapMap)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Date (java.util.Date)3 Condition (org.javarosa.core.model.condition.Condition)2 Recalculate (org.javarosa.core.model.condition.Recalculate)2 DeserializationException (org.javarosa.core.util.externalizable.DeserializationException)2 HashMap (java.util.HashMap)1 Constraint (org.javarosa.core.model.condition.Constraint)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 DataInstance (org.javarosa.core.model.instance.DataInstance)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 OSMTag (org.javarosa.core.model.osm.OSMTag)1 Localizer (org.javarosa.core.services.locale.Localizer)1 OrderedMap (org.javarosa.core.util.OrderedMap)1 ExtWrapBase (org.javarosa.core.util.externalizable.ExtWrapBase)1