use of org.javarosa.core.model.condition.IConditionExpr in project javarosa by opendatakit.
the class XFormsModule method registerModule.
public void registerModule() {
String[] classes = { "org.javarosa.model.xform.XPathReference", "org.javarosa.xpath.XPathConditional" };
PrototypeManager.registerPrototypes(classes);
PrototypeManager.registerPrototypes(XPathParseTool.xpathClasses);
RestoreUtils.xfFact = new IXFormyFactory() {
public TreeReference ref(String refStr) {
return FormInstance.unpackReference(new XPathReference(refStr));
}
public IDataPayload serializeInstance(FormInstance dm) {
try {
return (new XFormSerializingVisitor()).createSerializedPayload(dm);
} catch (IOException e) {
return null;
}
}
public FormInstance parseRestore(byte[] data, Class restorableType) {
return XFormParser.restoreDataModel(data, restorableType);
}
public IAnswerData parseData(String textVal, int dataType, TreeReference ref, FormDef f) {
return XFormAnswerDataParser.getAnswerData(textVal, dataType, XFormParser.ghettoGetQuestionDef(dataType, f, ref));
}
public String serializeData(IAnswerData data) {
return (String) (new XFormAnswerDataSerializer().serializeAnswerData(data));
}
public IConditionExpr refToPathExpr(TreeReference ref) {
return new XPathConditional(XPathPathExpr.fromRef(ref));
}
};
}
use of org.javarosa.core.model.condition.IConditionExpr in project javarosa by opendatakit.
the class FormDef method readExternal.
/**
* 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
*/
@Override
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((List<IFormElement>) ExtUtil.read(dis, new ExtWrapListPoly(), pf));
setInstance((FormInstance) ExtUtil.read(dis, FormInstance.class, pf));
setLocalizer((Localizer) ExtUtil.read(dis, new ExtWrapNullable(Localizer.class), pf));
List<Condition> vcond = (List<Condition>) ExtUtil.read(dis, new ExtWrapList(Condition.class), pf);
for (Condition condition : vcond) {
addTriggerable(condition);
}
List<Recalculate> vcalc = (List<Recalculate>) ExtUtil.read(dis, new ExtWrapList(Recalculate.class), pf);
for (Recalculate recalculate : vcalc) {
addTriggerable(recalculate);
}
finalizeTriggerables();
outputFragments = (List<IConditionExpr>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
submissionProfiles = (HashMap<String, SubmissionProfile>) ExtUtil.read(dis, new ExtWrapMap(String.class, SubmissionProfile.class));
formInstances = (HashMap<String, DataInstance>) ExtUtil.read(dis, new ExtWrapMap(String.class, new ExtWrapTagged()), pf);
eventListeners = (HashMap<String, List<Action>>) ExtUtil.read(dis, new ExtWrapMap(String.class, new ExtWrapListPoly()), pf);
extensions = (List<XFormExtension>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
resetEvaluationContext();
}
use of org.javarosa.core.model.condition.IConditionExpr in project javarosa by opendatakit.
the class FormDef method fillTemplateString.
public String fillTemplateString(String template, TreeReference contextRef, HashMap<String, ?> variables) {
HashMap<String, String> args = new HashMap<String, String>();
int depth = 0;
List<String> outstandingArgs = Localizer.getArgs(template);
while (outstandingArgs.size() > 0) {
for (String argName : outstandingArgs) {
if (!args.containsKey(argName)) {
int ix = -1;
try {
ix = Integer.parseInt(argName);
} catch (NumberFormatException nfe) {
Std.err.println("Warning: expect arguments to be numeric [" + argName + "]");
}
if (ix < 0 || ix >= outputFragments.size())
continue;
IConditionExpr expr = outputFragments.get(ix);
EvaluationContext ec = new EvaluationContext(exprEvalContext, contextRef);
ec.setOriginalContext(contextRef);
ec.setVariables(variables);
String value = expr.evalReadable(this.getMainInstance(), ec);
args.put(argName, value);
}
}
template = Localizer.processArguments(template, args);
outstandingArgs = Localizer.getArgs(template);
depth++;
if (depth >= TEMPLATING_RECURSION_LIMIT) {
throw new RuntimeException("Dependency cycle in <output>s; recursion limit exceeded!!");
}
}
return template;
}
use of org.javarosa.core.model.condition.IConditionExpr in project javarosa by opendatakit.
the class IDag method getConditionExpressionForTrueAction.
/**
* Pull this in from FormOverview so that we can make fields private.
*
* @param instanceNode
* @param action
* @return
*/
public final IConditionExpr getConditionExpressionForTrueAction(FormInstance mainInstance, TreeElement instanceNode, int action) {
IConditionExpr expr = null;
for (int i = 0; i < triggerablesDAG.size() && expr == null; i++) {
// Clayton Sims - Jun 1, 2009 : Not sure how legitimate this
// cast is. It might work now, but break later.
// Clayton Sims - Jun 24, 2009 : Yeah, that change broke things.
// For now, we won't bother to print out anything that isn't
// a condition.
QuickTriggerable qt = triggerablesDAG.get(i);
if (qt.t instanceof Condition) {
Condition c = (Condition) qt.t;
if (c.trueAction == action) {
List<TreeReference> targets = c.getTargets();
for (int j = 0; j < targets.size() && expr == null; j++) {
TreeReference target = targets.get(j);
TreeReference tr = (TreeReference) (new XPathReference(target)).getReference();
TreeElement element = mainInstance.getTemplatePath(tr);
if (instanceNode == element) {
expr = c.getExpr();
}
}
}
}
}
return expr;
}
Aggregations