/protocols/ss7/sgw/gateway/src/main/java/org/mobicents/ss7/sgw/Version.java

http://mobicents.googlecode.com/ · Java · 114 lines · 43 code · 14 blank · 57 comment · 3 complexity · cd6020ca17f1dbbcc901f1de2dec5ece MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.ss7.sgw;
  23. import java.io.InputStream;
  24. import java.util.Collections;
  25. import java.util.Map;
  26. import java.util.Properties;
  27. /**
  28. * Version class reads the version.properties packaged with media-server.jar for
  29. * run time display of Media Server Version
  30. *
  31. * @author amit.bhayani
  32. *
  33. */
  34. public final class Version {
  35. /**
  36. * The single instance.
  37. */
  38. public final static Version instance = new Version();
  39. /**
  40. * The version properties.
  41. */
  42. private Properties props;
  43. /**
  44. * Do not allow direct public construction.
  45. */
  46. private Version() {
  47. props = loadProperties();
  48. }
  49. /**
  50. * Returns an unmodifiable map of version properties.
  51. *
  52. * @return
  53. */
  54. public Map getProperties() {
  55. return Collections.unmodifiableMap(props);
  56. }
  57. /**
  58. * Returns the value for the given property name.
  59. *
  60. * @param name -
  61. * The name of the property.
  62. * @return The property value or null if the property is not set.
  63. */
  64. public String getProperty(final String name) {
  65. return props.getProperty(name);
  66. }
  67. /**
  68. * Returns the version information as a string.
  69. *
  70. * @return Basic information as a string.
  71. */
  72. public String toString() {
  73. StringBuilder sb = new StringBuilder("Mobicents Signaling Gateway: ");
  74. boolean first = true;
  75. for (Object key : props.keySet()) {
  76. if (first) {
  77. first = false;
  78. } else {
  79. sb.append(",");
  80. }
  81. sb.append(key).append('=').append(props.get(key));
  82. }
  83. return sb.toString();
  84. }
  85. /**
  86. * Load the version properties from a resource.
  87. */
  88. private Properties loadProperties() {
  89. props = new Properties();
  90. try {
  91. InputStream in = Version.class
  92. .getResourceAsStream("version.properties");
  93. props.load(in);
  94. in.close();
  95. } catch (Exception e) {
  96. throw new Error("Missing version.properties");
  97. }
  98. return props;
  99. }
  100. }