public boolean hasComponent(Object obj) {
return Web3DataSourceSelectorImpl.pools.containsKey(obj);
}
public Component select(Object obj) throws ComponentException {
Web3DataSource pool = null;
try {
Web3DataSourceSelectorImpl.lock.acquire();
if (null != obj) {
if (Web3DataSourceSelectorImpl.pools.containsKey(obj)) {
pool =
(Web3DataSource) Web3DataSourceSelectorImpl.pools.get(
obj);
} else {
Configuration a[] =
this.configuration.getChildren("backend"),
c = null;
if (null != a)
for (int i = 0; i < a.length; i++) {
try {
String s = a[i].getAttribute("name");
if (null != s && s.equals(obj.toString())) {
// a backend with a name can be defined only once
c = a[i];
break;
}
} catch (ConfigurationException x) {
// this configuration element has no mandatory
//attribute name
}
}
// No configuration for this backend-id found!
if (null == c) {
return null;
}
Class theClass =
Class.forName(
c.getChild("class").getValue(
"org.apache.cocoon.components.web3.impl.Web3DataSourceImpl"),
true,
ClassUtils.getClassLoader());
pool = (Web3DataSource) theClass.newInstance();
if (pool instanceof LogEnabled) {
((LogEnabled) pool).enableLogging(getLogger());
}
pool.compose(this.manager);
pool.configure(c);
pool.initialize();
Web3DataSourceSelectorImpl.pools.put(obj, pool);
}
}
} catch (Exception ex) {
getLogger().error(ex.getMessage(), ex);