private static Binding buildBinding ( UrlLepResourceKey scriptResourceKey , LepManagerService managerService , LepMethod method , ProceedingLep proceedingLep , LepMethodResult lepMethodResult , Object ... overrodeArgValues ) { boolean isOverrodeArgs = overrodeArgValues != null && overrodeArgValues . length > 0 ; if ( isOverrodeArgs ) { int actual = overrodeArgValues . length ; int expected = method . getMethodSignature ( ) . getParameterTypes ( ) . length ; if ( actual != expected ) { throw new IllegalArgumentException ( "When calling LEP resource: " + scriptResourceKey + ", overrode method argument values " + "count doesn't corresponds method signature (expected: " + expected + ", actual: " + actual + ")" ) ; } } Map < String , Object > lepContext = new LinkedHashMap <> ( ) ; Binding binding = new Binding ( ) ; // add execution context values ScopedContext executionContext = managerService . getContext ( ContextScopes . EXECUTION ) ; if ( executionContext != null ) { executionContext . getValues ( ) . forEach ( lepContext :: put ) ; } // add method arg values final String [ ] parameterNames = method . getMethodSignature ( ) . getParameterNames ( ) ; final Object [ ] methodArgValues = isOverrodeArgs ? overrodeArgValues : method . getMethodArgValues ( ) ; Map < String , Object > inVars = new LinkedHashMap <> ( parameterNames . length ) ; for ( int i = 0 ; i < parameterNames . length ; i ++ ) { String paramName = parameterNames [ i ] ; Object paramValue = methodArgValues [ i ] ; inVars . put ( paramName , paramValue ) ; } lepContext . put ( XmLepScriptConstants . BINDING_KEY_IN_ARGS , inVars ) ; // add proceedingLep support lepContext . put ( XmLepScriptConstants . BINDING_KEY_LEP , proceedingLep ) ; // add returned value if ( lepMethodResult != null ) { lepContext . put ( XmLepScriptConstants . BINDING_KEY_RETURNED_VALUE , lepMethodResult . getReturnedValue ( ) ) ; } // add method result lepContext . put ( XmLepScriptConstants . BINDING_KEY_METHOD_RESULT , lepMethodResult ) ; binding . setVariable ( XmLepScriptConstants . BINDING_VAR_LEP_SCRIPT_CONTEXT , lepContext ) ; return binding ; }
Build scripts bindings .