}
@SuppressWarnings("unchecked")
private ConstrettoConfiguration buildConfig(Element element, ConfigurationContextResolver configurationContextResolver) {
ConstrettoBuilder builder = new ConstrettoBuilder(configurationContextResolver, true);
Element storeElement = DomUtils.getChildElementByTagName(element, "stores");
if (storeElement != null) {
List<Element> stores = getAllChildElements(storeElement);
for (Element store : stores) {
String tagName = store.getLocalName();
if ("properties-store".equals(tagName)) {
ConstrettoBuilder.PropertiesStoreBuilder propertiesBuilder = builder.createPropertiesStore();
List<Element> resources = DomUtils.getChildElementsByTagName(store, "resource");
for (Element resource : resources) {
String location = resource.getAttribute("location");
propertiesBuilder.addResource(Resource.create(location));
}
propertiesBuilder.done();
} else if ("encrypted-properties-store".equals(tagName)) {
ConstrettoBuilder.EncryptedPropertiesStoreBuilder propertiesBuilder = builder.createEncryptedPropertiesStore(store.getAttribute("password-property"));
List<Element> resources = DomUtils.getChildElementsByTagName(store, "resource");
for (Element resource : resources) {
String location = resource.getAttribute("location");
propertiesBuilder.addResource(Resource.create(location));
}
propertiesBuilder.done();
} else if ("ini-store".equals(tagName)) {
ConstrettoBuilder.IniFileConfigurationStoreBuilder iniBuilder = builder.createIniFileConfigurationStore();
List<Element> resources = DomUtils.getChildElementsByTagName(store, "resource");
for (Element resource : resources) {
String location = resource.getAttribute("location");
iniBuilder.addResource(Resource.create(location));
}
iniBuilder.done();
} else if ("system-properties-store".equals(tagName)) {
builder.createSystemPropertiesStore();
} else if ("object-store".equals(tagName)) {
ConstrettoBuilder.ObjectConfigurationStoreBuilder objectBuilder = builder.createObjectConfigurationStore();
List<Element> objects = DomUtils.getChildElementsByTagName(store, "object");
for (Element object : objects) {
String clazz = object.getAttribute("class");
try {
objectBuilder.addObject(Class.forName(clazz).newInstance());
} catch (Exception e) {
throw new IllegalStateException("Could not instantiate configuration source object with class [" + clazz + "]");
}
}
objectBuilder.done();
}
}
}
return builder.getConfiguration();
}