001package ca.uhn.hl7v2.hoh.util;
002
003import java.io.InputStream;
004import java.util.Properties;
005
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * Class to log the HAPI version when HAPI is first used (mostly for troubleshooting purposes)
011 */
012public class VersionLogger {
013
014    private static final Logger LOG = LoggerFactory.getLogger(VersionLogger.class);
015        private static boolean ourInitialized = false;
016    private static String ourVersion; 
017    /**
018     * Non-instantiable
019     */
020    private VersionLogger() {
021        // nothing
022    }
023
024    /**
025         * @return Returns the current version of HAPI
026         */
027        public static String getVersion() {
028                init();
029                return ourVersion;
030        }
031
032        /**
033     * Logs the HAPI version on the first time this method is invoked, does nothing afterwards
034     */
035    public static void init() {
036        if (!ourInitialized) {
037            try {
038                InputStream is = VersionLogger.class.getResourceAsStream("/ca/uhn/hl7v2/hoh/hoh-version.properties");
039                Properties p = new Properties();
040                p.load(is);
041                ourVersion = p.getProperty("version");
042                String build = p.getProperty("build");
043                                LOG.info("HL7 over HTTP (HAPI) library version " + ourVersion + " - Build " + build);
044            } catch (Exception e) {
045                // ignore
046            }
047            ourInitialized = true;
048        }
049    }
050    
051}