View Javadoc
1   package ca.uhn.hl7v2.conf.spec.message;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import ca.uhn.hl7v2.conf.ProfileException;
7   
8   /**
9    * The specification for a particular field component in a message profile.
10   * 
11   * @author Bryan Tripp
12   */
13  public class Component extends AbstractComponent<Component> {
14  
15  	private final List<SubComponent> components = new ArrayList<>();
16  
17  	/** Creates a new instance of Component */
18  	public Component() {
19  	}
20  
21  	/**
22  	 * Indexed getter for property components (index starts at 1 following HL7
23  	 * convention).
24  	 * 
25  	 * @param index
26  	 *            Index of the property (starts at 1 following HL7 convention).
27  	 * @return Value of the property at <CODE>index</CODE>.
28  	 */
29  	public SubComponent getSubComponent(int index) {
30  		return this.components.get(index - 1);
31  	}
32  
33  	/**
34  	 * Indexed setter for property components (index starts at 1 following HL7
35  	 * convention).
36  	 * 
37  	 * @param index
38  	 *            Index of the property (starts at 1 following HL7 convention).
39  	 * @param component
40  	 *            New value of the property at <CODE>index</CODE>.
41  	 * 
42  	 * @throws ProfileException
43  	 */
44  	public void setSubComponent(int index, SubComponent component) throws ProfileException {
45  		index--;
46  		while (components.size() <= index) {
47  			components.add(null);
48  		}
49  		SubComponent oldComponent = this.components.get(index);
50  		this.components.set(index, component);
51  		try {
52  			vetoableChangeSupport.fireVetoableChange("components", null, null);
53  		} catch (java.beans.PropertyVetoException vetoException) {
54  			this.components.set(index, oldComponent);
55  			throw new ProfileException(null, vetoException);
56  		}
57  		propertyChangeSupport.firePropertyChange("components", null, null);
58  	}
59  
60  
61  	/** Returns the number of subcomponents in this component */
62  	public int getSubComponents() {
63  		return this.components.size();
64  	}
65  
66  	public List<SubComponent> getChildrenAsList() {
67  		return (this.components);
68  	}
69  
70  	@Override
71  	public String toString() {
72  		return "Component[" + getName() + "]";
73  	}
74  
75  }