001package ca.uhn.hl7v2.conf.spec.message; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import ca.uhn.hl7v2.conf.ProfileException; 007 008/** 009 * The specification for a particular field component in a message profile. 010 * 011 * @author Bryan Tripp 012 */ 013public class Component extends AbstractComponent<Component> { 014 015 private final List<SubComponent> components = new ArrayList<SubComponent>(); 016 017 /** Creates a new instance of Component */ 018 public Component() { 019 } 020 021 /** 022 * Indexed getter for property components (index starts at 1 following HL7 023 * convention). 024 * 025 * @param index 026 * Index of the property (starts at 1 following HL7 convention). 027 * @return Value of the property at <CODE>index</CODE>. 028 */ 029 public SubComponent getSubComponent(int index) { 030 return this.components.get(index - 1); 031 } 032 033 /** 034 * Indexed setter for property components (index starts at 1 following HL7 035 * convention). 036 * 037 * @param index 038 * Index of the property (starts at 1 following HL7 convention). 039 * @param component 040 * New value of the property at <CODE>index</CODE>. 041 * 042 * @throws ProfileException 043 */ 044 public void setSubComponent(int index, SubComponent component) throws ProfileException { 045 index--; 046 while (components.size() <= index) { 047 components.add(null); 048 } 049 SubComponent oldComponent = this.components.get(index); 050 this.components.set(index, component); 051 try { 052 vetoableChangeSupport.fireVetoableChange("components", null, null); 053 } catch (java.beans.PropertyVetoException vetoException) { 054 this.components.set(index, oldComponent); 055 throw new ProfileException(null, vetoException); 056 } 057 propertyChangeSupport.firePropertyChange("components", null, null); 058 } 059 060 061 /** Returns the number of subcomponents in this component */ 062 public int getSubComponents() { 063 return this.components.size(); 064 } 065 066 public List<SubComponent> getChildrenAsList() { 067 return (this.components); 068 } 069 070 @Override 071 public String toString() { 072 return "Component[" + getName() + "]"; 073 } 074 075}