Skip navigation links


com.bea.content.spi.flexspi.common
Class InvocationParameters

java.lang.Object
  extended by com.bea.content.spi.flexspi.common.InvocationParameters


public class InvocationParameters
extends Object

A class to hold implicit invocation parameters as a ContentContext object. It provides a temporary means to tunnel 'additional data' to a SPI method outside the standard parameters. The parameters which can be set are ContentContext ContextKey values.

NOTE: be sure to read the javadoc on the remove() method; this is critical to proper usage of this class.

The caller stores the ContentContext object (and later removes it), and the called routine fetches the object by calling InvocationParameters.get()

When used properly, this class will support re-entrant calls, ie in the midst of a call which has set InvocationParameters, another call which sets (possibly different) InvocationParameters can occur. The overall behavior is like a stack; as InvocationParameters.remove() is called, the parameters are popped off the stack and the previous parameters are now present.

Over time, the intent is that this class will no longer be necessary, as the ContentContext will become a standard parameter in method signatures (and ContentContext provides the ability to hold and arbitrary number of invocation parameters). <p/> Note this approach should only be used as a last resort; it is preferable for many reasons, such as compile-time checking, to use method signatures to specify parameters rather than using implicit data. <p/> That said, there are cases, such as for requesting that results not be cached, where this approach is necessary today.

Sample context key used to pass Boolean data:

 <p/>
 final ContextKey CACHE_RESULTS= new ContextKey( "CACHE_RESULTS", Boolean.class, true, false);
 <p/>
 

Sample code setting InvocationParameters (typically done in Latest*OpsDelegate methods)

 <p/>
 try {
    IContentContext scopedContext= context.copy();
    if ( !cacheResults ) {
      scopedContext.setParameter( CommonContextKeys.CACHE_RESULTS, Boolean.FALSE);
    }
    InvocationParameters.set(scopedContext);
    returnedNodes= nops.getNodeChildren(parentId, type);
 }
 finally {
    InvocationParameters.remove();
 }
 <p/>
 

Sample code retrieving and using InvocationParameters to vary behavior (typically done inside one of the SPI filters)

 <p/>
 Boolean cacheResultValue= (Boolean)context.getParameter(CommonContextKeys.CACHE_RESULTS);
 if ( cacheResultValue == null || !cacheResultValue.equals(Boolean.FALSE) ) {
    //default behavior (if not specified): cache results
    CacheHelper.addNodeCacheEntry(repositoryName, returnedNode.getId().getUid(), returnedNode);
    cacheObjectClassIfPresent( returnedNode );
 }
 else {
    // dont cache results
 }
 <p/>
 

Constructor Summary
InvocationParameters()
           

 

Method Summary
static IContentContext get()
          retrieve a ContentContext parameter object containing any invocation parameters which may exist.
static void remove()
          IMPORTANT! Call this method in a finally block to ensure that the threadLocal created by set(...) is diassociated from the current thread, no matter how the method invocation completes, before the thread is returned to the pool.
static void set(IContentContext context)
          store the specified ContentContext object as an implicit parameter (push onto the stack)

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

InvocationParameters

public InvocationParameters()

Method Detail

set

public static void set(IContentContext context)
store the specified ContentContext object as an implicit parameter (push onto the stack)
Parameters
context -

get

public static IContentContext get()
retrieve a ContentContext parameter object containing any invocation parameters which may exist. if no invocation parameters exist, an empty ContentContext object will be returned. This method will never return NULL.

remove

public static void remove()
IMPORTANT! Call this method in a finally block to ensure that the threadLocal created by set(...) is diassociated from the current thread, no matter how the method invocation completes, before the thread is returned to the pool.

Skip navigation links


Copyright © 2010, Oracle. All rights reserved.