use of org.javarosa.core.model.instance.AbstractTreeElement in project javarosa by opendatakit.
the class SetValueAction method processAction.
public void processAction(FormDef model, TreeReference contextRef) {
// Qualify the reference if necessary
TreeReference qualifiedReference = contextRef == null ? target : target.contextualize(contextRef);
// insert events should only trigger on the right nodes
if (contextRef != null) {
// strategy
if (!contextRef.isParentOf(qualifiedReference, false)) {
return;
}
}
// TODO: either the target or the value's node might not exist here, catch and throw
// reasonably
EvaluationContext context = new EvaluationContext(model.getEvaluationContext(), qualifiedReference);
Object result;
if (explicitValue != null) {
result = explicitValue;
} else {
result = XPathFuncExpr.unpack(value.eval(model.getMainInstance(), context));
}
AbstractTreeElement node = context.resolveReference(qualifiedReference);
if (node == null) {
throw new NullPointerException("Target of TreeReference " + qualifiedReference.toString(true) + " could not be resolved!");
}
int dataType = node.getDataType();
IAnswerData val = Recalculate.wrapData(result, dataType);
model.setValue(val == null ? null : AnswerDataFactory.templateByDataType(dataType).cast(val.uncast()), qualifiedReference, true);
}
use of org.javarosa.core.model.instance.AbstractTreeElement in project javarosa by opendatakit.
the class April2014DagImpl method addChildrenOfElement.
// Recursive step of utility method
private void addChildrenOfElement(AbstractTreeElement el, ArrayList<TreeReference> toAdd) {
for (int i = 0; i < el.getNumChildren(); ++i) {
AbstractTreeElement child = el.getChildAt(i);
toAdd.add(child.getRef().genericize());
addChildrenOfElement(child, toAdd);
}
}
use of org.javarosa.core.model.instance.AbstractTreeElement in project javarosa by opendatakit.
the class XFormParserTest method parsesExternalSecondaryInstanceForm.
@Test
public void parsesExternalSecondaryInstanceForm() throws IOException, XPathSyntaxException {
FormDef formDef = parse(EXTERNAL_SECONDARY_INSTANCE_XML).formDef;
assertEquals("Form with external secondary instance", formDef.getTitle());
TreeReference treeReference = ((XPathPathExpr) parseXPath("instance('towns')/data_set")).getReference();
EvaluationContext evaluationContext = formDef.getEvaluationContext();
List<TreeReference> treeReferences = evaluationContext.expandReference(treeReference);
assertEquals(1, treeReferences.size());
DataInstance townInstance = formDef.getNonMainInstance("towns");
AbstractTreeElement tiRoot = townInstance.getRoot();
assertEquals("towndata", tiRoot.getName());
assertEquals(1, tiRoot.getNumChildren());
AbstractTreeElement dataSetChild = tiRoot.getChild("data_set", 0);
assertEquals("us_east", dataSetChild.getValue().getDisplayText());
}
use of org.javarosa.core.model.instance.AbstractTreeElement in project javarosa by opendatakit.
the class QuestionDataGroupTests method testAcceptsVisitor.
public void testAcceptsVisitor() {
final MutableBoolean visitorAccepted = new MutableBoolean(false);
final MutableBoolean dispatchedWrong = new MutableBoolean(false);
ITreeVisitor sampleVisitor = new ITreeVisitor() {
public void visit(FormInstance tree) {
dispatchedWrong.setValue(true);
}
public void visit(AbstractTreeElement element) {
visitorAccepted.setValue(true);
}
};
stringElement.accept(sampleVisitor);
assertTrue("The visitor's visit method was not called correctly by the QuestionDataElement", visitorAccepted.getValue());
assertTrue("The visitor was dispatched incorrectly by the QuestionDataElement", !dispatchedWrong.getValue());
}
use of org.javarosa.core.model.instance.AbstractTreeElement in project javarosa by opendatakit.
the class QuestionDataElementTests method testAcceptsVisitor.
public void testAcceptsVisitor() {
final MutableBoolean visitorAccepted = new MutableBoolean(false);
final MutableBoolean dispatchedWrong = new MutableBoolean(false);
ITreeVisitor sampleVisitor = new ITreeVisitor() {
public void visit(FormInstance tree) {
dispatchedWrong.bool = true;
}
public void visit(AbstractTreeElement element) {
visitorAccepted.bool = true;
}
};
stringElement.accept(sampleVisitor);
assertTrue("The visitor's visit method was not called correctly by the QuestionDataElement", visitorAccepted.getValue());
assertTrue("The visitor was dispatched incorrectly by the QuestionDataElement", !dispatchedWrong.getValue());
}
Aggregations