View Javadoc
1   package ca.uhn.hl7v2.model;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * An unspecified Composite datatype that has an undefined number of components, each 
8    * of which is a Varies.  
9    * This is used to store Varies data, when the data type is unknown.  It is also 
10   * used to store unrecognized message constituents.  
11   * @author Bryan Tripp
12   */
13  @SuppressWarnings("serial")
14  public class GenericComposite extends AbstractComposite {
15      
16      private final List<Type> components;
17      private final Message message;
18  
19      /**
20       * Creates a generic composite
21       *
22       * @param message message this object is linked to
23       */
24      public GenericComposite(Message message) {
25          super(message);
26          this.message = message;
27          components = new ArrayList<>(20);
28      }
29      
30      /** 
31       * Returns the single component of this composite at the specified position (starting at 0) - 
32       * Creates it (and any nonexistent components before it) if necessary.  
33       */
34      public Type getComponent(int number) {
35          for (int i = components.size(); i <= number; i++) {
36              components.add(new Varies(message));
37          }
38          return components.get(number);
39      }    
40      
41      /** 
42       * Returns an array containing the components of this field.
43       */
44      public Type[] getComponents() {
45      	return components.toArray(new Type[0]);
46      }    
47      
48      /** Returns the name of the type (used in XML encoding and profile checking)  */
49      public String getName() {
50          return "UNKNOWN";
51      }
52  
53  
54  }