* @param errorMessage error message
* @return new annotation
*/
private static WebBeansAnnotation createInjectionPointAnnotation(NamedNodeMap attrs, Class<? extends Annotation> annotClazz, String valueText, String errorMessage)
{
WebBeansAnnotation annotation = JavassistProxyFactory.createNewAnnotationProxy(annotClazz);
boolean isValueAttrDefined = false;
for (int i = 0; i < attrs.getLength(); i++)
{
Attr attr = (Attr) attrs.item(i);
String attrName = attr.getName();
String attrValue = attr.getValue();
if (!isValueAttrDefined)
{
if (attrName.equals("value"))
{
isValueAttrDefined = true;
}
}
Class returnType = null;
try
{
returnType = SecurityUtil.doPrivilegedGetDeclaredMethod(annotClazz, attrName, new Class[]{}).getReturnType();
Object value = null;
if (returnType.isPrimitive())
{
value = ClassUtil.isValueOkForPrimitiveOrWrapper(returnType, attrValue);
}
else if (returnType.equals(String.class))
{
value = attrValue;
}
else if (returnType.equals(Class.class))
{
value = ClassUtil.getClassFromName(attrValue);
}
else if (returnType.isEnum())
{
value = ClassUtil.isValueOkForEnum(returnType, attrValue);
}
else
{
throw new WebBeansConfigurationException(
errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " does not have sutiable member return type");
}
if (value == null)
{
throw new WebBeansConfigurationException(
errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " value does not defined correctly");
}
annotation.setMemberValue(attrName, value);
}
catch (SecurityException e)
{
throw new WebBeansException(e);
}
catch (NoSuchMethodException e)
{
throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " does not have member with name : " + attrName);
}
}
if (!isValueAttrDefined)
{
if (valueText != null && !valueText.equals(""))
{
annotation.setMemberValue("value", valueText);
}
}
return annotation;
}