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