Class AbstractPrimitive

java.lang.Object
ca.uhn.hl7v2.model.AbstractType
ca.uhn.hl7v2.model.AbstractPrimitive
All Implemented Interfaces:
Primitive, Type, Visitable, Serializable
Direct Known Subclasses:
AbstractTextPrimitive, DT, GenericPrimitive, NULLDT, TM, TSComponentOne

public abstract class AbstractPrimitive extends AbstractType implements Primitive
Base class for Primitives. Performs validation in setValue().
Author:
Bryan Tripp
See Also:
  • Constructor Details

    • AbstractPrimitive

      public AbstractPrimitive(Message message)
      Parameters:
      message - message to which this type belongs
  • Method Details

    • toString

      public String toString()
      Returns the value of getValue()
      Overrides:
      toString in class AbstractType
      See Also:
    • getValue

      public String getValue()
      Description copied from interface: Primitive
      Returns a String representation of the value of this field.
      Specified by:
      getValue in interface Primitive
      Returns:
      a String representation of the value of this field
      See Also:
    • setValue

      public void setValue(String theValue) throws DataTypeException
      Sets the value of this Primitive, first performing validation as specified by getMessage().getValidationContext(). No validation is performed if getMessage() returns null.

      Note: as of the next HAPI release, the ValidationContext will be retrieved from getParser().getValidationContext(), which ultimately is the ValidationContext of the active HapiContext.

      Specified by:
      setValue in interface Primitive
      Parameters:
      theValue - the value to be set
      Throws:
      DataTypeException - if the given value is not valid in this context.
      See Also:
    • encode

      public String encode() throws HL7Exception
      Encodes this type using HL7 encoding.
      Specified by:
      encode in interface Type
      Overrides:
      encode in class AbstractType
      Returns:
      the encoded message
      Throws:
      HL7Exception - if errors occurred while encoding
    • parse

      public void parse(String string) throws HL7Exception

      Parses the string into this type and replaces the current contents with the parsed value. This method accepts HL7 encoded text and treats its input as such.

      Note that this method is subtly different from calling Primitive.setValue(String), but can be quite powerful. For example, using the argument of "milk&cookies" on an ST datatype:

      • If you are using Primitive.setValue(String), the ampersand is treated as an actual ampersand in the text, and the field will be treated as a single field which is encoded as "milk\T\cookies" (\T\ is the escape sequence for the subcomponent delimiter).
      • If you are using parse(String), the ampersand is treated as a subcomponent delimiter, meaning that the value is set to "milk", and a second component is added with the value of "cookies".

      This method makes use of the parser which is stored within the enclosing Message. At this time, only PipeParsers are supported.

      Specified by:
      parse in interface Type
      Overrides:
      parse in class AbstractType
      Parameters:
      string - the message to be parsed
      Throws:
      HL7Exception - if errors occurred while parsing
    • clear

      public void clear()
      Clears all data from this type
      Specified by:
      clear in interface Type
      Overrides:
      clear in class AbstractType
    • isEmpty

      public boolean isEmpty() throws HL7Exception
      Description copied from class: AbstractType
      Returns true if this Visitable has actual content
      Specified by:
      isEmpty in interface Visitable
      Overrides:
      isEmpty in class AbstractType
      Returns:
      true if Visitable is empty
      Throws:
      HL7Exception - if an error occurred while determining emptiness
    • accept

      public boolean accept(MessageVisitor visitor, Location location) throws HL7Exception
      Description copied from interface: Visitable
      Callback method for the visitor. This method is supposed to either directly call one of the visitors methods, passing this as parameter, or traverse through a hierarchical substructure and call accept(MessageVisitor) for each visited element.
      Specified by:
      accept in interface Visitable
      Parameters:
      visitor - MessageVisitor instance to be called back
      location - location of this object
      Returns:
      true if the visit process shall continue
      Throws:
      HL7Exception - if a problem occurred during visiting