Package org.apache.webbeans.inject.xml

Examples of org.apache.webbeans.inject.xml.XMLInjectionPointModel


        }

        XMLInjectableConstructor<T> injectableConstructor = new XMLInjectableConstructor<T>(componentConstructor, component);
        for (Element element : constructorParameterListElement)
        {
            XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(element, createConfigurationFailedMessage());
            injectableConstructor.addInjectionPointModel(model);
        }

        component.setInjectableConstructor(injectableConstructor);
    }
View Full Code Here


                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Declared field type is not assignable to class field type");
                }
                else
                {
                    XMLInjectionPointModel injectionPointModel = XMLUtil.getInjectionPointModel(directChild, createConfigurationFailedMessage());
                    component.addFieldInjectionPoint(field, injectionPointModel);

                    isTypeElement = true;
                    isApplicable = true;
                }
View Full Code Here

        }
        else
        {
            for (Element element : methodParameterElements)
            {
                XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(element, createConfigurationFailedMessage());
                component.addMethodInjectionPoint(initializeMethod, model);
            }
        }
    }
View Full Code Here

     * @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;
    }
View Full Code Here

     * @param errorMessage error message
     * @return new injection point model
     */
    public static XMLInjectionPointModel getArrayInjectionPointModel(Element typeElement, String errorMessage)
    {
        XMLInjectionPointModel model = null;

        List<Element> childElements = typeElement.elements();
        boolean isElementTypeDefined = false;

        Set<Annotation> anns = new HashSet<Annotation>();
        for (Element childElement : childElements)
        {
            Class<?> clazz = XMLUtil.getElementJavaType(childElement);

            if (clazz == null)
            {
                throw new NonexistentTypeException(errorMessage + "Class with name : " + XMLUtil.getElementJavaClassName(childElement) + " is not found for Array element type");
            }

            if (clazz.isAnnotation())
            {
                anns.add(getXMLDefinedAnnotationMember(childElement, (Class<? extends Annotation>) clazz, errorMessage));
            }
            else if (clazz.isArray() || clazz.isEnum())
            {
                throw new WebBeansConfigurationException(errorMessage + "<Array> element child with Java type : " + getElementJavaClassName(typeElement) + " must be class or interface type");
            }
            else
            {
                if (isElementTypeDefined)
                {
                    throw new WebBeansConfigurationException(errorMessage + "<Array> element can not have more than one child element. It has one child element that declares its type");
                }
                else
                {
                    model = new XMLInjectionPointModel(clazz);
                    isElementTypeDefined = true;
                }
            }
        }

        if (anns.size() == 0)
        {
            model.addBindingType(new CurrentLiteral());
        }

        for (Annotation ann : anns)
        {
            model.addBindingType(ann);
        }

        return model;
    }
View Full Code Here

        Iterator<Field> itField = fieldSet.iterator();

        while (itField.hasNext())
        {
            Field field = itField.next();
            XMLInjectionPointModel model = this.injectableFields.get(field);
            XMLInjectableField injectableField = new XMLInjectableField(field, instance, this, model);

            injectableField.doInjection();
        }
    }
View Full Code Here

                    if (!field.getType().isAssignableFrom(apType))
                    {
                        throw new WebBeansConfigurationException(errorMessage + "Field name : " + field.getName() + " xml defined class type must be assignable to the field actual class type");
                    }

                    XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(type, errorMessage);

                    WebBeansDecoratorConfig.configureXMLDecoratorClass((AbstractComponent<Object>) component, model);
                }
                else
                {
View Full Code Here

                    throw new WebBeansConfigurationException(errorMessage + "<Produces> element must define at least one java type child");
                }
            }
            else
            {
                XMLInjectionPointModel injectionPointModel = XMLUtil.getInjectionPointModel(childElement, errorMessage);
                injectedParameters.add(injectionPointModel);

            }
        }
View Full Code Here

        }
        /* Return type is java type */
        else
        {
            /* Configures the java api types and actual type parameters */
            XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(typeElement, errorMessage);

            producerComponentImpl.setActualTypeArguments(model.getActualTypeArguments());
            producerComponentImpl.addApiType(model.getInjectionClassType());

            if (model.getInjectionClassType().isPrimitive())
            {
                producerComponentImpl.setNullable(false);
            }
        }

View Full Code Here

                }

                Element typeElement = (Element) childElement.elements().get(0);

                /* Find disposal method model */
                XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(typeElement, errorMessage);

                /* Binding types for disposal method */
                Set<Annotation> bindingTypes = model.getBindingTypes();
                Annotation[] bindingAnns = new Annotation[bindingTypes.size()];
                bindingAnns = bindingTypes.toArray(bindingAnns);

                Set<Bean<T>> set = InjectionResolver.getInstance().implResolveByType(model.getInjectionClassType(), model.getActualTypeArguments(), bindingAnns);
                producerComponent = (XMLProducerComponentImpl<?>) set.iterator().next();

                if (producerComponent == null)
                {
                    throw new UnsatisfiedDependencyException(errorMessage + "Producer method component of the disposal method : " + disposalMethod.getName() + "is not found");
                }

                producerComponent.setDisposalMethod(disposalMethod);

            }
            /* Disposal method parameter other than @Disposes */
            else
            {
                otherParameterElements.add(childElement);
            }
        }// end of for childs

        /* Add other params injection point models */
        for (Element otherElement : otherParameterElements)
        {
            XMLInjectionPointModel injectionPointParamModel = XMLUtil.getInjectionPointModel(otherElement, errorMessage);
            producerComponent.addDisposalMethodInjectionPointModel(injectionPointParamModel);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.webbeans.inject.xml.XMLInjectionPointModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.