001 package ca.uhn.hl7v2.conf.spec.message;
002
003 import ca.uhn.hl7v2.conf.ProfileException;
004
005 /**
006 * The specification for a particular field component in a message profile.
007 * @author Bryan Tripp
008 */
009 public class Component extends AbstractComponent {
010
011 private SubComponent[] components;
012
013 /** Creates a new instance of Component */
014 public Component() {
015 components = new SubComponent[0];
016 }
017
018 /** Indexed getter for property components (index starts at 1 following HL7 convention).
019 * @param index Index of the property (starts at 1 following HL7 convention).
020 * @return Value of the property at <CODE>index</CODE>.
021 */
022 public SubComponent getSubComponent(int index) {
023 return this.components[index - 1];
024 }
025
026 /** Indexed setter for property components (index starts at 1 following HL7 convention).
027 * @param index Index of the property (starts at 1 following HL7 convention).
028 * @param component New value of the property at <CODE>index</CODE>.
029 *
030 * @throws ProfileException
031 */
032 public void setSubComponent(int index, SubComponent component) throws ProfileException {
033 index--;
034 extendChildList(index);
035 SubComponent oldComponent = this.components[index];
036 this.components[index] = component;
037 try {
038 vetoableChangeSupport.fireVetoableChange("components", null, null );
039 }
040 catch(java.beans.PropertyVetoException vetoException ) {
041 this.components[index] = oldComponent;
042 throw new ProfileException(null, vetoException);
043 }
044 propertyChangeSupport.firePropertyChange("components", null, null );
045 }
046
047 /** Makes child list long enough to accommodate setter. */
048 private void extendChildList(int index) {
049 if (index >= this.components.length) {
050 SubComponent[] newCopy = new SubComponent[index + 1];
051 System.arraycopy(this.components, 0, newCopy, 0, this.components.length);
052 this.components = newCopy;
053 }
054 }
055
056 /** Returns the number of subcomponents in this component */
057 public int getSubComponents() {
058 return this.components.length;
059 }
060
061 }