001    /**
002    The 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.
004    You may obtain a copy of the License at http://www.mozilla.org/MPL/
005    Software distributed under the License is distributed on an "AS IS" basis,
006    WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
007    specific language governing rights and limitations under the License.
008    
009    The Initial Developer of the Original Code is University Health Network. Copyright (C)
010    2001.  All Rights Reserved.
011    
012    Contributor(s): ______________________________________.
013    
014    Alternatively, the contents of this file may be used under the terms of the
015    GNU General Public License (the  ???GPL???), in which case the provisions of the GPL are
016    applicable instead of those above.  If you wish to allow use of your version of this
017    file only under the terms of the GPL and not to allow others to use your version
018    of this file under the MPL, indicate your decision by deleting  the provisions above
019    and replace  them with the notice and other provisions required by the GPL License.
020    If you do not delete the provisions above, a recipient may use your version of
021    this file under either the MPL or the GPL.
022    
023    */
024    package ca.uhn.hl7v2.parser;
025    
026    import ca.uhn.hl7v2.HL7Exception;
027    import ca.uhn.hl7v2.model.Type;
028    import ca.uhn.hl7v2.model.Segment;
029    import ca.uhn.hl7v2.model.Message;
030    import ca.uhn.hl7v2.model.Group;
031    
032    /**
033     * Specialized version of ModelClassFactory that always returns the same version. This is useful when designing
034     * applications which are expected to handle multiple versions of HL7. The recommended approach is to
035     * configure this factory to handle the newest version of HL7 you intend to support. Since HL7 is a backwards
036     * compatible protocol, older versions should always be able to parse correctly into a newer message structure.  
037     * 
038     * @version $Revision: 1.2 $ updated on $Date: 2009/10/03 15:25:46 $ by $Author: jamesagnew $
039     * @author This ModelClassFactory implementation is modified by Niranjan.Sharma@med.ge.com on 27-Jul-2009 for CanonicalModel of V2.6
040     */
041    public class CanonicalModelClassFactory extends DefaultModelClassFactory
042    {
043    
044        private static final long serialVersionUID = -1795680089524220526L;
045        
046        private String myVersion;
047    
048        /**
049         * Constructor which selects the newest version of HAPI known to 
050         * 
051         * @param theVersion The version to always return (e.g. "2.6")
052         */
053        public CanonicalModelClassFactory() {
054            myVersion = getHighestKnownVersion();
055        }
056    
057        /**
058         * Constructor
059         * 
060         * @param theVersion The version to always return (e.g. "2.6")
061         */
062        public CanonicalModelClassFactory(String theVersion) {
063            myVersion = theVersion;
064        }
065    
066        /**
067         * {@inheritDoc}
068         */
069        @Override
070        public Class<? extends Group> getGroupClass(String theName, String theVersion) throws HL7Exception {
071            return super.getGroupClass(theName, myVersion);
072        }
073    
074        /**
075         * {@inheritDoc}
076         */
077        @Override
078        public Class<? extends Message> getMessageClass(String theName, String theVersion, boolean theIsExplicit) throws HL7Exception {
079            return super.getMessageClass(theName, myVersion, theIsExplicit);
080        }
081    
082        /**
083         * {@inheritDoc}
084         */
085        @Override
086        public Class<? extends Segment> getSegmentClass(String theName, String theVersion) throws HL7Exception {
087            return super.getSegmentClass(theName, myVersion);
088        }
089    
090        /**
091         * {@inheritDoc}
092         */
093        @Override
094        public Class<? extends Type> getTypeClass(String theName, String theVersion) throws HL7Exception {
095            return super.getTypeClass(theName, myVersion);
096        }
097        
098    }