}
@Override
public Restriction createRestriction(String oakPath, String oakName, Value... values) throws RepositoryException {
if (isUnsupportedPath(oakPath)) {
throw new AccessControlException("Unsupported restriction at " + oakPath);
}
RestrictionDefinition definition = supported.get(oakName);
if (definition == null) {
throw new AccessControlException("Unsupported restriction: " + oakName);
}
Type requiredType = definition.getRequiredType();
for (Value v : values) {
if (requiredType.tag() != PropertyType.UNDEFINED && requiredType.tag() != v.getType()) {
throw new AccessControlException("Unsupported restriction: Expected value of type " + requiredType);
}
}
PropertyState propertyState;
if (requiredType.isArray()) {
propertyState = PropertyStates.createProperty(oakName, ImmutableList.of(values));
} else {
if (values.length != 1) {
throw new AccessControlException("Unsupported restriction: Expected single value.");
}
propertyState = PropertyStates.createProperty(oakName, values[0]);
}
return createRestriction(propertyState, definition);
}