Coverage Report - ca.uhn.hl7v2.conf.spec.message.AbstractSegmentContainer
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSegmentContainer
60%
34/56
100%
2/2
1.562
 
 1  
 package ca.uhn.hl7v2.conf.spec.message;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Arrays;
 5  
 import java.util.Iterator;
 6  
 import java.util.List;
 7  
 
 8  
 import ca.uhn.hl7v2.conf.ProfileException;
 9  
 
 10  
 /**
 11  
  * An abstraction of SegGroup and MessageProfile (both are containers for segment specs).  
 12  
  * @author Bryan Tripp
 13  
  */
 14  
 public class AbstractSegmentContainer implements Iterable<ProfileStructure> {
 15  
     
 16  
     private String description;
 17  
     private String reference;
 18  
     private String impNote;    
 19  165
     private List<ProfileStructure> children = new ArrayList<ProfileStructure>();
 20  
     
 21  
     /** Utility field used by bound properties. */
 22  165
     private java.beans.PropertyChangeSupport propertyChangeSupport =  new java.beans.PropertyChangeSupport(this);
 23  
     
 24  
     /** Utility field used by constrained properties. */
 25  165
     private java.beans.VetoableChangeSupport vetoableChangeSupport =  new java.beans.VetoableChangeSupport(this);
 26  
     
 27  
     /** Creates a new instance of AbstractSegmentContainer */
 28  165
     public AbstractSegmentContainer() {
 29  165
     }
 30  
     
 31  
     public List<ProfileStructure> getChildrenAsList() {
 32  0
             return (children);
 33  
     }
 34  
     
 35  
     /** Adds a PropertyChangeListener to the listener list.
 36  
      * @param l The listener to add.
 37  
      */
 38  
     public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
 39  0
         propertyChangeSupport.addPropertyChangeListener(l);
 40  0
     }
 41  
     
 42  
     /** Removes a PropertyChangeListener from the listener list.
 43  
      * @param l The listener to remove.
 44  
      */
 45  
     public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
 46  0
         propertyChangeSupport.removePropertyChangeListener(l);
 47  0
     }
 48  
     
 49  
     /** Adds a VetoableChangeListener to the listener list.
 50  
      * @param l The listener to add.
 51  
      */
 52  
     public void addVetoableChangeListener(java.beans.VetoableChangeListener l) {
 53  0
         vetoableChangeSupport.addVetoableChangeListener(l);
 54  0
     }
 55  
     
 56  
     /** Removes a VetoableChangeListener from the listener list.
 57  
      * @param l The listener to remove.
 58  
      */
 59  
     public void removeVetoableChangeListener(java.beans.VetoableChangeListener l) {
 60  0
         vetoableChangeSupport.removeVetoableChangeListener(l);
 61  0
     }
 62  
     
 63  
     /** Getter for property description.
 64  
      * @return Value of property description.
 65  
      */
 66  
     public String getDescription() {
 67  0
         return this.description;
 68  
     }
 69  
     
 70  
     /** Setter for property description.
 71  
      * @param description New value of property description.
 72  
      *
 73  
      * @throws ProfileException
 74  
      */
 75  
     public void setDescription(String description) throws ProfileException {
 76  165
         String oldDescription = this.description;
 77  
         try {
 78  165
             vetoableChangeSupport.fireVetoableChange("description", oldDescription, description);
 79  0
         } catch (Exception e) {
 80  0
             throw new ProfileException(null, e);
 81  165
         }
 82  165
         this.description = description;
 83  165
         propertyChangeSupport.firePropertyChange("description", oldDescription, description);
 84  165
     }
 85  
     
 86  
     /** Getter for property reference.
 87  
      * @return Value of property reference.
 88  
      */
 89  
     public String getReference() {
 90  0
         return this.reference;
 91  
     }
 92  
     
 93  
     /** Setter for property reference.
 94  
      * @param reference New value of property reference.
 95  
      *
 96  
      * @throws ProfileException
 97  
      */
 98  
     public void setReference(String reference) throws ProfileException {
 99  165
         String oldReference = this.reference;
 100  
         try {
 101  165
             vetoableChangeSupport.fireVetoableChange("reference", oldReference, reference);
 102  0
         } catch (Exception e) {
 103  0
             throw new ProfileException(null, e);
 104  165
         }
 105  165
         this.reference = reference;
 106  165
         propertyChangeSupport.firePropertyChange("reference", oldReference, reference);
 107  165
     }
 108  
     
 109  
     /** Getter for property impNote.
 110  
      * @return Value of property impNote.
 111  
      */
 112  
     public String getImpNote() {
 113  0
         return this.impNote;
 114  
     }
 115  
     
 116  
     /** Setter for property impNote.
 117  
      * @param impNote New value of property impNote.
 118  
      *
 119  
      * @throws ProfileException
 120  
      */
 121  
     public void setImpNote(String impNote) throws ProfileException {
 122  165
         String oldImpNote = this.impNote;
 123  
         try {
 124  165
             vetoableChangeSupport.fireVetoableChange("impNote", oldImpNote, impNote);
 125  0
         } catch (Exception e) {
 126  0
             throw new ProfileException(null, e);
 127  165
         }
 128  165
         this.impNote = impNote;
 129  165
         propertyChangeSupport.firePropertyChange("impNote", oldImpNote, impNote);
 130  165
     }
 131  
         
 132  
     
 133  
     /** Indexed getter for property structure (index starts at 1 following HL7 convention).
 134  
      * @param index Index of the property (starts at 1 following HL7 convention).
 135  
      * @return Value of the property at <CODE>index</CODE>.
 136  
      */
 137  
     public ProfileStructure getChild(int index) {
 138  20
         return this.children.get(index - 1);
 139  
     }
 140  
     
 141  
     /** Indexed setter for property structure.  Lengthens child list if necessary.  
 142  
      * @param index Index of the property (starts at 1 following HL7 convention).
 143  
      * @param structure New value of the property at <CODE>index</CODE>.
 144  
      *
 145  
      * @throws ProfileException
 146  
      */
 147  
     public void setChild(int index, ProfileStructure structure) throws ProfileException {
 148  540
         index--;
 149  1080
         while (children.size() <= index) {
 150  540
                 children.add(null);
 151  
         }
 152  540
         ProfileStructure oldStructure = this.children.get(index);
 153  540
         this.children.set(index, structure);
 154  
         try {
 155  540
             vetoableChangeSupport.fireVetoableChange("structure", null, null );
 156  
         }
 157  0
         catch(java.beans.PropertyVetoException vetoException ) {
 158  0
             this.children.set(index, oldStructure);
 159  0
             throw new ProfileException(null, vetoException);
 160  540
         }
 161  540
         propertyChangeSupport.firePropertyChange("structure", null, null );
 162  540
     }
 163  
     
 164  
     /** Returns the number of children */
 165  
     public int getChildren() {
 166  0
         return this.children.size();
 167  
     }
 168  
     
 169  
         public Iterator<ProfileStructure> iterator() {
 170  105
                 return (this.children).iterator();
 171  
         }
 172  
     
 173  
 }