use of org.javarosa.core.util.externalizable.ExtWrapList 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));
}
use of org.javarosa.core.util.externalizable.ExtWrapList 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");
}
}
use of org.javarosa.core.util.externalizable.ExtWrapList in project javarosa by opendatakit.
the class Triggerable method readExternal.
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
expr = (IConditionExpr) ExtUtil.read(in, new ExtWrapTagged(), pf);
contextRef = (TreeReference) ExtUtil.read(in, TreeReference.class, pf);
originalContextRef = (TreeReference) ExtUtil.read(in, TreeReference.class, pf);
List<TreeReference> tlist = (List<TreeReference>) ExtUtil.read(in, new ExtWrapList(TreeReference.class), pf);
targets = new ArrayList<TreeReference>(tlist);
}
use of org.javarosa.core.util.externalizable.ExtWrapList 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));
}
use of org.javarosa.core.util.externalizable.ExtWrapList 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);
}
Aggregations