1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
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 }