001 package ca.uhn.hl7v2.model;
002
003 import java.util.ArrayList;
004 import java.util.List;
005
006 /**
007 * An unspecified Composite datatype that has an undefined number of components, each
008 * of which is a Varies.
009 * This is used to store Varies data, when the data type is unknown. It is also
010 * used to store unrecognized message constituents.
011 * @author Bryan Tripp
012 */
013 @SuppressWarnings("serial")
014 public class GenericComposite extends AbstractComposite {
015
016 private List<Type> components;
017 private Message message;
018
019 /** Creates a new instance of GenericComposite */
020 public GenericComposite(Message message) {
021 super(message);
022 this.message = message;
023 components = new ArrayList<Type>(20);
024 }
025
026 /**
027 * Returns the single component of this composite at the specified position (starting at 0) -
028 * Creates it (and any nonexistent components before it) if necessary.
029 */
030 public Type getComponent(int number) throws DataTypeException {
031 for (int i = components.size(); i <= number; i++) {
032 components.add(new Varies(message));
033 }
034 return components.get(number);
035 }
036
037 /**
038 * Returns an array containing the components of this field.
039 */
040 public Type[] getComponents() {
041 return components.toArray(new Type[components.size()]);
042 }
043
044 /** Returns the name of the type (used in XML encoding and profile checking) */
045 public String getName() {
046 return "UNKNOWN";
047 }
048
049
050 }