ConversationSequence sequence = op.getConversationSequence();
Object contextId = null;
EndpointReference from = msg.getFrom();
ReferenceParameters parameters = null;
if (from != null) {
parameters = from.getReferenceParameters();
}
// check what sort of context is required
if (scopeContainer != null) {
Scope scope = scopeContainer.getScope();
if (scope == Scope.REQUEST) {
contextId = Thread.currentThread();
} else if (scope == Scope.CONVERSATION && parameters != null) {
contextId = parameters.getConversationID();
}
}
try {
OSGiInstanceWrapper wrapper = (OSGiInstanceWrapper)getInstance(contextId);
Object instance;
// detects whether the scope container has created a conversation Id. This will
// happen in the case that the component has conversational scope but only the
// callback interface is conversational. Or in the callback case if the service interface
// is conversational and the callback interface isn't. If we are in this situation we need
// to get the contextId of this component and remove it after we have invoked the method on
// it. It is possible that the component instance will not go away when it is removed below
// because a callback conversation will still be holding a reference to it
boolean removeTemporaryConversationalComponentAfterCall = false;
if (parameters != null && (contextId == null) && (parameters.getConversationID() != null)) {
contextId = parameters.getConversationID();
removeTemporaryConversationalComponentAfterCall = true;
}
instance = wrapper.getInstance(service);
Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
Object ret = invokeMethod(instance, m, msg);
scopeContainer.returnWrapper(wrapper, contextId);
if ((sequence == ConversationSequence.CONVERSATION_END) || (removeTemporaryConversationalComponentAfterCall)) {
// if end conversation, or we have the special case where a conversational
// object was created to service the stateless half of a stateful component
scopeContainer.remove(contextId);
parameters.setConversationID(null);
}
return ret;
} catch (InvocationTargetException e) {
throw e;