use of org.javarosa.core.util.externalizable.DeserializationException in project javarosa by opendatakit.
the class CompactInstanceWrapper method readTreeElement.
/**
* recursively read in a node of the instance, by filling out the template instance
* @param e
* @param ref
* @param in
* @param pf
* @throws IOException
* @throws DeserializationException
*/
private void readTreeElement(TreeElement e, DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
TreeElement templ = instance.getTemplatePath(e.getRef());
boolean isGroup = !templ.isLeaf();
if (isGroup) {
List<String> childTypes = new ArrayList<String>(templ.getNumChildren());
for (int i = 0; i < templ.getNumChildren(); i++) {
String childName = templ.getChildAt(i).getName();
if (!childTypes.contains(childName)) {
childTypes.add(childName);
}
}
for (int i = 0; i < childTypes.size(); i++) {
String childName = childTypes.get(i);
TreeReference childTemplRef = e.getRef().extendRef(childName, 0);
TreeElement childTempl = instance.getTemplatePath(childTemplRef);
boolean repeatable = childTempl.isRepeatable();
int n = ExtUtil.readInt(in);
boolean relevant = (n > 0);
if (!repeatable && n > 1) {
throw new DeserializationException("Detected repeated instances of a non-repeatable node");
}
if (repeatable) {
int mult = e.getChildMultiplicity(childName);
for (int j = mult - 1; j >= 0; j--) {
e.removeChild(childName, j);
}
for (int j = 0; j < n; j++) {
TreeReference dstRef = e.getRef().extendRef(childName, j);
try {
instance.copyNode(childTempl, dstRef);
} catch (InvalidReferenceException ire) {
// If there is an invalid reference, this is a malformed instance,
// so we'll throw a Deserialization exception.
TreeReference r = ire.getInvalidReference();
if (r == null) {
throw new DeserializationException("Null Reference while attempting to deserialize! " + ire.getMessage());
} else {
throw new DeserializationException("Invalid Reference while attemtping to deserialize! Reference: " + r.toString(true) + " | " + ire.getMessage());
}
}
TreeElement child = e.getChild(childName, j);
child.setRelevant(true);
readTreeElement(child, in, pf);
}
} else {
TreeElement child = e.getChild(childName, 0);
child.setRelevant(relevant);
if (relevant) {
readTreeElement(child, in, pf);
}
}
}
} else {
e.setValue((IAnswerData) ExtUtil.read(in, new ExtWrapAnswerData(e.getDataType())));
}
}
use of org.javarosa.core.util.externalizable.DeserializationException in project javarosa by opendatakit.
the class QuestionDataElementTests method setUp.
public void setUp() throws Exception {
super.setUp();
stringData = new StringData("Answer Value");
integerData = new IntegerData(4);
stringReference = new IDataReference() {
String reference = "stringValue";
public Object getReference() {
return reference;
}
public void setReference(Object reference) {
this.reference = (String) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.reference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(reference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
integerReference = new IDataReference() {
Integer intReference = new Integer(15);
public Object getReference() {
return intReference;
}
public void setReference(Object reference) {
this.intReference = (Integer) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.intReference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(intReference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
intElement = new TreeElement("intElement");
intElement.setValue(integerData);
stringElement = new TreeElement(stringElementName);
stringElement.setValue(stringData);
}
use of org.javarosa.core.util.externalizable.DeserializationException in project javarosa by opendatakit.
the class QuestionDataGroupTests method setUp.
public void setUp() throws Exception {
super.setUp();
stringData = new StringData("Answer Value");
integerData = new IntegerData(4);
stringReference = new IDataReference() {
String reference = "stringValue";
public Object getReference() {
return reference;
}
public void setReference(Object reference) {
this.reference = (String) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.reference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(reference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
integerReference = new IDataReference() {
Integer intReference = new Integer(15);
public Object getReference() {
return intReference;
}
public void setReference(Object reference) {
this.intReference = (Integer) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.intReference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(intReference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
intElement = new TreeElement("intElement");
intElement.setValue(integerData);
stringElement = new TreeElement(stringElementName);
stringElement.setValue(stringData);
group = new TreeElement(groupName);
}
use of org.javarosa.core.util.externalizable.DeserializationException in project javarosa by opendatakit.
the class XFormUtils method getFormFromSerializedResource.
public static FormDef getFormFromSerializedResource(String resource) {
FormDef returnForm = null;
InputStream is = System.class.getResourceAsStream(resource);
DataInputStream dis = null;
try {
if (is != null) {
dis = new DataInputStream(is);
returnForm = (FormDef) ExtUtil.read(dis, FormDef.class);
} else {
// #if debug.output==verbose
Std.out.println("ResourceStream NULL");
// #endif
}
} catch (IOException e) {
Std.printStack(e);
} catch (DeserializationException e) {
Std.printStack(e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
Std.printStack(e);
}
}
if (dis != null) {
try {
dis.close();
} catch (IOException e) {
Std.printStack(e);
}
}
}
return returnForm;
}
use of org.javarosa.core.util.externalizable.DeserializationException in project javarosa by opendatakit.
the class GroupDef method readExternal.
/**
* Reads a group definition object from the supplied stream.
*/
public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOException, DeserializationException {
try {
setID(ExtUtil.readInt(dis));
setAppearanceAttr((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setBind((IDataReference) ExtUtil.read(dis, new ExtWrapTagged(), pf));
setTextID((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setLabelInnerText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setRepeat(ExtUtil.readBool(dis));
setChildren((List<IFormElement>) ExtUtil.read(dis, new ExtWrapListPoly(), pf));
noAddRemove = ExtUtil.readBool(dis);
count = (IDataReference) ExtUtil.read(dis, new ExtWrapNullable(new ExtWrapTagged()), pf);
chooseCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
addCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
delCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
doneCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
addEmptyCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
doneEmptyCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
entryHeader = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
delHeader = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
mainHeader = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
additionalAttributes = ExtUtil.readAttributes(dis, null);
} catch (OutOfMemoryError e) {
throw new DeserializationException("serialization format change caused misalignment and out-of-memory error");
}
}
Aggregations