-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
283 additions
and
19 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/robotlegs/bender/extensions/payloadEvents/api/ExecutionReflectorError.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//------------------------------------------------------------------------------ | ||
// Copyright (c) 2009-2013 the original author or authors. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
//------------------------------------------------------------------------------ | ||
|
||
package robotlegs.bender.extensions.payloadEvents.api | ||
{ | ||
|
||
public class ExecutionReflectorError extends Error | ||
{ | ||
|
||
/*============================================================================*/ | ||
/* Constructor */ | ||
/*============================================================================*/ | ||
|
||
public function ExecutionReflectorError(message:* = "", id:* = 0) | ||
{ | ||
super(message, id); | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/robotlegs/bender/extensions/payloadEvents/impl/PayloadEventCommandMapper.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
//------------------------------------------------------------------------------ | ||
// Copyright (c) 2009-2013 the original author or authors. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
//------------------------------------------------------------------------------ | ||
|
||
package robotlegs.bender.extensions.payloadEvents.impl | ||
{ | ||
import robotlegs.bender.extensions.commandCenter.api.ICommandMapping; | ||
import robotlegs.bender.extensions.commandCenter.api.ICommandMappingList; | ||
import robotlegs.bender.extensions.commandCenter.dsl.ICommandConfigurator; | ||
import robotlegs.bender.extensions.commandCenter.dsl.ICommandMapper; | ||
import robotlegs.bender.extensions.commandCenter.dsl.ICommandUnmapper; | ||
import robotlegs.bender.extensions.commandCenter.impl.CommandMapping; | ||
import robotlegs.bender.extensions.payloadEvents.impl.execution.ExecutionReflector; | ||
|
||
public class PayloadEventCommandMapper implements ICommandMapper, ICommandUnmapper, ICommandConfigurator | ||
{ | ||
|
||
/*============================================================================*/ | ||
/* Private Properties */ | ||
/*============================================================================*/ | ||
|
||
private var _mappings:ICommandMappingList; | ||
|
||
private var _mapping:ICommandMapping; | ||
|
||
private var _executeReflector:ExecutionReflector; | ||
|
||
/*============================================================================*/ | ||
/* Constructor */ | ||
/*============================================================================*/ | ||
|
||
public function PayloadEventCommandMapper(mappings : ICommandMappingList) | ||
{ | ||
_mappings = mappings; | ||
_executeReflector = new ExecutionReflector(); | ||
} | ||
|
||
/*============================================================================*/ | ||
/* Public Functions */ | ||
/*============================================================================*/ | ||
|
||
public function toCommand(commandClass:Class):ICommandConfigurator | ||
{ | ||
_mapping = new CommandMapping(commandClass); | ||
const executeMethod:String = _executeReflector.describeExecutionMethodForClass(commandClass); | ||
executeMethod && _mapping.setExecuteMethod(executeMethod); | ||
_mappings.addMapping(_mapping); | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function fromCommand(commandClass:Class):void | ||
{ | ||
_mappings.removeMappingFor(commandClass); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function fromAll():void | ||
{ | ||
_mappings.removeAllMappings(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function once(value:Boolean = true):ICommandConfigurator | ||
{ | ||
_mapping.setFireOnce(value); | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function withGuards(... guards):ICommandConfigurator | ||
{ | ||
_mapping.addGuards.apply(null, guards); | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function withHooks(... hooks):ICommandConfigurator | ||
{ | ||
_mapping.addHooks.apply(null, hooks); | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function withExecuteMethod(name:String):ICommandConfigurator | ||
{ | ||
_mapping.setExecuteMethod(name); | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function withPayloadInjection(value:Boolean = true):ICommandConfigurator | ||
{ | ||
_mapping.setPayloadInjectionEnabled(value); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/robotlegs/bender/extensions/payloadEvents/impl/execution/ExecutionReflector.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//------------------------------------------------------------------------------ | ||
// Copyright (c) 2009-2013 the original author or authors. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
//------------------------------------------------------------------------------ | ||
|
||
package robotlegs.bender.extensions.payloadEvents.impl.execution | ||
{ | ||
import flash.utils.describeType; | ||
|
||
import robotlegs.bender.extensions.payloadEvents.api.ExecutionReflectorError; | ||
|
||
public class ExecutionReflector | ||
{ | ||
|
||
/*============================================================================*/ | ||
/* Public Functions */ | ||
/*============================================================================*/ | ||
|
||
public function describeExecutionMethodForClass(type:Class):String | ||
{ | ||
var factoryDescription:XML = describeType(type).factory[0]; | ||
var list:XMLList = factoryDescription.method.metadata.(@name == 'Execute'); | ||
switch (list.length()) | ||
{ | ||
case 1: | ||
var memberDescription:XML = list[0].parent(); | ||
return memberDescription.attribute('name'); | ||
case 0: | ||
return null; | ||
default: | ||
throw new ExecutionReflectorError('Only one Execute-tagged method allowed'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/robotlegs/bender/extensions/payloadEvents/impl/execution/ExecutionReflectorTest.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package robotlegs.bender.extensions.payloadEvents.impl.execution | ||
{ | ||
import org.hamcrest.assertThat; | ||
import org.hamcrest.object.equalTo; | ||
import org.hamcrest.object.nullValue; | ||
|
||
import robotlegs.bender.extensions.payloadEvents.support.ExecuteTaggedCommand; | ||
import robotlegs.bender.extensions.payloadEvents.support.MultipleExecuteTaggedMethodsCommand; | ||
|
||
public class ExecutionReflectorTest{ | ||
private var subject : ExecutionReflector; | ||
|
||
[Before] | ||
public function setup() : void{ | ||
subject = new ExecutionReflector(); | ||
} | ||
|
||
[Test] | ||
public function describes_execution_method_as_null_when_tag_not_found() : void{ | ||
assertThat(subject.describeExecutionMethodForClass(Class),nullValue()); | ||
} | ||
|
||
[Test] | ||
public function desscribes_execution_method_when_tag_found() : void{ | ||
assertThat(subject.describeExecutionMethodForClass(ExecuteTaggedCommand),equalTo('executeTaggedMethod')); | ||
} | ||
[Test(expects="robotlegs.bender.extensions.payloadEvents.api.ExecutionReflectorError")] | ||
public function error_is_thrown_when_multiple_execute_tags_found() : void{ | ||
subject.describeExecutionMethodForClass(MultipleExecuteTaggedMethodsCommand); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/robotlegs/bender/extensions/payloadEvents/support/ExecuteTaggedCommand.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//------------------------------------------------------------------------------ | ||
// Copyright (c) 2009-2013 the original author or authors. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
//------------------------------------------------------------------------------ | ||
|
||
package robotlegs.bender.extensions.payloadEvents.support | ||
{ | ||
|
||
public class ExecuteTaggedCommand | ||
{ | ||
|
||
/*============================================================================*/ | ||
/* Public Functions */ | ||
/*============================================================================*/ | ||
|
||
[Execute] | ||
public function executeTaggedMethod():void | ||
{ | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.