public class DefaultHapiContext extends Object implements HapiContext
HapiContext
.
With this class you can configure HAPI and obtain all major HAPI business
objects that are initialized accordingly. All configuration objects already
have reasonable defaults.
When using Spring Framework for initializing objects, you can use the factory methods like this:
<!-- Define the context --> <bean id="hapiContext" class="ca.uhn.hl7v2.DefaultHapiContext"> ... </bean> <!-- Obtain the default PipeParser instance --> <bean id="pipeParser" factory-bean="hapiContext" factory-method="getPipeParser"/> ...
Constructor and Description |
---|
DefaultHapiContext() |
DefaultHapiContext(ExecutorService executorService) |
DefaultHapiContext(HapiContext context) |
DefaultHapiContext(ModelClassFactory modelClassFactory) |
DefaultHapiContext(ParserConfiguration parserConfiguration,
ValidationContext validationContext,
ModelClassFactory modelClassFactory) |
DefaultHapiContext(ParserConfiguration parserConfiguration,
ValidationRuleBuilder builder,
ModelClassFactory modelClassFactory) |
DefaultHapiContext(ValidationContext validationContext) |
DefaultHapiContext(ValidationRuleBuilder builder) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
CodeStoreRegistry |
getCodeStoreRegistry() |
Validator |
getConformanceValidator()
Returns a ca.uhn.hl7v2.conf.check.Validator instance.
|
ConnectionHub |
getConnectionHub() |
ExecutorService |
getExecutorService() |
GenericParser |
getGenericParser() |
LowerLayerProtocol |
getLowerLayerProtocol() |
<R> Validator<R> |
getMessageValidator() |
ModelClassFactory |
getModelClassFactory() |
ParserConfiguration |
getParserConfiguration() |
PipeParser |
getPipeParser() |
ProfileStore |
getProfileStore() |
ServerConfiguration |
getServerConfiguration() |
SocketFactory |
getSocketFactory() |
ValidationContext |
getValidationContext()
Returns the ValidationContext.
|
<R> ValidationExceptionHandlerFactory<R> |
getValidationExceptionHandlerFactory() |
ValidationRuleBuilder |
getValidationRuleBuilder() |
XMLParser |
getXMLParser() |
Connection |
newClient(String host,
int port,
boolean tls)
Construct a new HL7 Client which will connect to an external TCP server for
the purpose of sending messages (and receiving responses).
|
Connection |
newClient(String host,
int outboundPort,
int inboundPort,
boolean tls)
Construct a new HL7 two-port client which will connect to an external TCP server for
the purpose of sending messages (and receiving responses).
|
Connection |
newLazyClient(String host,
int port,
boolean tls)
Construct a new HL7 Client which will connect to an external TCP server for
the purpose of sending messages (and receiving responses).
|
Connection |
newLazyClient(String host,
int outboundPort,
int inboundPort,
boolean tls)
Construct a new HL7 two-port client which will connect to an external TCP server for
the purpose of sending messages (and receiving responses).
|
<T extends Message> |
newMessage(Class<T> clazz)
Creates a new message of the provided message structure class, without further initializing the message
|
Message |
newMessage(String eventType,
String triggerEvent,
Version version)
Creates a new message of the given event type, trigger and version, and initializes the message header
|
SimpleServer |
newServer(int port,
boolean tls)
Construct a new HL7 Server which will listen for incoming connections
|
TwoPortService |
newServer(int port1,
int port2,
boolean tls)
Construct a new HL7 Server which will listen for a pair of connections (one for
incoming messages, one for outgoing)
|
void |
setCodeStoreRegistry(CodeStoreRegistry codeStoreRegistry) |
void |
setExecutorService(ExecutorService executorService) |
void |
setLowerLayerProtocol(LowerLayerProtocol llp) |
void |
setModelClassFactory(ModelClassFactory modelClassFactory) |
void |
setParserConfiguration(ParserConfiguration configuration) |
void |
setProfileStore(ProfileStore profileStore) |
void |
setServerConfiguration(ServerConfiguration theServerConfiguration)
Sets the
ServerConfiguration to be used by all HL7 servers obtained from this class. |
void |
setSocketFactory(SocketFactory socketFactory) |
void |
setValidationContext(String contextClassName)
Sets a default
ValidationContext . |
void |
setValidationContext(ValidationContext context) |
<R> void |
setValidationExceptionHandlerFactory(ValidationExceptionHandlerFactory<R> factory) |
void |
setValidationRuleBuilder(String builderClassName)
Sets a new instance of
ValidationRuleBuilder as default. |
void |
setValidationRuleBuilder(ValidationRuleBuilder validationRuleBuilder)
Sets a default
ValidationRuleBuilder . |
public DefaultHapiContext()
public DefaultHapiContext(ExecutorService executorService)
public DefaultHapiContext(ModelClassFactory modelClassFactory)
public DefaultHapiContext(ValidationContext validationContext)
public DefaultHapiContext(ValidationRuleBuilder builder)
public DefaultHapiContext(ParserConfiguration parserConfiguration, ValidationContext validationContext, ModelClassFactory modelClassFactory)
public DefaultHapiContext(ParserConfiguration parserConfiguration, ValidationRuleBuilder builder, ModelClassFactory modelClassFactory)
public DefaultHapiContext(HapiContext context)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public ExecutorService getExecutorService()
getExecutorService
in interface HapiContext
ExecutorService
to be used by all services that spawn threadspublic void setExecutorService(ExecutorService executorService)
setExecutorService
in interface HapiContext
executorService
- the ExecutorService
to be used by all services that spawn
threadspublic ConnectionHub getConnectionHub()
getConnectionHub
in interface HapiContext
public ParserConfiguration getParserConfiguration()
getParserConfiguration
in interface HapiContext
ParserConfiguration
to be used by all parsers obtained from this class.public void setParserConfiguration(ParserConfiguration configuration)
setParserConfiguration
in interface HapiContext
configuration
- ParserConfiguration
to be used by all parsers obtained from this
class.public ValidationContext getValidationContext()
getValidationRuleBuilder()
is called in order to to contruct a
context. If this is also null, the ca.uhn.hl7v2.validation.context_class
system property is evaluated, otherwise it returns the DefaultValidation
context.getValidationContext
in interface HapiContext
ValidationContext
to be used by all parsers obtained from this class.public void setValidationContext(ValidationContext context)
setValidationContext
in interface HapiContext
context
- ValidationContext
to be used by all parsers obtained from this class.public void setValidationContext(String contextClassName)
HapiContext
ValidationContext
. Note that a default ValidationRuleBuilder
has precedence of this ValidationContext.setValidationContext
in interface HapiContext
contextClassName
- class name of the ValidationContext
to be used by all parsers
obtained from this class.public ValidationRuleBuilder getValidationRuleBuilder()
getValidationRuleBuilder
in interface HapiContext
ValidationRuleBuilder
to be used by all parsers obtained from this class.public void setValidationRuleBuilder(ValidationRuleBuilder validationRuleBuilder)
HapiContext
ValidationRuleBuilder
. Note that this ValidationRuleBuilder
has precedence over a default ValidationContext
set with
HapiContext.setValidationContext(ValidationContext)
or HapiContext.setValidationContext(String)
setValidationRuleBuilder
in interface HapiContext
validationRuleBuilder
- ValidationRuleBuilder
to be used by all parsers obtained from this
class.public void setValidationRuleBuilder(String builderClassName)
HapiContext
ValidationRuleBuilder
as default. Note that this
ValidationRuleBuilder
has precedence over a default ValidationContext
set
with HapiContext.setValidationContext(ValidationContext)
or
HapiContext.setValidationContext(String)
setValidationRuleBuilder
in interface HapiContext
builderClassName
- class name of the ValidationRuleBuilder
to be used by all
parsers obtained from this class.public ModelClassFactory getModelClassFactory()
getModelClassFactory
in interface HapiContext
ModelClassFactory
to be used by all parsers obtained from this class.public void setModelClassFactory(ModelClassFactory modelClassFactory)
setModelClassFactory
in interface HapiContext
modelClassFactory
- the ModelClassFactory
to be used by all parsers obtained
from this class.public ProfileStore getProfileStore()
getProfileStore
in interface HapiContext
ProfileStore
to be used for loading conformance profile filespublic void setProfileStore(ProfileStore profileStore)
setProfileStore
in interface HapiContext
profileStore
- the ProfileStore
to be used for loading conformance profile filespublic CodeStoreRegistry getCodeStoreRegistry()
getCodeStoreRegistry
in interface HapiContext
CodeStoreRegistry
to be used for serving codes for conformance profilespublic void setCodeStoreRegistry(CodeStoreRegistry codeStoreRegistry)
setCodeStoreRegistry
in interface HapiContext
codeStoreRegistry
- the CodeStoreRegistry
to be used for serving codes for conformance profilespublic Validator getConformanceValidator()
HapiContext
HapiContext.getMessageValidator()
and configure a Validation rule that checks
a message against a conformance profilegetConformanceValidator
in interface HapiContext
HapiContext.setCodeStoreRegistry(CodeStoreRegistry)
public PipeParser getPipeParser()
getPipeParser
in interface HapiContext
HapiContext.setModelClassFactory(ModelClassFactory)
,
HapiContext.setValidationContext(String)
and
HapiContext.setParserConfiguration(ParserConfiguration)
.public XMLParser getXMLParser()
getXMLParser
in interface HapiContext
HapiContext.setModelClassFactory(ModelClassFactory)
,
HapiContext.setValidationContext(String)
and
HapiContext.setParserConfiguration(ParserConfiguration)
.public GenericParser getGenericParser()
getGenericParser
in interface HapiContext
HapiContext.setModelClassFactory(ModelClassFactory)
,
HapiContext.setValidationContext(String)
and
HapiContext.setParserConfiguration(ParserConfiguration)
.public <R> Validator<R> getMessageValidator()
getMessageValidator
in interface HapiContext
ValidationContext
as set
using HapiContext.setValidationContext(ValidationContext)
. For each validation it will
use a new instance of ValidationExceptionHandler
as obtained by
HapiContext.getValidationExceptionHandlerFactory()
.public <R> ValidationExceptionHandlerFactory<R> getValidationExceptionHandlerFactory()
getValidationExceptionHandlerFactory
in interface HapiContext
public <R> void setValidationExceptionHandlerFactory(ValidationExceptionHandlerFactory<R> factory)
setValidationExceptionHandlerFactory
in interface HapiContext
factory
- a ValidationExceptionHandlerFactory
that is used to create
a ValidationExceptionHandler
during message validation.public LowerLayerProtocol getLowerLayerProtocol()
getLowerLayerProtocol
in interface HapiContext
LowerLayerProtocol
instance used by all HL7 MLLP operationspublic void setLowerLayerProtocol(LowerLayerProtocol llp)
setLowerLayerProtocol
in interface HapiContext
llp
- the LowerLayerProtocol
instance used by all HL7 MLLP operationspublic SocketFactory getSocketFactory()
getSocketFactory
in interface HapiContext
SocketFactory
instance used by HL7 networking operationspublic void setSocketFactory(SocketFactory socketFactory)
setSocketFactory
in interface HapiContext
socketFactory
- the SocketFactory
instance used by HL7 networking operationspublic SimpleServer newServer(int port, boolean tls)
HapiContext
newServer
in interface HapiContext
port
- The port on which to listen for new connectionstls
- Whether or not to use SSL/TLSService.start()
or
Service.startAndWait()
HapiContext.setSocketFactory(SocketFactory)
public TwoPortService newServer(int port1, int port2, boolean tls)
HapiContext
newServer
in interface HapiContext
port1
- The port on which to listen for connections for inbound messagesport2
- The port on which to listen for connections for outgoing messagestls
- Whether or not to use SSL/TLSService.start()
or
Service.startAndWait()
HapiContext.setSocketFactory(SocketFactory)
public Connection newClient(String host, int port, boolean tls) throws HL7Exception
HapiContext
Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
newClient
in interface HapiContext
host
- The host IP/hostname to connect toport
- The port to connect totls
- Whether or not to use SSL/TLSHL7Exception
- If the connection can not be initialized for any reasonpublic Connection newClient(String host, int outboundPort, int inboundPort, boolean tls) throws HL7Exception
HapiContext
Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
newClient
in interface HapiContext
host
- The host IP/hostname to connect tooutboundPort
- The port to connect to for outgoing messagesinboundPort
- The port to connect to for inbound (response) messagestls
- Whether or not to use SSL/TLSHL7Exception
- If the connection can not be initialized for any reasonpublic Connection newLazyClient(String host, int port, boolean tls) throws HL7Exception
HapiContext
Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
newLazyClient
in interface HapiContext
host
- The host IP/hostname to connect toport
- The port to connect totls
- Whether or not to use SSL/TLSHL7Exception
- If the connection can not be initialized for any reasonpublic Connection newLazyClient(String host, int outboundPort, int inboundPort, boolean tls) throws HL7Exception
HapiContext
Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
newLazyClient
in interface HapiContext
host
- The host IP/hostname to connect tooutboundPort
- The port to connect to for outgoing messagesinboundPort
- The port to connect to for inbound (response) messagestls
- Whether or not to use SSL/TLSHL7Exception
- If the connection can not be initialized for any reasonpublic ServerConfiguration getServerConfiguration()
getServerConfiguration
in interface HapiContext
ServerConfiguration
to be used by all HL7 servers obtained from this class.HapiContext.newServer(int, boolean)
,
HapiContext.newServer(int, int, boolean)
public void setServerConfiguration(ServerConfiguration theServerConfiguration)
HapiContext
ServerConfiguration
to be used by all HL7 servers obtained from this class.setServerConfiguration
in interface HapiContext
HapiContext.newServer(int, boolean)
,
HapiContext.newServer(int, int, boolean)
public Message newMessage(String eventType, String triggerEvent, Version version) throws HL7Exception
HapiContext
newMessage
in interface HapiContext
eventType
- event type, e.g. ADTtriggerEvent
- trigger event, e.g. A01version
- HL7v2 versionHL7Exception
- if no message object could be createdpublic <T extends Message> T newMessage(Class<T> clazz) throws HL7Exception
HapiContext
newMessage
in interface HapiContext
T
- message structure class typeclazz
- message structure classHL7Exception
Copyright © 2001–2017 University Health Network. All rights reserved.