001/*
002 * Created on 21-Apr-2005
003 */
004package ca.uhn.hl7v2.parser;
005
006import java.io.Serializable;
007
008import ca.uhn.hl7v2.HL7Exception;
009import ca.uhn.hl7v2.Version;
010import ca.uhn.hl7v2.model.Group;
011import ca.uhn.hl7v2.model.Message;
012import ca.uhn.hl7v2.model.Segment;
013import ca.uhn.hl7v2.model.Type;
014
015/**
016 * Looks up classes for message model components (e.g. concrete implementations of Message, Group,
017 * Segment). A custom factory can be used to point to custom model components.
018 * 
019 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
020 * @version $Revision: 1.3 $ updated on $Date: 2009-10-03 15:25:46 $ by $Author: jamesagnew $
021 */
022public interface ModelClassFactory extends Serializable {
023
024        /**
025         * @param theName name of message
026         * @param theVersion HL7 version
027         * @param isExplicit true if the structure was specified explicitly in MSH-9-3, false if it was
028         *            inferred from MSH-9-1 and MSH-9-2. If false, a lookup may be performed to find an
029         *            alternate structure corresponding to that message type and event.
030         * @return a class that implements the specified message
031         * @throws HL7Exception if the version if not recognized or an appropriate class can not be
032         *             found
033         */
034        public Class<? extends Message> getMessageClass(String theName, String theVersion,
035                        boolean isExplicit) throws HL7Exception;
036
037        /**
038         * Retrieves a message class by looking in a specific java package for the message type.
039         * 
040         * @param theName The message structure type (e.g. "ADT_A01")
041         * @param theVersion The HL7 version (e.g. "2.3.1")
042         * @param isExplicit If false, the message structure is looked up using
043         *            {@link Parser#getMessageStructureForEvent(String, String)} and converted to the
044         *            appropriate structure type. For example, "ADT_A04" would be converted to "ADT_A01"
045         *            because the A04 trigger uses the A01 message structure according to HL7.
046         * @param packageName The package name to use. Note that if the message type can't be found in
047         *            this package, HAPI will return the standard type returned by
048         *            {@link #getMessageClass(String, String, boolean)}
049     * @return message class
050         * @since 2.0
051         */
052        public Class<? extends Message> getMessageClassInASpecificPackage(String theName,
053                        String theVersion, boolean isExplicit, String packageName) throws HL7Exception;
054
055        /**
056         * @param theName name of group
057         * @param theVersion HL7 version
058         * @return a class that implements the specified group
059         * @throws HL7Exception if the version if not recognized or an appropriate class can not be
060         *             found
061         */
062        public Class<? extends Group> getGroupClass(String theName, String theVersion)
063                        throws HL7Exception;
064
065        /**
066         * @param theName name of segment
067         * @param theVersion HL7 version
068         * @return a class that implements the specified segment
069         * @throws HL7Exception if the version if not recognized or an appropriate class can not be
070         *             found
071         */
072        public Class<? extends Segment> getSegmentClass(String theName, String theVersion)
073                        throws HL7Exception;
074
075        /**
076         * @param theName name of type
077         * @param theVersion HL7 version
078         * @return a class that implements the specified type
079         * @throws HL7Exception if the version if not recognized or an appropriate class can not be
080         *             found
081         */
082        public Class<? extends Type> getTypeClass(String theName, String theVersion)
083                        throws HL7Exception;
084
085        /**
086         * @param eventName event name
087         * @param version HL7 version
088         * @return message structure name for the eventName and version or <code>null</code> if none
089         *         could be found
090         * @throws HL7Exception if the version is unknown or the message structure list is inaccessible
091         */
092        public String getMessageStructureForEvent(String eventName, Version version)
093                        throws HL7Exception;
094}