示例#1
0
        /*
         * (non-Javadoc)
         * @see org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model.DataModelTree)
         */
        public virtual void  serialize(DataInstance instance, TreeReference base_Renamed)
        {
            //TODO: Namespaces?
            AbstractTreeElement root;

            if (base_Renamed == null)
            {
                root = instance.getRoot();
            }
            else
            {
                root = instance.resolveReference(base_Renamed);
            }

            //write root
            serializer.startTag(root.getNamespace(), root.getName());

            for (int i = 0; i < root.getNumChildren(); i++)
            {
                //write children
                AbstractTreeElement childAt = root.getChildAt(i);
                serializeNode(childAt);
            }

            //end root
            serializer.endTag(root.getNamespace(), root.getName());
            serializer.flush();
        }
示例#2
0
        public virtual void  serializeNode(AbstractTreeElement instanceNode)
        {
            //don't serialize template nodes or non-relevant nodes
            if (!instanceNode.isRelevant() || instanceNode.getMult() == TreeReference.INDEX_TEMPLATE)
            {
                return;
            }

            serializer.startTag(instanceNode.getNamespace(), instanceNode.getName());
            for (int i = 0; i < instanceNode.getAttributeCount(); ++i)
            {
                System.String val = instanceNode.getAttributeValue(i);
                val = val == null?"":val;
                serializer.attribute(instanceNode.getAttributeNamespace(i), instanceNode.getAttributeName(i), val);
            }

            if (instanceNode.getValue() != null)
            {
                serializer.text(instanceNode.getValue().uncast().getString());
            }
            else
            {
                for (int i = 0; i < instanceNode.getNumChildren(); ++i)
                {
                    serializeNode(instanceNode.getChildAt(i));
                }
            }

            serializer.endTag(instanceNode.getNamespace(), instanceNode.getName());
        }
示例#3
0
        public override void  processAction(FormDef model, TreeReference contextRef)
        {
            //Qualify the reference if necessary
            TreeReference qualifiedReference = contextRef == null?target:target.contextualize(contextRef);

            //For now we only process setValue actions which are within the
            //context if a context is provided. This happens for repeats where
            //insert events should only trigger on the right nodes
            if (contextRef != null)
            {
                //Note: right now we're qualifying then testing parentage to see wheter
                //there was a conflict, but it's not super clear whether this is a perfect
                //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.EvaluationContext, qualifiedReference);

            System.Object result;

            if (explicitValue != null)
            {
                result = explicitValue;
            }
            else
            {
                result = XPathFuncExpr.unpack(value_Renamed.eval(model.MainInstance, context));
            }

            AbstractTreeElement node = context.resolveReference(qualifiedReference);

            if (node == null)
            {
                throw new System.NullReferenceException("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);
        }