com.ibm.bpm.context
Interface ContextService


public interface ContextService

The ContextService interface represents the programming model for the context service in BPM. The BPM context service provides the ability to access and modify the execution context, and propagate the execution context to the downstream.

The following code is used to locate context service:

        ContextService contextService = (ContextService) ServiceManager.INSTANCE
                .locateService("com/ibm/bpm/context/ContextService");
        
The following features are supported:

The 2 features can be accessed by ContextObject too.

The data which is set into the execution context by context service can be propagated cross modules. Say there are 2 modules, Module A and Module B. Component A is in module A, component B is in module B, and, component A calls component B. In component A, the context data can be set like this:

   // Get header info
   HeaderInfo headerInfo = contextService.getHeaderInfo();
   // Get user defined context in current execution context
   UserDefinedContextType userDefinedContext = contextService.getUserDefinedContext();
   if(userDefinedContext == null){ // create a new context if context is null
        userDefinedContext = ContextObjectFactory.eINSTANCE.createUserDefinedContextType()
   }
   // Do some modification to header info and userDefinedContext
   ......
   
   // Set user defined context back to the current execution context. 
   contextService.setUserDefinedContext(userDefinedContext);
   
   // Set header info back to the current execution context.
   contextService.setHeaderInfo(headerInfo);
   
The context data will be propagated from component A to component B.

In component B, the context data can be accessed like below:

   UserDefinedContextType userDefinedContext = contextService.getUserDefinedContext();
   HeaderInfo headerInfo = contextService.getHeaderInfo();
   

Context access and propagation can make the business logic more clean, but too large data in execution context would impact the performance. Because once the data is set to current execution context, it will be propagated to downstream. So, please keep in mind -- do not put too large data into current execution context.

If the updated context data is not set back by setHeaderInfo, setUserDefinedContext, or setContextObject, the context service will NOT propagate the updated data to the downstream.


Field Summary
static java.lang.String COPYRIGHT
          Copyright
 
Method Summary
 com.ibm.bpm.context.cobo.ContextObject getContextObject()
          Get context object from current execution context.
 com.ibm.bpm.context.cobo.HeaderInfoType getHeaderInfo()
          Get the protocol headers in the current execution context
 com.ibm.bpm.context.cobo.UserDefinedContextType getUserDefinedContext()
          Get the user defined context data from the current execution context.
 void setContextObject(com.ibm.bpm.context.cobo.ContextObject contextObject)
          Set context object to current execution context.
 void setHeaderInfo(com.ibm.bpm.context.cobo.HeaderInfoType headerInfo)
          Set the protocol headers to the current execution context.
 void setUserDefinedContext(com.ibm.bpm.context.cobo.UserDefinedContextType userDefinedContext)
          Set user defined context data to the current execution context.
 

Field Detail

COPYRIGHT

static final java.lang.String COPYRIGHT
Copyright

See Also:
Constant Field Values
Method Detail

getHeaderInfo

com.ibm.bpm.context.cobo.HeaderInfoType getHeaderInfo()
Get the protocol headers in the current execution context

The protocol headers type is represented by HeaderInfo.

Returns:
the protocol header's information in current execution context
See Also:
HeaderInfoType

setHeaderInfo

void setHeaderInfo(com.ibm.bpm.context.cobo.HeaderInfoType headerInfo)
Set the protocol headers to the current execution context.

If the input headers value is null, the protocol headers in current execution context will be removed.

The context service will not propagate the updated context data if it is not set to current execution context.

Parameters:
headerInfo - the protocol header's information.
See Also:
HeaderInfoType

getUserDefinedContext

com.ibm.bpm.context.cobo.UserDefinedContextType getUserDefinedContext()
Get the user defined context data from the current execution context.

The user context type is presented by UserDefinedContextType

Returns:
the user defined context data in current execution context
See Also:
UserDefinedContextType

setUserDefinedContext

void setUserDefinedContext(com.ibm.bpm.context.cobo.UserDefinedContextType userDefinedContext)
Set user defined context data to the current execution context.

If the input context value is null, the user defined context data in the current context will be removed.

The context service will not propagate the context data if it is not set to current execution context.

Parameters:
userDefinedContext - the user defined context data.
See Also:
UserDefinedContextType

getContextObject

com.ibm.bpm.context.cobo.ContextObject getContextObject()
Get context object from current execution context.

ContextObject is the container of header info and user defined context. It provides xpath like style to access and modify context data. For example:

        ContextObject contextObject = contextService.getContextObject();
        HeaderInfo headers = (HeaderInfo) contextObject.get("headerInfo");
        

Returns:
context object
See Also:
ContextObject

setContextObject

void setContextObject(com.ibm.bpm.context.cobo.ContextObject contextObject)
Set context object to current execution context.

If the modified context object is not set to current execution context, context service will not propagate the modified data. So, after the context object is modified, please set it back to current execution context:

        // get context object
        ContextObject contextObject = contextService.getContextObject();
        // Do some modification on context object
        ... ... 
        // Set the modified context object back to current execution context
        contextService.setContextObject(contextObject);
 

Parameters:
contextObject - the context object.
See Also:
ContextObject