/** {@inheritDoc} */
 public Object processInvocation(final InterceptorContext context) throws Exception {
   Object target = targetReference.get().getInstance();
   if (target == null) {
     throw new IllegalStateException("No injection target found");
   }
   // if it's an optional injection and the injection source isn't available, then just proceed by
   // skipping the injection
   if (this.factory == null && this.optionalInjection) {
     return context.proceed();
   }
   ManagedReference reference = factory.getReference();
   boolean ok = false;
   try {
     valueReference.set(reference);
     method.invoke(target, reference.getInstance());
     Object result = context.proceed();
     ok = true;
     return result;
   } finally {
     if (!ok) {
       valueReference.set(null);
       reference.release();
     }
   }
 }
 /**
  * Processes an incoming invocation and checks for the presence of a remote transaction associated
  * with the invocation context.
  *
  * @param context The invocation context
  * @return
  * @throws Exception
  */
 @Override
 public Object processInvocation(InterceptorContext context) throws Exception {
   final RemotingAttachments remotingAttachments =
       context.getPrivateData(RemotingAttachments.class);
   final TransactionManager transactionManager =
       this.ejbRemoteTransactionsRepository.getTransactionManager();
   Transaction originatingRemoteTx = null;
   if (remotingAttachments != null) {
     // get the transaction attachment
     final byte[] transactionIDBytes = remotingAttachments.getPayloadAttachment(0x0001);
     // A (remote) tx is associated with the invocation, so propogate it appropriately
     if (transactionIDBytes != null) {
       final TransactionID transactionID = TransactionID.createTransactionID(transactionIDBytes);
       // if it's UserTransaction then create or resume the UserTransaction corresponding to the ID
       if (transactionID instanceof UserTransactionID) {
         this.createOrResumeUserTransaction((UserTransactionID) transactionID);
       } else if (transactionID instanceof XidTransactionID) {
         this.createOrResumeXidTransaction((XidTransactionID) transactionID);
       }
       // the invocation was associated with a remote tx, so keep a flag so that we can
       // suspend (on this thread) the originating tx when returning from the invocation
       originatingRemoteTx = transactionManager.getTransaction();
     }
   }
   try {
     // we are done with any tx propogation setup, let's move on
     return context.proceed();
   } finally {
     // suspend the originating remote tx on this thread now that the invocation has been done
     if (originatingRemoteTx != null) {
       transactionManager.suspend();
     }
   }
 }
  @Override
  public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    try {

      return interceptorContext.proceed();
    } finally {
      StatefulSessionComponentInstance sfsb =
          (StatefulSessionComponentInstance)
              interceptorContext.getPrivateData(ComponentInstance.class);
      SFSBContextHandleImpl sfsbContextHandle = new SFSBContextHandleImpl(sfsb);
      List<EntityManager> readyToClose = SFSBXPCMap.getINSTANCE().remove(sfsbContextHandle);
      if (readyToClose != null && readyToClose.size() > 0) {
        for (EntityManager entityManager : readyToClose) {
          if (entityManager instanceof ExtendedEntityManager) {
            // TODO:  continue iterating through remaining entity managers and chain any exceptions
            ((ExtendedEntityManager) entityManager).containerClose();
          } else {
            throw new RuntimeException(
                "can only close SFSB XPC entity manager that are instances of ExtendedEntityManager"
                    + entityManager.getClass().getName());
          }
        }
      }
    }
  }
  @Override
  public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);

    // if a session bean is participating in a transaction, it
    // is an error for a client to invoke the remove method
    // on the session object's home or component interface.
    final ComponentView view = context.getPrivateData(ComponentView.class);
    if (view != null) {
      Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
      if (viewType != null) {
        // this means it is an EJB 2.x view
        // which is not allowed to remove while enrolled in a TX
        final StatefulTransactionMarker marker =
            context.getPrivateData(StatefulTransactionMarker.class);
        if (marker != null && !marker.isFirstInvocation()) {
          throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
        }
      }
    }
    // just log a WARN and throw back the original exception
    if (component instanceof StatefulSessionComponent == false) {
      throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
    }
    final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
    Object invocationResult = null;
    try {
      // proceed
      invocationResult = context.proceed();
    } catch (Exception e) {
      // Exception caught during call to @Remove method. Handle it appropriately

      // If it's an application exception and if the @Remove method has set "retainIfException" to
      // true
      // then just throw back the exception and don't remove the session instance.
      if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod())
          && this.retainIfException) {
        throw e;
      }
      // otherwise, just remove it and throw back the original exception
      final StatefulSessionComponentInstance statefulComponentInstance =
          (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
      final SessionID sessionId = statefulComponentInstance.getId();
      statefulComponent.removeSession(sessionId);
      throw e;
    }
    final StatefulSessionComponentInstance statefulComponentInstance =
        (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
    final SessionID sessionId = statefulComponentInstance.getId();
    // just remove the session because of a call to @Remove method
    statefulComponent.removeSession(sessionId);
    // return the invocation result
    return invocationResult;
  }
 @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);
   }
 }
 @Override
 public Object proceed() throws Exception {
   return context.proceed();
 }