* @param context
*/
static JavaObjectValue createSession( XQueryContext context, Function fn ) throws XPathException
{
JavaObjectValue ret = null;
final RequestModule myModule = (RequestModule)context.getModule( RequestModule.NAMESPACE_URI );
// request object is read from global variable $request
final Variable var = myModule.resolveVariable( RequestModule.REQUEST_VAR );
if( var == null || var.getValue() == null ) {
throw( new XPathException( fn, "No request object found in the current XQuery context." ) );
}
if( var.getValue().getItemType() != Type.JAVA_OBJECT ) {
throw( new XPathException( fn, "Variable $request is not bound to an Java object." ) );
}
final JavaObjectValue value = (JavaObjectValue)var.getValue().itemAt( 0 );
if( value.getObject() instanceof RequestWrapper ) {
final SessionModule sessionModule = (SessionModule)context.getModule( SessionModule.NAMESPACE_URI );
final SessionWrapper session = ((RequestWrapper)value.getObject()).getSession( true );
sessionModule.declareVariable( SessionModule.SESSION_VAR, session );
ret = (JavaObjectValue)sessionModule.resolveVariable( SessionModule.SESSION_VAR ).getValue().itemAt( 0 );
} else {
throw( new XPathException( fn, "Variable $request is not bound to a Request object." ) );