001/**
002The contents of this file are subject to the Mozilla Public License Version 1.1
003(the "License"); you may not use this file except in compliance with the License.
004You may obtain a copy of the License at http://www.mozilla.org/MPL/
005Software distributed under the License is distributed on an "AS IS" basis,
006WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
007specific language governing rights and limitations under the License.
008
009The Initial Developer of the Original Code is University Health Network. Copyright (C)
0102001.  All Rights Reserved.
011
012Contributor(s): ______________________________________.
013
014Alternatively, the contents of this file may be used under the terms of the
015GNU General Public License (the  "GPL"), in which case the provisions of the GPL are
016applicable instead of those above.  If you wish to allow use of your version of this
017file only under the terms of the GPL and not to allow others to use your version
018of this file under the MPL, indicate your decision by deleting  the provisions above
019and replace  them with the notice and other provisions required by the GPL License.
020If you do not delete the provisions above, a recipient may use your version of
021this file under either the MPL or the GPL.
022
023*/
024package ca.uhn.hl7v2.parser;
025
026import ca.uhn.hl7v2.HL7Exception;
027import ca.uhn.hl7v2.model.GenericComposite;
028import ca.uhn.hl7v2.model.GenericGroup;
029import ca.uhn.hl7v2.model.GenericMessage;
030import ca.uhn.hl7v2.model.GenericSegment;
031import ca.uhn.hl7v2.model.Group;
032import ca.uhn.hl7v2.model.Message;
033import ca.uhn.hl7v2.model.Segment;
034import ca.uhn.hl7v2.model.Type;
035
036/**
037 * <p>
038 * GenericModelClassFactory is a {@link ModelClassFactory} implementation 
039 * which always returns generic types:
040 * </p>
041 * <ul>
042 *      <li>{@link GenericMessage}</li>
043 *      <li>{@link GenericSegment}</li>
044 *      <li>{@link GenericGroup}</li>
045 * </ul> 
046 * 
047 * <p>
048 * This can be used to run HAPI without any structure JARs, as the generic MCF
049 * has no structure dependencies. See the
050 * <a href="http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/HandlingMultipleVersions.html">using multiple versions</a>
051 * example for more information.
052 * </p>
053 * 
054 * <p>
055 * In combination with {@link ParserConfiguration#setAllowUnknownVersions(boolean)}, the GenericModelClassFactory
056 * can be used to parse future versions of HL7 for which HAPI has no support.
057 * </p>
058 * 
059 * @author James Agnew
060 */
061public class GenericModelClassFactory extends AbstractModelClassFactory {
062
063        private static final long serialVersionUID = 1L;
064
065        /**
066         * {@inheritDoc}
067         */
068        public Class<? extends Message> getMessageClass(String theName, String theVersion, boolean theIsExplicit) throws HL7Exception {
069                return GenericMessage.getGenericMessageClass(theVersion);
070        }
071
072        /**
073         * {@inheritDoc}
074         */
075        public Class<? extends Message> getMessageClassInASpecificPackage(String theName, String theVersion, boolean theIsExplicit, String thePackageName) throws HL7Exception {
076                return GenericMessage.getGenericMessageClass(theVersion);
077        }
078
079        /**
080         * {@inheritDoc}
081         */
082        public Class<? extends Group> getGroupClass(String theName, String theVersion) throws HL7Exception {
083                return GenericGroup.class;
084        }
085
086        /**
087         * {@inheritDoc}
088         */
089        public Class<? extends Segment> getSegmentClass(String theName, String theVersion) throws HL7Exception {
090                return GenericSegment.class;
091        }
092
093        /**
094         * {@inheritDoc}
095         */
096        public Class<? extends Type> getTypeClass(String theName, String theVersion) throws HL7Exception {
097                return GenericComposite.class;
098        }
099
100}