Search in sources :

Example 1 with IXFormyFactory

use of org.javarosa.core.model.util.restorable.IXFormyFactory 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));
        }
    };
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) IConditionExpr(org.javarosa.core.model.condition.IConditionExpr) IXFormyFactory(org.javarosa.core.model.util.restorable.IXFormyFactory) IOException(java.io.IOException) XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer) TreeReference(org.javarosa.core.model.instance.TreeReference) FormDef(org.javarosa.core.model.FormDef) FormInstance(org.javarosa.core.model.instance.FormInstance) XPathConditional(org.javarosa.xpath.XPathConditional) IDataPayload(org.javarosa.core.services.transport.payload.IDataPayload)

Aggregations

IOException (java.io.IOException)1 FormDef (org.javarosa.core.model.FormDef)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 IAnswerData (org.javarosa.core.model.data.IAnswerData)1 FormInstance (org.javarosa.core.model.instance.FormInstance)1 TreeReference (org.javarosa.core.model.instance.TreeReference)1 IXFormyFactory (org.javarosa.core.model.util.restorable.IXFormyFactory)1 IDataPayload (org.javarosa.core.services.transport.payload.IDataPayload)1 XFormAnswerDataSerializer (org.javarosa.xform.util.XFormAnswerDataSerializer)1 XPathConditional (org.javarosa.xpath.XPathConditional)1