コード例 #1
0
  @Override
  public void validate() {
    // Make sure more than one 'position' isn't picked.
    int positions = 0;

    if (before != null) positions++;
    if (after != null) positions++;
    if (index > -1) positions++;
    if (!position.equals(Position.OTHER_THAN_FIRST_OR_LAST)) positions++;

    switch (positions) {
      case 0:
        throw log.missingCustomInterceptorPosition(interceptor.getClass().getName());
      case 1:
        break;
      default:
        throw log.multipleCustomInterceptorPositions(interceptor.getClass().getName());
    }
    if (interceptor == null) {
      throw log.customInterceptorMissingClass();
    }
    if (!(interceptor instanceof BaseCustomInterceptor)) {
      log.suggestCustomInterceptorInheritance(interceptor.getClass().getName());
    }
  }
コード例 #2
0
  /**
   * Replaces the existing interceptor chain in the cache wih one represented by the interceptor
   * passed in. This utility updates dependencies on all components that rely on the interceptor
   * chain as well.
   *
   * @param cache cache that needs to be altered
   * @param interceptor the first interceptor in the new chain.
   */
  public static void replaceInterceptorChain(Cache cache, CommandInterceptor interceptor) {
    ComponentRegistry cr = extractComponentRegistry(cache);
    // make sure all interceptors here are wired.
    CommandInterceptor i = interceptor;
    do {
      cr.wireDependencies(i);
    } while ((i = i.getNext()) != null);

    InterceptorChain inch = cr.getComponent(InterceptorChain.class);
    inch.setFirstInChain(interceptor);
  }
コード例 #3
0
 /**
  * Replaces an existing interceptor of the given type in the interceptor chain with a new
  * interceptor instance passed as parameter.
  *
  * @param replacingInterceptor the interceptor to add to the interceptor chain
  * @param toBeReplacedInterceptorType the type of interceptor that should be swapped with the new
  *     one
  * @return true if the interceptor was replaced
  */
 public static boolean replaceInterceptor(
     Cache cache,
     CommandInterceptor replacingInterceptor,
     Class<? extends CommandInterceptor> toBeReplacedInterceptorType) {
   ComponentRegistry cr = extractComponentRegistry(cache);
   // make sure all interceptors here are wired.
   CommandInterceptor i = replacingInterceptor;
   do {
     cr.wireDependencies(i);
   } while ((i = i.getNext()) != null);
   InterceptorChain inch = cr.getComponent(InterceptorChain.class);
   return inch.replaceInterceptor(replacingInterceptor, toBeReplacedInterceptorType);
 }