private ThreadContextDescriptor appendInflowContext() throws WorkCompletedException {
        ThreadContextDescriptor merged = threadContextDescriptor.clone();
        Set<String> inflowContext = new HashSet<String>();

        // WorkContext
        if (workContexts != null)
            for (WorkContext workContext : workContexts)
                if (workContext instanceof HintsContext) {
                    if (hintsContextSetupFailure != null)
                        throw contextSetupFailure(workContext, WorkContextErrorCodes.CONTEXT_SETUP_FAILED, hintsContextSetupFailure);
                } else {
                    JCAContextProvider provider = bootstrapContext.getJCAContextProvider(workContext.getClass());
                    if (provider == null)
                        throw contextSetupFailure(workContext, WorkContextErrorCodes.UNSUPPORTED_CONTEXT_TYPE, null);
                    else {
                        ThreadContext context;
                        try {
                            context = provider.getInflowContext(workContext, executionProperties);
                        } catch (Throwable x) {
                            throw contextSetupFailure(workContext, WorkContextErrorCodes.CONTEXT_SETUP_FAILED, x);
                        }
                        String workContextProviderName = bootstrapContext.getJCAContextProviderName(workContext.getClass());
                        if (!inflowContext.add(workContextProviderName))
                            throw contextSetupFailure(workContext, WorkContextErrorCodes.DUPLICATE_CONTEXTS, null);
                        merged.set(workContextProviderName, context);
                    }
                }

        // ExecutionContext
        if (executionContext != null)
            if (inflowContext.isEmpty() && (executionContext.getXid() != null || executionContext.getTransactionTimeout() != WorkManager.UNKNOWN)) {
                JCAContextProvider provider = bootstrapContext.getJCAContextProvider(TransactionContext.class);
                if (provider == null)
                    throw contextSetupFailure(executionContext, WorkContextErrorCodes.UNSUPPORTED_CONTEXT_TYPE, null);
                ThreadContext context;
                try {
                    context = provider.getInflowContext(executionContext, executionProperties);
                } catch (Throwable x) {
                    throw contextSetupFailure(executionContext, WorkContextErrorCodes.CONTEXT_SETUP_FAILED, x);
                }
                String executionContextHandlerName = bootstrapContext.getJCAContextProviderName(TransactionContext.class);
                merged.set(executionContextHandlerName, context);
            } // else - already checked for this error condition earlier

        return merged;
    }
private ThreadContextDescriptor appendInflowContext ( ) throws WorkCompletedException { ThreadContextDescriptor merged = threadContextDescriptor . clone ( ) ; Set < String > inflowContext = new HashSet < String > ( ) ; if ( workContexts != null ) for ( WorkContext workContext : workContexts ) if ( workContext instanceof HintsContext ) { if ( hintsContextSetupFailure != null ) throw contextSetupFailure ( workContext , WorkContextErrorCodes . CONTEXT_SETUP_FAILED , hintsContextSetupFailure ) ; } else { JCAContextProvider provider = bootstrapContext . getJCAContextProvider ( workContext . getClass ( ) ) ; if ( provider == null ) throw contextSetupFailure ( workContext , WorkContextErrorCodes . UNSUPPORTED_CONTEXT_TYPE , null ) ; else { ThreadContext context ; try { context = provider . getInflowContext ( workContext , executionProperties ) ; } catch ( Throwable x ) { throw contextSetupFailure ( workContext , WorkContextErrorCodes . CONTEXT_SETUP_FAILED , x ) ; } String workContextProviderName = bootstrapContext . getJCAContextProviderName ( workContext . getClass ( ) ) ; if ( ! inflowContext . add ( workContextProviderName ) ) throw contextSetupFailure ( workContext , WorkContextErrorCodes . DUPLICATE_CONTEXTS , null ) ; merged . set ( workContextProviderName , context ) ; } } if ( executionContext != null ) if ( inflowContext . isEmpty ( ) && ( executionContext . getXid ( ) != null || executionContext . getTransactionTimeout ( ) != WorkManager . UNKNOWN ) ) { JCAContextProvider provider = bootstrapContext . getJCAContextProvider ( TransactionContext . class ) ; if ( provider == null ) throw contextSetupFailure ( executionContext , WorkContextErrorCodes . UNSUPPORTED_CONTEXT_TYPE , null ) ; ThreadContext context ; try { context = provider . getInflowContext ( executionContext , executionProperties ) ; } catch ( Throwable x ) { throw contextSetupFailure ( executionContext , WorkContextErrorCodes . CONTEXT_SETUP_FAILED , x ) ; } String executionContextHandlerName = bootstrapContext . getJCAContextProviderName ( TransactionContext . class ) ; merged . set ( executionContextHandlerName , context ) ; } return merged ; }
Append work inflow context to the captured thread context.

@return merged list of captured thread context and work inflow context.
@throws WorkCompletedException if work context is unacceptable.