}
private String getReplaceWithClass(List<ReplaceWithData> replaceWithList) {
// the default <replace-with>, with no filter
ReplaceWithData defaultReplaceWith = null;
Set<String> clientProperyNames = GwtConfig.get().getModuleRunner().getClientPropertyNames();
for (ReplaceWithData replaceWithData : replaceWithList) {
if ((clientProperyNames.size() == 0)) {
if (isDefault(replaceWithData)) {
// default case : nothing is specified
return replaceWithData.getReplaceWith();
}
// not a <replace-with> element to use
continue;
} else if (isDefault(replaceWithData)) {
// save the default <replace-with>, to use
defaultReplaceWith = replaceWithData;
continue;
}
// validate every when-property-is match
if (replaceWithData.hasWhenPropertyIs()) {
boolean validateProperties = true;
Iterator<String> it = clientProperyNames.iterator();
while (it.hasNext() && validateProperties) {
String propertyName = it.next();
String value = GwtConfig.get().getModuleRunner().getClientProperty(propertyName);
validateProperties = replaceWithData.whenPropertyIsMatch(propertyName, value);
}
if (!validateProperties) {
continue;
}
}
// validate at least one any/when-property-is matches
boolean validateAnyProperty = !replaceWithData.hasAnyWhenPropertyIs();
Iterator<String> it = clientProperyNames.iterator();
while (it.hasNext() && !validateAnyProperty) {
String propertyName = it.next();
String value = GwtConfig.get().getModuleRunner().getClientProperty(propertyName);
validateAnyProperty = replaceWithData.anyMatch(propertyName, value);
}
if (validateAnyProperty) {
return replaceWithData.getReplaceWith();
}
}
return (defaultReplaceWith != null) ? defaultReplaceWith.getReplaceWith() : null;
}