public static void throwsException(Exception e) throws WebBeansConfigurationException { if(e instanceof DefinitionException) { throw (DefinitionException)e; } else { throw new WebBeansConfigurationException(e); } }
public static void setSingletonService(SingletonService<WebBeansContext> singletonSvc) { if (customSingletonServiceUsed && !singletonService.equals(singletonSvc)) { throw new WebBeansConfigurationException("Already using another custom SingletonService!"); } singletonService = singletonSvc; customSingletonServiceUsed = true; }
protected void checkObserverCondition(AnnotatedParameter<T> annotatedObservesParameter) { if (annotatedObservesParameter.getAnnotation(WithAnnotations.class) != null) { throw new WebBeansConfigurationException("@WithAnnotations must only be used for ProcessAnnotatedType events"); } }
/** * {@inheritDoc} */ public void isManagedBean(Class<?> clazz) { if (isSessionBean(clazz)) { throw new WebBeansConfigurationException("Managed Bean implementation class : " + clazz.getName() + " can not be sesion bean class"); } }
/** * {@inheritDoc} */ @Override public void isManagedBean(Class<?> clazz) { if (isServletSpecClass(clazz)) { throw new WebBeansConfigurationException("Given class : " + clazz.getName() + " is not managed bean"); } }
public void checkDefaultConstructor() { for (AnnotatedConstructor<T> constructor: annotatedType.getConstructors()) { if (constructor.getParameters().isEmpty()) { return; } } throw new WebBeansConfigurationException("@Interceptors interceptor must have no-arg constructor, but " + annotatedType.getJavaClass() + " has not"); }
/** * @throws DefinitionException if {@link javax.enterprise.inject.spi.Decorator#getDecoratedTypes()} isEmpty */ private void validateDecoratorDecoratedTypes() { for (Decorator decorator : decoratorsManager.getDecorators()) { if (decorator.getDecoratedTypes().isEmpty()) { throw new WebBeansConfigurationException("Decorator must implement at least one interface (java.io.Serializeable will be ignored)"); } } }
private static void validateScope(final CdiEjbBean<?> bean) { final Class<? extends Annotation> scope = bean.getScope(); final BeanType beanType = bean.getBeanContext().getComponentType(); if (BeanType.STATELESS.equals(beanType) && !Dependent.class.equals(scope)) { throw new WebBeansConfigurationException("@Stateless can only be @Dependent"); } if (BeanType.SINGLETON.equals(beanType) && !Dependent.class.equals(scope) && !ApplicationScoped.class.equals(scope)) { throw new WebBeansConfigurationException("@Singleton can only be @Dependent or @ApplicationScoped"); } }
private static void validateScope(final CdiEjbBean<?> bean) { final Class<? extends Annotation> scope = bean.getScope(); final BeanType beanType = bean.getBeanContext().getComponentType(); if (BeanType.STATELESS.equals(beanType) && !Dependent.class.equals(scope)) { throw new WebBeansConfigurationException("@Stateless can only be @Dependent"); } if (BeanType.SINGLETON.equals(beanType) && !Dependent.class.equals(scope) && !ApplicationScoped.class.equals(scope)) { throw new WebBeansConfigurationException("@Singleton can only be @Dependent or @ApplicationScoped"); } }
private void validateDisposalMethod(AnnotatedType declaringType, AnnotatedMethod<? super P> annotatedMethod) { if (!annotatedMethod.getDeclaringType().equals(declaringType)) { throw new WebBeansConfigurationException("Producer method component of the disposal method : " + annotatedMethod.getJavaMember().getName() + " in class : " + annotatedMethod.getDeclaringType().getJavaClass() + " must be in the same class!"); } checkDisposalMethod(annotatedMethod); }
private void validateInitializerConstructor(AnnotatedConstructor<?> constructor) { for (AnnotatedParameter<?> parameter: constructor.getParameters()) { if (parameter.isAnnotationPresent(Disposes.class)) { throw new WebBeansConfigurationException("Constructor parameter annotations can not contain @Disposes annotation in annotated constructor : " + constructor); } if(parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class)) { throw new WebBeansConfigurationException("Constructor parameter annotations can not contain @Observes nor @ObservesAsync annotation in annotated constructor : " + constructor); } } }
private static void checkProducerMethods(Set<ProducerMethodBean<?>> producerMethodBeans, BaseEjbBean<?> bean) { for(ProducerMethodBean<?> producerMethodBean : producerMethodBeans) { Method producerMethod = producerMethodBean.getCreatorMethod(); if(!ClassUtil.isStatic(producerMethod.getModifiers())) { if(!isBusinessMethod(producerMethod, bean)) { throw new WebBeansConfigurationException("Producer Method Bean must be business method of session bean : " + bean); } } } }
private static void validateObserverMethods(final CdiEjbBean<?> bean, final Map<ObserverMethod<?>, AnnotatedMethod<?>> methods) { final BeanContext beanContext = bean.getBeanContext(); if (beanContext.isLocalbean()) { return; } for (final Map.Entry<ObserverMethod<?>, AnnotatedMethod<?>> m : methods.entrySet()) { final Method method = m.getValue().getJavaMember(); if (!Modifier.isStatic(method.getModifiers()) && doResolveViewMethod(bean, method) == null) { throw new WebBeansConfigurationException("@Observes " + method + " neither in the ejb view of ejb " + bean.getBeanContext().getEjbName() + " nor static"); } } }
private static void validateObserverMethods(final CdiEjbBean<?> bean, final Map<ObserverMethod<?>, AnnotatedMethod<?>> methods) { final BeanContext beanContext = bean.getBeanContext(); if (beanContext.isLocalbean()) { return; } for (final Map.Entry<ObserverMethod<?>, AnnotatedMethod<?>> m : methods.entrySet()) { final Method method = m.getValue().getJavaMember(); if (!Modifier.isStatic(method.getModifiers()) && doResolveViewMethod(bean, method) == null) { throw new WebBeansConfigurationException("@Observes " + method + " neither in the ejb view of ejb " + bean.getBeanContext().getEjbName() + " nor static"); } } }
protected void defineInterceptorBindings() { Annotation[] bindings = webBeansContext.getAnnotationManager().getInterceptorBindingMetaAnnotations(annotatedType.getAnnotations()); if (bindings == null || bindings.length == 0) { throw new WebBeansConfigurationException("WebBeans Interceptor class : " + annotatedType.getJavaClass() + " must have at least one @InterceptorBinding annotation"); } interceptorBindings = ArrayUtil.asSet(bindings); }
@Override public void validate() throws DefinitionException { super.validate(); for (AnnotatedParameter<?> parameter : annotatedMember.getParameters()) { Type type = parameter.getBaseType(); if (Bean.class.equals(ClassUtil.getClass(type)) && !annotatedMember.getBaseType().equals(ClassUtil.getActualTypeArguments(type)[0])) { throw new WebBeansConfigurationException("Type parameter of the injected bean must be the same as the return type. Producer method: " + annotatedMember); } } } }
public void checkManagedBeanCondition(Class<?> clazz) throws WebBeansConfigurationException { if (AnnotationUtil.hasClassAnnotation(clazz, Decorator.class) && AnnotationUtil.hasClassAnnotation(clazz, javax.interceptor.Interceptor.class)) { throw new WebBeansConfigurationException("ManagedBean implementation class : " + clazz.getName() + " may not annotated with both @Interceptor and @Decorator annotation"); } if (!AnnotationUtil.hasClassAnnotation(clazz, Decorator.class) && !AnnotationUtil.hasClassAnnotation(clazz, javax.interceptor.Interceptor.class)) { webBeansContext.getInterceptorUtil().checkSimpleWebBeansInterceptorConditions(clazz); } }
private static void validateProduceMethods(final CdiEjbBean<?> bean, final Set<ProducerMethodBean<?>> methods) { final BeanContext beanContext = bean.getBeanContext(); if (beanContext.isLocalbean()) { return; } for (final ProducerMethodBean<?> m : methods) { final Method method = m.getCreatorMethod(); if (doResolveViewMethod(bean, method) == null) { throw new WebBeansConfigurationException("@Produces " + method + " not in the ejb view of ejb " + beanContext.getEjbName()); } } }
private static void validateProduceMethods(final CdiEjbBean<?> bean, final Set<ProducerMethodBean<?>> methods) { final BeanContext beanContext = bean.getBeanContext(); if (beanContext.isLocalbean()) { return; } for (final ProducerMethodBean<?> m : methods) { final Method method = m.getCreatorMethod(); if (doResolveViewMethod(bean, method) == null) { throw new WebBeansConfigurationException("@Produces " + method + " not in the ejb view of ejb " + beanContext.getEjbName()); } } }
public <X, T extends Annotation> X getResourceReference(ResourceReference<X, T> resourceReference) { try { return ResourceFactory.getInstance().getResourceReference(resourceReference); } catch(Exception e) { logger.error(OWBLogConst.ERROR_0024, e, resourceReference.getResourceType(), resourceReference.getOwnerClass(), resourceReference.getName()); throw new WebBeansConfigurationException(MessageFormat.format(logger.getTokenString(OWBLogConst.ERROR_0024), resourceReference.getResourceType(), resourceReference.getOwnerClass(), resourceReference.getName()), e); } }