input = processFreeMarkerTemplate(trimedConfigFileName);
} else {
input = new FileInputStream(configFile);
}
final XmlConfig xmlConfig;
try {
xmlConfig = xmlConfigParser.loadConfig(input);
} finally {
input.close();
}
Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(xmlConfig.getClassName());
ConfigInjector<?> configInjector = ConfigInjector.forClass(cls, converter);
final String cfgFileName = configFileName;
instance = (T) configInjector.inject(xmlConfig.getProperties(), new Injection.ContextualPropertyResolver() {
@Override
public Object getProperty(InjectableProperty property, Value configValue) throws Exception {
// Allow injection of this configuration loader
if (ConfigurationLoader.class.isAssignableFrom(property.getType())) {
return ConfigurationLoader.this;
}
if (CONFIG_FILE_NAME_PROP.equals(property.getName())) {
return cfgFileName;
}
String refConfigFile = configValue != null ? configValue.getValue() : null;
if (refConfigFile != null) {
return getReferencedObject(refConfigFile, configFile.getParentFile(), customResolver, converter,
enhancer);
}
if (customResolver != null) {
try {
return customResolver.getProperty(property, configValue);
} catch (NoSuchFieldException e) {
// ok
}
}
throw new NoSuchFieldException(property.getName());
}
});
T decoratedInstance = instance;
instance = decorateInstance(decoratedInstance, xmlConfig.getDecorators(), configFile.getParentFile(), customResolver,
converter, enhancer);
configInjector.notifyPostConstruct(decoratedInstance);
if (doRegisterMBeans) {