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