ConfigurationBeanLoader will ignore unexpected properties on instances.

If no method has been annotated to accept that property, don't complain,
don't throw an exception, just continue.
This commit is contained in:
Jim Blake 2018-01-06 14:09:03 -05:00
parent 9e3ac4fb54
commit 8fbfc6d4ff
2 changed files with 27 additions and 36 deletions

View file

@ -70,7 +70,8 @@ public class WrappedInstance<T> {
*/
public void checkCardinality(Set<PropertyStatement> propertyStatements)
throws CardinalityException {
Map<String, Integer> statementCounts = countPropertyStatementsByPredicateUri(propertyStatements);
Map<String, Integer> statementCounts = countPropertyStatementsByPredicateUri(
propertyStatements);
for (PropertyMethod pm : propertyMethods.values()) {
Integer c = statementCounts.get(pm.getPropertyUri());
int count = (c == null) ? 0 : c;
@ -109,12 +110,11 @@ public class WrappedInstance<T> {
*/
public void setProperties(ConfigurationBeanLoader loader,
Collection<PropertyStatement> propertyStatements)
throws PropertyTypeException, NoSuchPropertyMethodException,
ConfigurationBeanLoaderException {
throws PropertyTypeException, ConfigurationBeanLoaderException {
for (PropertyStatement ps : propertyStatements) {
PropertyMethod pm = propertyMethods.get(ps.getPredicateUri());
if (pm == null) {
throw new NoSuchPropertyMethodException(ps);
continue; // No method for this property? Ignore it.
}
pm.confirmCompatible(ps);
@ -141,7 +141,8 @@ public class WrappedInstance<T> {
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new ValidationFailedException(
"Error executing validation method '" + method + "'", e);
"Error executing validation method '" + method + "'",
e);
}
}
}
@ -165,12 +166,6 @@ public class WrappedInstance<T> {
}
}
public static class NoSuchPropertyMethodException extends Exception {
public NoSuchPropertyMethodException(PropertyStatement ps) {
super("No property method for '" + ps.getPredicateUri() + "'");
}
}
public static class CardinalityException extends Exception {
public CardinalityException(String message) {
super(message);