001package ca.uhn.hl7v2.model;
002
003import java.util.ArrayList;
004import 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")
014public class GenericComposite extends AbstractComposite {
015    
016    private List<Type> components;
017    private Message message;
018
019    /**
020     * Creates a generic composite
021     *
022     * @param message message this object is linked to
023     */
024    public GenericComposite(Message message) {
025        super(message);
026        this.message = message;
027        components = new ArrayList<Type>(20);
028    }
029    
030    /** 
031     * Returns the single component of this composite at the specified position (starting at 0) - 
032     * Creates it (and any nonexistent components before it) if necessary.  
033     */
034    public Type getComponent(int number) throws DataTypeException {
035        for (int i = components.size(); i <= number; i++) {
036            components.add(new Varies(message));
037        }
038        return components.get(number);
039    }    
040    
041    /** 
042     * Returns an array containing the components of this field.
043     */
044    public Type[] getComponents() {
045        return components.toArray(new Type[components.size()]);
046    }    
047    
048    /** Returns the name of the type (used in XML encoding and profile checking)  */
049    public String getName() {
050        return "UNKNOWN";
051    }
052
053
054}