1 9 package org.jboss.mx.remoting.connector; 10 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.Map ; 15 import java.util.Set ; 16 import java.util.StringTokenizer ; 17 import javax.management.remote.JMXProviderException ; 18 19 26 public class ConnectorFactoryUtil 27 { 28 private ConnectorFactoryUtil() 29 { 30 } 32 33 public static String normalizeProtocol(String protocol) 34 { 35 protocol = protocol.replace('+', '.'); 37 protocol = protocol.replace('-', '_'); 38 return protocol; 39 } 40 41 public static void validateEnvironmentMap(Map environment) 42 { 43 Set keys = environment.keySet(); 46 Iterator itr = keys.iterator(); 47 while(itr.hasNext()) 48 { 49 Object keyValue = null; 50 try 51 { 52 keyValue = itr.next(); 53 String keyAsString = (String ) keyValue; 54 } 55 catch(ClassCastException e) 56 { 57 throw new IllegalArgumentException ("All keys within environment map must be of type java.lang.String. " + 58 keyValue + " is of type " + keyValue.getClass().getName()); 59 } 60 } 61 } 62 63 public static ClassLoader locateClassLoader(Map environment, String classLoaderKey) 64 { 65 ClassLoader classloader = null; 66 67 Object val = environment.get(classLoaderKey); 68 if(val != null) 69 { 70 if(val instanceof ClassLoader ) 71 { 72 classloader = (ClassLoader ) val; 73 } 74 else 75 { 76 throw new IllegalArgumentException ("Error using value specified for " + classLoaderKey + 77 " because is not an instance of " + ClassLoader .class.getName()); 78 } 79 } 80 else 81 { 82 classloader = Thread.currentThread().getContextClassLoader(); 84 } 85 86 environment.put(classLoaderKey, classloader); 87 88 89 return classloader; 90 } 91 92 public static List locateProviderPackage(Map environment, String providerPackageKey) 93 throws JMXProviderException 94 { 95 96 String providerPackage = null; 97 98 Object val = environment.get(providerPackageKey); 100 101 if(providerPackage != null) 104 { 105 if(val instanceof String ) 106 { 107 providerPackage = ((String ) val).trim(); 108 if(providerPackage.startsWith("|") || providerPackage.endsWith("|") || 110 providerPackage.indexOf("||") != -1) 111 { 112 113 throw new JMXProviderException ("Error processing " + providerPackageKey + " from the " + 114 "environment map. An empty provider package exists."); 115 } 116 } 117 else 118 { 119 throw new JMXProviderException ("Error processing " + providerPackageKey + " from the " + 120 "environment map. Is is not of type String."); 121 } 122 } 123 else 124 { 125 providerPackage = System.getProperty(providerPackageKey); 127 } 128 129 List providerPackages = new ArrayList (); 130 if(providerPackage != null && providerPackage.length() > 0) 131 { 132 StringTokenizer tokenizer = new StringTokenizer (providerPackage, "|"); 133 while(tokenizer.hasMoreElements()) 134 { 135 providerPackages.add(tokenizer.nextElement()); 136 } 137 } 138 139 return providerPackages; 140 } 141 142 } | Popular Tags |