public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { if (in.readByte() == (byte) 0x00) { d = ExtUtil.readNumeric(in); } else { d = ExtUtil.readDecimal(in); } }
public void writeExternal(DataOutputStream out) throws IOException { if (d == (int) d) { out.writeByte(0x00); ExtUtil.writeNumeric(out, (int) d); } else { out.writeByte(0x01); ExtUtil.writeDecimal(out, d); } }
@Test public void testRegressionXFormSerializations() { FormDef def = XFormUtils.getFormFromResource("/resources/forms/placeholder.xml"); try { ExtUtil.deserialize(ExtUtil.serialize(def), FormDef.class, TestUtils.factory); } catch (IOException | DeserializationException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } }
@Override public void writeExternal(DataOutputStream out) throws IOException { out.writeInt(data.length); for (int i = 0; i < data.length; ++i) { ExtUtil.write(out, new ExtWrapTagged(data[i])); } }
public static String printObj(Object o) { o = ExtUtil.unwrap(o); if (o == null) { return "(null)"; } else if (o instanceof List) { StringBuilder sb = new StringBuilder(); sb.append("V["); List lo = (List) o; boolean first = true; for (Object obj : lo) { if (!first) { sb.append(", "); } first = false; sb.append(printObj(obj)); } sb.append("]"); return sb.toString(); } else if (o instanceof HashMap) { StringBuilder sb = new StringBuilder(); sb.append((o instanceof OrderedMap ? "oH" : "H") + "["); for (Iterator e = ((HashMap) o).keySet().iterator(); e.hasNext(); ) { Object key = e.next(); sb.append(printObj(key)); sb.append("=>"); sb.append(printObj(((HashMap) o).get(key))); if (e.hasNext()) sb.append(", "); } sb.append("]"); return sb.toString(); } else { return "{" + o.getClass().getName() + ":" + o.toString() + "}"; } }
/** * Read serialized {@link FormDef} from file and recreate as object. * * @param formDef * serialized FormDef file * @return {@link FormDef} object */ public FormDef deserializeFormDef(File formDef) { // TODO: any way to remove reliance on jrsp? FileInputStream fis = null; FormDef fd = null; try { // create new form def fd = new FormDef(); fis = new FileInputStream(formDef); DataInputStream dis = new DataInputStream(fis); // read serialized formdef into new formdef fd.readExternal(dis, ExtUtil.defaultPrototypes()); dis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); fd = null; } catch (IOException e) { e.printStackTrace(); fd = null; } catch (DeserializationException e) { e.printStackTrace(); fd = null; } catch (Exception e) { e.printStackTrace(); fd = null; } return fd; }
@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()); } }
public Object getMetaData(String fieldName) { if (fieldName.equals("DESCRIPTOR")) { return name; } if (fieldName.equals("XMLNS")) { return ExtUtil.emptyIfNull(instance.schema); } else { throw new IllegalArgumentException(); } }
public static void testExternalizable( Object orig, Object template, PrototypeFactory pf, TestCase tc, String failMessage) { if (failMessage == null) failMessage = "Serialization Failure"; byte[] bytes; Object deser; print(""); print("Original: " + printObj(orig)); try { bytes = ExtUtil.serialize(orig); print("Serialized as:"); print(ExtUtil.printBytes(bytes)); if (template instanceof Class) { deser = ExtUtil.deserialize(bytes, (Class) template, pf); } else if (template instanceof ExternalizableWrapper) { deser = ExtUtil.read( new DataInputStream(new ByteArrayInputStream(bytes)), (ExternalizableWrapper) template, pf); } else { throw new ClassCastException(); } print("Reconstituted: " + printObj(deser)); if (ExtUtil.equals(orig, deser)) { print("SUCCESS"); } else { print("FAILURE"); tc.fail(failMessage + ": Objects do not match"); } print("---------------------------------------------"); } catch (Exception e) { tc.fail(failMessage + ": Exception! " + e.getClass().getName() + " " + e.getMessage()); } }
/** * 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 */ 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((Vector) ExtUtil.read(dis, new ExtWrapListPoly(), pf)); setInstance((FormInstance) ExtUtil.read(dis, FormInstance.class, pf)); setLocalizer((Localizer) ExtUtil.read(dis, new ExtWrapNullable(Localizer.class), pf)); Vector vcond = (Vector) ExtUtil.read(dis, new ExtWrapList(Condition.class), pf); for (Enumeration e = vcond.elements(); e.hasMoreElements(); ) addTriggerable((Condition) e.nextElement()); Vector vcalc = (Vector) ExtUtil.read(dis, new ExtWrapList(Recalculate.class), pf); for (Enumeration e = vcalc.elements(); e.hasMoreElements(); ) addTriggerable((Recalculate) e.nextElement()); finalizeTriggerables(); outputFragments = (Vector) ExtUtil.read(dis, new ExtWrapListPoly(), pf); submissionProfiles = (Hashtable<String, SubmissionProfile>) ExtUtil.read(dis, new ExtWrapMap(String.class, SubmissionProfile.class)); }
/** * Writes the form definition object to the supplied stream. * * @param dos - the stream to write to. * @throws IOException */ 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, instance); ExtUtil.write(dos, new ExtWrapNullable(localizer)); Vector conditions = new Vector(); Vector recalcs = new Vector(); for (int i = 0; i < triggerables.size(); i++) { Triggerable t = (Triggerable) triggerables.elementAt(i); if (t instanceof Condition) { conditions.addElement(t); } else if (t instanceof Recalculate) { recalcs.addElement(t); } } ExtUtil.write(dos, new ExtWrapList(conditions)); ExtUtil.write(dos, new ExtWrapList(recalcs)); ExtUtil.write(dos, new ExtWrapListPoly(outputFragments)); ExtUtil.write(dos, new ExtWrapMap(submissionProfiles)); }
public void writeExternal(DataOutputStream out) throws IOException { ExtUtil.write(out, new ExtWrapTagged(expr)); ExtUtil.writeBool(out, hasNow); }
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { expr = (XPathExpression) ExtUtil.read(in, new ExtWrapTagged(), pf); hasNow = (boolean) ExtUtil.readBool(in); }
public void writeExternal(DataOutputStream out) throws IOException { ExtUtil.write(out, new ExtWrapTagged(a)); ExtUtil.write(out, new ExtWrapTagged(b)); }
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { v = (Vector) ExtUtil.read(in, new ExtWrapList(Integer.class)); }
public void writeExternal(DataOutputStream out) throws IOException { ExtUtil.write(out, new ExtWrapList(v)); }