Class DefaultModelClassFactory
- All Implemented Interfaces:
ModelClassFactory,Serializable
- Direct Known Subclasses:
CanonicalModelClassFactory
- Version:
- $Revision: 1.9 $ updated on $Date: 2010-08-05 17:51:16 $ by $Author: jamesagnew $
- Author:
- Bryan Tripp
- See Also:
-
Field Summary
Fields inherited from class ca.uhn.hl7v2.parser.AbstractModelClassFactory
DEFAULT_EVENT_MAP_DIRECTORY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetGroupClass(String theName, String theVersion) static StringReturns a string containing the highest known version of HL7 known to HAPI (i.e.getMessageClass(String theName, String theVersion, boolean isExplicit) Attempts to return the message class corresponding to the given name, by searching through default and user-defined (as per packageList()) packages.getMessageClassInASpecificPackage(String theName, String theVersion, boolean isExplicit, String packageName) Retrieves and instantiates a message class by looking in a specific java package for the message type.getMessageStructureForEvent(String name, Version version) Returns the event structure.getSegmentClass(String theName, String theVersion) getTypeClass(String theName, String theVersion) static StringReturns the package name for model elements of the given version - e.g.static StringReturns the path to the base package for model elements of the given version - e.g.static String[]packageList(String version) Lists all the packages (user-definable) where classes for standard and custom messages may be found.static voidReloads the packages.Methods inherited from class ca.uhn.hl7v2.parser.AbstractModelClassFactory
getEventMapDirectory, getEventMapForVersion, loadMessageStructures, setEventMapDirectory
-
Constructor Details
-
DefaultModelClassFactory
public DefaultModelClassFactory()
-
-
Method Details
-
getMessageClass
public Class<? extends Message> getMessageClass(String theName, String theVersion, boolean isExplicit) throws HL7Exception Attempts to return the message class corresponding to the given name, by searching through default and user-defined (as per packageList()) packages. Returns GenericMessage if the class is not found.
It is important to note that there can only be one implementation of a particular message structure (i.e. one class with the message structure name, regardless of its package) among the packages defined as per the
packageList()method. If there are duplicates (e.g. two ADT_A01 classes) the first one in the search order will always be used. However, this restriction only applies to message classes, not (normally) segment classes, etc. This is because classes representing parts of a message are referenced explicitly in the code for the message class, rather than being looked up (using findMessageClass() ) based on the String value of MSH-9. The exception is that Segments may have to be looked up by name when they appear in unexpected locations (e.g. by local extension) -- see findSegmentClass().Note: the current implementation will be slow if there are multiple user- defined packages, because the JVM will try to load a number of non-existent classes every parse. This should be changed so that specific classes, rather than packages, are registered by name.
- Parameters:
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.- Returns:
- corresponding message subclass if found; GenericMessage otherwise
- Throws:
HL7Exception- if the version if not recognized or an appropriate class can not be found
-
getGroupClass
- Parameters:
theName- name of grouptheVersion- HL7 version- Returns:
- a class that implements the specified group
- Throws:
HL7Exception- if the version if not recognized or an appropriate class can not be found- See Also:
-
getSegmentClass
public Class<? extends Segment> getSegmentClass(String theName, String theVersion) throws HL7Exception - Parameters:
theName- name of segmenttheVersion- HL7 version- Returns:
- a class that implements the specified segment
- Throws:
HL7Exception- if the version if not recognized or an appropriate class can not be found- See Also:
-
getTypeClass
- Parameters:
theName- name of typetheVersion- HL7 version- Returns:
- a class that implements the specified type
- Throws:
HL7Exception- if the version if not recognized or an appropriate class can not be found- See Also:
-
getMessageClassInASpecificPackage
public Class<? extends Message> getMessageClassInASpecificPackage(String theName, String theVersion, boolean isExplicit, String packageName) throws HL7Exception Retrieves and instantiates a message class by looking in a specific java package for the message type.- Parameters:
theName- The message structure type (e.g. "ADT_A01")theVersion- The HL7 version (e.g. "2.3.1")isExplicit- If false, the message structure is looked up usingParser.getMessageStructureForEvent(String, String)and converted to the appropriate structure type. For example, "ADT_A04" would be converted to "ADT_A01" because the A04 trigger uses the A01 message structure according to HL7.packageName- The package name to use. Note that if the message type can't be found in this package, HAPI will return the standard type returned bygetMessageClass(String, String, boolean)- Returns:
- message class
- Throws:
HL7Exception- Since:
- 1.3
-
getVersionPackagePath
Returns the path to the base package for model elements of the given version - e.g. "ca/uhn/hl7v2/model/v24/". This package should have the packages datatype, segment, group, and message under it. The path ends in with a slash.- Parameters:
ver- HL7 version- Returns:
- package path of the version
- Throws:
HL7Exception- if the HL7 version is unknown
-
getVersionPackageName
Returns the package name for model elements of the given version - e.g. "ca.uhn.hl7v2.model.v24.". This method is identical togetVersionPackagePath(...)except that path separators are replaced with dots.- Parameters:
ver- HL7 version- Returns:
- package name of the version
- Throws:
HL7Exception- if the HL7 version is unknown
-
packageList
Lists all the packages (user-definable) where classes for standard and custom messages may be found. Each package has subpackages called "message", "group", "segment", and "datatype" in which classes for these message elements can be found.
At a minimum, this method returns the standard package for the given version. For example, for version 2.4, the package list contains
ca.uhn.hl7v2.model.v24. In addition, user-defined packages may be specified for custom messages.If you define custom message classes, and want Parsers to be able to find them, you must register them as follows (otherwise you will get an exception when the corresponding messages are parsed). For each HL7 version you want to support, you must put a text file on your classpath, under the folder /custom_packages, named after the version. For example, for version 2.4, you might put the file "custom_packages/2.4" in your application JAR. Each line in the file should name a package to search for message classes of that version. For example, if you work at foo.org, you might create a v2.4 message structure called "ZFO" and define it in the class
org.foo.hl7.custom.message.ZFO. In order for parsers to find this message class, you would need to enter the following line in custom_packages/2.4:org.foo.hl7.custom
Packages are searched in the order specified. The standard package for a given version is searched last, allowing you to override the default implementation. Please note that if you create custom classes for messages, segments, etc., their names must correspond exactly to their names in the message text. For example, if you subclass the QBP segment in order to add your own fields, your subclass must also be called QBP. although it will obviously be in a different package. To make sure your class is used instead of the default implementation, put your package in the package list. User-defined packages are searched first, so yours will be found first and used.
It is important to note that there can only be one implementation of a particular message structure (i.e. one class with the message structure name, regardless of its package) among the packages defined as per the
packageList()method. If there are duplicates (e.g. two ADT_A01 classes) the first one in the search order will always be used. However, this restriction only applies to message classes, not segment classes, etc. This is because classes representing parts of a message are referenced explicitly in the code for the message class, rather than being looked up (using findMessageClass() ) based on the String value of MSH-9.- Parameters:
version- HL7 version- Returns:
- array of package prefix names
-
reloadPackages
Reloads the packages. Note that this should not be performed after and messages have been parsed or otherwise generated, as undetermined behaviour may result. -
getHighestKnownVersion
Returns a string containing the highest known version of HL7 known to HAPI (i.e. "2.6"). Note that this is determined by checking which structure JARs are available on the classpath, so if this release of HAPI supports version 2.6, but only the hapi-structures-v23.jar is available on the classpath, "2.3" will be returned- Returns:
- the most recent HL7 version known to HAPI
-
getMessageStructureForEvent
Returns the event structure. If nothing could be found, the event name is returned- Specified by:
getMessageStructureForEventin interfaceModelClassFactory- Overrides:
getMessageStructureForEventin classAbstractModelClassFactory- Parameters:
name- event nameversion- HL7 version- Returns:
- message structure name for the eventName and version or
nullif none could be found - Throws:
HL7Exception- if the version is unknown or the message structure list is inaccessible- See Also:
-