*/
@SuppressWarnings("unchecked")
public Transport getServiceBroker(String serviceName) {
log.fine("ServiceHandler::getServiceBroker for " + serviceName);
Transport broker = this.brokers.get(serviceName);
if (broker != null)
return broker;
log.fine(this.cowebConfig.get("bots").toString());
Object[] botConfigs = (Object[]) this.cowebConfig.get("bots");
if (botConfigs == null) {
return null;
}
Map<String, Object> botConfig = null;
for (int i = 0; i < botConfigs.length; i++) {
Map<String, Object> tmp = (Map<String, Object>) botConfigs[i];
String s = (String) tmp.get("service");
if (s.equals(serviceName)) {
botConfig = tmp;
break;
}
}
if (botConfig == null)
return null;
String brokerStr = (String) botConfig.get("broker");
if (brokerStr == null) {
if (botConfig.get("class") != null)
brokerStr = "org.coweb.bots.transport.LocalTransport";
else
return null;
}
try {
Class<? extends Transport> clazz = Class.forName(brokerStr)
.asSubclass(Transport.class);
broker = clazz.newInstance();
} catch (Exception e) {
e.printStackTrace();
return null;
}
broker.setBotConfig(botConfig);
broker.setSessionId(this.sessionId);
this.brokers.put(serviceName, broker);
return broker;
}