Changeset 1518

Show
Ignore:
Timestamp:
12/03/08 16:46:45 (5 weeks ago)
Author:
droos
Message:

adding changes-in-progress for construction of repeat-aware data model instance

Location:
branches/dev-repeat/javarosa
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataElement.java

    r1516 r1518  
    4949         */ 
    5050        public QuestionDataElement(String name) { 
    51                 this(name, 1); 
     51                this(name, 0); 
    5252        } 
    5353 
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataGroup.java

    r1516 r1518  
    5252         */ 
    5353        public QuestionDataGroup(String name) { 
    54                 this(name, 1); 
     54                this(name, 0); 
    5555        } 
    5656         
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/TreeReference.java

    r1517 r1518  
    3838        public int size () { 
    3939                return names.size(); 
     40        } 
     41         
     42        public void add (String name, int index) { 
     43                names.addElement(name); 
     44                multiplicity.addElement(new Integer(index)); 
    4045        } 
    4146         
  • branches/dev-repeat/javarosa/org.javarosa.xform/src/org/javarosa/xform/parse/XFormParser.java

    r1517 r1518  
    6161        private static Vector bindings; 
    6262        private static Vector repeats; 
     63        private static Vector selectOnes; 
     64        private static Vector selectMultis; 
    6365        private static Element instanceNode; //top-level data node of the instance; saved off so it can be processed after the <bind>s 
    6466 
     
    164166                bindings = new Vector(); 
    165167                repeats = new Vector(); 
     168                selectOnes = new Vector(); 
     169                selectMultis = new Vector(); 
    166170                instanceNode = null; 
    167171        } 
     
    335339                        } 
    336340                        question.setBind(dataRef); 
     341                         
     342                        if (controlType == Constants.CONTROL_SELECT_ONE) { 
     343                                selectOnes.addElement(dataRef); 
     344                        } else if (controlType == Constants.CONTROL_SELECT_MULTI) { 
     345                                selectMultis.addElement(dataRef); 
     346                        } 
    337347                }                
    338348 
     
    806816        } 
    807817 
     818        //e is the top-level _data_ node of the instance (immediate (and only) child of <instance>) 
    808819        private static void parseInstance (FormDef f, Element e) { 
    809                 TreeElement root = parseInstanceNodes(e, TreeReference.rootRef()).getRoot(); 
     820                TreeElement root = buildInstanceStructure(e, null, TreeReference.rootRef()); 
     821                applyInstanceProperties(root); 
     822                loadInstanceData(e, root); 
     823                 
     824                //TreeElement root = parseInstanceNodes(e, TreeReference.rootRef()).getRoot(); 
    810825                DataModelTree instanceModel = new DataModelTree(root); 
    811826                instanceModel.setName(f.getName()); 
     
    813828        } 
    814829 
     830        //create node structure 
     831        //evaluate binds and apply properties 
     832        //load data based on data type 
     833 
     834        private static TreeElement buildInstanceStructure (Element node, QuestionDataGroup parent, TreeReference ref) { 
     835                TreeElement element = null; 
     836                boolean isGroup; 
     837 
     838                boolean hasText = false; 
     839                boolean hasElements = false; 
     840                 
     841                int numChildren = node.getChildCount();          
     842                for (int i = 0; i < numChildren; i++) { 
     843                        switch (node.getType(i)) { 
     844                        case Node.ELEMENT: hasElements = true; break; 
     845                        case Node.TEXT: hasText = true; break; 
     846                        } 
     847                } 
     848                 
     849                if (hasElements) { 
     850                        isGroup = true; 
     851                        if (hasText) { 
     852                                System.out.println("Warning: instance node contains both elements and text as children; text ignored"); 
     853                        } 
     854                } else { 
     855                        isGroup = false; 
     856                } 
     857 
     858                String name = node.getName(); 
     859                int multiplicity = (parent == null ? 0 : parent.getMultiplicity(name)); 
     860                 
     861                if (isGroup) { 
     862                        element = new QuestionDataGroup(name, multiplicity); 
     863 
     864                        for (int i = 0; i < numChildren; i++) { 
     865                                if (node.getType(i) == Node.ELEMENT) { 
     866                                        ((QuestionDataGroup)element).addChild(buildInstanceStructure(node.getElement(i), (QuestionDataGroup)element)); 
     867                                } 
     868                        } 
     869                } else { 
     870                        element = new QuestionDataElement(name, multiplicity); 
     871                } 
     872 
     873                //handle attributes 
     874                if (node.getAttributeCount() > 0) { 
     875                        for (int i = 0; i < node.getAttributeCount(); i++) { 
     876                                element.setAttribute(node.getAttributeNamespace(i), node.getAttributeName(i), node.getAttributeValue(i)); 
     877                                //#if debug.output==verbose 
     878                                System.out.println(element.getName()+ " has added attr: "+element.getAttributeName(i)+"="+element.getAttributeValue(i)); 
     879                                //#endif 
     880                        } 
     881                } 
     882                 
     883                return element; 
     884        } 
     885         
    815886        private static TreeElement parseInstanceNodes (Element node, TreeReference cur) { 
    816887                int childNum = node.getChildCount(); 
     
    820891                XPathReference reference = new XPathReference(refStr); 
    821892 
     893                //dgr: this is now obsolete: new process-- create nodes, iterate over binds, evaluate, and apply properties 
    822894                if (bindingsByRef.containsKey(refStr)) { 
    823895                        DataBinding binding = (DataBinding) bindingsByRef.get(refStr);