001package ca.uhn.hl7v2.conf.spec.message;
002
003import ca.uhn.hl7v2.conf.ProfileException;
004
005/**
006 * An abstraction of the common features of Field, Component, and SubComponent.  
007 * @author Bryan Tripp
008 */
009public class AbstractComponent {
010    
011    /** Creates a new instance of AbstractComponent */
012    public AbstractComponent() {
013        dataValues = new DataValue[0];
014    }
015    
016    
017    /** Utility field used by bound properties. */
018    protected java.beans.PropertyChangeSupport propertyChangeSupport =  new java.beans.PropertyChangeSupport(this);
019    
020    /** Utility field used by constrained properties. */
021    protected java.beans.VetoableChangeSupport vetoableChangeSupport =  new java.beans.VetoableChangeSupport(this);
022    
023    private String impNote;
024    private String description;
025    private String reference;
026    private String predicate;
027    private DataValue[] dataValues;
028    private String name;
029    private String usage;
030    private String datatype;
031    private long length;
032    private String constantValue;
033    private String table;
034    
035    /** Adds a PropertyChangeListener to the listener list.
036     * @param l The listener to add.
037     */
038    public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
039        propertyChangeSupport.addPropertyChangeListener(l);
040    }
041    
042    /** Removes a PropertyChangeListener from the listener list.
043     * @param l The listener to remove.
044     */
045    public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
046        propertyChangeSupport.removePropertyChangeListener(l);
047    }
048    
049    /** Adds a VetoableChangeListener to the listener list.
050     * @param l The listener to add.
051     */
052    public void addVetoableChangeListener(java.beans.VetoableChangeListener l) {
053        vetoableChangeSupport.addVetoableChangeListener(l);
054    }
055    
056    /** Removes a VetoableChangeListener from the listener list.
057     * @param l The listener to remove.
058     */
059    public void removeVetoableChangeListener(java.beans.VetoableChangeListener l) {
060        vetoableChangeSupport.removeVetoableChangeListener(l);
061    }
062    
063    /** Getter for property impNote.
064     * @return Value of property impNote.
065     */
066    public String getImpNote() {
067        return this.impNote;
068    }
069    
070    /** Setter for property impNote.
071     * @param impNote New value of property impNote.
072     *
073     * @throws ProfileException
074     */
075    public void setImpNote(String impNote) throws ProfileException {
076        String oldImpNote = this.impNote;
077        try {
078            vetoableChangeSupport.fireVetoableChange("impNote", oldImpNote, impNote);
079        } catch (Exception e) {
080            throw new ProfileException(null, e);
081        }
082        this.impNote = impNote;
083        propertyChangeSupport.firePropertyChange("impNote", oldImpNote, impNote);
084    }
085    
086    /** Getter for property description.
087     * @return Value of property description.
088     */
089    public String getDescription() {
090        return this.description;
091    }
092    
093    /** Setter for property description.
094     * @param description New value of property description.
095     *
096     * @throws ProfileException
097     */
098    public void setDescription(String description) throws ProfileException {
099        String oldDescription = this.description;
100        try {
101            vetoableChangeSupport.fireVetoableChange("description", oldDescription, description);
102        } catch (Exception e) {
103            throw new ProfileException(null, e);
104        }
105        this.description = description;
106        propertyChangeSupport.firePropertyChange("description", oldDescription, description);
107    }
108    
109    /** Getter for property reference.
110     * @return Value of property reference.
111     */
112    public String getReference() {
113        return this.reference;
114    }
115    
116    /** Setter for property reference.
117     * @param reference New value of property reference.
118     *
119     * @throws ProfileException
120     */
121    public void setReference(String reference) throws ProfileException {
122        String oldReference = this.reference;
123        try {
124            vetoableChangeSupport.fireVetoableChange("reference", oldReference, reference);
125        } catch (Exception e) {
126            throw new ProfileException(null, e);
127        }
128        this.reference = reference;
129        propertyChangeSupport.firePropertyChange("reference", oldReference, reference);
130    }
131    
132    /** Getter for property predicate.
133     * @return Value of property predicate.
134     */
135    public String getPredicate() {
136        return this.predicate;
137    }
138    
139    /** Setter for property predicate.
140     * @param predicate New value of property predicate.
141     *
142     * @throws ProfileException
143     */
144    public void setPredicate(String predicate) throws ProfileException {
145        String oldPredicate = this.predicate;
146        try {
147            vetoableChangeSupport.fireVetoableChange("predicate", oldPredicate, predicate);
148        } catch (Exception e) {
149            throw new ProfileException(null, e);
150        }
151        this.predicate = predicate;
152        propertyChangeSupport.firePropertyChange("predicate", oldPredicate, predicate);
153    }
154    
155    /** Indexed getter for property dataValues.
156     * @param index Index of the property.
157     * @return Value of the property at <CODE>index</CODE>.
158     */
159    public DataValue getDataValues(int index) {
160        return this.dataValues[index];
161    }
162    
163    /** Indexed setter for property dataValues.
164     * @param index Index of the property.
165     * @param dataValues New value of the property at <CODE>index</CODE>.
166     *
167     * @throws ProfileException
168     */
169    public void setDataValues(int index, DataValue dataValue) throws ProfileException {
170        extendDataValuesList(index);
171        DataValue oldDataValues = this.dataValues[index];
172        this.dataValues[index] = dataValue;
173        try {
174            vetoableChangeSupport.fireVetoableChange("dataValues", null, null );
175        }
176        catch(java.beans.PropertyVetoException vetoException ) {
177            this.dataValues[index] = oldDataValues;
178            throw new ProfileException(null, vetoException);
179        }
180        propertyChangeSupport.firePropertyChange("dataValues", null, null );
181    }
182    
183    /** Makes data value list long enough to accommodate setter.  */
184    private void extendDataValuesList(int index) {
185        if (index >= this.dataValues.length) {
186            DataValue[] newCopy = new DataValue[index + 1];
187            System.arraycopy(this.dataValues, 0, newCopy, 0, this.dataValues.length);
188            this.dataValues = newCopy;
189        }        
190    }
191    
192    
193    
194    /** Getter for property name.
195     * @return Value of property name.
196     */
197    public String getName() {
198        return this.name;
199    }
200    
201    /** Setter for property name.
202     * @param name New value of property name.
203     *
204     * @throws ProfileException
205     */
206    public void setName(String name) throws ProfileException {
207        String oldName = this.name;
208        try {
209            vetoableChangeSupport.fireVetoableChange("name", oldName, name);
210        } catch (Exception e) {
211            throw new ProfileException(null, e);
212        }
213        this.name = name;
214        propertyChangeSupport.firePropertyChange("name", oldName, name);
215    }
216    
217    /** Getter for property usage.
218     * @return Value of property usage.
219     */
220    public String getUsage() {
221        return this.usage;
222    }
223    
224    /** Setter for property usage.
225     * @param usage New value of property usage.
226     *
227     * @throws ProfileException
228     */
229    public void setUsage(String usage) throws ProfileException {
230        String oldUsage = this.usage;
231        try {
232            vetoableChangeSupport.fireVetoableChange("usage", oldUsage, usage);
233        } catch (Exception e) {
234            throw new ProfileException(null, e);
235        }
236        this.usage = usage;
237        propertyChangeSupport.firePropertyChange("usage", oldUsage, usage);
238    }
239    
240    /** Getter for property datatype.
241     * @return Value of property datatype.
242     */
243    public String getDatatype() {
244        return this.datatype;
245    }
246    
247    /** Setter for property datatype.
248     * @param datatype New value of property datatype.
249     *
250     * @throws ProfileException
251     */
252    public void setDatatype(String datatype) throws ProfileException {
253        String oldDatatype = this.datatype;
254        try {
255            vetoableChangeSupport.fireVetoableChange("datatype", oldDatatype, datatype);
256        } catch (Exception e) {
257            throw new ProfileException(null, e);
258        }
259        this.datatype = datatype;
260        propertyChangeSupport.firePropertyChange("datatype", oldDatatype, datatype);
261    }
262    
263    /** Getter for property length.
264     * @return Value of property length.
265     */
266    public long getLength() {
267        return this.length;
268    }
269    
270    /** Setter for property length.
271     * @param length New value of property length.
272     *
273     * @throws ProfileException
274     */
275    public void setLength(long length) throws ProfileException {
276        long oldLength = this.length;
277        try {
278            vetoableChangeSupport.fireVetoableChange("length", new Long(oldLength), new Long(length));
279        } catch (Exception e) {
280            throw new ProfileException(null, e);
281        }
282        this.length = length;
283        propertyChangeSupport.firePropertyChange("length", new Long(oldLength), new Long(length));
284    }
285    
286    /** Getter for property constantValue.
287     * @return Value of property constantValue.
288     */
289    public String getConstantValue() {
290        return this.constantValue;
291    }
292    
293    /** Setter for property constantValue.
294     * @param constantValue New value of property constantValue.
295     *
296     * @throws ProfileException
297     */
298    public void setConstantValue(String constantValue) throws ProfileException {
299        String oldConstantValue = this.constantValue;
300        try {
301            vetoableChangeSupport.fireVetoableChange("constantValue", oldConstantValue, constantValue);
302        } catch (Exception e) {
303            throw new ProfileException(null, e);
304        }
305        this.constantValue = constantValue;
306        propertyChangeSupport.firePropertyChange("constantValue", oldConstantValue, constantValue);
307    }
308    
309    /** Getter for property table.
310     * @return Value of property table.
311     */
312    public String getTable() {
313        return this.table;
314    }
315    
316    /** Setter for property table.
317     * @param table New value of property table.
318     *
319     * @throws ProfileException
320     */
321    public void setTable(String table) throws ProfileException {
322        String oldTable = this.table;
323        try {
324            vetoableChangeSupport.fireVetoableChange("table", oldTable, table);
325        } catch (Exception e) {
326            throw new ProfileException(null, e);
327        }
328        this.table = table;
329        propertyChangeSupport.firePropertyChange("table", oldTable, table);
330    }
331    
332}