コード例 #1
0
  public void destroy() {
    for (BeanFactoryAware beanFactoryAware : _beanFactoryAwares) {
      try {
        beanFactoryAware.setBeanFactory(null);
      } catch (Exception e) {
      }
    }

    _beanFactoryAwares.clear();

    for (AspectJExpressionPointcut aspectJExpressionPointcut : _aspectJExpressionPointcuts) {

      try {
        Map<Method, ShadowMatch> shadowMatchCache =
            (Map<Method, ShadowMatch>) _shadowMatchCacheField.get(aspectJExpressionPointcut);

        shadowMatchCache.clear();
      } catch (Exception e) {
      }
    }

    _aspectJExpressionPointcuts.clear();
  }
コード例 #2
0
 /**
  * Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and {@link BeanFactoryAware}
  * contracts if implemented by the given {@code bean}.
  */
 private void invokeAwareMethods(Object importStrategyBean) {
   if (importStrategyBean instanceof Aware) {
     if (importStrategyBean instanceof EnvironmentAware) {
       ((EnvironmentAware) importStrategyBean).setEnvironment(this.environment);
     }
     if (importStrategyBean instanceof ResourceLoaderAware) {
       ((ResourceLoaderAware) importStrategyBean).setResourceLoader(this.resourceLoader);
     }
     if (importStrategyBean instanceof BeanClassLoaderAware) {
       ClassLoader classLoader =
           (this.registry instanceof ConfigurableBeanFactory
               ? ((ConfigurableBeanFactory) this.registry).getBeanClassLoader()
               : this.resourceLoader.getClassLoader());
       ((BeanClassLoaderAware) importStrategyBean).setBeanClassLoader(classLoader);
     }
     if (importStrategyBean instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
       ((BeanFactoryAware) importStrategyBean).setBeanFactory((BeanFactory) this.registry);
     }
   }
 }
コード例 #3
0
 private static void registerBean(String beanName, Object bean, BeanFactory beanFactory) {
   Assert.notNull(beanName, "bean name must not be null");
   ConfigurableListableBeanFactory configurableListableBeanFactory = null;
   if (beanFactory instanceof ConfigurableListableBeanFactory) {
     configurableListableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
   } else if (beanFactory instanceof GenericApplicationContext) {
     configurableListableBeanFactory = ((GenericApplicationContext) beanFactory).getBeanFactory();
   }
   if (bean instanceof BeanNameAware) {
     ((BeanNameAware) bean).setBeanName(beanName);
   }
   if (bean instanceof BeanFactoryAware) {
     ((BeanFactoryAware) bean).setBeanFactory(beanFactory);
   }
   if (bean instanceof InitializingBean) {
     try {
       ((InitializingBean) bean).afterPropertiesSet();
     } catch (Exception e) {
       throw new FatalBeanException("failed to register bean with test context", e);
     }
   }
   configurableListableBeanFactory.registerSingleton(beanName, bean);
 }
コード例 #4
0
  /**
   * Initializes the Content Enricher. Will instantiate an internal Gateway if the requestChannel is
   * set.
   */
  @Override
  protected void doInit() {
    Assert.state(
        !(this.requestChannelName != null && this.requestChannel != null),
        "'requestChannelName' and 'requestChannel' are mutually exclusive.");

    Assert.state(
        !(this.replyChannelName != null && this.replyChannel != null),
        "'replyChannelName' and 'replyChannel' are mutually exclusive.");

    Assert.state(
        !(this.errorChannelName != null && this.errorChannel != null),
        "'errorChannelName' and 'errorChannel' are mutually exclusive.");

    if (this.replyChannel != null || this.replyChannelName != null) {
      Assert.state(
          this.requestChannel != null || this.requestChannelName != null,
          "If the replyChannel is set, then the requestChannel must not be null");
    }
    if (this.errorChannel != null || this.errorChannelName != null) {
      Assert.state(
          this.requestChannel != null || this.requestChannelName != null,
          "If the errorChannel is set, then the requestChannel must not be null");
    }
    if (this.requestChannel != null || this.requestChannelName != null) {
      this.gateway = new Gateway();
      this.gateway.setRequestChannel(this.requestChannel);
      if (this.requestChannelName != null) {
        this.gateway.setRequestChannelName(this.requestChannelName);
      }

      if (this.requestTimeout != null) {
        this.gateway.setRequestTimeout(this.requestTimeout);
      }
      if (this.replyTimeout != null) {
        this.gateway.setReplyTimeout(this.replyTimeout);
      }

      this.gateway.setReplyChannel(replyChannel);
      if (this.replyChannelName != null) {
        this.gateway.setReplyChannelName(this.replyChannelName);
      }

      this.gateway.setErrorChannel(errorChannel);
      if (this.errorChannelName != null) {
        this.gateway.setErrorChannelName(this.errorChannelName);
      }

      if (this.getBeanFactory() != null) {
        this.gateway.setBeanFactory(this.getBeanFactory());
      }

      this.gateway.afterPropertiesSet();
    }

    if (this.sourceEvaluationContext == null) {
      this.sourceEvaluationContext =
          ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
    }

    StandardEvaluationContext targetContext =
        ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
    // bean resolution is NOT allowed for the target of the enrichment
    targetContext.setBeanResolver(null);
    this.targetEvaluationContext = targetContext;

    if (this.getBeanFactory() != null) {
      for (HeaderValueMessageProcessor<?> headerValueMessageProcessor :
          this.headerExpressions.values()) {
        if (headerValueMessageProcessor instanceof BeanFactoryAware) {
          ((BeanFactoryAware) headerValueMessageProcessor).setBeanFactory(getBeanFactory());
        }
      }
      for (HeaderValueMessageProcessor<?> headerValueMessageProcessor :
          this.nullResultHeaderExpressions.values()) {
        if (headerValueMessageProcessor instanceof BeanFactoryAware) {
          ((BeanFactoryAware) headerValueMessageProcessor).setBeanFactory(getBeanFactory());
        }
      }
    }
  }