View Javadoc

1   package ca.uhn.hl7v2.conf.spec.message;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import ca.uhn.hl7v2.conf.ProfileException;
7   
8   /**
9    * A specification for a message segment in a conformance profile.  
10   * @author Bryan Tripp
11   */
12  public class Seg implements ProfileStructure {
13      
14      
15      /** Utility field used by bound properties. */
16      private java.beans.PropertyChangeSupport propertyChangeSupport =  new java.beans.PropertyChangeSupport(this);
17      
18      /** Utility field used by constrained properties. */
19      private java.beans.VetoableChangeSupport vetoableChangeSupport =  new java.beans.VetoableChangeSupport(this);
20      
21      private String impNote;    
22      private String description;
23      private String reference;
24      private String predicate;
25      private final List<Field> fields = new ArrayList<Field>();
26      private String name;
27      private String longName;
28      private String usage;
29      private short min;
30      private short max;
31      
32      /** Creates a new instance of Segment */
33      public Seg() {
34      }
35      
36      /** Adds a PropertyChangeListener to the listener list.
37       * @param l The listener to add.
38       */
39      public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
40          propertyChangeSupport.addPropertyChangeListener(l);
41      }
42      
43      /** Removes a PropertyChangeListener from the listener list.
44       * @param l The listener to remove.
45       */
46      public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
47          propertyChangeSupport.removePropertyChangeListener(l);
48      }
49      
50      /** Adds a VetoableChangeListener to the listener list.
51       * @param l The listener to add.
52       */
53      public void addVetoableChangeListener(java.beans.VetoableChangeListener l) {
54          vetoableChangeSupport.addVetoableChangeListener(l);
55      }
56      
57      /** Removes a VetoableChangeListener from the listener list.
58       * @param l The listener to remove.
59       */
60      public void removeVetoableChangeListener(java.beans.VetoableChangeListener l) {
61          vetoableChangeSupport.removeVetoableChangeListener(l);
62      }
63      
64      /** Getter for property impNote.
65       * @return Value of property impNote.
66       */
67      public String getImpNote() {
68          return this.impNote;
69      }
70      
71      /** Setter for property impNote.
72       * @param impNote New value of property impNote.
73       *
74       * @throws ProfileException
75       */
76      public void setImpNote(String impNote) throws ProfileException {
77          String oldImpNote = this.impNote;
78          try {
79              vetoableChangeSupport.fireVetoableChange("impNote", oldImpNote, impNote);
80          } catch (Exception e) {
81              throw new ProfileException(null, e);
82          }
83          this.impNote = impNote;
84          propertyChangeSupport.firePropertyChange("impNote", oldImpNote, impNote);
85      }
86      
87      /** Getter for property description.
88       * @return Value of property description.
89       */
90      public String getDescription() {
91          return this.description;
92      }
93      
94      /** Setter for property description.
95       * @param description New value of property description.
96       *
97       * @throws ProfileException
98       */
99      public void setDescription(String description) throws ProfileException {
100         String oldDescription = this.description;
101         try {
102             vetoableChangeSupport.fireVetoableChange("description", oldDescription, description);
103         } catch (Exception e) {
104             throw new ProfileException(null, e);
105         }
106         this.description = description;
107         propertyChangeSupport.firePropertyChange("description", oldDescription, description);
108     }
109     
110     /** Getter for property reference.
111      * @return Value of property reference.
112      */
113     public String getReference() {
114         return this.reference;
115     }
116     
117     /** Setter for property reference.
118      * @param reference New value of property reference.
119      *
120      * @throws ProfileException
121      */
122     public void setReference(String reference) throws ProfileException {
123         String oldReference = this.reference;
124         try {
125             vetoableChangeSupport.fireVetoableChange("reference", oldReference, reference);
126         } catch (Exception e) {
127             throw new ProfileException(null, e);
128         }
129         this.reference = reference;
130         propertyChangeSupport.firePropertyChange("reference", oldReference, reference);
131     }
132     
133     /** Getter for property predicate.
134      * @return Value of property predicate.
135      */
136     public String getPredicate() {
137         return this.predicate;
138     }
139     
140     /** Setter for property predicate.
141      * @param predicate New value of property predicate.
142      *
143      * @throws ProfileException
144      */
145     public void setPredicate(String predicate) throws ProfileException {
146         String oldPredicate = this.predicate;
147         try {
148             vetoableChangeSupport.fireVetoableChange("predicate", oldPredicate, predicate);
149         } catch (Exception e) {
150             throw new ProfileException(null, e);
151         }
152         this.predicate = predicate;
153         propertyChangeSupport.firePropertyChange("predicate", oldPredicate, predicate);
154     }
155     
156     /** Indexed getter for property field (index starts at 1 following HL7 convention).
157      * @param index Index of the property (starts at 1 following HL7 convention).
158      * @return Value of the property at <CODE>index</CODE>.
159      */
160     public Field getField(int index) {
161         return this.fields.get(index - 1);
162     }
163     
164     /** Indexed setter for property field (index starts at 1 following HL7 convention).
165      * @param index Index of the property (starts at 1 following HL7 convention).
166      * @param field New value of the property at <CODE>index</CODE>.
167      *
168      * @throws ProfileException
169      */
170     public void setField(int index, Field field) throws ProfileException {
171         index--;
172         while (fields.size() <= index) {
173         	fields.add(null);
174         }
175         Field oldField = this.fields.get(index);
176         this.fields.set(index,field);
177         try {
178             vetoableChangeSupport.fireVetoableChange("fields", null, null );
179         }
180         catch(java.beans.PropertyVetoException vetoException ) {
181             this.fields.set(index, oldField);
182             throw new ProfileException(null, vetoException);
183         }
184         propertyChangeSupport.firePropertyChange("fields", null, null );
185     }
186     
187     /** Getter for property name.
188      * @return Value of property name.
189      */
190     public String getName() {
191         return this.name;
192     }
193     
194     /** Setter for property name.
195      * @param name New value of property name.
196      *
197      * @throws ProfileException
198      */
199     public void setName(String name) throws ProfileException {
200         String oldName = this.name;
201         try {
202             vetoableChangeSupport.fireVetoableChange("name", oldName, name);
203         } catch (Exception e) {
204             throw new ProfileException(null, e);
205         }
206         this.name = name;
207         propertyChangeSupport.firePropertyChange("name", oldName, name);
208     }
209     
210     /** Getter for property longName.
211      * @return Value of property longName.
212      */
213     public String getLongName() {
214         return this.longName;
215     }
216     
217     /** Setter for property longName.
218      * @param longName New value of property longName.
219      *
220      * @throws ProfileException
221      */
222     public void setLongName(String longName) throws ProfileException {
223         String oldLongName = this.longName;
224         try {
225             vetoableChangeSupport.fireVetoableChange("longName", oldLongName, longName);
226         } catch (Exception e) {
227             throw new ProfileException(null, e);
228         }
229         this.longName = longName;
230         propertyChangeSupport.firePropertyChange("longName", oldLongName, longName);
231     }
232     
233     /** Getter for property usage.
234      * @return Value of property usage.
235      */
236     public String getUsage() {
237         return this.usage;
238     }
239     
240     /** Setter for property usage.
241      * @param optionality New value of property usage.
242      *
243      * @throws ProfileException
244      */
245     public void setUsage(String usage) throws ProfileException {
246         String oldUsage = this.usage;
247         try {
248             vetoableChangeSupport.fireVetoableChange("usage", oldUsage, usage);
249         } catch (Exception e) {
250             throw new ProfileException(null, e);
251         }            
252         this.usage = usage;
253         propertyChangeSupport.firePropertyChange("usage", oldUsage, usage);
254     }
255     
256     /** Getter for property min.
257      * @return Value of property min.
258      */
259     public short getMin() {
260         return this.min;
261     }
262     
263     /** Setter for property min.
264      * @param min New value of property min.
265      *
266      * @throws ProfileException
267      */
268     public void setMin(short min) throws ProfileException {
269         short oldMin = this.min;
270         try {
271             vetoableChangeSupport.fireVetoableChange("min", new Short(oldMin), new Short(min));
272         } catch (Exception e) {
273             throw new ProfileException(null, e);
274         }            
275         this.min = min;
276         propertyChangeSupport.firePropertyChange("min", new Short(oldMin), new Short(min));
277     }
278     
279     /** Getter for property max.
280      * @return Value of property max.
281      */
282     public short getMax() {
283         return this.max;
284     }
285     
286     /** Setter for property max.
287      * @param max New value of property max.
288      *
289      * @throws ProfileException
290      */
291     public void setMax(short max) throws ProfileException {
292         short oldMax = this.max;
293         try {
294             vetoableChangeSupport.fireVetoableChange("max", new Short(oldMax), new Short(max));
295         } catch (Exception e) {
296             throw new ProfileException(null, e);
297         }
298         this.max = max;
299         propertyChangeSupport.firePropertyChange("max", new Short(oldMax), new Short(max));
300     }
301     
302 
303     /** Returns the number of fields in the segment */
304     public int getFields() {
305         return this.fields.size();
306     }
307 
308     /** Returns the number of fields in the segment */
309     public List<Field> getFieldsAsList() {
310         return (this.fields);
311     }
312 
313     /** Returns the number of fields in the segment */
314     public List<Field> getChildrenAsList() {
315         return (this.fields);
316     }
317 
318 }