1 45 package org.exolab.jms.config; 46 47 import java.net.InetAddress ; 48 import java.net.UnknownHostException ; 49 50 import org.exolab.jms.config.types.SchemeType; 51 52 53 59 public class ConfigHelper { 60 61 68 public static String getServerURL(SchemeType scheme, 69 Configuration config) { 70 String url = null; 71 ServerConfiguration server = config.getServerConfiguration(); 72 73 if (scheme.equals(SchemeType.TCP)) { 74 url = getServerURL(scheme, server.getHost(), 75 config.getTcpConfiguration()); 76 } else if (scheme.equals(SchemeType.TCPS)) { 77 url = getServerURL(scheme, server.getHost(), 78 config.getTcpsConfiguration()); 79 } else if (scheme.equals(SchemeType.RMI)) { 80 RmiConfiguration rmi = config.getRmiConfiguration(); 81 if (rmi.getEmbeddedRegistry()) { 82 url = getServerURL(scheme, server.getHost(), rmi); 85 } else { 86 url = getServerURL(scheme, rmi.getRegistryHost(), rmi); 87 } 88 } else if (scheme.equals(SchemeType.HTTP)) { 89 url = getServerURL(scheme, config.getHttpConfiguration()); 90 } else if (scheme.equals(SchemeType.HTTPS)) { 91 url = getServerURL(scheme, config.getHttpsConfiguration()); 92 } else if (scheme.equals(SchemeType.EMBEDDED)) { 93 url = "vm:openjms"; 94 } 95 return url; 96 } 97 98 105 public static String getJndiURL(SchemeType scheme, Configuration config) { 106 String url = null; 107 ServerConfiguration server = config.getServerConfiguration(); 108 109 if (scheme.equals(SchemeType.TCP)) { 110 url = getJndiURL(scheme, server.getHost(), 111 config.getTcpConfiguration()); 112 } else if (scheme.equals(SchemeType.TCPS)) { 113 url = getJndiURL(scheme, server.getHost(), 114 config.getTcpsConfiguration()); 115 } else if (scheme.equals(SchemeType.HTTP)) { 116 url = getJndiURL(scheme, config.getHttpConfiguration()); 117 } else if (scheme.equals(SchemeType.HTTPS)) { 118 url = getJndiURL(scheme, config.getHttpsConfiguration()); 119 } else if (scheme.equals(SchemeType.RMI)) { 120 RmiConfiguration rmi = config.getRmiConfiguration(); 121 if (rmi.getEmbeddedRegistry()) { 122 url = getJndiURL(scheme, server.getHost(), rmi); 125 } else { 126 url = getJndiURL(scheme, rmi.getRegistryHost(), rmi); 127 } 128 } else if (scheme.equals(SchemeType.EMBEDDED)) { 129 url = "vm:openjms"; 130 } 131 return url; 132 } 133 134 141 public static String getAdminURL(SchemeType scheme, Configuration config) { 142 String url = null; 143 ServerConfiguration server = config.getServerConfiguration(); 144 145 if (scheme.equals(SchemeType.TCP)) { 146 url = getAdminURL(scheme, server.getHost(), 147 config.getTcpConfiguration()); 148 } else if (scheme.equals(SchemeType.TCPS)) { 149 url = getAdminURL(scheme, server.getHost(), 150 config.getTcpsConfiguration()); 151 } else if (scheme.equals(SchemeType.RMI)) { 152 RmiConfiguration rmi = config.getRmiConfiguration(); 153 if (rmi.getEmbeddedRegistry()) { 154 url = getAdminURL(scheme, server.getHost(), rmi); 157 } else { 158 url = getAdminURL(scheme, rmi.getRegistryHost(), rmi); 159 } 160 } else if (scheme.equals(SchemeType.HTTP)) { 161 url = getAdminURL(scheme, config.getHttpConfiguration()); 162 } else if (scheme.equals(SchemeType.HTTPS)) { 163 url = getAdminURL(scheme, config.getHttpsConfiguration()); 164 } else if (scheme.equals(SchemeType.EMBEDDED)) { 165 url = "vm:openjms"; 166 } 167 return url; 168 } 169 170 178 private static String getServerURL(SchemeType scheme, String host, 179 TcpConfigurationType config) { 180 return getURL(scheme, host, config.getPort()); 181 } 182 183 191 private static String getServerURL(SchemeType scheme, String host, 192 RmiConfiguration config) { 193 return getURL(scheme, host, config.getRegistryPort()); 194 } 195 196 203 private static String getServerURL(SchemeType scheme, 204 HttpConfigurationType config) { 205 return getURL(scheme, config.getWebServerHost(), 206 config.getWebServerPort(), config.getServlet()); 207 } 208 209 214 private static String getJndiURL(SchemeType scheme, String host, 215 TcpConfigurationType config) { 216 int port = config.getJndiPort(); 217 if (port == 0) { 218 port = config.getPort(); 219 } 220 return getURL(scheme, host, port); 221 } 222 223 228 private static String getJndiURL(SchemeType scheme, String host, 229 RmiConfiguration config) { 230 return getURL(scheme, host, config.getRegistryPort()); 231 } 232 233 238 private static String getJndiURL(SchemeType scheme, 239 HttpConfigurationType config) { 240 return getURL(scheme, config.getWebServerHost(), 241 config.getWebServerPort(), config.getServlet()); 242 } 243 244 249 private static String getAdminURL(SchemeType scheme, String host, 250 TcpConfigurationType config) { 251 int port = config.getAdminPort(); 252 if (port == 0) { 253 port = config.getPort(); 254 } 255 return getURL(scheme, host, port); 256 } 257 258 263 private static String getAdminURL(SchemeType scheme, String host, 264 RmiConfiguration config) { 265 return getURL(scheme, host, config.getRegistryPort()); 266 } 267 268 273 private static String getAdminURL(SchemeType scheme, 274 HttpConfigurationType config) { 275 return getURL(scheme, config.getWebServerHost(), 276 config.getWebServerPort(), config.getServlet()); 277 } 278 279 287 private static String getURL(SchemeType scheme, String host, int port) { 288 return getURL(scheme, host, port, ""); 289 } 290 291 300 private static String getURL(SchemeType scheme, String host, int port, 301 String path) { 302 return getURL(scheme.toString(), host, port, path); 303 } 304 305 314 private static String getURL(String scheme, String host, int port, 315 String path) { 316 String result = scheme + "://" + getHost(host) + ":" + port; 317 if (!path.startsWith("/")) { 318 result += "/" + path; 319 } else { 320 result += path; 321 } 322 return result; 323 } 324 325 329 private static String getHost(String host) { 330 if (host.equals("localhost")) { 331 try { 332 host = InetAddress.getLocalHost().getHostAddress(); 333 } catch (UnknownHostException ignore) { 334 } 335 } 336 return host; 337 } 338 339 } 340 | Popular Tags |