| | |
| | | |
| | | |
| | | import static org.forgerock.util.Reject.ifNull; |
| | | import static org.opends.server.admin.PropertyException.*; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.EnumSet; |
| | |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) |
| | | throws IllegalPropertyValueStringException { |
| | | throws PropertyException { |
| | | ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value, e.getCause()); |
| | | } catch (PropertyException e) { |
| | | throw illegalPropertyValueException(this, value, e.getCause()); |
| | | } |
| | | |
| | | return value; |
| | |
| | | * The class representing the requested type. |
| | | * @return Returns the named class cast to a subclass of the |
| | | * specified class. |
| | | * @throws IllegalPropertyValueException |
| | | * @throws PropertyException |
| | | * If the named class was invalid, could not be loaded, or |
| | | * did not implement the required interfaces. |
| | | * @throws ClassCastException |
| | |
| | | * requested type. |
| | | */ |
| | | public <T> Class<? extends T> loadClass(String className, |
| | | Class<T> instanceOf) throws IllegalPropertyValueException, |
| | | Class<T> instanceOf) throws PropertyException, |
| | | ClassCastException { |
| | | ifNull(className, instanceOf); |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public String normalizeValue(String value) |
| | | throws IllegalPropertyValueException { |
| | | throws PropertyException { |
| | | ifNull(value); |
| | | |
| | | return value.trim(); |
| | |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) |
| | | throws IllegalPropertyValueException { |
| | | throws PropertyException { |
| | | ifNull(value); |
| | | |
| | | // Always make sure the name is a valid class name. |
| | |
| | | * definition. |
| | | */ |
| | | private Class<?> validateClassInterfaces(String className, boolean initialize) |
| | | throws IllegalPropertyValueException { |
| | | throws PropertyException { |
| | | Class<?> theClass = loadClassForValidation(className, className, |
| | | initialize); |
| | | for (String i : instanceOfInterfaces) { |
| | | Class<?> instanceOfClass = loadClassForValidation(className, i, |
| | | initialize); |
| | | if (!instanceOfClass.isAssignableFrom(theClass)) { |
| | | throw new IllegalPropertyValueException(this, className); |
| | | throw PropertyException.illegalPropertyValueException(this, className); |
| | | } |
| | | } |
| | | return theClass; |
| | |
| | | return loadClass(classToBeLoaded.trim(), initialize); |
| | | } catch (ClassNotFoundException e) { |
| | | // If the class cannot be loaded then it is an invalid value. |
| | | throw new IllegalPropertyValueException(this, componentClassName, e); |
| | | throw illegalPropertyValueException(this, componentClassName, e); |
| | | } catch (LinkageError e) { |
| | | // If the class cannot be initialized then it is an invalid value. |
| | | throw new IllegalPropertyValueException(this, componentClassName, e); |
| | | throw illegalPropertyValueException(this, componentClassName, e); |
| | | } |
| | | } |
| | | |
| | |
| | | * Do some basic checks to make sure the string representation is valid. |
| | | */ |
| | | private void validateClassName(String className) |
| | | throws IllegalPropertyValueException { |
| | | throws PropertyException { |
| | | String nvalue = className.trim(); |
| | | if (!nvalue.matches(CLASS_RE)) { |
| | | throw new IllegalPropertyValueException(this, className); |
| | | throw PropertyException.illegalPropertyValueException(this, className); |
| | | } |
| | | } |
| | | } |