* @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 + "Java type with name : " + getElementJavaClassName(typeElement) + " is not found in the deployment");
}
else if (clazz.isAnnotation() || clazz.isArray() || clazz.isEnum())
{
throw new WebBeansConfigurationException(errorMessage + "Java type with name : " + getElementJavaClassName(typeElement) + " must be class or interface type");
}
else
{
TypeVariable[] typeVariables = clazz.getTypeParameters();
int actualTypeArgument = typeVariables.length;
List<Element> childElements = typeElement.elements();
List<Type> typeArguments = new ArrayList<Type>();
List<Annotation> bindingAnnots = new ArrayList<Annotation>();
Class<? extends Annotation> definedBindingType = null;
for (Element childElement : childElements)
{
Type actualType = getElementJavaType(childElement);
if (actualType == null)
{
throw new NonexistentTypeException(errorMessage + "Java type with name : " + getElementJavaClassName(typeElement) + " is not found in the deployment");
}
else if (((Class) actualType).isArray() || ((Class) actualType).isEnum())
{
throw new WebBeansConfigurationException(errorMessage + "Java type with name : " + getElementJavaClassName(typeElement) + " must be class or interface type");
}
else if (((Class) actualType).isAnnotation())
{
Class<? extends Annotation> annotClazz = (Class<? extends Annotation>) actualType;
if (!AnnotationUtil.isBindingAnnotation(annotClazz))
{
throw new WebBeansConfigurationException(errorMessage + "Java type with name : " + getElementJavaClassName(typeElement) + " is not a @BindingType");
}
if (definedBindingType == null)
{
definedBindingType = annotClazz;
}
else
{
if (definedBindingType.equals(annotClazz))
{
throw new DuplicateBindingTypeException(errorMessage + "Java type with name : " + getElementJavaClassName(typeElement) + " is duplicated");
}
}
bindingAnnots.add(getXMLDefinedAnnotationMember(childElement, annotClazz, errorMessage));
}
else
{
typeArguments.add(actualType);
}
}
if (actualTypeArgument != typeArguments.size())
{
throw new WebBeansConfigurationException(errorMessage + "Java type with name : " + 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 + "Java type with name : " + 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 CurrentLiteral());
}
for (Annotation annot : bindingAnnots)
{
model.addBindingType(annot);
}
}
return model;
}