Beispiel #1
0
    public ComponentViewInstance createInstance(Map<Object, Object> contextData) {
      final SimpleInterceptorFactoryContext factoryContext = new SimpleInterceptorFactoryContext();
      final Map<Method, InterceptorFactory> viewInterceptorFactories =
          ViewService.this.viewInterceptorFactories;
      final Map<Method, Interceptor> viewEntryPoints =
          new IdentityHashMap<Method, Interceptor>(viewInterceptorFactories.size());
      factoryContext.getContextData().put(Component.class, component);
      factoryContext.getContextData().putAll(contextData);
      // the post construct interceptors currently MUST be created first
      // and in some cases the instance is attached in this create process
      // TODO: this is probably not a good thing. {@see ManagedBeanCreateInterceptorFactory}
      final Interceptor postConstructInterceptor = viewPostConstruct.create(factoryContext);

      for (Method method : viewInterceptorFactories.keySet()) {
        viewEntryPoints.put(method, viewInterceptorFactories.get(method).create(factoryContext));
      }
      final Interceptor preDestroyInterceptor = viewPreDestroy.create(factoryContext);

      final ComponentViewInstance instance =
          new ViewInstance(viewEntryPoints, preDestroyInterceptor);
      try {
        InterceptorContext context = new InterceptorContext();
        context.putPrivateData(ComponentView.class, this);
        context.putPrivateData(Component.class, component);
        postConstructInterceptor.processInvocation(context);
      } catch (Exception e) {
        // TODO: What is the best exception type to throw here?
        throw new RuntimeException("Failed to instantiate component view", e);
      }
      return instance;
    }
  @Override
  public void callTimeout(final TimerImpl timer, final Method timeoutMethod) throws Exception {
    final Interceptor interceptor;
    synchronized (this) {
      if (!started) {
        // this can happen if an invocation has been triggered as the deployment is shutting down
        throw EjbLogger.ROOT_LOGGER.timerInvocationFailedDueToInvokerNotBeingStarted();
      }
      interceptor = timeoutInterceptors.get(timeoutMethod);
    }
    if (interceptor == null) {
      throw EjbLogger.ROOT_LOGGER.failToInvokeTimeout(timeoutMethod);
    }
    final InterceptorContext context = new InterceptorContext();
    context.setContextData(new HashMap<String, Object>());
    context.setMethod(timeoutMethod);
    if (timeoutMethod.getParameterTypes().length == 0) {
      context.setParameters(new Object[0]);
    } else {
      final Object[] params = new Object[1];
      params[0] = timer;
      context.setParameters(params);
    }
    context.setTimer(timer);

    if (timer.getPrimaryKey() != null) {
      context.putPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY, timer.getPrimaryKey());
    }
    context.putPrivateData(Component.class, ejbComponent.getValue());
    context.putPrivateData(MethodIntf.class, MethodIntf.TIMER);
    context.putPrivateData(InvocationType.class, InvocationType.TIMER);
    interceptor.processInvocation(context);
  }
Beispiel #3
0
      public Object createProxy() {
        final SimpleInterceptorFactoryContext factoryContext =
            new SimpleInterceptorFactoryContext();
        factoryContext.getContextData().put(Component.class, component);
        factoryContext.getContextData().put(ComponentView.class, View.this);
        factoryContext.getContextData().put(ComponentViewInstance.class, this);

        final Map<Method, InterceptorFactory> clientInterceptorFactories =
            ViewService.this.clientInterceptorFactories;
        final Map<Method, Interceptor> clientEntryPoints =
            new IdentityHashMap<Method, Interceptor>(clientInterceptorFactories.size());
        for (Method method : clientInterceptorFactories.keySet()) {
          clientEntryPoints.put(
              method, clientInterceptorFactories.get(method).create(factoryContext));
        }
        final Interceptor postConstructInterceptor = clientPostConstruct.create(factoryContext);
        try {
          Object object =
              proxyFactory.newInstance(
                  new ProxyInvocationHandler(clientEntryPoints, component, View.this, this));
          InterceptorContext interceptorContext = new InterceptorContext();
          interceptorContext.putPrivateData(ComponentView.class, View.this);
          interceptorContext.putPrivateData(ComponentViewInstance.class, this);
          interceptorContext.putPrivateData(Component.class, component);
          try {
            postConstructInterceptor.processInvocation(interceptorContext);
          } catch (Exception e) {
            InstantiationException exception =
                new InstantiationException("Post-construct lifecycle failed");
            exception.initCause(e);
            throw exception;
          }
          return object;
        } catch (InstantiationException e) {
          InstantiationError error = new InstantiationError(e.getMessage());
          Throwable cause = e.getCause();
          if (cause != null) error.initCause(cause);
          throw error;
        } catch (IllegalAccessException e) {
          IllegalAccessError error = new IllegalAccessError(e.getMessage());
          Throwable cause = e.getCause();
          if (cause != null) error.initCause(cause);
          throw error;
        }
      }
Beispiel #4
0
 public void destroy() {
   try {
     InterceptorContext interceptorContext = new InterceptorContext();
     interceptorContext.putPrivateData(ComponentView.class, View.this);
     interceptorContext.putPrivateData(ComponentViewInstance.class, this);
     interceptorContext.putPrivateData(Component.class, component);
     preDestroyInterceptor.processInvocation(interceptorContext);
   } catch (Exception e) {
     logger.warn(
         "Exception while invoking pre-destroy interceptor for component class: "
             + this.getComponent().getComponentClass(),
         e);
   }
 }
 public void invokeTimeoutMethod(final Method method, final Timer timer) {
   final Interceptor interceptor = timeoutInterceptors.get(method);
   if (interceptor == null) {
     throw MESSAGES.failToCallTimeOutMethod(method);
   }
   try {
     InterceptorContext context = prepareInterceptorContext();
     context.setMethod(method);
     context.setTimer(timer);
     context.setTarget(getInstance());
     final Object[] params;
     if (method.getParameterTypes().length == 1) {
       params = new Object[1];
       params[0] = timer;
     } else {
       params = EMPTY_OBJECT_ARRAY;
     }
     context.setParameters(params);
     interceptor.processInvocation(context);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }