public abstract class Parser extends HapiContextSupport
Constructor and Description |
---|
Parser()
Uses DefaultModelClassFactory for model class lookup.
|
Parser(HapiContext context)
Creates a new parser, using the
ModelClassFactory , the ParserConfiguration
and the ValidationContext as defined in the context. |
Parser(ModelClassFactory modelClassFactory)
Initialize parser with custom ModelClassFactory and default ValidationContext
|
Modifier and Type | Method and Description |
---|---|
protected void |
applySuperStructureName(Message theMessage) |
static void |
assertVersionExists(String version)
Like
validVersion(String) but throws an HL7Exception instead |
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() |
String |
getMessageStructureForEvent(String name,
String version)
Deprecated.
|
ParserConfiguration |
getParserConfiguration()
Returns the parser configuration.
|
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 configuration)
Deprecated.
use a dedicated
HapiContext and set its ParserConfiguration property |
void |
setValidationContext(ValidationContext context)
Deprecated.
use a dedicated
HapiContext and set its ValidationContext property |
boolean |
supportsEncoding(String encoding)
Returns true if and only if the given encoding is supported by this Parser.
|
static boolean |
validVersion(String version)
Deprecated.
|
getHapiContext, setHapiContext
public Parser()
public Parser(HapiContext context)
ModelClassFactory
, the ParserConfiguration
and the ValidationContext
as defined in the context.context
- HapiContextpublic Parser(ModelClassFactory modelClassFactory)
modelClassFactory
- custom factory to use for model class lookuppublic ModelClassFactory getFactory()
public ValidationContext getValidationContext()
null
public void setValidationContext(ValidationContext context)
HapiContext
and set its ValidationContext propertycontext
- the set of validation rules to be applied to messages parsed or encoded by
this parser (defaults to ValidationContextFactory.DefaultValidation)public ParserConfiguration getParserConfiguration()
Returns the parser configuration. This is a bean which contains configuration instructions relating to how a parser should be parsing or encoding messages it deals with.
Note that the parser configuration comes from the HAPI Context
.
Changes to the configuration for one parser will affect all parsers which share the same
context.
public void setParserConfiguration(ParserConfiguration configuration)
HapiContext
and set its ParserConfiguration propertyconfiguration
- The parser configurationpublic abstract String getEncoding(String message)
message
- message stringpublic boolean supportsEncoding(String encoding)
encoding
- the encoding, "XML" or "ER7"public abstract String getDefaultEncoding()
public Message parse(String message) throws HL7Exception
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
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
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
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 stringHL7Exception
- 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:
message
- the messageHL7Exception
- if no MSH segment could be createdpublic abstract String getAckID(String message)
message
- the messagepublic abstract String getVersion(String message) throws HL7Exception
message
- the messageHL7Exception
- 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
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.message
- message stringpackageName
- name of the package of the modelsHL7Exception
- if an error occurred while parsingprotected abstract Message doParseForSpecificPackage(String message, String version, String packageName) throws HL7Exception
HL7Exception
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
segment
- The segment to encodestring
- The string to parseencodingCharacters
- The encoding charactersHL7Exception
- If there is a problem encodingpublic abstract void parse(Message message, String string) throws HL7Exception
message
- The message to encodestring
- The string to parseHL7Exception
- If there is a problem encodingpublic static Segment makeControlMSH(String version, ModelClassFactory factory) throws HL7Exception
Creates a version-specific MSH object and returns it as a version-independent MSH interface.
Since HAPI 2.1, if a version specific MSH
segment can't be found (for example because the specific
structure JAR is not found on the classpath), an instance of
GenericSegment
is returned.
version
- HL7 versionfactory
- model class factory to be usedHL7Exception
- if no matching segment could be found@Deprecated public static boolean validVersion(String version)
Version.supportsVersion(String)
version
- HL7 version stringtrue
if version is knownpublic static void assertVersionExists(String version) throws HL7Exception
validVersion(String)
but throws an HL7Exception insteadversion
- HL7 versionHL7Exception
- if version is unknownpublic String getMessageStructureForEvent(String name, String version) throws HL7Exception
ModelClassFactory.getMessageStructureForEvent(String, Version)
HL7Exception
- if there is an error retrieving the map, or if the given version is
invalidprotected Message instantiateMessage(String theName, String theVersion, boolean isExplicit) throws HL7Exception
theName
- name of the desired structure in the form XXX_YYYtheVersion
- 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)protected void applySuperStructureName(Message theMessage) throws HL7Exception
HL7Exception
Copyright © 2001–2017 University Health Network. All rights reserved.