Changeset 1516

Show
Ignore:
Timestamp:
12/02/08 18:20:46 (5 weeks ago)
Author:
droos
Message:

adding in first wave of repeat dev (does not build)

Location:
branches/dev-repeat/javarosa
Files:
1 added
10 modified

Legend:

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

    r1363 r1516  
    55import java.io.IOException; 
    66 
    7 import org.javarosa.core.JavaRosaServiceProvider; 
    87import org.javarosa.core.model.condition.Condition; 
    9 import org.javarosa.core.model.storage.FormDefRMSUtility; 
     8import org.javarosa.core.model.condition.IConditionExpr; 
    109import org.javarosa.core.util.externalizable.DeserializationException; 
    1110import org.javarosa.core.util.externalizable.ExtUtil; 
     
    1312import org.javarosa.core.util.externalizable.ExtWrapTagged; 
    1413import org.javarosa.core.util.externalizable.Externalizable; 
    15 import org.javarosa.core.util.externalizable.ExternalizableHelperDeprecated; 
    1614import org.javarosa.core.util.externalizable.PrototypeFactory; 
    17 import org.javarosa.core.util.externalizable.PrototypeFactoryDeprecated; 
    1815 
    1916/** 
     
    3633        private IDataReference ref; 
    3734        private int dataType; 
    38         //private ... constraints; 
    39  
    40         //do getters/setters later 
     35         
    4136        public Condition relevancyCondition; 
     37        public boolean relevantAbsolute; 
    4238        public Condition requiredCondition; 
    4339        public boolean requiredAbsolute; 
    4440        public Condition readonlyCondition; 
    4541        public boolean readonlyAbsolute; 
     42        public IConditionExpr constraint; 
    4643         
    4744        private String preload; 
    4845        private String preloadParams; 
     46        public String constraintMessage; 
    4947         
    5048        public DataBinding () { 
     49                relevantAbsolute = true; 
    5150                requiredAbsolute = false; 
    5251                readonlyAbsolute = false; 
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/FormDef.java

    r1482 r1516  
    3535public class FormDef implements IFormElement, Localizable, IDRecordable, Externalizable{ 
    3636        private Vector children;        /** A collection of group definitions. */ 
    37         private Vector dataBindings = new Vector(); 
    3837        private int id;         /** The numeric unique identifier of the form definition. */     
    3938        private String name;    /** The display name of the form. */ 
     
    238237                return null; 
    239238        } 
    240          
    241         public Vector getBindings () { 
    242                 return dataBindings; 
    243         } 
    244          
    245         public void setBindings (Vector v) { 
    246                 this.dataBindings = v; 
    247         } 
    248          
     239                         
    249240        /** 
    250241         * @return the preloads 
     
    259250        public void setPreloader(QuestionPreloader preloads) { 
    260251                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); 
    270252        } 
    271253 
     
    290272        public void preloadModel() { 
    291273                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                                 
    298275                Enumeration en = getBindings().elements(); 
    299276                while(en.hasMoreElements()) { 
     
    352329                setName((String)ExtUtil.read(dis, new ExtWrapNullable(String.class), pf)); 
    353330                setChildren((Vector)ExtUtil.read(dis, new ExtWrapListPoly(), pf)); 
    354                 setBindings((Vector)ExtUtil.read(dis, new ExtWrapList(DataBinding.class), pf)); 
    355331                 
    356332                model = (IFormDataModel)ExtUtil.read(dis, new ExtWrapTagged(), pf); 
     
    392368                ExtUtil.write(dos, new ExtWrapNullable(getName())); 
    393369                ExtUtil.write(dos, new ExtWrapListPoly(getChildren())); 
    394                 ExtUtil.write(dos, new ExtWrapList(ExtUtil.emptyIfNull(getBindings()))); 
    395370                ExtUtil.write(dos, new ExtWrapTagged(model)); 
    396371                ExtUtil.write(dos, new ExtWrapNullable(localizer)); 
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/GroupDef.java

    r1482 r1516  
    3232        private int id; /** The group number. */ 
    3333        private String name;    /** The name of the group. */ 
     34        private IDataReference binding; /** reference to a location in the model to store data in */ 
    3435         
    3536        private String longText; 
     
    3738        private String shortText; 
    3839        private String shortTextID; 
     40         
     41        public boolean noAddRemove = false; 
     42        //public boolean startEmpty = false; 
     43        public IDataReference count = null; 
    3944         
    4045        public GroupDef () { 
     
    6570        } 
    6671 
     72        public IDataReference getBind() { 
     73                return binding; 
     74        } 
     75         
     76        public void setBind(IDataReference binding) { 
     77                this.binding = binding; 
     78        } 
     79         
    6780        public Vector getChildren() { 
    6881                return children; 
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/QuestionDef.java

    r1482 r1516  
    5555        private Vector selectItemsLocalizable; 
    5656         
    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; 
    6566                 
    6667        Vector observers; 
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/DataModelTree.java

    r1366 r1516  
    66import java.util.Date; 
    77import java.util.Enumeration; 
     8import java.util.Vector; 
    89 
    910import org.javarosa.core.model.IDataReference; 
     
    1920import org.javarosa.core.util.externalizable.ExtWrapTagged; 
    2021import org.javarosa.core.util.externalizable.PrototypeFactory; 
     22import org.javarosa.model.xform.XPathReference; 
    2123 
    2224/** 
     
    7880        } 
    7981 
     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         
    80141        /* 
    81142         * (non-Javadoc) 
     
    84145         * Object) 
    85146         */ 
    86         public boolean updateDataValue(IDataReference questionBinding, 
    87                         IAnswerData value) { 
     147        public boolean updateDataValue(IDataReference questionBinding, IAnswerData value) { 
    88148                TreeElement treeElement = resolveReference(questionBinding); 
    89149                if (treeElement != null) { 
     
    108168                } 
    109169        } 
    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        } 
    111256         
    112257        /** 
     
    118263         */ 
    119264        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)); 
    154266        } 
    155267         
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataElement.java

    r1482 r1516  
    3434        private IAnswerData value; 
    3535 
    36         /** A Binding for the Question Definition */ 
    37         private IDataReference reference; 
    38  
    3936        /** 
    4037         * Creates a new, blank, QuestionDataElement; 
     
    5047         * @param name 
    5148         *            The name of this TreeElement 
    52          * @param reference 
    53          *            The reference for Question Definitions 
    5449         */ 
    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); 
    5952        } 
    6053 
     54        public QuestionDataElement (String name, int multiplicity) { 
     55                this.name = name; 
     56                this.multiplicity = multiplicity; 
     57        } 
     58         
    6159        /** 
    6260         * Creates a new QuestionDataElement for the question defined by the name 
     
    6563         * @param name 
    6664         *            The name of this TreeElement 
    67          * @param reference 
    68          *            The reference for Question Definitions 
    6965         * @param value 
    7066         *            The value for this Question Definition 
    7167         */ 
    72         public QuestionDataElement(String name, IDataReference reference, 
    73                         IAnswerData value) { 
    74                 this(name, reference); 
     68        public QuestionDataElement(String name, IAnswerData value) { 
     69                this(name); 
    7570                this.value = value; 
    7671        } 
    7772 
    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; 
    8576        } 
    86  
     77                 
    8778        /** 
    8879         * @return The value for the question defined by IBinding 
     
    10697        } 
    10798 
     99        public void setMult (int multiplicity) { 
     100                this.multiplicity = multiplicity; 
     101        } 
     102         
    108103        /* 
    109104         * (non-Javadoc) 
     
    137132        } 
    138133 
    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  
    151134        /** 
    152135         * @return a string representing the value of this question's answer 
     
    173156        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { 
    174157                name = ExtUtil.readString(in); 
    175                 reference = (IDataReference)ExtUtil.read(in, new ExtWrapTagged(), pf); 
     158                //FIXME: reference = (IDataReference)ExtUtil.read(in, new ExtWrapTagged(), pf); 
    176159                 
    177160                // read attributes 
     
    189172        public void writeExternal(DataOutputStream out) throws IOException { 
    190173                ExtUtil.writeString(out, name); 
    191                 ExtUtil.write(out, new ExtWrapTagged(reference)); 
     174                //FIXME: ExtUtil.write(out, new ExtWrapTagged(reference)); 
    192175 
    193176                // write attributes. 
  • branches/dev-repeat/javarosa/org.javarosa.core.model/src/org/javarosa/core/model/instance/QuestionDataGroup.java

    r1366 r1516  
    5252         */ 
    5353        public QuestionDataGroup(String name) { 
    54                 this(); 
     54                this(name, 1); 
     55        } 
     56         
     57        public QuestionDataGroup(String name, int multiplicity) { 
    5558                this.name = name; 
     59                this.multiplicity = multiplicity; 
    5660        } 
    5761         
     
    6468        } 
    6569         
    66         /* 
    67          * (non-Javadoc) 
    68          * @see org.javarosa.core.model.TreeElement#getName() 
    69          */ 
    70         public String getName() { 
    71                 return name; 
    72         } 
    73          
    7470        /** 
    7571         * @return A list of TreeElement that are this Element's children 
     
    7773        public Vector getChildren() { 
    7874                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