javax.enterprise.inject.spi.Interceptor类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中javax.enterprise.inject.spi.Interceptor类的一些代码示例,展示了Interceptor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Interceptor类的具体详情如下:
包路径:javax.enterprise.inject.spi.Interceptor
类名称:Interceptor

Interceptor介绍

[英]Represents an enabled javax.interceptor.

Since CDI 2.0, an implementation of this interface may implement Prioritized in order to enable the interceptor with given priority value for entire application.
[中]表示已启用的javax。拦截器。
自CDI 2.0以来,此接口的实现可能会实现优先级,以便为整个应用程序启用具有给定优先级值的拦截器。

代码示例

代码示例来源:origin: wildfly/wildfly

private void addInterceptorInstance(Interceptor<Object> interceptor, BeanManagerImpl beanManager, Map<String, SerializableContextualInstance<Interceptor<Object>, Object>> instances, final CreationalContext<Object> creationalContext) {
  Object instance = beanManager.getReference(interceptor, interceptor.getBeanClass(), creationalContext, true);
  SerializableContextualInstance<Interceptor<Object>, Object> serializableContextualInstance
      = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>, Object>getSerializableContextualInstance(interceptor, instance, creationalContext);
  instances.put(interceptor.getBeanClass().getName(), serializableContextualInstance);
}

代码示例来源:origin: weld/core

private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
  InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(classBean.getAnnotated());
  if (interceptionModel != null) {
    Set<? extends InterceptorClassMetadata<?>> interceptors = interceptionModel.getAllInterceptors();
    if (interceptors.size() > 0) {
      boolean passivationCapabilityCheckRequired = beanManager.isPassivatingScope(classBean.getScope());
      for (InterceptorClassMetadata<?> interceptorMetadata : interceptors) {
          Interceptor<?> interceptor = cdiInterceptorFactory.getInterceptor();
          boolean isSerializable = (interceptor instanceof InterceptorImpl) ? ((InterceptorImpl<?>) interceptor).isSerializable() : Beans.isPassivationCapableDependency(interceptor);
          if (!isSerializable) {
            throw ValidatorLogger.LOG.passivatingBeanWithNonserializableInterceptor(classBean, interceptor);
            beanManager = ((InterceptorImpl<?>) interceptor).getBeanManager();
          for (InjectionPoint injectionPoint : interceptor.getInjectionPoints()) {
            Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
            validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);
          PlainInterceptorFactory<?> factory = (PlainInterceptorFactory<?>) interceptorMetadata.getInterceptorFactory();
          Class<?> interceptorClass = interceptorMetadata.getJavaClass();
          if (passivationCapabilityCheckRequired && !Reflections.isSerializable(interceptorClass)) {
            throw ValidatorLogger.LOG.passivatingBeanWithNonserializableInterceptor(this, interceptorClass.getName());
            validateInjectionPoint(injectionPoint, beanManager);
            if (passivationCapabilityCheckRequired) {
              Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
              validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);

代码示例来源:origin: org.jboss.weld.se/weld-se

@Override
protected boolean matches(InterceptorResolvable resolvable, Interceptor<?> bean) {
  return bean.intercepts(resolvable.getInterceptionType())
      && bean.getInterceptorBindings().size() > 0
      && Beans.containsAllInterceptionBindings(bean.getInterceptorBindings(), resolvable.getQualifiers(), getManager())
      && manager.getEnabled().isInterceptorEnabled(bean.getBeanClass());
}

代码示例来源:origin: weld/core

@Override
public T create(CreationalContext<T> ctx, BeanManagerImpl manager) {
  return cast(manager.getReference(interceptor, interceptor.getBeanClass(), ctx, true));
}

代码示例来源:origin: org.jboss.weld.se/weld-se

protected void validateInterceptor(Interceptor<?> interceptor, BeanManagerImpl manager) {
  if (interceptor instanceof InterceptorImpl<?>) {
    EnhancedAnnotatedType<?> annotated = ((InterceptorImpl<?>) interceptor).getEnhancedAnnotated();
    if (!BeanMethods.getObserverMethods(annotated).isEmpty()) {
      throw ValidatorLogger.LOG.interceptorsCannotHaveObserverMethods(interceptor);
    }
    if (!interceptor.getScope().equals(Dependent.class)) {
      throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(interceptor);
    }
    while (annotated != null && annotated.getJavaClass() != Object.class) {
      if (!annotated.getDeclaredEnhancedMethods(Produces.class).isEmpty()) {
        throw ValidatorLogger.LOG.interceptorsCannotHaveProducerMethods(interceptor);
      }
      if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) {
        throw ValidatorLogger.LOG.interceptorsCannotHaveProducerFields(interceptor);
      }
      if (!annotated.getDeclaredEnhancedMethodsWithAnnotatedParameters(Disposes.class).isEmpty()) {
        throw ValidatorLogger.LOG.interceptorsCannotHaveDisposerMethods(interceptor);
      }
      annotated = annotated.getEnhancedSuperclass();
    }
  }
  for (InjectionPoint injectionPoint : interceptor.getInjectionPoints()) {
    validateInjectionPoint(injectionPoint, manager);
  }
}

代码示例来源:origin: weld/core

private void validateEnabledInterceptorClasses(BeanManagerImpl beanManager, BeanDeployment deployment) {
  BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml();
  if (beansXml != null && !beansXml.getEnabledInterceptors().isEmpty()) {
    Set<String> interceptorBeanClasses = new HashSet<String>();
    for (Interceptor<?> interceptor : beanManager.getDynamicAccessibleInterceptors()) {
      interceptorBeanClasses.add(interceptor.getBeanClass().getName());
    }
    for (Metadata<String> interceptorClassName : beansXml.getEnabledInterceptors()) {
      if (!interceptorBeanClasses.contains(interceptorClassName.getValue())) {
        throw ValidatorLogger.LOG.interceptorClassDoesNotMatchInterceptorBean(interceptorClassName.getValue(), interceptorClassName.getLocation());
      }
    }
  }
}

代码示例来源:origin: weld/core

private void initInterceptor(InterceptionType interceptionType, AnnotatedMethod<?> method, Set<Annotation> methodBindingAnnotations) {
  List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(interceptionType, methodBindingAnnotations);
  if (methodBoundInterceptors != null && methodBoundInterceptors.size() > 0) {
    Method javaMethod = method.getJavaMember();
    if (Reflections.isFinal(javaMethod)) {
      if (configuration.isFinalMethodIgnored(javaMethod.getDeclaringClass().getName())) {
        BeanLogger.LOG.finalMethodNotIntercepted(javaMethod, methodBoundInterceptors.get(0).getBeanClass().getName());
      } else {
        throw BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodBoundInterceptors.get(0).getBeanClass().getName());
      }
    } else {
      builder.interceptMethod(interceptionType, javaMethod, asInterceptorMetadata(methodBoundInterceptors), methodBindingAnnotations);
    }
  }
}

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl

@Override
public Object proceed() throws Exception
{
  currentInterceptorIdx++;
  return interceptor.intercept(interceptionType, instance, this);
}

代码示例来源:origin: weld/core

@SuppressWarnings("unchecked")
public static <T> CustomInterceptorMetadata<T> of(Interceptor<T> interceptor) {
  return new CustomInterceptorMetadata<T>(new CdiInterceptorFactory<T>(interceptor), (Class<T>) interceptor.getBeanClass(),
      interceptor.getName() != null && !interceptor.getName().isEmpty() ? interceptor.getName() : null);
}

代码示例来源:origin: org.jboss.as/jboss-as-weld

@SuppressWarnings("unchecked")
private void addInterceptorInstance(Interceptor<Object> interceptor, BeanManagerImpl beanManager, Map<String, SerializableContextualInstance<Interceptor<Object>, Object>> instances) {
  Object instance = beanManager.getContext(interceptor.getScope()).get(interceptor, creationalContext);
  SerializableContextualInstance<Interceptor<Object>, Object> serializableContextualInstance
      = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>, Object>getSerializableContextualInstance(interceptor, instance, creationalContext);
  instances.put(interceptor.getBeanClass().getName(), serializableContextualInstance);
}

代码示例来源:origin: weld/core

@Override
public Object intercept(InterceptionType type, T instance, InvocationContext ctx) throws Exception {
  return delegate().intercept(type, instance, ctx);
}

代码示例来源:origin: org.jboss.jbossas/weld-int-ejb

@SuppressWarnings("unchecked")
private void addInterceptorInstance(Interceptor<Object> interceptor, InvocationContext invocationContext)
{
 CreationalContext<Object> creationalContext = (CreationalContext<Object>) invocationContext.getContextData().get(SessionBeanInterceptor.CREATIONAL_CONTEXT);
 Object instance = beanManager.getContext(interceptor.getScope()).get(interceptor, creationalContext);
 SerializableContextualInstance<Interceptor<Object>,Object> serializableContextualInstance
    = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>,Object>getSerializableContextualInstance(interceptor, instance, creationalContext);
 interceptorInstances.put(interceptor.getBeanClass().getName(), serializableContextualInstance);
}

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

.map(i -> bm.getReference(i, i.getBeanClass(), bm.createCreationalContext(null)))
      .collect(toList());
  return new Interception(interceptors, instances);
final Iterator<Object> instances = interception.instances.iterator();
final Interceptor next = it.next();
return next.intercept(AROUND_INVOKE, instances.next(), new DelegateInvocationContext(invocationContext, it, instances));

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl

if(interceptor.getScope() != Dependent.class)
    logger.log(Level.WARNING, OWBLogConst.WARN_0005_1, interceptor.getBeanClass().getName());
if(interceptor.getName() != null)
    logger.log(Level.WARNING, OWBLogConst.WARN_0005_2, interceptor.getBeanClass().getName());
if(interceptor.isAlternative())
    logger.log(Level.WARNING, OWBLogConst.WARN_0005_3, interceptor.getBeanClass().getName());

代码示例来源:origin: weld/core

private void validateInterceptor(Interceptor<?> interceptor) {
  Set<Annotation> bindings = interceptor.getInterceptorBindings();
  if (bindings == null) {
    throw InterceptorLogger.LOG.nullInterceptorBindings(interceptor);
  }
  for (Annotation annotation : bindings) {
    if (!getBeanManager().isInterceptorBinding(annotation.annotationType())) {
      throw MetadataLogger.LOG.notAnInterceptorBinding(annotation, interceptor);
    }
  }
}

代码示例来源:origin: weld/core

@Override
public Set<Annotation> getInterceptorBindings() {
  return delegate().getInterceptorBindings();
}

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl

if (!interceptor.intercepts(type))
  return interceptor.intercept(type, instances.get(interceptor), this);

代码示例来源:origin: wildfly/wildfly

protected Object delegateInterception(InvocationContext invocationContext, InterceptionType interceptionType, List<Interceptor<?>> currentInterceptors, InterceptorInstances interceptorInstances)
    throws Exception {
  List<Object> currentInterceptorInstances = new ArrayList<Object>();
  for (Interceptor<?> interceptor : currentInterceptors) {
    currentInterceptorInstances.add(interceptorInstances.getInstances().get(interceptor.getBeanClass().getName()).getInstance());
  }
  if (currentInterceptorInstances.size() > 0) {
    return interceptorSupport.delegateInterception(invocationContext, interceptionType, currentInterceptors, currentInterceptorInstances);
  } else {
    return invocationContext.proceed();
  }
}

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl

public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
{
  List<Interceptor<?>> interceptorList = new ArrayList<>();
  for (Interceptor<?> interceptor : cdiInterceptors)
  {
    if (interceptor.intercepts(type) && intercepts(interceptor, interceptorBindings) && isInterceptorClassEnabled(interceptor.getBeanClass()))
    {
      interceptorList.add(interceptor);
    }
  }
  Collections.sort(interceptorList, new InterceptorComparator(webBeansContext));
  return interceptorList;
}

代码示例来源:origin: weld/core

@Override
public boolean intercepts(InterceptionType type) {
  return delegate().intercepts(type);
}

相关文章