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 package org.marre.sms.transport;
36
37 import java.util.Properties;
38
39 import org.marre.sms.SmsException;
40
41 /***
42 * SMS Transport Manager.
43 *
44 * Contains methods to manage the different transports.
45 *
46 * @author Markus Eriksson
47 * @version $Id: SmsTransportManager.java,v 1.8 2005/04/26 16:59:11 c95men Exp $
48 */
49 public final class SmsTransportManager
50 {
51 private SmsTransportManager()
52 {
53
54 }
55
56 /***
57 * Dynamically instantiates and initializes an SmsTransport.
58 *
59 * @param theClassname
60 * Full classname of the transport. E.g.
61 * "org.marre.sms.transport.gsm.GsmTransport"
62 * @param theProps
63 * Properties to initialize the transport with.
64 * @return An initialized SmsTransport object
65 * @throws SmsException
66 * If we failed to load the requested transport
67 */
68 public static SmsTransport getTransport(String theClassname, Properties theProps) throws SmsException
69 {
70 SmsTransport transport = null;
71
72 try
73 {
74
75 Class clazz = Class.forName(theClassname);
76 Object obj = clazz.newInstance();
77
78
79 transport = (SmsTransport) obj;
80 transport.init(theProps);
81
82 return (SmsTransport) obj;
83 }
84 catch (ClassCastException ex)
85 {
86 throw new SmsException(theClassname + "is not an SmsTransport.", ex);
87 }
88 catch (ClassNotFoundException ex)
89 {
90 throw new SmsException("Couldn't find " + theClassname + ". Please check your classpath.", ex);
91 }
92 catch (InstantiationException ex)
93 {
94 throw new SmsException("Couldn't create " + theClassname + ". Please check your classpath.", ex);
95 }
96 catch (IllegalAccessException ex)
97 {
98 throw new SmsException("Couldn't create " + theClassname + ". Please check your classpath.", ex);
99 }
100 }
101 }