01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.remote;
10:
11: import java.security.AccessController;
12: import java.security.PrivilegedAction;
13:
14: import mx4j.log.Log;
15: import mx4j.log.Logger;
16:
17: /**
18: * @version $Revision: 1.5 $
19: */
20: public abstract class ProviderHelper {
21: protected static String normalizeProtocol(String protocol) {
22: // Replace special chars as required by the spec
23: String normalized = protocol.replace('+', '.');
24: normalized = normalized.replace('-', '_');
25: Logger logger = getLogger();
26: if (logger.isEnabledFor(Logger.TRACE))
27: logger.trace("Normalizing protocol: " + protocol + " --> "
28: + normalized);
29: return normalized;
30: }
31:
32: protected static String findSystemPackageList(final String key) {
33: Logger logger = getLogger();
34: String providerPackages = (String) AccessController
35: .doPrivileged(new PrivilegedAction() {
36: public Object run() {
37: return System.getProperty(key);
38: }
39: });
40: if (logger.isEnabledFor(Logger.DEBUG))
41: logger.debug("Packages in the system property '" + key
42: + "': " + providerPackages);
43: return providerPackages;
44: }
45:
46: protected static Class loadClass(String className,
47: ClassLoader loader) throws ClassNotFoundException {
48: Logger logger = getLogger();
49: if (logger.isEnabledFor(Logger.DEBUG))
50: logger.debug("Loading class: " + className
51: + " with classloader " + loader);
52: return loader.loadClass(className);
53: }
54:
55: protected static String constructClassName(String packageName,
56: String protocol, String className) {
57: return new StringBuffer(packageName).append(".").append(
58: protocol).append(".").append(className).toString();
59: }
60:
61: protected static Logger getLogger() {
62: return Log.getLogger(ProviderHelper.class.getName());
63: }
64: }
|