Package ca.uhn.hl7v2.conf.spec.message

Source Code of ca.uhn.hl7v2.conf.spec.message.AbstractSegmentContainer

package ca.uhn.hl7v2.conf.spec.message;

import ca.uhn.hl7v2.conf.ProfileException;

/**
* An abstraction of SegGroup and MessageProfile (both are containers for segment specs). 
* @author Bryan Tripp
*/
public class AbstractSegmentContainer {
   
    private String description;
    private String reference;
    private String impNote;   
    private ProfileStructure[] children;
   
    /** Utility field used by bound properties. */
    private java.beans.PropertyChangeSupport propertyChangeSupport =  new java.beans.PropertyChangeSupport(this);
   
    /** Utility field used by constrained properties. */
    private java.beans.VetoableChangeSupport vetoableChangeSupport =  new java.beans.VetoableChangeSupport(this);
   
    /** Creates a new instance of AbstractSegmentContainer */
    public AbstractSegmentContainer() {
        children = new ProfileStructure[0];
    }
   
    /** Adds a PropertyChangeListener to the listener list.
     * @param l The listener to add.
     */
    public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
        propertyChangeSupport.addPropertyChangeListener(l);
    }
   
    /** Removes a PropertyChangeListener from the listener list.
     * @param l The listener to remove.
     */
    public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
        propertyChangeSupport.removePropertyChangeListener(l);
    }
   
    /** Adds a VetoableChangeListener to the listener list.
     * @param l The listener to add.
     */
    public void addVetoableChangeListener(java.beans.VetoableChangeListener l) {
        vetoableChangeSupport.addVetoableChangeListener(l);
    }
   
    /** Removes a VetoableChangeListener from the listener list.
     * @param l The listener to remove.
     */
    public void removeVetoableChangeListener(java.beans.VetoableChangeListener l) {
        vetoableChangeSupport.removeVetoableChangeListener(l);
    }
   
    /** Getter for property description.
     * @return Value of property description.
     */
    public String getDescription() {
        return this.description;
    }
   
    /** Setter for property description.
     * @param description New value of property description.
     *
     * @throws ProfileException
     */
    public void setDescription(String description) throws ProfileException {
        String oldDescription = this.description;
        try {
            vetoableChangeSupport.fireVetoableChange("description", oldDescription, description);
        } catch (Exception e) {
            throw new ProfileException(null, e);
        }
        this.description = description;
        propertyChangeSupport.firePropertyChange("description", oldDescription, description);
    }
   
    /** Getter for property reference.
     * @return Value of property reference.
     */
    public String getReference() {
        return this.reference;
    }
   
    /** Setter for property reference.
     * @param reference New value of property reference.
     *
     * @throws ProfileException
     */
    public void setReference(String reference) throws ProfileException {
        String oldReference = this.reference;
        try {
            vetoableChangeSupport.fireVetoableChange("reference", oldReference, reference);
        } catch (Exception e) {
            throw new ProfileException(null, e);
        }
        this.reference = reference;
        propertyChangeSupport.firePropertyChange("reference", oldReference, reference);
    }
   
    /** Getter for property impNote.
     * @return Value of property impNote.
     */
    public String getImpNote() {
        return this.impNote;
    }
   
    /** Setter for property impNote.
     * @param impNote New value of property impNote.
     *
     * @throws ProfileException
     */
    public void setImpNote(String impNote) throws ProfileException {
        String oldImpNote = this.impNote;
        try {
            vetoableChangeSupport.fireVetoableChange("impNote", oldImpNote, impNote);
        } catch (Exception e) {
            throw new ProfileException(null, e);
        }
        this.impNote = impNote;
        propertyChangeSupport.firePropertyChange("impNote", oldImpNote, impNote);
    }
       
   
    /** Indexed getter for property structure (index starts at 1 following HL7 convention).
     * @param index Index of the property (starts at 1 following HL7 convention).
     * @return Value of the property at <CODE>index</CODE>.
     */
    public ProfileStructure getChild(int index) {
        return this.children[index - 1];
    }
   
    /** Indexed setter for property structure.  Lengthens child list if necessary. 
     * @param index Index of the property (starts at 1 following HL7 convention).
     * @param structure New value of the property at <CODE>index</CODE>.
     *
     * @throws ProfileException
     */
    public void setChild(int index, ProfileStructure structure) throws ProfileException {
        index--;
        extendChildList(index);
        ProfileStructure oldStructure = this.children[index];
        this.children[index] = structure;
        try {
            vetoableChangeSupport.fireVetoableChange("structure", null, null );
        }
        catch(java.beans.PropertyVetoException vetoException ) {
            this.children[index] = oldStructure;
            throw new ProfileException(null, vetoException);
        }
        propertyChangeSupport.firePropertyChange("structure", null, null );
    }
   
    /** Returns the number of children */
    public int getChildren() {
        return this.children.length;
    }
   
    /** Makes child list long enough to accommodate setter.  */
    private void extendChildList(int index) {
        if (index >= this.children.length) {
            ProfileStructure[] newCopy = new ProfileStructure[index + 1];
            System.arraycopy(this.children, 0, newCopy, 0, this.children.length);
            this.children = newCopy;
        }       
    }
   
}
TOP

Related Classes of ca.uhn.hl7v2.conf.spec.message.AbstractSegmentContainer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.