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, Visitable { 038 039 /** 040 * Returns the name of the type (used in XML encoding and profile checking) 041 * 042 * @return the name of the type 043 */ 044 public String getName(); 045 046 /** 047 * Returns an object containing any extra (non-standard) components that 048 * have been added to this type at run-time. This object can also be used 049 * to add components. 050 * 051 * @return an object containing any extra (non-standard) components 052 */ 053 public ExtraComponents getExtraComponents(); 054 055 /** 056 * @return the message to which this Type belongs 057 */ 058 public Message getMessage(); 059 060 /** 061 * <p> 062 * Parses the string into this type and replaces the current contents with 063 * the parsed value. This method accepts HL7 encoded text and treats its 064 * input as such. 065 * </p> 066 * <p> 067 * Note that this method is subtly different from calling {@link Primitive#setValue(String)}, but 068 * can be quite powerful. For example, using the argument of "milk&cookies" on an ST datatype: 069 * <ul> 070 * <li> 071 * If you are using {@link Primitive#setValue(String)}, the ampersand is treated as an actual ampersand 072 * in the text, and the field will be treated as a single field which is encoded as "milk\T\cookies" (\T\ is the 073 * escape sequence for the subcomponent delimiter). 074 * </li> 075 * <li> 076 * If you are using parse(String), the ampersand is treated as a subcomponent delimiter, meaning that 077 * the value is set to "milk", and a second component is added with the value of "cookies". 078 * </li> 079 * </ul> 080 * </p> 081 * <p> 082 * This method makes use of the parser which is stored within the enclosing {@link #getMessage() Message}. 083 * At this time, only PipeParsers are supported. 084 * </p> 085 * 086 * @param string the message to be parsed 087 * @throws HL7Exception if errors occurred while parsing 088 */ 089 public void parse(String string) throws HL7Exception; 090 091 092 /** 093 * Encodes this type using HL7 encoding. 094 * 095 * @return the encoded message 096 * @throws HL7Exception if errors occurred while encoding 097 */ 098 public String encode() throws HL7Exception; 099 100 101 /** 102 * Clears all data from this type 103 */ 104 void clear(); 105 106}