/**
  * Reply to a message. The message an {@link IInternalMessage} or a {@link Map} with a "content"
  * key with the return Object.
  */
 @SuppressWarnings("unchecked")
 public void reply(String pid, Object in, Object out) throws BpmScriptException {
   IInternalMessage messageToSend = null;
   String correlationId = ((IInternalMessage) in).getCorrelationId();
   if (out instanceof ExceptionMessage) {
     ExceptionMessage exceptionMessage = (ExceptionMessage) out;
     exceptionMessage.setCorrelationId(correlationId);
     messageToSend = exceptionMessage;
   } else if (out instanceof ResponseMessage) {
     ResponseMessage responseMessage = (ResponseMessage) out;
     responseMessage.setCorrelationId(correlationId);
     messageToSend = responseMessage;
   } else {
     Map<String, Object> map = (Map<String, Object>) out;
     Object content = map.get("content");
     if (content != null && content instanceof Throwable) {
       messageToSend = new ExceptionMessage(correlationId, (Throwable) content);
     } else {
       messageToSend = new MapResponseMessage(map);
     }
     map.put("correlationId", correlationId);
   }
   if (in instanceof IInvocationMessage) {
     final IInvocationMessage inMessage = (IInvocationMessage) in;
     sender.send(inMessage.getReplyTo(), messageToSend);
   } else {
     sender.send(errorAddress, messageToSend);
   }
 }
 /**
  * Calls either getArgs on an {@link IInvocationMessage}, getContent on {@link IResponseMessage}
  * or getThrowable on {@link IExceptionMessage}
  *
  * @see org.bpmscript.channel.IScriptChannel#getContent(java.lang.Object)
  */
 public Object getContent(Object message) {
   if (message instanceof IInvocationMessage) {
     IInvocationMessage invocationMessage = (IInvocationMessage) message;
     return invocationMessage.getArgs();
   } else if (message instanceof IResponseMessage) {
     IResponseMessage responseMessage = (IResponseMessage) message;
     return responseMessage.getContent();
   } else if (message instanceof IExceptionMessage) {
     IExceptionMessage exceptionMessage = (IExceptionMessage) message;
     return exceptionMessage.getThrowable();
   }
   return message;
 }