Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class DataLoadingCommandLookup implements IDataLoadingCommandLookup {
  2.  
  3. private var _commandsByDataType:Dictionary;
  4.  
  5. public function DataLoadingCommandLookup() {
  6. }
  7.  
  8. //---------------------------------------
  9. // IDataLoadingCommandLookup Implementation
  10. //---------------------------------------
  11.  
  12. public function mapCommandToClass(commandClazz:Class, dataClazz:Class):void
  13. {
  14. if(commandsByDataType[dataClazz] != null)
  15. {
  16. throw(new IllegalOperationError('Ambiguous mapping: This data class has already been mapped to a command class.'));
  17. }
  18.  
  19. if(isNotACommand(commandClazz))
  20. {
  21. throw(new IllegalOperationError('The command class you passed is missing an execute method.'));
  22. }
  23.  
  24. commandsByDataType[dataClazz] = commandClazz;
  25. }
  26.  
  27. public function getCommandForClass(dataClazz:Class):Class
  28. {
  29. return commandsByDataType[dataClazz];
  30. }
  31.  
  32.  
  33. private function get commandsByDataType():Dictionary
  34. {
  35. return _commandsByDataType || (_commandsByDataType = new Dictionary());
  36. }
  37.  
  38. private function isNotACommand(commandClazz:Class):Boolean
  39. {
  40. if(describeType(commandClazz).factory.method.(@name == "execute").length() > 0)
  41. {
  42. return false;
  43. }
  44.  
  45. return true;
  46. }
  47.  
  48. }
Add Comment
Please, Sign In to add comment