| 1 | |
package ca.uhn.hl7v2; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.InputStream; |
| 5 | |
import java.util.Properties; |
| 6 | |
|
| 7 | |
import org.slf4j.Logger; |
| 8 | |
import org.slf4j.LoggerFactory; |
| 9 | |
import org.w3c.dom.DOMImplementation; |
| 10 | |
|
| 11 | |
import ca.uhn.hl7v2.util.XMLUtils; |
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
public class VersionLogger { |
| 17 | |
|
| 18 | 5 | private static boolean ourInitialized = false; |
| 19 | |
private static String ourVersion; |
| 20 | 5 | private static final Logger LOG = LoggerFactory.getLogger(VersionLogger.class); |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | 0 | private VersionLogger() { |
| 26 | |
|
| 27 | 0 | } |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public static void init() { |
| 33 | 5585 | if (!ourInitialized) { |
| 34 | 5 | printHapiVersion(); |
| 35 | 5 | checkStructureLibraries(); |
| 36 | 5 | checkDOMImplementation(); |
| 37 | 5 | ourInitialized = true; |
| 38 | |
} |
| 39 | 5585 | } |
| 40 | |
|
| 41 | |
private static void checkDOMImplementation() { |
| 42 | |
try { |
| 43 | |
|
| 44 | 5 | DOMImplementation impl = XMLUtils.getDOMImpl(); |
| 45 | 5 | if (impl == null) { |
| 46 | 0 | LOG.warn("DOM Level 3 (Load and Save) is NOT supported by the XML library found first on your classpath!"); |
| 47 | 0 | LOG.warn("XML parsing and encoding as well as working with Conformance Profiles will fail."); |
| 48 | |
} |
| 49 | 0 | } catch (Throwable e) { |
| 50 | 0 | LOG.warn("Error occured while trying to retrieve a DOMImplementation.", e); |
| 51 | 0 | LOG.warn("XML parsing and encoding as well as working with Conformance Profiles will fail."); |
| 52 | 5 | } |
| 53 | 5 | } |
| 54 | |
|
| 55 | |
private static void checkStructureLibraries() { |
| 56 | |
|
| 57 | 5 | StringBuilder sb = new StringBuilder(); |
| 58 | 5 | for (Version v : Version.availableVersions()) { |
| 59 | 55 | sb.append(v.getVersion()); |
| 60 | 55 | sb.append(sb.length() > 0 ? ", " : ""); |
| 61 | 55 | } |
| 62 | 5 | if (sb.length() == 0) { |
| 63 | 0 | LOG.warn("No HL7 structure libraries found on the classpath!"); |
| 64 | |
} else { |
| 65 | 5 | LOG.info("Default Structure libraries found for HL7 versions {}", sb.toString()); |
| 66 | |
} |
| 67 | 5 | } |
| 68 | |
|
| 69 | |
private static void printHapiVersion() { |
| 70 | 5 | InputStream is = null; |
| 71 | |
try { |
| 72 | 5 | is = VersionLogger.class |
| 73 | 5 | .getResourceAsStream("/ca/uhn/hl7v2/hapi-version.properties"); |
| 74 | 5 | Properties p = new Properties(); |
| 75 | 5 | p.load(is); |
| 76 | 5 | ourVersion = p.getProperty("version"); |
| 77 | 5 | LOG.info("HAPI version is: " + ourVersion); |
| 78 | 0 | } catch (IOException e) { |
| 79 | 0 | LOG.warn("Unable to determine HAPI version information", e); |
| 80 | |
} finally { |
| 81 | 5 | if (is != null) { |
| 82 | |
try { |
| 83 | 5 | is.close(); |
| 84 | 0 | } catch (IOException e) { |
| 85 | |
|
| 86 | 5 | } |
| 87 | |
} |
| 88 | |
} |
| 89 | 5 | } |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
public static String getVersion() { |
| 95 | 0 | return ourVersion; |
| 96 | |
} |
| 97 | |
|
| 98 | |
} |