ca.uhn.hl7v2.model
Class AbstractMessage

java.lang.Object
  extended by ca.uhn.hl7v2.model.AbstractGroup
      extended by ca.uhn.hl7v2.model.AbstractMessage
All Implemented Interfaces:
Group, Message, Structure, java.io.Serializable
Direct Known Subclasses:
GenericMessage

public abstract class AbstractMessage
extends AbstractGroup
implements Message

A default implementation of Message.

Author:
Bryan Tripp (bryan_tripp@sourceforge.net)
See Also:
Serialized Form

Constructor Summary
AbstractMessage(ModelClassFactory theFactory)
           
 
Method Summary
 java.lang.String encode()
          Encodes this message using the parser returned by Message.getParser()
 Message generateACK()
           Generates and returns an ACK message which would be used to acknowledge this message successfully, with an MSA-1 code of "AA".
 Message generateACK(java.lang.String theAcknowledgementCode, HL7Exception theException)
           Generates and returns an ACK message which would be used to acknowledge this message successfully.
 java.lang.String getEncodingCharactersValue()
          Convenience method which retrieves the encoding characters value from the second field of the first segment.
 java.lang.Character getFieldSeparatorValue()
          Convenience method which retrieves the field separator value from the first field of the first segment.
 Message getMessage()
          Returns this Message object - this is an implementation of the abstract method in AbstractGroup.
 Parser getParser()
          Returns the parser to be used when parse/encode methods are called on this Message, as well as its children.
 ValidationContext getValidationContext()
           
 java.lang.String getVersion()
          Returns the version number.
 void parse(java.lang.String string)
          Parses the string into this message using the parser returned by Message.getParser()
 void setParser(Parser parser)
          Sets the parser to be used when parse/encode methods are called on this Message, as well as its children.
 void setValidationContext(ValidationContext theContext)
           
 
Methods inherited from class ca.uhn.hl7v2.model.AbstractGroup
add, add, addNonstandardSegment, addNonstandardSegment, clear, currentReps, get, get, getAll, getClass, getModelClassFactory, getName, getNames, getParent, insertRepetition, insertRepetition, isRepeating, isRequired, removeRepetition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ca.uhn.hl7v2.model.Group
addNonstandardSegment, addNonstandardSegment, get, get, getAll, getClass, getNames, isRepeating, isRequired
 
Methods inherited from interface ca.uhn.hl7v2.model.Structure
getName, getParent
 

Constructor Detail

AbstractMessage

public AbstractMessage(ModelClassFactory theFactory)
Parameters:
theFactory - factory for model classes (e.g. group, segment) for this message
Method Detail

getMessage

public Message getMessage()
Returns this Message object - this is an implementation of the abstract method in AbstractGroup.

Specified by:
getMessage in interface Structure
Overrides:
getMessage in class AbstractGroup

getVersion

public java.lang.String getVersion()
Returns the version number. This default implementation inspects this.getClass().getName(). This should be overridden if you are putting a custom message definition in your own package, or it will default.

Specified by:
getVersion in interface Message
See Also:
Message.getVersion()

getValidationContext

public ValidationContext getValidationContext()
Specified by:
getValidationContext in interface Message
Returns:
the set of validation rules that applies to this message

setValidationContext

public void setValidationContext(ValidationContext theContext)
Specified by:
setValidationContext in interface Message
Parameters:
theContext - the set of validation rules that are to apply to this message

getFieldSeparatorValue

public java.lang.Character getFieldSeparatorValue()
                                           throws HL7Exception
Convenience method which retrieves the field separator value from the first field of the first segment. Typically, the first segment is MSH, so this method will retrieve the value of MSH-1.

Specified by:
getFieldSeparatorValue in interface Message
Returns:
The field separator
Throws:
HL7Exception - If an error occurs

getEncodingCharactersValue

public java.lang.String getEncodingCharactersValue()
                                            throws HL7Exception
Convenience method which retrieves the encoding characters value from the second field of the first segment. Typically, the first segment is MSH, so this method will retrieve the value of MSH-2.

Specified by:
getEncodingCharactersValue in interface Message
Returns:
The encoding characters
Throws:
HL7Exception - If an error occurs

setParser

public void setParser(Parser parser)

Sets the parser to be used when parse/encode methods are called on this Message, as well as its children. It is recommended that if these methods are going to be called, a parser be supplied with the validation context wanted. Where possible, the parser should be reused for best performance, unless thread safety is an issue.

Note that not all parsers can be used. As of version 1.0, only PipeParser supports this functionality

Serialization note: The message parser is marked as transient, so it will not survive serialization.

Specified by:
setParser in interface Message

getParser

public Parser getParser()

Returns the parser to be used when parse/encode methods are called on this Message, as well as its children. The default value is a new PipeParser.

Serialization note: The message parser is marked as transient, so it will not survive serialization.

Specified by:
getParser in interface Message

parse

public void parse(java.lang.String string)
           throws HL7Exception
Parses the string into this message using the parser returned by Message.getParser()

Specified by:
parse in interface Message
Throws:
HL7Exception

encode

public java.lang.String encode()
                        throws HL7Exception
Encodes this message using the parser returned by Message.getParser()

Specified by:
encode in interface Message
Throws:
HL7Exception

generateACK

public Message generateACK()
                    throws HL7Exception,
                           java.io.IOException

Generates and returns an ACK message which would be used to acknowledge this message successfully, with an MSA-1 code of "AA". The ACK generated will be of the same version as the value of MSH-12 in this message (as opposed to the version of the message class instance, if they are different)

Note that this method will fail if it is not possible to generate an ACK for any reason, such as


generateACK

public Message generateACK(java.lang.String theAcknowledgementCode,
                           HL7Exception theException)
                    throws HL7Exception,
                           java.io.IOException

Generates and returns an ACK message which would be used to acknowledge this message successfully. The ACK generated will be of the same version as the value of MSH-12 in this message (as opposed to the version of the message class instance, if they are different)

Note that this method will fail if it is not possible to generate an ACK for any reason, such as



Copyright © 2001-2011 University Health Network. All Rights Reserved.