Package javax.enterprise.inject.spi

Examples of javax.enterprise.inject.spi.DefinitionException


                final Set<Annotation> qualifiers = ip.getQualifiers();
                if (EventMetadata.class == ip.getType()
                        && qualifiers != null && ip.getQualifiers().size() == 1
                        && Default.class == qualifiers.iterator().next().annotationType())
                {
                    throw new DefinitionException(ip + " is not an observer parameter");
                }
            }
        }
       
        return definedObservers;
View Full Code Here


                do
                {
                    Class<? super C> superclass = annotatedToSpecialize.getJavaClass().getSuperclass();
                    if (superclass.equals(Object.class))
                    {
                        throw new DefinitionException("@Specialized Class : " + getAnnotated().getJavaClass().getName()
                                + " must not directly extend Object.class");
                    }
                    annotatedToSpecialize = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(superclass);
                } while(annotatedToSpecialize.getAnnotation(Specializes.class) != null);


                defineName(annotatedToSpecialize, WebBeansUtil.getManagedBeanDefaultName(annotatedToSpecialize.getJavaClass().getSimpleName()));
            }
            if (name == null)
            {
                defineName(getAnnotated(), WebBeansUtil.getManagedBeanDefaultName(getAnnotated().getJavaClass().getSimpleName()));
            }
            else
            {
                // TODO XXX We have to check stereotypes here, too
                if (getAnnotated().getJavaClass().isAnnotationPresent(Named.class))
                {
                    throw new DefinitionException("@Specialized Class : " + getAnnotated().getJavaClass().getName()
                            + " may not explicitly declare a bean name");
                }
            }
        }
View Full Code Here

            else
            {
                // TODO XXX We have to check stereotypes here, too
                if (getAnnotated().isAnnotationPresent(Named.class))
                {
                    throw new DefinitionException("@Specialized Producer method : " + getAnnotated().getJavaMember().getName()
                            + " may not explicitly declare a bean name");
                }
            }
        }
View Full Code Here

       
        if(annotatedMethod.isAnnotationPresent(Inject.class)
            || AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, Observes.class)
            || annotatedMethod.isAnnotationPresent(Produces.class))
        {
            throw new DefinitionException("Error in definining disposal method of annotated method : " + annotatedMethod
                    + ". Disposal methods  can not be annotated with" + " @Initializer/@Destructor/@Produces annotation or has a parameter annotated with @Observes.");
        }

        for (AnnotatedParameter param : annotatedMethod.getParameters())
        {
            Type type = param.getBaseType();
            if (type.equals(InjectionPoint.class))
            {

                throw new DefinitionException("Error in definining disposal method of annotated method : " + annotatedMethod
                    + ". Disposal methods must not have an InjectionPoint.");
            }
            else if (Bean.class.isAssignableFrom(ClassUtil.getClass(type)))
            {
                throw new DefinitionException("Error in defining disposal method of annoted method: " + annotatedMethod +
                        ". Disposal methods must not have a Bean parameter.");
            }
        }
    }
View Full Code Here

        {
            Type type = parameter.getBaseType();
            if (Bean.class.equals(ClassUtil.getClass(type)) &&
                !annotatedMember.getBaseType().equals(ClassUtil.getActualTypeArguments(type)[0]))
            {
                throw new DefinitionException("Type parameter of the injected bean must be the same as the return type. Producer method: " + annotatedMember);
            }
        }
    }
View Full Code Here

        Set<AnnotatedMethod<? super T>> annotatedMethods = annotatedType.getMethods();
        for (final AnnotatedMethod<?> annotatedMethod : annotatedMethods)
        {
            if (annotatedMethod.isAnnotationPresent(Produces.class))
            {
                throw new DefinitionException("This class must not have a @Produces method" + annotatedMethod.getJavaMember());
            }

            for (AnnotatedParameter<?> parameter : annotatedMethod.getParameters())
            {
                if (parameter.isAnnotationPresent(Observes.class))
                {
                    throw new DefinitionException("This class must not have a @Observes method " + annotatedMethod.getJavaMember());
                }
            }
        }

        Set<AnnotatedField<? super T>> annotatedFields = annotatedType.getFields();
        for (final AnnotatedField<? super T> annotatedField : annotatedFields)
        {
            if (annotatedField.isAnnotationPresent(Produces.class))
            {
                throw new DefinitionException("This class must not have a @Produces field" + annotatedField.getJavaMember());
            }
        }
    }
View Full Code Here

                        //Added by GE, method check is necessary otherwise getting wrong method qualifier annotations
                        if (superMethod != null && superMethod.equals(pb.getCreatorMethod()))
                        {
                            if (disabledProducerMethods.contains(superMethod))
                            {
                                throw new DefinitionException("Multiple specializations for the same producer method got detected for type"
                                        + pbean.toString());
                            }
                            disabledProducerMethods.add(superMethod);
                            producerBeanListHelper.add(pb);
                            pLeft = (pb.isSpecializedBean()) ? pb : null;
View Full Code Here

                    rawType.equals(Interceptor.class))
                {
                    Type[] types = ClassUtil.getActualTypeArguments(injectionPoint.getType());
                    if (types.length != 1 || !GenericsUtil.isAssignableFrom(false, AbstractProducerBean.class.isInstance(bean), bean.getBeanClass(), types[0]))
                    {
                        throw new DefinitionException("injected bean parameter must be " + rawType);
                    }
                }

                if (isDecorator)
                {
                    List<Method> abstractMethods = ClassUtil.getAbstractMethods(bean.getBeanClass());
                    if (!abstractMethods.isEmpty())
                    {
                        Set<Type> types = ((javax.enterprise.inject.spi.Decorator) bean).getDecoratedTypes();
                        for (Method abstractMethod : abstractMethods)
                        {
                            boolean methodDeclared = false;
                            for (Type type : types)
                            {
                                if (ClassUtil.isMethodDeclared(ClassUtil.getClass(type), abstractMethod.getName(), abstractMethod.getParameterTypes()))
                                {
                                    methodDeclared = true;
                                    break;
                                }
                            }

                            if (!methodDeclared)
                            {
                                throw new DefinitionException("Decorator must not declare abstract methods which is not declared in any Decorated type.");
                            }
                        }
                    }
                }
            }

            if (!injectionPoint.isDelegate())
            {
                webBeansContext.getBeanManagerImpl().validate(injectionPoint);
            }
            else
            {
                if (!isDecorator)
                {
                    throw new WebBeansConfigurationException(
                            "Delegate injection points can not defined by beans that are not decorator. Injection point : "
                                    + injectionPoint);
                }
                else if (delegateFound)
                {
                    throw new WebBeansConfigurationException(
                            "Only one Delegate injection point can be defined by decorator. Decorator : "
                                    + injectionPoint.getBean());
                }
                else
                {
                    delegateFound = true;
                }
            }

            if (injectionPoint.getQualifiers().contains(DefaultLiteral.INSTANCE)
                    && ParameterizedType.class.isInstance(injectionPoint.getType())
                    && javax.enterprise.inject.spi.Decorator.class == ParameterizedType.class.cast(injectionPoint.getType()).getRawType()
                    && !isDecorator)
            {
                throw new DefinitionException("@Inject Decorator<X> only supported in decorators");
            }
            if (injectionPoint.getQualifiers().contains(DefaultLiteral.INSTANCE)
                    && ParameterizedType.class.isInstance(injectionPoint.getType())
                    && Interceptor.class == ParameterizedType.class.cast(injectionPoint.getType()).getRawType()
                    && !isInterceptor)
            {
                throw new DefinitionException("@Inject Interceptor<X> only supported in interceptors");
            }
        }
    }
View Full Code Here

        {
            webBeansContext.getBeanManagerImpl().fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
        }
        catch (final Exception e)
        {
            throw new DefinitionException("event ProcessBeanAttributes thrown an exception for " + annotatedType, e);
        }

        if (event.getDefinitionError() != null)
        {
            throw new DefinitionException(event.getDefinitionError());
        }

        final BeanAttributes<T> beanAttributes;
        if (event.getAttributes() != ba)
        {
            beanAttributes = event.getAttributes();
            if (!webBeansContext.getBeanManagerImpl().isScope(beanAttributes.getScope()))
            {
                throw new DefinitionException(beanAttributes.getScope() + " is not a scope");
            }
        }
        else
        {
            beanAttributes = ba;
View Full Code Here

                    final Class<?> beanClass = AbstractOwbBean.class.isInstance(injectionPointBean) ?
                            AbstractOwbBean.class.cast(injectionPointBean).getReturnType() : injectionPointBean.getBeanClass();
                    final Type beanType = pt.getActualTypeArguments()[0];
                    if (!GenericsUtil.isAssignableFrom(false, AbstractProducerBean.class.isInstance(bean), beanClass, beanType))
                    {
                        throw new DefinitionException("@Inject Bean<X> can only be done in X, found " + beanType + " and " + beanClass);
                    }
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of javax.enterprise.inject.spi.DefinitionException

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.