1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is "SMS Library for the Java platform".
15 *
16 * The Initial Developer of the Original Code is Markus Eriksson.
17 * Portions created by the Initial Developer are Copyright (C) 2002
18 * the Initial Developer. All Rights Reserved.
19 *
20 * Contributor(s):
21 * Boris von Loesch
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36 package org.marre.sms;
37
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.util.Properties;
41
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /***
46 * Contains MCC and MNC definitions for various GSM operators.
47 *
48 * TODO: Is this class really needed?
49 *
50 * @author Markus Eriksson
51 * @version $Id: GsmOperators.java,v 1.2 2005/11/26 17:05:04 c95men Exp $
52 */
53 public final class GsmOperators
54 {
55 private static Logger log_ = LoggerFactory.getLogger(GsmOperators.class);
56
57 private static Properties mccMncProperties_ = new Properties();
58
59 private GsmOperators()
60 {
61 // Utility function
62 }
63
64 /***
65 * Returns the Mcc and Mnc number for the given operator.
66 *
67 * @param mccmncProp The property file
68 * @param country the countrycode for the country (e.g. "se", "fi")
69 * @param operator the receivers number in international format (e.g. +49172..)
70 * @return
71 */
72 public static int[] getMCC_MNC(Properties mccmncProp, String country, String operator)
73 {
74 int[] ret = {0, 0};
75
76 String mccStr = mccmncProp.getProperty(country + "." + operator + ".mcc");
77 String mncStr = mccmncProp.getProperty(country + "." + operator + ".mnc");
78
79 if ((mccStr != null) && (mncStr != null))
80 {
81 ret[0] = Integer.valueOf(mccStr).intValue();
82 ret[1] = Integer.valueOf(mncStr).intValue();
83 }
84
85 return ret;
86 }
87
88 /***
89 * Returns the Mcc and Mnc number for the given operator.
90 * The property file is loaded as resource mccmnc.prop
91 *
92 * @param country the countrycode for the country (e.g. "se", "fi")
93 * @param operator the receivers number in international format (e.g. +49172..)
94 * @return
95 */
96 public static int[] getMCC_MNC(String country, String operator)
97 {
98 return getMCC_MNC(mccMncProperties_, country, operator);
99 }
100
101 private static void readMccMncFromResource(String resourceName)
102 {
103 InputStream in = GsmOperators.class.getResourceAsStream(resourceName);
104
105 if (in != null)
106 {
107 try
108 {
109 mccMncProperties_.load(in);
110 }
111 catch (IOException ex)
112 {
113 log_.error("Failed to load mcc and mnc properties", ex);
114 }
115 }
116 }
117
118 static
119 {
120 readMccMncFromResource("resources/gsmoperators.properties");
121 }
122 }