001/**
002The contents of this file are subject to the Mozilla Public License Version 1.1 
003(the "License"); you may not use this file except in compliance with the License. 
004You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
005Software distributed under the License is distributed on an "AS IS" basis, 
006WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
007specific language governing rights and limitations under the License. 
008
009The Original Code is "Type.java".  Description: 
010"An HL7 datatype" 
011
012The Initial Developer of the Original Code is University Health Network. Copyright (C) 
0132001.  All Rights Reserved. 
014
015Contributor(s): ______________________________________. 
016
017Alternatively, the contents of this file may be used under the terms of the 
018GNU General Public License (the  �GPL�), in which case the provisions of the GPL are 
019applicable instead of those above.  If you wish to allow use of your version of this 
020file only under the terms of the GPL and not to allow others to use your version 
021of this file under the MPL, indicate your decision by deleting  the provisions above 
022and replace  them with the notice and other provisions required by the GPL License.  
023If you do not delete the provisions above, a recipient may use your version of 
024this file under either the MPL or the GPL. 
025
026*/
027
028package ca.uhn.hl7v2.model;
029
030import ca.uhn.hl7v2.HL7Exception;
031import java.io.Serializable;
032
033/**
034 * An HL7 datatype.  Datatypes normally implement either Composite or Primitive.    
035 * @author Bryan Tripp (bryan_tripp@sourceforge.net)
036 */
037public interface Type extends Serializable {
038
039    /** Returns the name of the type (used in XML encoding and profile checking) */
040    public String getName();
041    
042    /**
043     * Returns an object containing any extra (non-standard) components that 
044     * have been added to this type at run-time.  This object can also be used
045     * to add components.  
046     */
047    public ExtraComponents getExtraComponents();
048    
049    /**
050     * @return the message to which this Type belongs
051     */
052    public Message getMessage();
053
054    /**
055     * <p>
056     * Parses the string into this type and replaces the current contents with
057     * the parsed value. This method accepts HL7 encoded text and treats its
058     * input as such.
059     * </p>
060     * <p>
061     * Note that this method is subtly different from calling {@link Primitive#setValue(String)}, but
062     * can be quite powerful. For example, using the argument of "milk&cookies" on an ST datatype:
063     * <ul>
064     * <li>
065     * If you are using {@link Primitive#setValue(String)}, the ampersand is treated as an actual ampersand 
066     * in the text, and the field will be treated as a single field which is encoded as "milk\T\cookies" (\T\ is the 
067     * escape sequence for the subcomponent delimiter).
068     * </li>
069     * <li>
070     * If you are using parse(String), the ampersand is treated as a subcomponent delimiter, meaning that
071     * the value is set to "milk", and a second component is added with the value of "cookies".
072     * </li>
073     * </ul>
074     * </p>  
075     * <p>
076     * This method makes use of the parser which is stored within the enclosing {@link #getMessage() Message}.
077     * At this time, only PipeParsers are supported. 
078     * </p>
079     */
080    public void parse(String string) throws HL7Exception;
081
082
083    /**
084     * Encodes this type using HL7 encoding.
085     */
086    public String encode() throws HL7Exception;
087
088
089        /**
090         * Clears all data from this type
091         */
092        void clear();
093}