Changeset 1518
- Timestamp:
- 12/03/08 16:46:45 (5 weeks ago)
- Location:
- branches/dev-repeat/javarosa
- Files:
-
- 4 modified
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataElement.java (modified) (1 diff)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataGroup.java (modified) (1 diff)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/TreeReference.java (modified) (1 diff)
-
org.javarosa.xform/src/org/javarosa/xform/parse/XFormParser.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataElement.java
r1516 r1518 49 49 */ 50 50 public QuestionDataElement(String name) { 51 this(name, 1);51 this(name, 0); 52 52 } 53 53 -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataGroup.java
r1516 r1518 52 52 */ 53 53 public QuestionDataGroup(String name) { 54 this(name, 1);54 this(name, 0); 55 55 } 56 56 -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/TreeReference.java
r1517 r1518 38 38 public int size () { 39 39 return names.size(); 40 } 41 42 public void add (String name, int index) { 43 names.addElement(name); 44 multiplicity.addElement(new Integer(index)); 40 45 } 41 46 -
branches/dev-repeat/javarosa/org.javarosa.xform/src/org/javarosa/xform/parse/XFormParser.java
r1517 r1518 61 61 private static Vector bindings; 62 62 private static Vector repeats; 63 private static Vector selectOnes; 64 private static Vector selectMultis; 63 65 private static Element instanceNode; //top-level data node of the instance; saved off so it can be processed after the <bind>s 64 66 … … 164 166 bindings = new Vector(); 165 167 repeats = new Vector(); 168 selectOnes = new Vector(); 169 selectMultis = new Vector(); 166 170 instanceNode = null; 167 171 } … … 335 339 } 336 340 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 } 337 347 } 338 348 … … 806 816 } 807 817 818 //e is the top-level _data_ node of the instance (immediate (and only) child of <instance>) 808 819 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(); 810 825 DataModelTree instanceModel = new DataModelTree(root); 811 826 instanceModel.setName(f.getName()); … … 813 828 } 814 829 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 815 886 private static TreeElement parseInstanceNodes (Element node, TreeReference cur) { 816 887 int childNum = node.getChildCount(); … … 820 891 XPathReference reference = new XPathReference(refStr); 821 892 893 //dgr: this is now obsolete: new process-- create nodes, iterate over binds, evaluate, and apply properties 822 894 if (bindingsByRef.containsKey(refStr)) { 823 895 DataBinding binding = (DataBinding) bindingsByRef.get(refStr);
