aConfiguration
.
*
* @param aConfiguration {@inheritDoc}
* @throws CheckstyleException {@inheritDoc}
* @see Configurable
*/
public final void configure(Configuration aConfiguration)
throws CheckstyleException
{
mConfiguration = aConfiguration;
final BeanUtilsBean beanUtils = createBeanUtilsBean();
// TODO: debug log messages
final String[] attributes = aConfiguration.getAttributeNames();
for (final String key : attributes) {
final String value = aConfiguration.getAttribute(key);
try {
// BeanUtilsBean.copyProperties silently ignores missing setters
// for key, so we have to go through great lengths here to
// figure out if the bean property really exists.
final PropertyDescriptor pd =
PropertyUtils.getPropertyDescriptor(this, key);
if ((pd == null) || (pd.getWriteMethod() == null)) {
throw new CheckstyleException(
"Property '" + key + "' in module "
+ aConfiguration.getName()
+ " does not exist, please check the documentation");
}
// finally we can set the bean property
beanUtils.copyProperty(this, key, value);
}
catch (final InvocationTargetException e) {
throw new CheckstyleException(
"Cannot set property '" + key + "' in module "
+ aConfiguration.getName() + " to '" + value
+ "': " + e.getTargetException().getMessage(), e);
}
catch (final IllegalAccessException e) {
throw new CheckstyleException(
"cannot access " + key + " in "
+ this.getClass().getName(), e);
}
catch (final NoSuchMethodException e) {
throw new CheckstyleException(
"cannot access " + key + " in "
+ this.getClass().getName(), e);
}
catch (final IllegalArgumentException e) {
throw new CheckstyleException(
"illegal value '" + value + "' for property '" + key
+ "' of module " + aConfiguration.getName(), e);
}
catch (final ConversionException e) {
throw new CheckstyleException(
"illegal value '" + value + "' for property '" + key
+ "' of module " + aConfiguration.getName(), e);
}
}
finishLocalSetup();
final Configuration[] childConfigs = aConfiguration.getChildren();
for (final Configuration childConfig : childConfigs) {
setupChild(childConfig);
}
}
/**
* Implements the Contextualizable interface using bean introspection.
* @param aContext {@inheritDoc}
* @throws CheckstyleException {@inheritDoc}
* @see Contextualizable
*/
public final void contextualize(Context aContext)
throws CheckstyleException
{
final BeanUtilsBean beanUtils = createBeanUtilsBean();
// TODO: debug log messages
final Collection* The default implementation does nothing. *
* @throws CheckstyleException if there is a configuration error. */ protected void finishLocalSetup() throws CheckstyleException { } /** * Called by configure() for every child of this component's Configuration. ** The default implementation does nothing. *
* @param aChildConf a child of this component's Configuration * @throws CheckstyleException if there is a configuration error. * @see Configuration#getChildren */ protected void setupChild(Configuration aChildConf) throws CheckstyleException { } /** * A converter that does not care whether the array elements contain String * characters like '*' or '_'. The normal ArrayConverter class has problems * with this characters. */ private static class RelaxedStringArrayConverter implements Converter { /** {@inheritDoc} */ public Object convert(@SuppressWarnings("rawtypes") Class aType, Object aValue) { if (null == aType) { throw new ConversionException("Cannot convert from null."); } // Convert to a String and trim it for the tokenizer. final StringTokenizer st = new StringTokenizer( aValue.toString().trim(), ","); final List