PageRenderTime 28ms CodeModel.GetById 23ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 23package org.mobicents.ss7.sgw;
 24
 25import java.io.InputStream;
 26import java.util.Collections;
 27import java.util.Map;
 28import java.util.Properties;
 29
 30/**
 31 * Version class reads the version.properties packaged with media-server.jar for
 32 * run time display of Media Server Version
 33 * 
 34 * @author amit.bhayani
 35 * 
 36 */
 37public final class Version {
 38
 39	/**
 40	 * The single instance.
 41	 */
 42	public final static Version instance = new Version();
 43
 44	/**
 45	 * The version properties.
 46	 */
 47	private Properties props;
 48
 49	/**
 50	 * Do not allow direct public construction.
 51	 */
 52	private Version() {
 53		props = loadProperties();
 54	}
 55
 56	/**
 57	 * Returns an unmodifiable map of version properties.
 58	 * 
 59	 * @return
 60	 */
 61	public Map getProperties() {
 62		return Collections.unmodifiableMap(props);
 63	}
 64
 65	/**
 66	 * Returns the value for the given property name.
 67	 * 
 68	 * @param name -
 69	 *            The name of the property.
 70	 * @return The property value or null if the property is not set.
 71	 */
 72	public String getProperty(final String name) {
 73		return props.getProperty(name);
 74	}
 75
 76	/**
 77	 * Returns the version information as a string.
 78	 * 
 79	 * @return Basic information as a string.
 80	 */
 81	public String toString() {
 82		StringBuilder sb = new StringBuilder("Mobicents Signaling Gateway: ");
 83		boolean first = true;
 84		for (Object key : props.keySet()) {
 85			if (first) {
 86				first = false;
 87			} else {
 88				sb.append(",");
 89			}
 90			sb.append(key).append('=').append(props.get(key));
 91		}
 92		return sb.toString();
 93	}
 94
 95	/**
 96	 * Load the version properties from a resource.
 97	 */
 98	private Properties loadProperties() {
 99
100		props = new Properties();
101
102		try {
103			InputStream in = Version.class
104					.getResourceAsStream("version.properties");
105			props.load(in);
106			in.close();
107		} catch (Exception e) {
108			throw new Error("Missing version.properties");
109		}
110
111		return props;
112	}
113
114}