public abstract class Parser extends Object
| Constructor and Description |
|---|
Parser()
Uses DefaultModelClassFactory for model class lookup.
|
Parser(ModelClassFactory theFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract String |
doEncode(Message source)
Called by encode(Message) to perform implementation-specific encoding work.
|
protected abstract String |
doEncode(Message source,
String encoding)
Called by encode(Message, String) to perform implementation-specific encoding work.
|
abstract String |
doEncode(Segment structure,
EncodingCharacters encodingCharacters)
Encodes a particular segment and returns the encoded structure
|
abstract String |
doEncode(Type type,
EncodingCharacters encodingCharacters)
Encodes a particular type and returns the encoded structure
|
protected abstract Message |
doParse(String message,
String version)
Called by parse() to perform implementation-specific parsing work.
|
protected abstract Message |
doParseForSpecificPackage(String message,
String version,
String packageName)
Attempt the parse a message using a specific model package
|
String |
encode(Message source)
Formats a Message object into an HL7 message string using this parser's
default encoding.
|
String |
encode(Message source,
String encoding)
Formats a Message object into an HL7 message string using the given
encoding.
|
abstract String |
getAckID(String message)
For response messages, returns the value of MSA-2 (the message ID of the message
sent by the sending system).
|
abstract Segment |
getCriticalResponseData(String message)
Returns a minimal amount of data from a message string, including only the
data needed to send a response to the remote system.
|
abstract String |
getDefaultEncoding() |
abstract String |
getEncoding(String message)
Returns a String representing the encoding of the given message, if
the encoding is recognized.
|
ModelClassFactory |
getFactory() |
static String |
getMessageStructureForEvent(String name,
String version)
Given a concatenation of message type and event (e.g.
|
static Properties |
getMessageStructures(String version)
Returns a copy of the message structure map for a specific version.
|
ParserConfiguration |
getParserConfiguration() |
ValidationContext |
getValidationContext() |
abstract String |
getVersion(String message)
Returns the version ID (MSH-12) from the given message, without fully parsing the message.
|
protected Message |
instantiateMessage(String theName,
String theVersion,
boolean isExplicit)
Note that the validation context of the resulting message is set to this parser's validation
context.
|
protected Message |
instantiateMessageInASpecificPackage(String theName,
String theVersion,
boolean isExplicit,
String packageName)
Instantiate a message type using a specific package name
|
static Segment |
makeControlMSH(String version,
ModelClassFactory factory)
Creates a version-specific MSH object and returns it as a version-independent
MSH interface.
|
abstract void |
parse(Message message,
String string)
Parses a particular message and returns the encoded structure
|
abstract void |
parse(Segment segment,
String string,
EncodingCharacters encodingCharacters)
Parses a particular segment and returns the encoded structure
|
Message |
parse(String message)
Parses a message string and returns the corresponding Message object.
|
abstract void |
parse(Type type,
String string,
EncodingCharacters encodingCharacters)
Parses a particular type and returns the encoded structure
|
Message |
parseForSpecificPackage(String message,
String packageName)
Parse a message using a specific model package instead of the default, using
ModelClassFactory.getMessageClassInASpecificPackage(String, String, boolean, String). |
void |
setParserConfiguration(ParserConfiguration theParserConfiguration)
Sets the parser configuration for this parser (may not be null).
|
void |
setValidationContext(ValidationContext theContext) |
abstract boolean |
supportsEncoding(String encoding)
Returns true if and only if the given encoding is supported
by this Parser.
|
static boolean |
validVersion(String version)
Returns true if the given string represents a valid 2.x version.
|
public Parser()
public Parser(ModelClassFactory theFactory)
theFactory - custom factory to use for model class lookuppublic ModelClassFactory getFactory()
public ValidationContext getValidationContext()
nullpublic void setValidationContext(ValidationContext theContext)
theContext - the set of validation rules to be applied to messages parsed or
encoded by this parser (defaults to ValidationContextFactory.DefaultValidation)public ParserConfiguration getParserConfiguration()
public void setParserConfiguration(ParserConfiguration theParserConfiguration)
theParserConfiguration - The parser configurationpublic abstract String getEncoding(String message)
public abstract boolean supportsEncoding(String encoding)
public abstract String getDefaultEncoding()
public Message parse(String message) throws HL7Exception, EncodingNotSupportedException
message - a String that contains an HL7 messageHL7Exception - if the message is not correctly formatted.EncodingNotSupportedException - if the message encoded
is not supported by this parser.protected abstract Message doParse(String message, String version) throws HL7Exception, EncodingNotSupportedException
message - a String that contains an HL7 messageversion - the name of the HL7 version to which the message belongs (eg "2.5")HL7Exception - if the message is not correctly formatted.EncodingNotSupportedException - if the message encoded
is not supported by this parser.public String encode(Message source, String encoding) throws HL7Exception, EncodingNotSupportedException
source - a Message object from which to construct an encoded message stringencoding - the name of the HL7 encoding to use (eg "XML"; most implementations support only
one encoding)HL7Exception - if the data fields in the message do not permit encoding
(e.g. required fields are null)EncodingNotSupportedException - if the requested encoding is not
supported by this parser.protected abstract String doEncode(Message source, String encoding) throws HL7Exception, EncodingNotSupportedException
source - a Message object from which to construct an encoded message stringencoding - the name of the HL7 encoding to use (eg "XML"; most implementations support only
one encoding)HL7Exception - if the data fields in the message do not permit encoding
(e.g. required fields are null)EncodingNotSupportedException - if the requested encoding is not
supported by this parser.public String encode(Message source) throws HL7Exception
source - a Message object from which to construct an encoded message stringencoding - the name of the encoding to use (eg "XML"; most implementations support only one
encoding)HL7Exception - if the data fields in the message do not permit encoding
(e.g. required fields are null)protected abstract String doEncode(Message source) throws HL7Exception
source - a Message object from which to construct an encoded message stringHL7Exception - if the data fields in the message do not permit encoding
(e.g. required fields are null)EncodingNotSupportedException - if the requested encoding is not
supported by this parser.public abstract Segment getCriticalResponseData(String message) throws HL7Exception
Returns a minimal amount of data from a message string, including only the data needed to send a response to the remote system. This includes the following fields:
HL7Exceptionpublic abstract String getAckID(String message)
public abstract String getVersion(String message) throws HL7Exception
HL7Exception - if the version field can not be found.public abstract String doEncode(Segment structure, EncodingCharacters encodingCharacters) throws HL7Exception
structure - The structure to encodeencodingCharacters - The encoding charactersHL7Exception - If there is a problem encodingpublic abstract String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception
type - The type to encodeencodingCharacters - The encoding charactersHL7Exception - If there is a problem encodingpublic abstract void parse(Type type, String string, EncodingCharacters encodingCharacters) throws HL7Exception
string - The string to parsetype - The type to encodeencodingCharacters - The encoding charactersHL7Exception - If there is a problem encodingpublic Message parseForSpecificPackage(String message, String packageName) throws HL7Exception, EncodingNotSupportedException
ModelClassFactory.getMessageClassInASpecificPackage(String, String, boolean, String).
WARNING: This method is only implemented in some parser implementations. Currently it will only
work with the PipeParser parser implementation. Use with caution.protected abstract Message doParseForSpecificPackage(String message, String version, String packageName) throws HL7Exception, EncodingNotSupportedException
protected Message instantiateMessageInASpecificPackage(String theName, String theVersion, boolean isExplicit, String packageName) throws HL7Exception
public abstract void parse(Segment segment, String string, EncodingCharacters encodingCharacters) throws HL7Exception
string - The string to parsesegment - The segment to encodeencodingCharacters - The encoding charactersHL7Exception - If there is a problem encodingpublic abstract void parse(Message message, String string) throws HL7Exception
string - The string to parsemessage - The message to encodeHL7Exception - If there is a problem encodingpublic static Segment makeControlMSH(String version, ModelClassFactory factory) throws HL7Exception
HL7Exceptionpublic static boolean validVersion(String version)
public static String getMessageStructureForEvent(String name, String version) throws HL7Exception
HL7Exception - if there is an error retrieving the map, or if the given
version is invalidpublic static Properties getMessageStructures(String version) throws IOException
IOException - If the event map can't be loadedprotected Message instantiateMessage(String theName, String theVersion, boolean isExplicit) throws HL7Exception
name - name of the desired structure in the form XXX_YYYversion - HL7 version (e.g. "2.3")isExplicit - true if the structure was specified explicitly in MSH-9-3, false if it
was inferred from MSH-9-1 and MSH-9-2. If false, a lookup may be performed to find
an alternate structure corresponding to that message type and event.HL7Exception - if the version is not recognized or no appropriate class can be found or the Message
class throws an exception on instantiation (e.g. if args are not as expected)Copyright © 2001-2012 University Health Network. All Rights Reserved.