Search in sources :

Example 76 with TreeReference

use of org.javarosa.core.model.instance.TreeReference 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);
}
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) List(java.util.List) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList)

Example 77 with TreeReference

use of org.javarosa.core.model.instance.TreeReference 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 78 with TreeReference

use of org.javarosa.core.model.instance.TreeReference in project javarosa by opendatakit.

the class Triggerable method equals.

public boolean equals(Object o) {
    if (o instanceof Triggerable) {
        Triggerable t = (Triggerable) o;
        if (this == t)
            return true;
        if (this.expr.equals(t.expr)) {
            // the
            try {
                // resolved triggers should match...
                Set<TreeReference> Atriggers = this.getTriggers();
                Set<TreeReference> Btriggers = t.getTriggers();
                return (Atriggers.size() == Btriggers.size()) && Atriggers.containsAll(Btriggers);
            } catch (XPathException e) {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : XPathException(org.javarosa.xpath.XPathException) TreeReference(org.javarosa.core.model.instance.TreeReference) QuickTriggerable(org.javarosa.core.model.QuickTriggerable)

Example 79 with TreeReference

use of org.javarosa.core.model.instance.TreeReference 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());
}
Also used : AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement) DataInstance(org.javarosa.core.model.instance.DataInstance) FormDef(org.javarosa.core.model.FormDef) TreeReference(org.javarosa.core.model.instance.TreeReference) XPathPathExpr(org.javarosa.xpath.expr.XPathPathExpr) EvaluationContext(org.javarosa.core.model.condition.EvaluationContext) Test(org.junit.Test)

Example 80 with TreeReference

use of org.javarosa.core.model.instance.TreeReference in project javarosa by opendatakit.

the class XFormParserTest method parseGroupWithNodesetAttrForm.

@Test
public void parseGroupWithNodesetAttrForm() throws IOException {
    // Given & When
    ParseResult parseResult = parse(r("group-with-nodeset-attr.xml"));
    // Then
    assertEquals(parseResult.formDef.getTitle(), "group with nodeset attribute");
    assertEquals("Number of error messages", 0, parseResult.errorMessages.size());
    final TreeReference expectedTreeReference = new TreeReference();
    // absolute reference
    expectedTreeReference.setRefLevel(-1);
    // the instance root
    expectedTreeReference.add("data", -1);
    // the outer repeat
    expectedTreeReference.add("R1", -1);
    // the inner group
    expectedTreeReference.add("G2", -1);
    final IDataReference expectedXPathReference = new XPathReference(expectedTreeReference);
    IFormElement groupElement = parseResult.formDef.getChild(0).getChild(0);
    assertThat(groupElement, instanceOf(GroupDef.class));
    assertThat(((GroupDef) groupElement).getRepeat(), is(false));
    assertThat(groupElement.getBind(), is(expectedXPathReference));
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) TreeReference(org.javarosa.core.model.instance.TreeReference) IDataReference(org.javarosa.core.model.IDataReference) XPathReference(org.javarosa.model.xform.XPathReference) GroupDef(org.javarosa.core.model.GroupDef) Test(org.junit.Test)

Aggregations

TreeReference (org.javarosa.core.model.instance.TreeReference)85 ArrayList (java.util.ArrayList)30 TreeElement (org.javarosa.core.model.instance.TreeElement)29 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)16 Constraint (org.javarosa.core.model.condition.Constraint)12 HashSet (java.util.HashSet)11 Test (org.junit.Test)9 FormInstance (org.javarosa.core.model.instance.FormInstance)8 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)7 IFormElement (org.javarosa.core.model.IFormElement)6 Condition (org.javarosa.core.model.condition.Condition)6 IAnswerData (org.javarosa.core.model.data.IAnswerData)6 InstanceInitializationFactory (org.javarosa.core.model.instance.InstanceInitializationFactory)6 GroupDef (org.javarosa.core.model.GroupDef)5 XPathReference (org.javarosa.model.xform.XPathReference)5 DataBinding (org.javarosa.core.model.DataBinding)4 IDataReference (org.javarosa.core.model.IDataReference)4 DataInstance (org.javarosa.core.model.instance.DataInstance)4 EvaluationResult (org.javarosa.debug.EvaluationResult)4 XPathException (org.javarosa.xpath.XPathException)4