public static void throwsException(Exception e) throws WebBeansConfigurationException { if(e instanceof DefinitionException) { throw (DefinitionException)e; } else { throw new WebBeansConfigurationException(e); } }
@Override public Object newInstance(String className, ClassLoader classLoader) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException { try { final Class<?> clazz = classLoader.loadClass(className); final Object object = webContext.newInstance(clazz); postConstruct(object, clazz); return object; } catch (OpenEJBException e) { throw (InstantiationException) new InstantiationException(e.getMessage()).initCause(e); } catch (WebBeansConfigurationException e) { throw (InstantiationException) new InstantiationException(e.getMessage()).initCause(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; }
/** * Verify that we have a legal Type at the injection point. * CDI can basically only handle Class and ParameterizedType injection points atm. * @throws WebBeansConfigurationException on TypeVariable, WildcardType and GenericArrayType * @throws IllegalArgumentException if the type is not yet supported by the spec. */ private void validateInjectionPointType(Type injectionPointType) { if (injectionPointType instanceof TypeVariable || injectionPointType instanceof WildcardType || injectionPointType instanceof GenericArrayType) { throw new WebBeansConfigurationException("Injection point cannot define Type Variable " + injectionPointType); } if (!(injectionPointType instanceof Class) && !(injectionPointType instanceof ParameterizedType)) { throw new IllegalArgumentException("Unsupported type " + injectionPointType.getClass()); } }
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"); } }
@Override public void isManagedBean(Class<?> clazz) { if(Servlet.class.isAssignableFrom(clazz) || Filter.class.isAssignableFrom(clazz) || ServletContextListener.class.isAssignableFrom(clazz) || ServletContextAttributeListener.class.isAssignableFrom(clazz) || HttpSessionActivationListener.class.isAssignableFrom(clazz) || HttpSessionAttributeListener.class.isAssignableFrom(clazz) || HttpSessionBindingListener.class.isAssignableFrom(clazz) || HttpSessionListener.class.isAssignableFrom(clazz) || ServletRequestListener.class.isAssignableFrom(clazz) || ServletRequestAttributeListener.class.isAssignableFrom(clazz) || AsyncListener.class.isAssignableFrom(clazz) ) { throw new WebBeansConfigurationException("Given class : " + clazz.getName() + " is not managed bean"); } }
/** * Checks the generic type requirements. */ public static void checkGenericType(Class<?> clazz, Class<? extends Annotation> scope) { Asserts.assertNotNull(clazz); if (clazz.getTypeParameters().length > 0) { if(!scope.equals(Dependent.class)) { throw new WebBeansConfigurationException("Generic type may only defined with scope @Dependent " + "for ManagedBean class : " + clazz.getName()); } } }
/** * {@inheritDoc} */ @Override public void isManagedBean(Class<?> clazz) { if(Servlet.class.isAssignableFrom(clazz) || Filter.class.isAssignableFrom(clazz) || ServletContextListener.class.isAssignableFrom(clazz) || ServletContextAttributeListener.class.isAssignableFrom(clazz) || HttpSessionActivationListener.class.isAssignableFrom(clazz) || HttpSessionAttributeListener.class.isAssignableFrom(clazz) || HttpSessionBindingListener.class.isAssignableFrom(clazz) || HttpSessionListener.class.isAssignableFrom(clazz) || ServletRequestListener.class.isAssignableFrom(clazz) || ServletRequestAttributeListener.class.isAssignableFrom(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"); }
private void validateTarget() { boolean isLifecycleOnly = ( // spec seems to be more strict but breaks apps + does it really makes sense? interceptionMethods.containsKey(InterceptionType.POST_CONSTRUCT) || interceptionMethods.containsKey(InterceptionType.PRE_DESTROY)) && !(interceptionMethods.containsKey(InterceptionType.AROUND_INVOKE) || interceptionMethods.containsKey(InterceptionType.AROUND_TIMEOUT) || interceptionMethods.containsKey(InterceptionType.AROUND_CONSTRUCT)); if (isLifecycleOnly && interceptorBindings != null) { for (Annotation a : interceptorBindings) { Target target = a.annotationType().getAnnotation(Target.class); if (target == null || !asList(target.value()).equals(asList(ElementType.TYPE))) { throw new WebBeansConfigurationException( a.annotationType().getName() + " doesn't have strictly @Target(TYPE) but has lifecycle methods. " + "Interceptor: " + annotatedType.getJavaClass().getName()); } } } }
/** * Validates session bean decorator/interceptor conditions. * * @param ejbClass ejb bean class */ public static void validateDecoratorOrInterceptor(Class<?> ejbClass) { Asserts.assertNotNull(ejbClass, "ejbClass parameter can not be null"); if (AnnotationUtil.hasClassAnnotation(ejbClass, Decorator.class)) { throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Decorator"); } if (AnnotationUtil.hasClassAnnotation(ejbClass, Interceptor.class)) { throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Interceptor"); } }
@Override public void shutDown() { try { super.shutDown(); this.deployedApplications.clear(); this.statelessBeans.clear(); this.statefulBeans.clear(); this.singletonBeans.clear(); this.containerSystem = null; this.ejbInstances.clear(); this.nameStrategies.clear(); this.assembler.removeDeploymentListener(this); } catch (Exception e) { throw new WebBeansConfigurationException(e); } }
public <T> Class<T> createImplementedSubclass(ClassLoader classLoader, AnnotatedType<T> annotatedType) { Class<T> classToProxy = annotatedType.getJavaClass(); if (!Modifier.isAbstract(classToProxy.getModifiers())) { throw new WebBeansConfigurationException("Only abstract classes should get subclassed, not " + classToProxy); } // todo: using a cache is faster (no synchronized) Class<T> proxyClass = tryToLoadClass(classLoader, classToProxy); if (proxyClass != null) { return proxyClass; } proxyClass = createSubClass(classLoader, annotatedType); return proxyClass; }
/** * Validates session bean decorator/interceptor conditions. * * @param ejbClass ejb bean class */ public static void validateDecoratorOrInterceptor(Class<?> ejbClass) { Asserts.assertNotNull(ejbClass, "ejbClass"); if (AnnotationUtil.hasClassAnnotation(ejbClass, Decorator.class)) { throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Decorator"); } if (AnnotationUtil.hasClassAnnotation(ejbClass, Interceptor.class)) { throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Interceptor"); } }
/** * @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)"); } } }
/** * Check generic type conditions. * @param ejbClass ebj class * @param scopeType scope type */ public static void validateGenericBeanType(Class<?> ejbClass, Class<? extends Annotation> scopeType) { Asserts.assertNotNull(ejbClass, "ejbClass"); Asserts.assertNotNull(ejbClass, "scopeType"); if (ejbClass.getTypeParameters().length > 0) { if(!scopeType.equals(Dependent.class)) { throw new WebBeansConfigurationException("Ejb generic bean class : " + ejbClass.getName() + "scope must be @Dependent"); } } }
throw new WebBeansConfigurationException("@StereoType annotation can not contain more " + "than one @Scope/@NormalScope annotation"); if (!name.value().equals("")) throw new WebBeansConfigurationException("@StereoType annotation can not define @Named " + "annotation with value");
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"); } }