@Override
  public <T> T getBusinessObject(SessionContext ctx, Class<T> businessInterface)
      throws IllegalStateException {
    if (businessInterface == null) {
      throw new IllegalStateException("Business interface type cannot be null");
    }

    final Serializable sessionId =
        ((SessionBeanComponentInstance.SessionBeanComponentInstanceContext) ctx).getId();

    if (viewServices.containsKey(businessInterface.getName())) {
      final ServiceController<?> serviceController =
          CurrentServiceRegistry.getServiceRegistry()
              .getRequiredService(viewServices.get(businessInterface.getName()));
      final ComponentView view = (ComponentView) serviceController.getValue();
      final ComponentViewInstance instance;
      if (sessionId != null) {
        instance =
            view.createInstance(
                Collections.<Object, Object>singletonMap(
                    StatefulSessionComponent.SESSION_ATTACH_KEY, sessionId));
      } else {
        instance = view.createInstance();
      }
      return (T) instance.createProxy();
    } else {
      throw new IllegalStateException(
          "View of type " + businessInterface + " not found on bean " + this);
    }
  }
 @Override
 public Object processInvocation(InterceptorContext context) throws Exception {
   final Method invokedMethod = context.getMethod();
   final ComponentViewInstance componentViewInstance =
       context.getPrivateData(ComponentViewInstance.class);
   // For a lifecycle interception, the ComponentViewInstance (and the invoked business interface)
   // will be null.
   // On a normal method invocation, the invoked business interface will be obtained from the
   // ComponentViewInstance
   final Class<?> invokedBusinessInterface =
       componentViewInstance == null ? null : componentViewInstance.getViewClass();
   Object[] parameters = context.getParameters();
   SessionInvocationContext sessionInvocationContext =
       new CustomSessionInvocationContext(
           lifecycleCallback, context, invokedBusinessInterface, invokedMethod, parameters);
   context.putPrivateData(InvocationContext.class, sessionInvocationContext);
   CurrentInvocationContext.push(sessionInvocationContext);
   try {
     return context.proceed();
   } finally {
     CurrentInvocationContext.pop();
     context.putPrivateData(InvocationContext.class, null);
   }
 }