Beispiel #1
0
 public static WeldClass<?> getWeldClassOfDecoratedType(BeanManagerImpl beanManager, Type type) {
   if (type instanceof Class<?>) {
     return (WeldClass<?>) beanManager.createAnnotatedType((Class<?>) type);
   }
   if (type instanceof ParameterizedType
       && (((ParameterizedType) type).getRawType() instanceof Class)) {
     return (WeldClass<?>)
         beanManager.createAnnotatedType((Class<?>) ((ParameterizedType) type).getRawType());
   }
   throw new IllegalStateException(UNABLE_TO_PROCESS, type);
 }
Beispiel #2
0
  private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
    InterceptionModel<ClassMetadata<?>, ?> interceptionModel =
        beanManager.getInterceptorModelRegistry().get(classBean.getType());
    if (interceptionModel != null) {
      Set<? extends InterceptorMetadata<?>> interceptors = interceptionModel.getAllInterceptors();
      if (interceptors.size() > 0) {
        boolean passivationCapabilityCheckRequired =
            isPassivationCapabilityCheckRequired(beanManager, classBean);
        for (InterceptorMetadata<?> interceptorMetadata : interceptors) {
          if (interceptorMetadata.getInterceptorReference().getInterceptor()
              instanceof SerializableContextual) {
            SerializableContextual<Interceptor<?>, ?> serializableContextual =
                cast(interceptorMetadata.getInterceptorReference().getInterceptor());

            if (passivationCapabilityCheckRequired) {
              Interceptor<?> interceptor = serializableContextual.get();
              boolean isSerializable =
                  (interceptor instanceof InterceptorImpl)
                      ? ((InterceptorImpl<?>) interceptor).isSerializable()
                      : (interceptor instanceof PassivationCapable);
              if (isSerializable == false)
                throw new DeploymentException(
                    PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, classBean, interceptor);
            }
            for (InjectionPoint injectionPoint :
                serializableContextual.get().getInjectionPoints()) {
              Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
              validateInjectionPoint(injectionPoint, beanManager);
              if (passivationCapabilityCheckRequired) {
                validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
              }
            }
          }
          if (interceptorMetadata.getInterceptorReference().getInterceptor()
              instanceof ClassMetadata<?>) {
            ClassMetadata<?> classMetadata =
                (ClassMetadata<?>) interceptorMetadata.getInterceptorReference().getInterceptor();
            if (passivationCapabilityCheckRequired
                && !Reflections.isSerializable(classMetadata.getJavaClass())) {
              throw new DeploymentException(
                  PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR,
                  this,
                  classMetadata.getJavaClass().getName());
            }
            InjectionTarget<Object> injectionTarget =
                cast(
                    beanManager.createInjectionTarget(
                        beanManager.createAnnotatedType(classMetadata.getJavaClass())));
            for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints()) {
              Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
              validateInjectionPoint(injectionPoint, beanManager);
              if (passivationCapabilityCheckRequired) {
                validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
              }
            }
          }
        }
      }
    }
  }
 public T createFor(InterceptorReference<Object> interceptorReference) {
   if (interceptorReference.getInterceptor() instanceof ClassMetadata<?>) {
     try {
       // this is not a managed instance - assume no-argument constructor exists
       Class<T> clazz = cast(interceptorReference.getClassMetadata().getJavaClass());
       Constructor<T> constructor = SecureReflections.getDeclaredConstructor(clazz);
       T interceptorInstance = SecureReflections.ensureAccessible(constructor).newInstance();
       // inject
       AnnotatedType<T> type = manager.createAnnotatedType(clazz);
       InjectionTarget<T> target = manager.createInjectionTarget(type);
       target.inject(interceptorInstance, creationalContext);
       return interceptorInstance;
     } catch (Exception e) {
       throw new DeploymentException(e);
     }
   }
   if (interceptorReference.getInterceptor() instanceof SerializableContextual) {
     try {
       // this is not a managed instance - assume no-argument constructor exists
       SerializableContextual<Interceptor<T>, T> serializableContextual =
           cast(interceptorReference.getInterceptor());
       return Reflections.<T>cast(
           manager.getReference(serializableContextual.get(), creationalContext, false));
     } catch (Exception e) {
       throw new DeploymentException(e);
     }
   }
   throw new IllegalStateException();
 }