public static Context begin(final String _user,
                                final Locale _locale,
                                final Map<String, Object> _sessionAttributes,
                                final Map<String, String[]> _parameters,
                                final Map<String, FileParameter> _fileParameters,
                                final Inheritance _inheritance)
        throws EFapsException
    {
        if (Inheritance.Inheritable.equals(_inheritance)  && Context.INHERITTHREADCONTEXT.get() != null
                        || Inheritance.Local.equals(_inheritance)  && Context.THREADCONTEXT.get() != null) {
            throw new EFapsException(Context.class, "begin.Context4ThreadAlreadSet");
        }
        try {
            // the timeout set is reseted on creation of a new Current object in
            // the transaction manager,
            // so if the default must be overwritten it must be set explicitly
            // again
            if (Context.TRANSMANAGTIMEOUT > 0) {
                Context.TRANSMANAG.setTransactionTimeout(Context.TRANSMANAGTIMEOUT);
            }
            Context.TRANSMANAG.begin();
        } catch (final SystemException e) {
            throw new EFapsException(Context.class, "begin.beginSystemException", e);
        } catch (final NotSupportedException e) {
            throw new EFapsException(Context.class, "begin.beginNotSupportedException", e);
        }
        final Transaction transaction;
        try {
            transaction = Context.TRANSMANAG.getTransaction();
        } catch (final SystemException e) {
            throw new EFapsException(Context.class, "begin.getTransactionSystemException", e);
        }
        final Context context = new Context(transaction, _locale, _sessionAttributes, _parameters,
                        _fileParameters, Inheritance.Inheritable.equals(_inheritance));
        switch (_inheritance) {
            case Inheritable:
                Context.INHERITTHREADCONTEXT.set(context);
                break;
            case Local:
                Context.THREADCONTEXT.set(context);
                break;
            case Standalone:
                Context.THREADCONTEXT.set(context);
                Context.INHERITTHREADCONTEXT.set(context);
                break;
            default:
                break;
        }

        if (_user != null) {
            context.person = UUIDUtil.isUUID(_user) ? Person.get(UUID.fromString(_user)) : Person.get(_user);
            MDC.put("person", String.format("'%s' (%s %s)", context.person.getName(),
                            context.person.getFirstName(), context.person.getLastName()));
            context.locale = context.person.getLocale();
            context.timezone = context.person.getTimeZone();
            context.chronology = context.person.getChronology();
            context.language = context.person.getLanguage();
            if (_sessionAttributes != null) {
                if (context.containsUserAttribute(Context.CURRENTCOMPANY)) {
                    final Company comp = Company.get(Long.parseLong(context.getUserAttribute(Context.CURRENTCOMPANY)));
                    if (comp != null && !context.person.getCompanies().isEmpty() && context.person.isAssigned(comp)) {
                        context.companyId = comp.getId();
                    } else {
                        context.setUserAttribute(Context.CURRENTCOMPANY, "0");
                    }
                }
                // if no current company is set in the UserAttributes, the first one found is set
                if (context.companyId == null && context.person.getCompanies().size() > 0) {
                    final Long compID = context.person.getCompanies().iterator().next();
                    context.setUserAttribute(Context.CURRENTCOMPANY, compID.toString());
                    context.companyId = compID;
                }
            }
        }
        return context;
    }
public static Context begin ( final String _user , final Locale _locale , final Map < String , Object > _sessionAttributes , final Map < String , String [ ] > _parameters , final Map < String , FileParameter > _fileParameters , final Inheritance _inheritance ) throws EFapsException { if ( Inheritance . Inheritable . equals ( _inheritance ) && Context . INHERITTHREADCONTEXT . get ( ) != null || Inheritance . Local . equals ( _inheritance ) && Context . THREADCONTEXT . get ( ) != null ) { throw new EFapsException ( Context . class , "begin.Context4ThreadAlreadSet" ) ; } try { if ( Context . TRANSMANAGTIMEOUT > 0 ) { Context . TRANSMANAG . setTransactionTimeout ( Context . TRANSMANAGTIMEOUT ) ; } Context . TRANSMANAG . begin ( ) ; } catch ( final SystemException e ) { throw new EFapsException ( Context . class , "begin.beginSystemException" , e ) ; } catch ( final NotSupportedException e ) { throw new EFapsException ( Context . class , "begin.beginNotSupportedException" , e ) ; } final Transaction transaction ; try { transaction = Context . TRANSMANAG . getTransaction ( ) ; } catch ( final SystemException e ) { throw new EFapsException ( Context . class , "begin.getTransactionSystemException" , e ) ; } final Context context = new Context ( transaction , _locale , _sessionAttributes , _parameters , _fileParameters , Inheritance . Inheritable . equals ( _inheritance ) ) ; switch ( _inheritance ) { case Inheritable : Context . INHERITTHREADCONTEXT . set ( context ) ; break ; case Local : Context . THREADCONTEXT . set ( context ) ; break ; case Standalone : Context . THREADCONTEXT . set ( context ) ; Context . INHERITTHREADCONTEXT . set ( context ) ; break ; default : break ; } if ( _user != null ) { context . person = UUIDUtil . isUUID ( _user ) ? Person . get ( UUID . fromString ( _user ) ) : Person . get ( _user ) ; MDC . put ( "person" , String . format ( "'%s' (%s %s)" , context . person . getName ( ) , context . person . getFirstName ( ) , context . person . getLastName ( ) ) ) ; context . locale = context . person . getLocale ( ) ; context . timezone = context . person . getTimeZone ( ) ; context . chronology = context . person . getChronology ( ) ; context . language = context . person . getLanguage ( ) ; if ( _sessionAttributes != null ) { if ( context . containsUserAttribute ( Context . CURRENTCOMPANY ) ) { final Company comp = Company . get ( Long . parseLong ( context . getUserAttribute ( Context . CURRENTCOMPANY ) ) ) ; if ( comp != null && ! context . person . getCompanies ( ) . isEmpty ( ) && context . person . isAssigned ( comp ) ) { context . companyId = comp . getId ( ) ; } else { context . setUserAttribute ( Context . CURRENTCOMPANY , "0" ) ; } } if ( context . companyId == null && context . person . getCompanies ( ) . size ( ) > 0 ) { final Long compID = context . person . getCompanies ( ) . iterator ( ) . next ( ) ; context . setUserAttribute ( Context . CURRENTCOMPANY , compID . toString ( ) ) ; context . companyId = compID ; } } } return context ; }
For current thread a new context object must be created.

@param _user                 name or UIID of current user to set
@param _locale               locale instance (which language settings has the user)
@param _sessionAttributes    attributes for this session
@param _parameters           map with parameters for this thread context
@param _fileParameters       map with file parameters
@param _inheritance the inheritance
@return new context of thread
@throws EFapsException if a new transaction could not be started or if
current thread context is already set
@see #INHERITTHREADCONTEXT