import { injectable , inject } from "inversify" ; import { IContext } from "../../../framework/api/IContext" ; import { IInjector } from "../../../framework/api/IInjector" ; import { IClass } from "../../matching/IClass" ; import { CommandPayload } from "../../commandCenter/api/CommandPayload" ; import { ICommand } from "../../commandCenter/api/ICommand" ; import { ICommandExecutor } from "../../commandCenter/api/ICommandExecutor" ; import { CommandExecutor } from "../../commandCenter/impl/CommandExecutor" ; import { CommandMappingList } from "../../commandCenter/impl/CommandMappingList" ; import { NullCommandTrigger } from "../../commandCenter/impl/NullCommandTrigger" ; import { IDirectCommandMap } from "../api/IDirectCommandMap" ; import { IDirectCommandConfigurator } from "../dsl/IDirectCommandConfigurator" ; import { DirectCommandMapper } from "./DirectCommandMapper" ; /**
 * Maps commands for direct (manual) execution
 */ @ injectable ( ) export class DirectCommandMap implements IDirectCommandMap { private _mappingProcessors : any [ ] = [ ] ; private _context : IContext ; private _executor : ICommandExecutor ; private _mappings : CommandMappingList ; param context constructor ( @ inject ( IContext ) context ) { this . _context = context ; let sandboxedInjector = context . injector . createChild ( ) ; sandboxedInjector . bind ( IDirectCommandMap ) . toConstantValue ( this ) ; this . _mappings = new CommandMappingList ( new NullCommandTrigger ( ) , this . _mappingProcessors , context . getLogger ( this ) ) ; this . _executor = new CommandExecutor ( sandboxedInjector , this . _mappings . removeMapping . bind ( this . _mappings ) ) ; } inheritDoc public map ( commandClass ) { return new DirectCommandMapper ( this . _executor , this . _mappings , commandClass ) ; } inheritDoc public detain ( command ) { this . _context . detain ( command ) ; } inheritDoc public release ( command ) { this . _context . release ( command ) ; } inheritDoc public execute ( payload ? ) { this . _executor . executeCommands ( this . _mappings . getList ( ) , payload ) ; } inheritDoc public addMappingProcessor ( handler ) { if ( this . _mappingProcessors . indexOf ( handler ) === - 1 ) { this . _mappingProcessors . push ( handler ) ; } return this ; } }