Ejemplo n.º 1
0
    public void configure(
        final DeploymentPhaseContext context,
        final ComponentConfiguration componentConfiguration,
        final ViewDescription description,
        final ViewConfiguration configuration)
        throws DeploymentUnitProcessingException {
      // Create method indexes
      final DeploymentReflectionIndex reflectionIndex =
          context.getDeploymentUnit().getAttachment(REFLECTION_INDEX);
      final List<Method> methods = configuration.getProxyFactory().getCachedMethods();
      for (final Method method : methods) {
        MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
        Method componentMethod =
            ClassReflectionIndexUtil.findMethod(
                reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier);

        if (componentMethod != null) {

          if ((BRIDGE & componentMethod.getModifiers()) != 0) {
            Collection<Method> otherMethods =
                ClassReflectionIndexUtil.findMethods(
                    reflectionIndex,
                    reflectionIndex.getClassIndex(componentConfiguration.getComponentClass()),
                    methodIdentifier.getName(),
                    methodIdentifier.getParameterTypes());
            // try and find the non-bridge method to delegate to
            for (final Method other : otherMethods) {
              if ((BRIDGE & other.getModifiers()) == 0) {
                componentMethod = other;
                break;
              }
            }
          }

          configuration.addViewInterceptor(
              method,
              new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)),
              InterceptorOrder.View.COMPONENT_DISPATCHER);
          configuration.addClientInterceptor(
              method,
              CLIENT_DISPATCHER_INTERCEPTOR_FACTORY,
              InterceptorOrder.Client.CLIENT_DISPATCHER);
        }
      }

      configuration.addClientPostConstructInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
      configuration.addClientPreDestroyInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
    }