* @param errorMessage error message
* @return new injection point model
*/
private static XMLInjectionPointModel getTypeInjectionPointModel(Element typeElement, String errorMessage)
{
XMLInjectionPointModel model = null;
Class<?> clazz = getElementJavaType(typeElement);
if (clazz == null)
{
throw new NonexistentTypeException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " is not found in the deployment");
}
else if (clazz.isAnnotation() || clazz.isArray() || clazz.isEnum())
{
throw new WebBeansConfigurationException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " must be class or interface type");
}
else
{
TypeVariable[] typeVariables = clazz.getTypeParameters();
int actualTypeArgument = typeVariables.length;
List<Type> typeArguments = new ArrayList<Type>();
List<Annotation> bindingAnnots = new ArrayList<Annotation>();
Class<? extends Annotation> definedBindingType = null;
Node node;
Element childElement;
NodeList ns = typeElement.getChildNodes();
for (int i = 0; i < ns.getLength(); i++)
{
node = ns.item(i);
if (!(node instanceof Element))
{
continue;
}
childElement = (Element) node;
Type actualType = getElementJavaType(childElement);
if (actualType == null)
{
throw new NonexistentTypeException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " is not found in the deployment");
}
else if (((Class) actualType).isArray() || ((Class) actualType).isEnum())
{
throw new WebBeansConfigurationException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " must be class or interface type");
}
else if (((Class) actualType).isAnnotation())
{
Class<? extends Annotation> annotClazz = (Class<? extends Annotation>) actualType;
if (!AnnotationUtil.isQualifierAnnotation(annotClazz))
{
throw new WebBeansConfigurationException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " is not a @Qualifier");
}
if (definedBindingType == null)
{
definedBindingType = annotClazz;
}
else
{
if (definedBindingType.equals(annotClazz))
{
throw new IllegalArgumentException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " is duplicated");
}
}
bindingAnnots.add(getXMLDefinedAnnotationMember(childElement, annotClazz, errorMessage));
}
else
{
typeArguments.add(actualType);
}
}
if (actualTypeArgument != typeArguments.size())
{
throw new WebBeansConfigurationException(errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) +
" actual type parameters size are not equals defined in the xml");
}
int i = 0;
for (Type type : typeArguments)
{
TypeVariable typeVariable = typeVariables[i];
Type[] bounds = typeVariable.getBounds();
Class<?> clazzBound = (Class<?>) bounds[0];
if (!clazzBound.isAssignableFrom((Class<?>) type))
{
throw new WebBeansConfigurationException(
errorMessage + log.getTokenString(OWBLogConst.TEXT_JAVA_TYPENAME) + getElementJavaClassName(typeElement) + " actual type parameter bounded exception");
}
}
Type[] typeArray = new Type[typeArguments.size()];
typeArray = typeArguments.toArray(typeArray);
model = new XMLInjectionPointModel(clazz, typeArray);
if (bindingAnnots.isEmpty())
{
model.addBindingType(new DefaultLiteral());
}
for (Annotation annot : bindingAnnots)
{
model.addBindingType(annot);
}
}
return model;
}