1 45 package org.exolab.jms.config; 46 47 import java.io.IOException ; 48 import java.io.InputStream ; 49 import java.io.InputStreamReader ; 50 51 import org.apache.commons.logging.Log; 52 import org.apache.commons.logging.LogFactory; 53 54 import org.exolab.jms.config.types.SchemeType; 55 56 57 64 public class ConnectorHelper { 65 66 69 private static final ConnectorResource[] _connectors; 70 71 74 private static final Log _log = LogFactory.getLog(ConnectorHelper.class); 75 76 79 private static final String RESOURCE = 80 "/org/exolab/jms/config/connectors.xml"; 81 82 83 91 public static ConnectorResource getConnectorResource(SchemeType scheme) { 92 return getConnectorResource(scheme, ConfigurationManager.getConfig()); 93 } 94 95 105 public static ConnectorResource getConnectorResource( 106 SchemeType scheme, Configuration config) { 107 108 if (scheme == null) { 109 throw new IllegalArgumentException ("Argument 'scheme' is null"); 110 } 111 if (config == null) { 112 throw new IllegalArgumentException ("Argument 'config' is null"); 113 } 114 115 ConnectorResource result = null; 116 ConnectorResource[] connectors = _connectors; 117 if (config.getConnectorResources() != null) { 118 connectors = config.getConnectorResources().getConnectorResource(); 120 } 121 122 String name = scheme.toString(); 123 for (int i = 0; i < connectors.length; ++i) { 124 if (connectors[i].getScheme().toString().equals(name)) { 125 result = connectors[i]; 126 break; 127 } 128 } 129 return result; 130 } 131 132 static { 133 135 InputStream stream = null; 136 try { 137 ConnectorResources connectors = null; 138 stream = ConnectorHelper.class.getResourceAsStream(RESOURCE); 139 connectors = ConnectorResources.unmarshal( 140 new InputStreamReader (stream)); 141 _connectors = connectors.getConnectorResource(); 142 } catch (Exception exception) { 143 _log.error(exception, exception); 144 throw new RuntimeException (exception.getMessage()); 145 } finally { 146 if (stream != null) { 147 try { 148 stream.close(); 149 } catch (IOException ignore) { 150 } 151 } 152 } 153 } 154 155 } | Popular Tags |