public static void checkManagedBeanDecoratorConditions(ManagedBean<?> component) {
Asserts.assertNotNull("component", "component parameter can not be null");
Set< Annotation > annSet = component.getQualifiers();
Annotation[] anns = new Annotation[annSet.size()];
anns = annSet.toArray(anns);
List< Decorator< ? > > decoratorList = BeanManagerImpl.getManager().resolveDecorators(component.getTypes(), anns);
if (!decoratorList.isEmpty())
{
Class< ? > clazz = component.getReturnType();
if (ClassUtil.isFinal(clazz.getModifiers()))
{
throw new WebBeansConfigurationException("Managed Bean : " + component.getReturnType().getName() + " can not be declared final, because it has one or more decorators");
}
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods)
{
int modifiers = method.getModifiers();
if (!ClassUtil.isStatic(modifiers) && !ClassUtil.isPrivate(modifiers) && ClassUtil.isFinal(modifiers))
{
// Check decorator implements this
Iterator< Decorator< ? > > itDecorator = decoratorList.iterator();
while (itDecorator.hasNext())
{
WebBeansDecorator< ? > decorator = (WebBeansDecorator< ? >) itDecorator.next();
Class< ? > decClazz = decorator.getClazz();
try
{
if (decClazz.getMethod(method.getName(), method.getParameterTypes()) != null)
{
throw new WebBeansConfigurationException("Managed Bean : " + component.getReturnType().getName() + " can not define non-private, non-static, final method : " + method.getName() + ", because one of its decorators implements this method");
}
}
catch (SecurityException e)
{
logger.error("Security exception, can not access decorator class : " + decClazz.getName() + " method : " + method.getName(), e);
throw new WebBeansException(e);
}
catch (NoSuchMethodException e)
{
continue;
}
}
}
}
}
}
|