Changeset 1516
- Timestamp:
- 12/02/08 18:20:46 (5 weeks ago)
- Location:
- branches/dev-repeat/javarosa
- Files:
-
- 1 added
- 10 modified
-
org.javarosa.core.model/src/org/javarosa/core/model/DataBinding.java (modified) (3 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/FormDef.java (modified) (6 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/GroupDef.java (modified) (3 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/QuestionDef.java (modified) (1 diff)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/DataModelTree.java (modified) (6 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataElement.java (modified) (7 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataGroup.java (modified) (3 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/TreeElement.java (modified) (2 diffs)
-
org.javarosa.core.model/src/org/javarosa/core/model/instance/TreeReference.java (added)
-
org.javarosa.xform/src/org/javarosa/model/xform/XPathReference.java (modified) (6 diffs)
-
org.javarosa.xform/src/org/javarosa/xform/parse/XFormParser.java (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/DataBinding.java
r1363 r1516 5 5 import java.io.IOException; 6 6 7 import org.javarosa.core.JavaRosaServiceProvider;8 7 import org.javarosa.core.model.condition.Condition; 9 import org.javarosa.core.model. storage.FormDefRMSUtility;8 import org.javarosa.core.model.condition.IConditionExpr; 10 9 import org.javarosa.core.util.externalizable.DeserializationException; 11 10 import org.javarosa.core.util.externalizable.ExtUtil; … … 13 12 import org.javarosa.core.util.externalizable.ExtWrapTagged; 14 13 import org.javarosa.core.util.externalizable.Externalizable; 15 import org.javarosa.core.util.externalizable.ExternalizableHelperDeprecated;16 14 import org.javarosa.core.util.externalizable.PrototypeFactory; 17 import org.javarosa.core.util.externalizable.PrototypeFactoryDeprecated;18 15 19 16 /** … … 36 33 private IDataReference ref; 37 34 private int dataType; 38 //private ... constraints; 39 40 //do getters/setters later 35 41 36 public Condition relevancyCondition; 37 public boolean relevantAbsolute; 42 38 public Condition requiredCondition; 43 39 public boolean requiredAbsolute; 44 40 public Condition readonlyCondition; 45 41 public boolean readonlyAbsolute; 42 public IConditionExpr constraint; 46 43 47 44 private String preload; 48 45 private String preloadParams; 46 public String constraintMessage; 49 47 50 48 public DataBinding () { 49 relevantAbsolute = true; 51 50 requiredAbsolute = false; 52 51 readonlyAbsolute = false; -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/FormDef.java
r1482 r1516 35 35 public class FormDef implements IFormElement, Localizable, IDRecordable, Externalizable{ 36 36 private Vector children; /** A collection of group definitions. */ 37 private Vector dataBindings = new Vector();38 37 private int id; /** The numeric unique identifier of the form definition. */ 39 38 private String name; /** The display name of the form. */ … … 238 237 return null; 239 238 } 240 241 public Vector getBindings () { 242 return dataBindings; 243 } 244 245 public void setBindings (Vector v) { 246 this.dataBindings = v; 247 } 248 239 249 240 /** 250 241 * @return the preloads … … 259 250 public void setPreloader(QuestionPreloader preloads) { 260 251 this.preloader = preloads; 261 }262 263 /**264 * @param db A new DataBinding to be added to the form's list.265 */266 public void addBinding (DataBinding db) {267 if (dataBindings == null)268 dataBindings = new Vector();269 dataBindings.addElement(db);270 252 } 271 253 … … 290 272 public void preloadModel() { 291 273 IAnswerData preload = null; 292 293 // 25/08/2008 BWD 294 // Fixed bug where it expected bindings. Not all forms have bindings! 295 if(getBindings() == null) 296 return; 297 274 298 275 Enumeration en = getBindings().elements(); 299 276 while(en.hasMoreElements()) { … … 352 329 setName((String)ExtUtil.read(dis, new ExtWrapNullable(String.class), pf)); 353 330 setChildren((Vector)ExtUtil.read(dis, new ExtWrapListPoly(), pf)); 354 setBindings((Vector)ExtUtil.read(dis, new ExtWrapList(DataBinding.class), pf));355 331 356 332 model = (IFormDataModel)ExtUtil.read(dis, new ExtWrapTagged(), pf); … … 392 368 ExtUtil.write(dos, new ExtWrapNullable(getName())); 393 369 ExtUtil.write(dos, new ExtWrapListPoly(getChildren())); 394 ExtUtil.write(dos, new ExtWrapList(ExtUtil.emptyIfNull(getBindings())));395 370 ExtUtil.write(dos, new ExtWrapTagged(model)); 396 371 ExtUtil.write(dos, new ExtWrapNullable(localizer)); -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/GroupDef.java
r1482 r1516 32 32 private int id; /** The group number. */ 33 33 private String name; /** The name of the group. */ 34 private IDataReference binding; /** reference to a location in the model to store data in */ 34 35 35 36 private String longText; … … 37 38 private String shortText; 38 39 private String shortTextID; 40 41 public boolean noAddRemove = false; 42 //public boolean startEmpty = false; 43 public IDataReference count = null; 39 44 40 45 public GroupDef () { … … 65 70 } 66 71 72 public IDataReference getBind() { 73 return binding; 74 } 75 76 public void setBind(IDataReference binding) { 77 this.binding = binding; 78 } 79 67 80 public Vector getChildren() { 68 81 return children; -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/QuestionDef.java
r1482 r1516 55 55 private Vector selectItemsLocalizable; 56 56 57 private boolean required; /** A flag to tell whether the question is to be answered or is optional. */ 58 //constraints? 59 60 private boolean visible; /** A flag to tell whether the question should be shown or not. */ 61 private boolean enabled; /** A flag to tell whether the question should be enabled or disabled. */ 62 private boolean locked; /** A flag to tell whether a question is to be locked or not. A locked question is one which is visible, enabled, but cannot be edited. */ 63 64 private IAnswerData defaultValue; /** this shouldn't be used for default values that are already pre-loaded in the instance */ 57 //private boolean required; /** A flag to tell whether the question is to be answered or is optional. */ 58 //private boolean visible; /** A flag to tell whether the question should be shown or not. */ 59 //private boolean enabled; /** A flag to tell whether the question should be enabled or disabled. */ 60 //private boolean locked; /** A flag to tell whether a question is to be locked or not. A locked question is one which is visible, enabled, but cannot be edited. */ 61 62 //this may be used in the future, but it is not the default value you're probably thinking about 63 //"these are not the default values you are looking for..." 64 //"not your mothers's default value anymore!" 65 //private IAnswerData defaultValue; 65 66 66 67 Vector observers; -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/DataModelTree.java
r1366 r1516 6 6 import java.util.Date; 7 7 import java.util.Enumeration; 8 import java.util.Vector; 8 9 9 10 import org.javarosa.core.model.IDataReference; … … 19 20 import org.javarosa.core.util.externalizable.ExtWrapTagged; 20 21 import org.javarosa.core.util.externalizable.PrototypeFactory; 22 import org.javarosa.model.xform.XPathReference; 21 23 22 24 /** … … 78 80 } 79 81 82 //throws classcastexception if not using XPathReference 83 public static TreeReference unpackReference (IDataReference ref) { 84 return (TreeReference)ref.getReference(); 85 } 86 87 //create the specified node in the tree, creating all intermediary nodes 88 //terminal = true: create element, false: create group (albeit empty) 89 //at each step, if multiplicity = 90 // ALL or count: always create a new node at the step 91 // [0,count): use that specific node 92 //return a reference that unambiguously refers to the newly created node 93 public TreeReference createNode (IDataReference ref, boolean terminal) { 94 QuestionDataGroup node = (QuestionDataGroup)root; 95 TreeReference tref = unpackReference(ref); 96 97 for (int k = 0; k < tref.size(); k++) { 98 String name = (String)tref.names.elementAt(k); 99 int count = node.getMultiplicity(name); 100 int mult = ((Integer)tref.multiplicity.elementAt(k)).intValue(); 101 102 TreeElement child; 103 if (mult < count) { 104 //fetch existing 105 child = node.getChild(name, mult); 106 if (child == null) 107 return null; //something wrong 108 } else if (mult == TreeReference.INDEX_UNBOUND || mult == count) { 109 //create new 110 if (k == tref.size() - 1 && terminal) { 111 child = new QuestionDataElement(name, count, null); 112 } else { 113 child = new QuestionDataGroup(name, count); 114 } 115 node.addChild(child); 116 tref.multiplicity.setElementAt(new Integer(count), k); 117 } else { 118 return null; 119 } 120 121 if (k < tref.size() - 1) { 122 if (child instanceof QuestionDataElement) { 123 throw new IllegalArgumentException(); 124 } 125 126 node = (QuestionDataGroup)child; 127 } 128 } 129 } 130 //think this works 131 132 public boolean deleteNode (IDataReference ref) { 133 return false; 134 } 135 136 //for making new repeat instances; worry about later 137 public boolean copyNode (IDataReference from, IDataReference to) { 138 return false; 139 } 140 80 141 /* 81 142 * (non-Javadoc) … … 84 145 * Object) 85 146 */ 86 public boolean updateDataValue(IDataReference questionBinding, 87 IAnswerData value) { 147 public boolean updateDataValue(IDataReference questionBinding, IAnswerData value) { 88 148 TreeElement treeElement = resolveReference(questionBinding); 89 149 if (treeElement != null) { … … 108 168 } 109 169 } 110 170 171 //return a vector of TreeReferences that refer to all nodes in the instance (one ref per node) that match 172 //the passed-in TreeReference, accounting for all repeats. 173 //the returned refs will each unambiguously refer to a single node (i.e., no multiplicities will be 'ALL') 174 public Vector expandReference (TreeReference ref) { 175 if (!ref.absolute) 176 return null; 177 178 Vector v = new Vector(); 179 expandReference(ref, TreeReference.rootRef(), root, v); 180 return v; 181 } 182 183 //helper function for expandReference(ref) 184 //sourceRef: original path we're matching against 185 //node: current node that has matched the sourceRef thus far 186 //templateRef: explicit path that refers to the current node 187 //refs: Vector to collect matching paths; if 'node' is a target node that matches sourceRef, templateRef is added to refs 188 private void expandReference (TreeReference sourceRef, TreeReference templateRef, TreeElement node, Vector refs) { 189 int depth = templateRef.size(); 190 191 if (depth == sourceRef.size()) { 192 refs.addElement(templateRef); 193 } else if (node instanceof QuestionDataGroup) { 194 QuestionDataGroup group = (QuestionDataGroup)node; 195 String name = (String)sourceRef.names.elementAt(depth); 196 int mult = ((Integer)sourceRef.multiplicity.elementAt(depth)).intValue(); 197 198 Vector children = new Vector(); 199 if (mult == TreeReference.INDEX_ALL) { 200 int count = group.getMultiplicity(name); 201 for (int i = 0; i < count; i++) { 202 TreeElement child = group.getChild(name, i); 203 if (child != null) { 204 children.addElement(child); 205 } else { 206 throw new IllegalStateException(); //missing/non-sequential nodes 207 } 208 } 209 } else { 210 TreeElement child = group.getChild(name, mult); 211 if (child != null) 212 children.addElement(child); 213 } 214 215 for (Enumeration e = children.elements(); e.hasMoreElements(); ) { 216 TreeElement child = (TreeElement)e.nextElement(); 217 TreeReference newTemplateRef = (children.size() == 1 ? templateRef : templateRef.clone()); //don't clone templateRef unnecessarily 218 newTemplateRef.names.addElement(name); 219 newTemplateRef.multiplicity.addElement(new Integer(child.getMult())); 220 221 expandReference(sourceRef, newTemplateRef, child, refs); 222 } 223 } 224 } 225 226 public TreeElement resolveReference (TreeReference ref) { 227 if (!ref.absolute) 228 return null; 229 230 TreeElement node = root; 231 for (int i = 0; i < ref.size(); i++) { 232 if (!(node instanceof QuestionDataGroup)) { 233 node = null; 234 break; 235 } 236 QuestionDataGroup group = (QuestionDataGroup)node; 237 238 String name = (String)ref.names.elementAt(i); 239 int mult = ((Integer)ref.multiplicity.elementAt(i)).intValue(); 240 if (mult == TreeReference.INDEX_ALL) { 241 if (group.children.size() == 1) { 242 mult = 0; 243 } else { 244 //reference is not unambiguous 245 node = null; 246 break; 247 } 248 } 249 250 node = group.getChild(name, mult); 251 if (node == null) 252 break; 253 } 254 return node; 255 } 111 256 112 257 /** … … 118 263 */ 119 264 public TreeElement resolveReference(IDataReference binding) { 120 if (root.isLeaf()) { 121 if (root.matchesReference(binding)) { 122 return root; 123 } else { 124 return null; 125 } 126 } else { 127 return resolveReference(binding,(QuestionDataGroup)root); 128 } 129 } 130 131 /** 132 * Resolves a binding to a particular question data element 133 * @param binding The binding representing a particular question 134 * @param group 135 * @return A QuestionDataElement corresponding to the binding 136 * provided. Null if none exists in this tree. 137 */ 138 private TreeElement resolveReference(IDataReference binding, QuestionDataGroup group) { 139 //TODO: We can do this much more intelligently given that we know the format of the bindings 140 TreeElement target = null; 141 142 Enumeration en = group.getChildren().elements(); 143 while(target == null && en.hasMoreElements()) { 144 TreeElement dme = (TreeElement)en.nextElement(); 145 if (dme.matchesReference(binding)) { 146 return dme; 147 } 148 else if(!dme.isLeaf()) { 149 target = resolveReference(binding, (QuestionDataGroup)dme); 150 } 151 } 152 153 return target; 265 return resolveReference(unpackReference(binding)); 154 266 } 155 267 -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataElement.java
r1482 r1516 34 34 private IAnswerData value; 35 35 36 /** A Binding for the Question Definition */37 private IDataReference reference;38 39 36 /** 40 37 * Creates a new, blank, QuestionDataElement; … … 50 47 * @param name 51 48 * The name of this TreeElement 52 * @param reference53 * The reference for Question Definitions54 49 */ 55 public QuestionDataElement(String name, IDataReference reference) { 56 this(); 57 this.name = name; 58 this.reference = reference; 50 public QuestionDataElement(String name) { 51 this(name, 1); 59 52 } 60 53 54 public QuestionDataElement (String name, int multiplicity) { 55 this.name = name; 56 this.multiplicity = multiplicity; 57 } 58 61 59 /** 62 60 * Creates a new QuestionDataElement for the question defined by the name … … 65 63 * @param name 66 64 * The name of this TreeElement 67 * @param reference68 * The reference for Question Definitions69 65 * @param value 70 66 * The value for this Question Definition 71 67 */ 72 public QuestionDataElement(String name, IDataReference reference, 73 IAnswerData value) { 74 this(name, reference); 68 public QuestionDataElement(String name, IAnswerData value) { 69 this(name); 75 70 this.value = value; 76 71 } 77 72 78 /* 79 * (non-Javadoc) 80 * 81 * @see org.javarosa.core.model.TreeElement#getName() 82 */ 83 public String getName() { 84 return name; 73 public QuestionDataElement(String name, int multiplicity, IAnswerData value) { 74 this(name, multiplicity); 75 this.value = value; 85 76 } 86 77 87 78 /** 88 79 * @return The value for the question defined by IBinding … … 106 97 } 107 98 99 public void setMult (int multiplicity) { 100 this.multiplicity = multiplicity; 101 } 102 108 103 /* 109 104 * (non-Javadoc) … … 137 132 } 138 133 139 public void setReference(IDataReference reference) {140 this.reference = reference;141 }142 143 public boolean matchesReference(IDataReference reference) {144 if (this.reference == null) {145 return false;146 } else {147 return this.reference.referenceMatches(reference);148 }149 }150 151 134 /** 152 135 * @return a string representing the value of this question's answer … … 173 156 public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { 174 157 name = ExtUtil.readString(in); 175 reference = (IDataReference)ExtUtil.read(in, new ExtWrapTagged(), pf);158 //FIXME: reference = (IDataReference)ExtUtil.read(in, new ExtWrapTagged(), pf); 176 159 177 160 // read attributes … … 189 172 public void writeExternal(DataOutputStream out) throws IOException { 190 173 ExtUtil.writeString(out, name); 191 ExtUtil.write(out, new ExtWrapTagged(reference));174 //FIXME: ExtUtil.write(out, new ExtWrapTagged(reference)); 192 175 193 176 // write attributes. -
branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataGroup.java
r1366 r1516 52 52 */ 53 53 public QuestionDataGroup(String name) { 54 this(); 54 this(name, 1); 55 } 56 57 public QuestionDataGroup(String name, int multiplicity) { 55 58 this.name = name; 59 this.multiplicity = multiplicity; 56 60 } 57 61 … … 64 68 } 65 69 66 /*67 * (non-Javadoc)68 * @see org.javarosa.core.model.TreeElement#getName()69 */70 public String getName() {71 return name;72 }73 74 70 /** 75 71 * @return A list of TreeElement that are this Element's children … … 77 73 public Vector getChildren() { 78 74 return children; 75 } 76 77 public int getMultiplicity (String name) { 78 int count = 0; 79 for (int i = 0; i < children.size(); i++) { 80 TreeElement child = (TreeElement)children.elementAt(i); 81 if (child.getName().equals(name)) 82 &n
