container/services/src/main/java/org/mobicents/slee/runtime/sbbentity/SbbEntityImpl.java
public void invokeEventHandler(EventContext sleeEvent, ActivityContext ac,
			EventContext eventContextImpl) throws Exception {

		
		// get event handler method
		final SbbComponent sbbComponent = getSbbComponent();
		final EventHandlerMethod eventHandlerMethod = sbbComponent
				.getEventHandlerMethods().get(sleeEvent.getEventTypeId());
		// build aci
		ActivityContextInterface aci = asSbbActivityContextInterface(ac.getActivityContextInterface());
		// now build the param array
		final Object[] parameters ;
		if (eventHandlerMethod.getHasEventContextParam()) {
			parameters = new Object[] { sleeEvent.getEvent(),
					aci, eventContextImpl };
		} else {
			parameters = new Object[] { sleeEvent.getEvent(),
					aci };
		}

		// store some info about the invocation in the tx context
		final EventRoutingTransactionData data = new EventRoutingTransactionDataImpl(
				sleeEvent, aci);		
		final TransactionContext txContext = sleeContainer.getTransactionManager().getTransactionContext();
		txContext.setEventRoutingTransactionData(data);
		// track sbb entity invocations if reentrant
		Set<SbbEntityID> invokedSbbentities = null;
		if (!isReentrant()) {
			invokedSbbentities = txContext.getInvokedNonReentrantSbbEntities();
			invokedSbbentities.add(sbbeId);
		}
		final JndiManagement jndiManagement = sleeContainer.getJndiManagement();
		jndiManagement.pushJndiContext(sbbComponent);
		// invoke method
		try {

			//This is required. Since domain chain may indicate RA for instance, or SLEE deployer. If we dont do that test: tests/runtime/security/Test1112012Test.xml and second one, w
			//will fail because domain of SLEE tck ra is too restrictive (or we have bad desgin taht allows this to happen?)
			if(System.getSecurityManager()!=null) {
				AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
				public Object run() throws IllegalAccessException, InvocationTargetException{
					eventHandlerMethod.getEventHandlerMethod().invoke(
							sbbObject.getSbbConcrete(), parameters);
					return null;
				}});
			}
			else {
				eventHandlerMethod.getEventHandlerMethod().invoke(
						sbbObject.getSbbConcrete(), parameters);
			}
		} catch(PrivilegedActionException pae) {
			Throwable cause = pae.getException();
			if(cause instanceof  IllegalAccessException)
			 {
				throw new RuntimeException(cause);
			} else if(cause instanceof InvocationTargetException ) {
				// Remember the actual exception is hidden inside the
				// InvocationTarget exception when you use reflection!
				Throwable realException = cause.getCause();
				if (realException instanceof RuntimeException) {
				    throw (RuntimeException) realException;
				} else if (realException instanceof Error) {
				    throw (Error) realException;
				} else if (realException instanceof Exception) {
				    throw (Exception) realException;
				}
			}else
			{
				pae.printStackTrace();
			}
		} catch(IllegalAccessException iae) {
			throw new RuntimeException(iae);
		} catch(InvocationTargetException ite) {
			Throwable realException = ite.getCause();
			if (realException instanceof RuntimeException) {
			    throw (RuntimeException) realException;
			} else if (realException instanceof Error) {
			    throw (Error) realException;
			} else if (realException instanceof Exception) {
			    throw (Exception) realException;
			}
		} catch(Exception e) {
			log.error(e.getMessage(),e);
		}
		finally {
			jndiManagement.popJndiContext();
			if(invokedSbbentities != null) {
				invokedSbbentities.remove(sbbeId);
			}
		}
		// remove data from tx context
		txContext.setEventRoutingTransactionData(null);
		
	}
public void invokeEventHandler(EventContext sleeEvent, ActivityContext ac,
			EventContext eventContextImpl) throws Exception {

		
		// get event handler method
		final SbbComponent sbbComponent = getSbbComponent();
		final EventHandlerMethod eventHandlerMethod = sbbComponent
				.getEventHandlerMethods().get(sleeEvent.getEventTypeId());
		// build aci
		ActivityContextInterface aci = asSbbActivityContextInterface(ac.getActivityContextInterface());
		// now build the param array
		final Object[] parameters ;
		if (eventHandlerMethod.getHasEventContextParam()) {
			parameters = new Object[] { sleeEvent.getEvent(),
					aci, eventContextImpl };
		} else {
			parameters = new Object[] { sleeEvent.getEvent(),
					aci };
		}

		// store some info about the invocation in the tx context
		final EventRoutingTransactionData data = new EventRoutingTransactionDataImpl(
				sleeEvent, aci);		
		final TransactionContext txContext = sleeContainer.getTransactionManager().getTransactionContext();
		txContext.setEventRoutingTransactionData(data);
		// track sbb entity invocations if reentrant
		Set<SbbEntityID> invokedSbbentities = null;
		if (!isReentrant()) {
			invokedSbbentities = txContext.getInvokedNonReentrantSbbEntities();
			invokedSbbentities.add(sbbeId);
		}
		final JndiManagement jndiManagement = sleeContainer.getJndiManagement();
		jndiManagement.pushJndiContext(sbbComponent);
		// invoke method
		try {

			//This is required. Since domain chain may indicate RA for instance, or SLEE deployer. If we dont do that test: tests/runtime/security/Test1112012Test.xml and second one, w
			//will fail because domain of SLEE tck ra is too restrictive (or we have bad desgin taht allows this to happen?)
			if(System.getSecurityManager()!=null) {
				AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
				public Object run() throws IllegalAccessException, InvocationTargetException{
					eventHandlerMethod.getEventHandlerMethod().invoke(
							sbbObject.getSbbConcrete(), parameters);
					return null;
				}});
			}
			else {
				eventHandlerMethod.getEventHandlerMethod().invoke(
						sbbObject.getSbbConcrete(), parameters);
			}
		} catch(PrivilegedActionException pae) {
			Throwable cause = pae.getException();
			if(cause instanceof  IllegalAccessException)
			 {
				throw new RuntimeException(cause);
			} else if(cause instanceof InvocationTargetException ) {
				// Remember the actual exception is hidden inside the
				// InvocationTarget exception when you use reflection!
				Throwable realException = cause.getCause();
				if (realException instanceof RuntimeException) {
				    throw (RuntimeException) realException;
				} else if (realException instanceof Error) {
				    throw (Error) realException;
				} else if (realException instanceof Exception) {
				    throw (Exception) realException;
				}
			}else
			{
				pae.printStackTrace();
			}
		} catch(IllegalAccessException iae) {
			throw new RuntimeException(iae);
		} catch(InvocationTargetException ite) {
			Throwable realException = ite.getCause();
			if (realException instanceof RuntimeException) {
			    throw (RuntimeException) realException;
			} else if (realException instanceof Error) {
			    throw (Error) realException;
			} else if (realException instanceof Exception) {
			    throw (Exception) realException;
			}
		} catch(Exception e) {
			log.error(e.getMessage(),e);
		}
		finally {
			jndiManagement.popJndiContext();
			if(invokedSbbentities != null) {
				invokedSbbentities.remove(sbbeId);
			}
		}
		// remove data from tx context
		txContext.setEventRoutingTransactionData(null);
		
	}
/*
(non-Javadoc)
@see org.mobicents.slee.runtime.sbbentity.SbbEntity#invokeEventHandler(org.mobicents.slee.core.event.SleeEvent, org.mobicents.slee.runtime.activity.ActivityContext, org.mobicents.slee.core.event.EventContext)