if (expression.indexOf(":") != -1) {
expression = expression.substring(0, expression.indexOf(":"));
}
boolean isMapOrList = expression.contains("=");
Property p;
if (isMapOrList) {
String mapPropLocation = expression.substring(0, expression.indexOf("="));
if (mapPropLocation.contains("/")) {
mapPropLocation = mapPropLocation.substring(0, mapPropLocation.indexOf('/'));
}
p = configuration.get(mapPropLocation);
} else {
p = configuration.get(expression);
}
if (p == null) {
if (LOG.isDebugEnabled()) {
LOG.debug(resource + " in " + baseResource + ": option source expression for property " + pds.getName()
+ " and target configuration of " + foundResource + " not found");
}
return false;
}
if (!(p instanceof PropertyList)) {
LOG.warn(resource + " in " + baseResource + ": option source expression for property " + pds.getName()
+ " and target configuration does not point to a list");
return false;
}
PropertyList pl = (PropertyList) p;
List<Property> propertyList = pl.getList();
if (propertyList.size() == 0)
return false;
// Now List of simple or list of maps (of simple) ?
if (propertyList.get(0) instanceof PropertySimple) {
if (isMapOrList) {
LOG.warn(resource + " in " + baseResource + ": expected a List of Maps, but got a list of simple");
return false;
}
for (Property tmp : propertyList) {
PropertySimple ps = (PropertySimple) tmp;
String name = ps.getStringValue();
if (name != null) {
PropertyDefinitionEnumeration pde = new PropertyDefinitionEnumeration(name, name);
pds.getEnumeratedValues().add(pde);
}
}
} else if (propertyList.get(0) instanceof PropertyMap) {
if (!isMapOrList) {
LOG.warn(resource + " in " + baseResource + ": expected a List of simple, but got a list of Maps");
return false;
}
String subPropName;
subPropName = expression.substring(expression.indexOf("=") + 1);
for (Property tmp : propertyList) {
PropertyMap pm = (PropertyMap) tmp;
Property ps = pm.get(subPropName);
if (ps == null) {
LOG.warn(resource + " in " + baseResource + ": option source expression for property "
+ pds.getName() + " and target configuration does not have a map element " + subPropName);
return false;
}