Search in sources :

Example 26 with ExtWrapTagged

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

the class Triggerable method writeExternal.

public void writeExternal(DataOutputStream out) throws IOException {
    ExtUtil.write(out, new ExtWrapTagged(expr));
    ExtUtil.write(out, contextRef);
    ExtUtil.write(out, originalContextRef);
    List<TreeReference> tlist = new ArrayList<TreeReference>(targets);
    ExtUtil.write(out, new ExtWrapList(tlist));
}
Also used : TreeReference(org.javarosa.core.model.instance.TreeReference) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ArrayList(java.util.ArrayList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList)

Example 27 with ExtWrapTagged

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

the class MultiPointerAnswerData method readExternal.

@Override
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
    int length = in.readInt();
    data = new IDataPointer[length];
    for (int i = 0; i < data.length; ++i) {
        data[i] = (IDataPointer) ExtUtil.read(in, new ExtWrapTagged());
    }
}
Also used : ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged)

Example 28 with ExtWrapTagged

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

the class ExternalizableTest method doTests.

public void doTests() {
    // base types (built-in + externalizable)
    testExternalizable("string", String.class);
    testExternalizable(new Byte((byte) 0), Byte.class);
    testExternalizable(new Byte((byte) 0x55), Byte.class);
    testExternalizable(new Byte((byte) 0xe9), Byte.class);
    testExternalizable(new Short((short) 0), Short.class);
    testExternalizable(new Short((short) -12345), Short.class);
    testExternalizable(new Short((short) 12345), Short.class);
    testExternalizable(new Integer(0), Integer.class);
    testExternalizable(new Integer(1234567890), Integer.class);
    testExternalizable(new Integer(-1234567890), Integer.class);
    testExternalizable(new Long(0), Long.class);
    testExternalizable(new Long(1234567890123456789l), Long.class);
    testExternalizable(new Long(-1234567890123456789l), Long.class);
    testExternalizable(Boolean.TRUE, Boolean.class);
    testExternalizable(Boolean.FALSE, Boolean.class);
    testExternalizable(new Character('e'), Character.class);
    testExternalizable(new Float(123.45e6), Float.class);
    testExternalizable(new Double(123.45e6), Double.class);
    testExternalizable(new Date(), Date.class);
    testExternalizable(new SampleExtz("your", "mom"), SampleExtz.class);
    // base wrapper (end user will never use)
    testExternalizable("string", new ExtWrapBase(String.class));
    testExternalizable(new ExtWrapBase("string"), String.class);
    // nullables on base types
    testExternalizable(new ExtWrapNullable((String) null), new ExtWrapNullable(String.class));
    testExternalizable(new ExtWrapNullable("string"), new ExtWrapNullable(String.class));
    testExternalizable(new ExtWrapNullable((Integer) null), new ExtWrapNullable(Integer.class));
    testExternalizable(new ExtWrapNullable(new Integer(17)), new ExtWrapNullable(Integer.class));
    testExternalizable(new ExtWrapNullable((SampleExtz) null), new ExtWrapNullable(SampleExtz.class));
    testExternalizable(new ExtWrapNullable(new SampleExtz("hi", "there")), new ExtWrapNullable(SampleExtz.class));
    // lists of base types
    List<Integer> v = new ArrayList<Integer>();
    v.add(new Integer(27));
    v.add(new Integer(-73));
    v.add(new Integer(1024));
    v.add(new Integer(66066066));
    testExternalizable(new ExtWrapList(v), new ExtWrapList(Integer.class));
    List<String> vs = new ArrayList<String>();
    vs.add("alpha");
    vs.add("beta");
    vs.add("gamma");
    testExternalizable(new ExtWrapList(vs), new ExtWrapList(String.class));
    List<Object> w = new ArrayList<Object>();
    w.add(new SampleExtz("where", "is"));
    w.add(new SampleExtz("the", "beef"));
    testExternalizable(new ExtWrapList(w), new ExtWrapList(SampleExtz.class));
    // nullable lists; lists of nullables (no practical use)
    testExternalizable(new ExtWrapNullable(new ExtWrapList(v)), new ExtWrapNullable(new ExtWrapList(Integer.class)));
    testExternalizable(new ExtWrapNullable((ExtWrapList) null), new ExtWrapNullable(new ExtWrapList(Integer.class)));
    testExternalizable(new ExtWrapList(v, new ExtWrapNullable()), new ExtWrapList(new ExtWrapNullable(Integer.class)));
    // empty lists (base types)
    testExternalizable(new ExtWrapList(new ArrayList<String>()), new ExtWrapList(String.class));
    // sub-types don't matter for empties
    testExternalizable(new ExtWrapList(new ArrayList(), new ExtWrapBase(Integer.class)), new ExtWrapList(String.class));
    // lists of lists (including empties)
    ArrayList x = new ArrayList();
    x.add(new Integer(-35));
    x.add(new Integer(-31415926));
    ArrayList y = new ArrayList();
    y.add(v);
    y.add(x);
    y.add(new ArrayList());
    // risky to not specify 'leaf' type (Integer), but works in limited situations
    testExternalizable(new ExtWrapList(y, new ExtWrapList()), new ExtWrapList(new ExtWrapList(Integer.class)));
    // same as above
    testExternalizable(new ExtWrapList(new ArrayList(), new ExtWrapList()), new ExtWrapList(new ExtWrapList(Integer.class)));
    // tagged base types
    testExternalizable(new ExtWrapTagged("string"), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new Integer(5000)), new ExtWrapTagged());
    // tagged custom type
    PrototypeFactory pf = new PrototypeFactory();
    pf.addClass(SampleExtz.class);
    testExternalizable(new ExtWrapTagged(new SampleExtz("bon", "jovi")), new ExtWrapTagged(), pf);
    // tagged list (base type)
    testExternalizable(new ExtWrapTagged(new ExtWrapList(v)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapList(w)), new ExtWrapTagged(), pf);
    // tagged nullables and compound lists
    testExternalizable(new ExtWrapTagged(new ExtWrapNullable("string")), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapNullable((String) null)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapList(y, new ExtWrapList(Integer.class))), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapList(new ArrayList(), new ExtWrapList(Integer.class))), new ExtWrapTagged());
    // polymorphic lists
    List a = new ArrayList();
    a.add(new Integer(47));
    a.add("string");
    a.add(Boolean.FALSE);
    a.add(new SampleExtz("hello", "dolly"));
    testExternalizable(new ExtWrapListPoly(a), new ExtWrapListPoly(), pf);
    testExternalizable(new ExtWrapTagged(new ExtWrapListPoly(a)), new ExtWrapTagged(), pf);
    // polymorphic list with complex sub-types
    // note: must manually wrap children in polymorphic lists
    a.add(new ExtWrapList(y, new ExtWrapList(Integer.class)));
    testExternalizable(new ExtWrapListPoly(a), new ExtWrapListPoly(), pf);
    testExternalizable(new ExtWrapListPoly(new ArrayList()), new ExtWrapListPoly());
    // hashtables
    OrderedMap oh = new OrderedMap();
    testExternalizable(new ExtWrapMap(oh), new ExtWrapMap(String.class, Integer.class, ExtWrapMap.TYPE_ORDERED));
    testExternalizable(new ExtWrapMapPoly(oh), new ExtWrapMapPoly(Date.class, true));
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(oh)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapMapPoly(oh)), new ExtWrapTagged());
    oh.put("key1", new SampleExtz("a", "b"));
    oh.put("key2", new SampleExtz("c", "d"));
    oh.put("key3", new SampleExtz("e", "f"));
    testExternalizable(new ExtWrapMap(oh), new ExtWrapMap(String.class, SampleExtz.class, ExtWrapMap.TYPE_ORDERED), pf);
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(oh)), new ExtWrapTagged(), pf);
    HashMap h = new HashMap();
    testExternalizable(new ExtWrapMap(h), new ExtWrapMap(String.class, Integer.class));
    testExternalizable(new ExtWrapMapPoly(h), new ExtWrapMapPoly(Date.class));
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(h)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapMapPoly(h)), new ExtWrapTagged());
    h.put("key1", new SampleExtz("e", "f"));
    h.put("key2", new SampleExtz("c", "d"));
    h.put("key3", new SampleExtz("a", "b"));
    testExternalizable(new ExtWrapMap(h), new ExtWrapMap(String.class, SampleExtz.class), pf);
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(h)), new ExtWrapTagged(), pf);
    HashMap j = new HashMap();
    j.put(new Integer(17), h);
    j.put(new Integer(-3), h);
    HashMap k = new HashMap();
    k.put("key", j);
    testExternalizable(new ExtWrapMap(k, new ExtWrapMap(Integer.class, new ExtWrapMap(String.class, SampleExtz.class))), new ExtWrapMap(String.class, new ExtWrapMap(Integer.class, new ExtWrapMap(String.class, SampleExtz.class))), // note: this example contains mixed hashtable types; would choke if we used a tagging wrapper
    pf);
    OrderedMap m = new OrderedMap();
    m.put("a", "b");
    m.put("b", new Integer(17));
    m.put("c", new Short((short) -443));
    m.put("d", new SampleExtz("boris", "yeltsin"));
    m.put("e", new ExtWrapList(vs));
    testExternalizable(new ExtWrapMapPoly(m), new ExtWrapMapPoly(String.class, true), pf);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExtWrapMap(org.javarosa.core.util.externalizable.ExtWrapMap) ExtWrapListPoly(org.javarosa.core.util.externalizable.ExtWrapListPoly) ArrayList(java.util.ArrayList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) List(java.util.List) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) Date(java.util.Date) ExtWrapBase(org.javarosa.core.util.externalizable.ExtWrapBase) PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) OrderedMap(org.javarosa.core.util.OrderedMap) ExtWrapMapPoly(org.javarosa.core.util.externalizable.ExtWrapMapPoly)

Example 29 with ExtWrapTagged

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

the class XPathParseTest method testXPathValid.

private void testXPathValid(String expr, String expected) {
    try {
        XPathExpression xpe = XPathParseTool.parseXPath(expr);
        String result = (xpe != null ? xpe.toString() : null);
        if (result == null || !result.equals(expected)) {
            fail("XPath Parse Failed! Incorrect parse tree." + "\n    expression:[" + expr + "]" + "\n    expected:[" + expected + "]" + "\n    result:[" + result + "]");
        }
        // test serialization of parse tree
        ExternalizableTest.testExternalizable(new ExtWrapTagged(xpe), new ExtWrapTagged(), pf, this, "XPath");
    } catch (XPathSyntaxException xse) {
        fail("XPath Parse Failed! Unexpected syntax error." + "\n    expression:[" + expr + "]");
    }
}
Also used : XPathExpression(org.javarosa.xpath.expr.XPathExpression) XPathSyntaxException(org.javarosa.xpath.parser.XPathSyntaxException) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged)

Aggregations

ExtWrapTagged (org.javarosa.core.util.externalizable.ExtWrapTagged)29 ExtWrapNullable (org.javarosa.core.util.externalizable.ExtWrapNullable)13 ExtWrapList (org.javarosa.core.util.externalizable.ExtWrapList)7 ExtWrapListPoly (org.javarosa.core.util.externalizable.ExtWrapListPoly)7 ArrayList (java.util.ArrayList)6 ExtWrapMap (org.javarosa.core.util.externalizable.ExtWrapMap)5 List (java.util.List)4 Condition (org.javarosa.core.model.condition.Condition)2 Recalculate (org.javarosa.core.model.condition.Recalculate)2 TreeReference (org.javarosa.core.model.instance.TreeReference)2 DeserializationException (org.javarosa.core.util.externalizable.DeserializationException)2 Date (java.util.Date)1 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 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