if (factoryWrapper == null) {
log.error("unknown factory id", new Exception(factoryId));
return null;
}
final ComponentInstance instanceWrapper;
try {
instanceWrapper = factoryWrapper.newInstance(props);
} catch (final Exception e) {
log.error("factory can not produce instance", new Exception(
factoryId));
return null;
}
@SuppressWarnings("unchecked")
final F instance = (F) instanceWrapper.getInstance();
if (instance == null) {
log.error("instance == null", new Exception(factoryId));
instanceWrapper.dispose();
return null;
}
final String instanceId;
try {
instanceId = instance.getInstanceId();
} catch (final Exception e) {
log.error("invalid instanceId", new Exception(factoryId));
instanceWrapper.dispose();
return null;
}
if (instanceId == null) {
log.error("instanceId == null", new Exception(factoryId));
instanceWrapper.dispose();
return null;
}
if (instanceMap.containsKey(instanceId)) {
log.error("duplicate instance id", new Exception(instanceId));
instanceWrapper.dispose();
return null;
}
instanceMap.put(instanceId, instanceWrapper);