Changeset 33
- Timestamp:
- 08/16/08 07:57:59 (5 months ago)
- Files:
-
- project/trunk/src/pyxoo/command.py (modified) (63 diffs)
- project/trunk/src/pyxoo/core.py (modified) (39 diffs)
- project/trunk/src/pyxoo/event.py (modified) (37 diffs)
- project/trunk/src/pyxoo/model.py (modified) (6 diffs)
- project/trunk/src/pyxoo/plugin.py (modified) (1 diff)
- project/trunk/src/pyxoo/service.py (deleted)
- project/trunk/src/pyxoo/utils/__init__.py (modified) (1 diff)
- project/trunk/src/pyxoo/utils/interface.py (deleted)
- project/trunk/src/pyxoo/utils/map.py (deleted)
- project/trunk/src/pyxoo/utils/stringifier.py (modified) (1 diff)
- project/trunk/src/pyxoo/utils/type.py (modified) (1 diff)
- project/trunk/src/pyxoo/view.py (modified) (1 diff)
- project/trunk/test/commands/TestBatch.py (modified) (1 diff)
- project/trunk/test/commands/TestDelegate.py (modified) (1 diff)
- project/trunk/test/commands/TestFrontController.py (modified) (2 diffs)
- project/trunk/test/core/TestMethodAccessor.py (modified) (1 diff)
- project/trunk/test/core/TestPropertyAccessor.py (modified) (1 diff)
- project/trunk/test/events/TestApplicationBroadcaster.py (modified) (2 diffs)
- project/trunk/test/events/TestChannelBroadcaster.py (modified) (1 diff)
- project/trunk/test/events/TestEventBroadcaster.py (modified) (1 diff)
- project/trunk/test/events/TestTimer.py (modified) (1 diff)
- project/trunk/test/model/TestModelLocator.py (modified) (3 diffs)
- project/trunk/test/plugin/TestAbstractPlugin.py (modified) (4 diffs)
- project/trunk/test/plugin/TestChannelExpert.py (modified) (1 diff)
- project/trunk/test/plugin/TestNullPlugin.py (modified) (1 diff)
- project/trunk/test/plugin/TestPluginChannel.py (modified) (1 diff)
- project/trunk/test/utils/TestHashMap.py (deleted)
- project/trunk/test/utils/TestInterface.py (deleted)
- project/trunk/test/utils/TestType.py (modified) (2 diffs)
- project/trunk/test/view/TestAbstractView.py (modified) (1 diff)
- project/trunk/test/view/TestViewLocator.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
project/trunk/src/pyxoo/command.py
r29 r33 10 10 11 11 12 class Command ( pyxoo.utils.Interface ):12 class Command: 13 13 """Encapsulate a request as an object, thereby letting you parameterize 14 14 clients with different requests, queue or log requests, … … 23 23 """ 24 24 25 def execute( self, event=None):25 def execute(self, event=None): 26 26 """ 27 27 Execute the request according to the current command data. … … 38 38 39 39 40 class AbstractCommand( Command):40 class AbstractCommand(Command): 41 41 """AbstractCommand provides a skeleton for commands which 42 42 might work within plugin's FrontController. Abstract command … … 53 53 __owner = None 54 54 55 def execute( self, event=None):55 def execute(self, event=None): 56 56 """ 57 57 Override the execute virtual method … … 64 64 @raise pyxoo.exceptions.UnreachableDataException: Stateless command use the passed-in event as data source for its execution, so the event must provide the right data for the current Command object. 65 65 """ 66 raise NotImplementedError( "%s.execute() must be implemented in concrete class."%self)67 68 def get Owner( self):66 raise NotImplementedError("%s.execute() must be implemented in concrete class."%self) 67 68 def get_owner(self): 69 69 """ 70 70 Returns a reference to the owner of this command. … … 74 74 return self.__owner 75 75 76 def set Owner( self, owner):76 def set_owner(self, owner): 77 77 """ 78 78 Defines the plugin owner of this command. … … 84 84 @rtype: void 85 85 """ 86 if owner and not isinstance( owner, pyxoo.plugin.Plugin ):87 raise TypeError( "owner param must be a Plugin object" )88 86 self.__owner = owner 89 87 90 def get ModelLocator( self):88 def get_model_locator(self): 91 89 """ 92 90 Returns a reference to the owner ModelLocator. … … 96 94 @return: a reference to the owner model locator 97 95 """ 98 return self.get Owner().getModelLocator()99 100 def get ViewLocator( self):96 return self.get_owner().get_model_locator() 97 98 def get_view_locator(self): 101 99 """ 102 100 Returns a reference to the owner ViewLocator. … … 106 104 @return: a reference to the owner view locator 107 105 """ 108 return self.get Owner().getViewLocator()109 110 def _fire PrivateEvent( self, event):106 return self.get_owner().get_view_locator() 107 108 def _fire_private_event(self, event): 111 109 """ 112 110 Fires a private event directly on this command's owner. … … 114 112 @rtype: void 115 113 """ 116 self.get Owner().firePrivateEvent( event)117 118 def __str__( self):114 self.get_owner().fire_private_event(event) 115 116 def __str__(self): 119 117 """ 120 118 Returns the string representation of this instance. 121 119 @rtype: String 122 120 """ 123 return pyxoo.utils.PyxooStringifier.stringify( self)124 125 126 class MacroCommand( Command, pyxoo.utils.Interface):121 return pyxoo.utils.PyxooStringifier.stringify(self) 122 123 124 class MacroCommand(Command): 127 125 """A macro command wraps many commands execution in a single 128 126 execute call. The MacroCommand … … 142 140 interface to provide a feedback for its execution end. 143 141 """ 144 def add Command( self, command):142 def add_command(self, command): 145 143 """ 146 144 Adds the passed-in command to this macro command. … … 151 149 """ 152 150 153 def remove Command( self, command):151 def remove_command(self, command): 154 152 """ 155 153 Removes the passed-in command from this macro command. … … 161 159 162 160 163 164 class Batch( MacroCommand, AbstractCommand ): 161 class Batch(AbstractCommand, MacroCommand): 165 162 """Batch object encapsulate a set of Commands 166 163 to execute at the same time. … … 173 170 """ 174 171 175 def __init__( self):172 def __init__(self): 176 173 """ 177 174 Constructs a MacroCommand implementation. … … 179 176 self.__commands = list() 180 177 181 def add Command( self, command):178 def add_command(self, command): 182 179 """ 183 180 Adds a command in the batch stack. … … 194 191 """ 195 192 if command is None:return False 196 if isinstance( command, AbstractCommand ):command.setOwner( self.getOwner())197 self.__commands.append( command)193 if isinstance(command, AbstractCommand):command.set_owner(self.get_owner()) 194 self.__commands.append(command) 198 195 return True 199 196 200 def remove Command( self, command):197 def remove_command(self, command): 201 198 """ 202 199 Removes all references to the passed-in command. … … 210 207 """ 211 208 if command in self.__commands: 212 self.__commands.remove( command)209 self.__commands.remove(command) 213 210 return True 214 211 return False 215 212 216 def set Owner( self, owner):213 def set_owner(self, owner): 217 214 """ 218 215 Defines the plugin owner of this command. … … 224 221 @rtype: void 225 222 """ 226 AbstractCommand.set Owner( self, owner)223 AbstractCommand.set_owner(self, owner) 227 224 for command in self.__commands: 228 if isinstance( command, AbstractCommand ):command.setOwner( owner)229 230 def execute( self, event=None):225 if isinstance(command, AbstractCommand):command.set_owner(owner) 226 227 def execute(self, event=None): 231 228 """ 232 229 Executes the whole set of commands in the order they were … … 240 237 """ 241 238 for command in self.__commands: 242 command.execute( event)239 command.execute(event) 243 240 244 def contains( self, command):241 def contains(self, command): 245 242 """ 246 243 Returns true if the passed-in command is stored … … 253 250 return command in self.__commands 254 251 255 def remove All( self):252 def remove_all(self): 256 253 """ 257 254 Removes all commands. … … 261 258 self.__commands = list() 262 259 263 def size( self):260 def size(self): 264 261 """ 265 262 Returns the number of commands stored in this batch. … … 267 264 @rtype: Integer 268 265 """ 269 return len( self.__commands)270 271 272 class ReversedBatch( Batch):266 return len(self.__commands) 267 268 269 class ReversedBatch(Batch): 273 270 """ReversedBatch is a concrete implementation of MacroCommand interface but execution is reversed""" 274 def execute( self, event=None):271 def execute(self, event=None): 275 272 """ 276 273 Executes the whole set of commands in the reversed order … … 286 283 commands = self.getCommands() 287 284 while index > -1: 288 commands[index].execute( event)285 commands[index].execute(event) 289 286 index -= 1 290 287 291 288 292 289 293 class Delegate( Command):294 __logger = logging.getLogger( "pyxoo.command.Delegate")290 class Delegate(Command): 291 __logger = logging.getLogger("pyxoo.command.Delegate") 295 292 296 293 @classmethod 297 def create( cls, method, *args):294 def create(cls, method, *args): 298 295 """ 299 296 @param method: … … 303 300 @rtype: Function 304 301 """ 305 def function( *rest):302 def function(*rest): 306 303 try: 307 return apply( method, args+rest)308 except( TypeError):309 msg = str( cls) + " execution failed, you passed incorrect number of arguments or wrong type"310 cls.__logger.fatal( msg)311 raise TypeError( msg)304 return apply(method, args+rest) 305 except(TypeError): 306 msg = str(cls) + " execution failed, you passed incorrect number of arguments or wrong type" 307 cls.__logger.fatal(msg) 308 raise TypeError(msg) 312 309 return function 313 310 314 def __init__( self, function, *args):311 def __init__(self, function, *args): 315 312 """ 316 313 @param function: … … 320 317 """ 321 318 self.__function = function 322 self.__args = list( args)323 324 def get Arguments( self):319 self.__args = list(args) 320 321 def get_arguments(self): 325 322 """ 326 323 @return: … … 329 326 return self.__args 330 327 331 def set Arguments( self, *args):328 def set_arguments(self, *args): 332 329 """ 333 330 @param *args: … … 335 332 @rtype: void 336 333 """ 337 self.set ArgumentsArray( list( args ))338 339 def set ArgumentsArray( self, array):334 self.set_arguments_array(list(args)) 335 336 def set_arguments_array(self, array): 340 337 """ 341 338 @param array: … … 343 340 @rtype: void 344 341 """ 345 if not isinstance( array, list ): 346 raise TypeError( "array param must be a list." ) 347 if array.__len__() > 0: 342 if len(array) > 0: 348 343 self.__args = array 349 344 350 def add Arguments( self, *args):345 def add_arguments(self, *args): 351 346 """ 352 347 @param *args: … … 354 349 @rtype: void 355 350 """ 356 self.add ArgumentsArray( list( args ))351 self.add_arguments_array(list(args)) 357 352 358 def add ArgumentsArray( self, array):353 def add_arguments_array(self, array): 359 354 """ 360 355 @param array: … … 362 357 @rtype: void 363 358 """ 364 if not isinstance( array, list ): 365 raise TypeError( "array param must be a list." ) 366 if array.__len__() > 0: 359 if len(array) > 0: 367 360 self.__args += array 368 361 369 def execute( self, event=None):362 def execute(self, event=None): 370 363 """ 371 364 @param event: Can be None 372 @type event: pyxoo.event. IEvent365 @type event: pyxoo.event.Event 373 366 @rtype: void 374 367 """ 375 if event is not None and not isinstance( event, pyxoo.event.IEvent ):376 raise TypeError( "event param must be an instance of IEvent class." )377 368 args = list() 378 if event is not None:args.append( event)369 if event is not None:args.append(event) 379 370 try: 380 apply( self.__function, args+self.__args)381 except( TypeError):382 msg = str( self) + " execution failed, you passed incorrect number of arguments or wrong type"383 self.__logger.fatal( msg)384 raise TypeError( msg)385 386 def handle Event( self, event):371 apply(self.__function, args+self.__args) 372 except(TypeError): 373 msg = str(self) + " execution failed, you passed incorrect number of arguments or wrong type" 374 self.__logger.fatal(msg) 375 raise TypeError(msg) 376 377 def handle_event(self, event): 387 378 """ 388 379 @param event: 389 @type event: pyxoo.event. IEvent390 @rtype: void 391 """ 392 self.execute( event)393 394 def call Function( self):380 @type event: pyxoo.event.Event 381 @rtype: void 382 """ 383 self.execute(event) 384 385 def call_function(self): 395 386 """ 396 387 @rtype: Object 397 388 """ 398 return apply( self.__function, self.__args)399 400 def __str__( self):389 return apply(self.__function, self.__args) 390 391 def __str__(self): 401 392 """ 402 393 Returns the string representation of this instance. 403 394 @rtype: String 404 395 """ 405 return pyxoo.utils.PyxooStringifier.stringify( self ) 406 407 408 class ASyncCommandListener( pyxoo.utils.Interface ): 409 """ 410 Interface for objects which want to be notified of the end of execution 411 of an asynchronous command. 412 """ 413 def onCommandEnd( self, event ): 414 """ 415 Called when the command have completed its process. 416 @param event: event dispatched by the command 417 @type event: pyxoo.event.IEvent 418 @rtype: void 419 """ 420 421 422 class FrontController( pyxoo.core.AbstractLocator, ASyncCommandListener ): 396 return pyxoo.utils.PyxooStringifier.stringify(self) 397 398 399 class FrontController(pyxoo.core.AbstractLocator): 423 400 """ 424 401 A base class for an application specific front controller, … … 444 421 plugin's MVC components. 445 422 """ 446 __logger = logging.getLogger( "pyxoo.command.FrontController")447 448 def __init__( self, owner=None):423 __logger = logging.getLogger("pyxoo.command.FrontController") 424 425 def __init__(self, owner=None): 449 426 """ 450 427 Creates a new Front Controller instance for the passed-in … … 454 431 @type owner: pyxoo.plugin.Plugin 455 432 """ 456 pyxoo.core.AbstractLocator.__init__( self, None, None)433 pyxoo.core.AbstractLocator.__init__(self, None) 457 434 if owner: 458 if not isinstance( owner, pyxoo.plugin.Plugin ):459 raise TypeError( "owner param must be a Plugin instance" )460 435 self.__owner = owner 461 436 else: 462 self.__owner = pyxoo.plugin.NullPlugin .getInstance()463 pyxoo.event. EventBroadcaster.getInstance().addListener( self)464 self.__a SyncCommands = pyxoo.utils.HashMap()465 466 def get Owner( self):437 self.__owner = pyxoo.plugin.NullPlugin() 438 pyxoo.event.eventbroadcaster().add_listener(self) 439 self.__async_commands = dict() 440 441 def get_owner(self): 467 442 """ 468 443 Returns the owner plugin of this controller … … 472 447 return self.__owner 473 448 474 def register( self, eventName, object):449 def register(self, event_type, object): 475 450 try: 476 if pyxoo.utils.Type.isClass( object):477 self.push CommandClass( eventName, object)451 if pyxoo.utils.Type.isClass(object): 452 self.push_command_class(event_type, object) 478 453 else: 479 self.push CommandInstance( eventName, object)454 self.push_command_instance(event_type, object) 480 455 except Exception, e: 481 self.__logger.fatal( e.message)456 self.__logger.fatal(e.message) 482 457 raise e 483 458 484 def push CommandClass( self, eventName, commandClass):459 def push_command_class(self, event_type, command_class): 485 460 """ 486 461 Registers the passed-in command class to be triggered at each time … … 493 468 If there is already a command or a class associated with the passed-in event, 494 469 the association failed and an exception is throw. 495 @param event Name: name of the event type with which the command will be registered496 @param command Class: class to associate with the passed-in event type497 @type event Name: String498 @type command Class: Class470 @param event_type: name of the event type with which the command will be registered 471 @param command_class: class to associate with the passed-in event type 472 @type event_type: String 473 @type command_class: Class 499 474 @return: true if the command class have been succesfully registered with the passed-in event type 500 475 @rtype: Boolean 501 476 @raise IllegalArgumentException: There is already a command or class registered with the specified key. 502 """ 503 if not pyxoo.utils.Type.isString( eventName ): 504 raise TypeError( "eventName param must be a String value" ) 505 if not issubclass( commandClass, Command ): 506 msg = "The class '%s' doesn't inherit from Command interface in %s"%( commandClass, self ) 507 self.__logger.fatal( msg ) 508 raise TypeError( msg ) 509 510 if self.isRegistered( eventName ): 511 msg = "There is already a command class registered with '%s' name in %s"%( eventName, self ); 512 self.__logger.fatal( msg ) 513 raise pyxoo.exceptions.IllegalArgumentException( msg ) 477 """ 478 if self.is_registered(event_type): 479 msg = "There is already a command class registered with '%s' name in %s"%(event_type, self); 480 self.__logger.fatal(msg) 481 raise pyxoo.exceptions.IllegalArgumentException(msg) 514 482 else: 515 self._elements .put( eventName, commandClass )516 517 def push CommandInstance( self, eventName, command):483 self._elements[event_type] = command_class 484 485 def push_command_instance(self, event_type, command): 518 486 """ 519 487 Registers the passed-in command to be triggered at each time … … 522 490 If there is already a class or a command associated with the passed-in 523 491 event, the association failed and an exception is throw. 524 @param event Name: name of the event type with which the command will be registered492 @param event_type: name of the event type with which the command will be registered 525 493 @param command: command to associate with the passed-in event type 526 @type event Name: String494 @type event_type: String 527 495 @type command: Command 528 496 @return: true if the command have been succesfully registered with the passed-in event type … … 530 498 @raise IllegalArgumentException: There is already a command or class registered with the specified key. 531 499 """ 532 if not pyxoo.utils.Type.isString( eventName ): 533 raise TypeError( "eventName param must be a String value" ) 534 if not isinstance( command, Command ): 535 raise TypeError( "command param msut be a Command instance." ) 536 if self.isRegistered( eventName ): 537 msg = "There is already a command class registered with '%s' name in %s"%( eventName, self ); 538 self.__logger.fatal( msg ) 539 raise pyxoo.exceptions.IllegalArgumentException( msg ) 500 if self.is_registered(event_type): 501 msg = "There is already a command class registered with '%s' name in %s"%(event_type, self); 502 self.__logger.fatal(msg) 503 raise pyxoo.exceptions.IllegalArgumentException(msg) 540 504 else: 541 self._elements .put( eventName, command )505 self._elements[event_type] = command 542 506 543 def remove( self, eventName):507 def remove(self, event_type): 544 508 """ 545 509 Removes the class or the command registered with the … … 549 513 @rtype: void 550 514 """ 551 self._elements.remove( eventName )552 553 def handle Event( self, event):515 del self._elements[event_type] 516 517 def handle_event(self, event): 554 518 """ 555 519 Handles all events received by this object. … … 569 533 @rtype: void 570 534 """ 571 if not isinstance( event, pyxoo.event.IEvent ): 572 raise TypeError( "event param must an IEvent instance" ) 573 type = event.getType() 535 type = event.type 574 536 command = None 575 537 try: 576 command = self.locate( type)538 command = self.locate(type) 577 539 except Exception, e: 578 self.__logger.debug( "%s.handleEvent() fails to retrieve command associated with '%s' event type."%( self, type ))540 self.__logger.debug("%s.handleEvent() fails to retrieve command associated with '%s' event type."%(self, type)) 579 541 if command: 580 if isinstance( command, ASyncCommand):581 self.__a SyncCommands.put( command, True )582 command.addASyncCommandListener( self)583 command.execute( event)542 if isinstance(command, ASyncCommand): 543 self.__async_commands[command] = True 544 command.addASyncCommandListener(self) 545 command.execute(event) 584 546 585 def onCommandEnd( self, event):547 def onCommandEnd(self, event): 586 548 """ 587 549 Catch callback events from asynchronous commands thiggered … … 593 555 @rtype: void 594 556 """ 595 if not isinstance( event, pyxoo.event.IEvent ): 596 raise TypeError( "event param must an IEvent instance" ) 597 self.__aSyncCommands.remove( event.getTarget() ) 598 599 def locate( self, key ): 557 del self.__async_commands[event.target] 558 559 def locate(self, key): 600 560 """ 601 561 Returns the command located at the specified key … … 613 573 """ 614 574 try: 615 object = pyxoo.core.AbstractLocator.locate( self, key)575 object = pyxoo.core.AbstractLocator.locate(self, key) 616 576 except Exception, e: 617 msg = "Can't find Command instance with '%s' name in %s"%( key, self)618 self.__logger.fatal( msg)619 raise pyxoo.exceptions.NoSuchElementException( msg)620 if isinstance( object, Command):577 msg = "Can't find Command instance with '%s' name in %s"%(key, self) 578 self.__logger.fatal(msg) 579 raise pyxoo.exceptions.NoSuchElementException(msg) 580 if isinstance(object, Command): 621 581 command = object 622 582 else: 623 583 command = object() 624 if isinstance( command, AbstractCommand):584 if isinstance(command, AbstractCommand): 625 585 if not command.getOwner(): 626 command.setOwner( self.getOwner())586 command.setOwner(self.getOwner()) 627 587 return command 628 588 629 def add( self, dictionnary):589 def add(self, dictionnary): 630 590 """ 631 591 Adds all key/commands associations within the passed-in … … 644 604 try: 645 605 if command is None: 646 raise pyxoo.exceptions.NullPointerException( "Command associated to '%s' is None"%(name))647 if issubclass( command, Command):648 self.pushCommandClass( name, command)606 raise pyxoo.exceptions.NullPointerException("Command associated to '%s' is None"%(name)) 607 if issubclass(command, Command): 608 self.pushCommandClass(name, command) 649 609 else: 650 self.pushCommandInstance( name, command)610 self.pushCommandInstance(name, command) 651 611 except Exception, e: 652 e.message = "%s.add() fails. %s"( self, e.message)653 self.__logger.error( msg)612 e.message = "%s.add() fails. %s"(self, e.message) 613 self.__logger.error(msg) 654 614 raise e 655 615 … … 657 617 658 618 659 class Runnable ( pyxoo.utils.Interface ):619 class Runnable: 660 620 """ 661 621 The Runnable interface should be implemented by any … … 692 652 extends the Runnable interface to define process ending rules. 693 653 """ 694 def run( self):654 def run(self): 695 655 """ 696 656 Starts the asynchronous process of this runnable object. … … 703 663 """ 704 664 705 def isRunning( self):665 def isRunning(self): 706 666 """ 707 667 Returns true if this object is running. … … 711 671 712 672 713 class Suspendable( Runnable, pyxoo.utils.Interface):673 class Suspendable(Runnable): 714 674 """ 715 675 Suspendable defines rules for Runnable … … 734 694 and Cancelable interfaces. 735 695 """ 736 def start( self):696 def start(self): 737 697 """ 738 698 Starts the operation of this suspendable operation. … … 743 703 """ 744 704 745 def stop( self):705 def stop(self): 746 706 """ 747 707 Stops the operation in process. If a call to the … … 751 711 """ 752 712 753 def reset( self):713 def reset(self): 754 714 """ 755 715 Resets the state of this object. The state of an operation … … 761 721 """ 762 722 763 class Cancelable( Runnable, pyxoo.utils.Interface):723 class Cancelable(Runnable): 764 724 """ 765 725 Cancelable defines rules for Runnable … … 780 740 """ 781 741 782 def cancel( self):742 def cancel(self): 783 743 """ 784 744 Attempts to cancel execution of this task. … … 796 756 """ 797 757 798 def isCancelled( self):758 def isCancelled(self): 799 759 """ 800 760 Returns true if the operation have been stopped … … 804 764 """ 805 765 806 class ASyncCommand( Command, Runnable, pyxoo.utils.Interface):766 class ASyncCommand(Command, Runnable): 807 767 """ 808 768 An asynchronous command is a runnable command, which is not terminated … … 813 773 command dispatch an onCommandEnd event at the end of its process. 814 774 """ 815 def addASyncCommandListener( self, listener, *args):775 def addASyncCommandListener(self, listener, *args): 816 776 """ 817 777 Adds the passed-in command listener object as listener … … 828 788 """ 829 789 830 def removeASyncCommandListener( self, listener):790 def removeASyncCommandListener(self, listener): 831 791 """ 832 792 Removes the passed-in command listener object as listener … … 838 798 """ 839 799 840 def fireCommandEndEvent( self):800 def fireCommandEndEvent(self): 841 801 """ 842 802 Fires the onCommandEnd event to the listeners of this command. … … 847 807 848 808 849 class AbstractSyncCommand( AbstractCommand, ASyncCommand):809 class AbstractSyncCommand(AbstractCommand, ASyncCommand): 850 810 """ 851 811 AbstractSyncCommand provides a skeleton to create … … 867 827 onCommandEndEVENT = "onCommandEnd" 868 828 869 def __init__( self):829 def __init__(self): 870 830 """ 871 831 Initializes event dispatching behavior and Runnable implementation 872 832 """ 873 833 self.__isRunning = False 874 self.__eventBroadcaster = pyxoo.event.EventBroadcaster( self)875 self.__onCommandEnd = pyxoo.event.BasicEvent( AbstractSyncCommand.onCommandEndEVENT, self)876 877 def addASyncCommandListener( self, listener, *args):834 self.__eventBroadcaster = pyxoo.event.EventBroadcaster(self) 835 self.__onCommandEnd = pyxoo.event.BasicEvent(AbstractSyncCommand.onCommandEndEVENT, self) 836 837 def addASyncCommandListener(self, listener, *args): 878 838 """ 879 839 Adds the passed-in listener as listener for the onCommandEnd event of this command. … … 884 844 @rtype: Boolean 885 845 """ 886 if not isinstance( listener, ASyncCommandListener):887 raise TypeError( "listener param must be an ASyncCommandListener instance")888 return self.__eventBroadcaster.addEventListener( AbstractSyncCommand.onCommandEndEVENT, listener, *args)889 890 def removeASyncCommandListener( self, listener):846 if not isinstance(listener, ASyncCommandListener): 847 raise TypeError("listener param must be an ASyncCommandListener instance") 848 return self.__eventBroadcaster.addEventListener(AbstractSyncCommand.onCommandEndEVENT, listener, *args) 849 850 def removeASyncCommandListener(self, listener): 891 851 """ 892 852 Removes the passed-in listener for listening … … 896 856 @rtype: Boolean 897 857 """ 898 if not isinstance( listener, ASyncCommandListener):899 raise TypeError( "listener param must be an ASyncCommandListener instance")900 return self.__eventBroadcaster.removeEventListener( AbstractSyncCommand.onCommandEndEVENT, listener)901 902 def fireCommandEndEvent( self):858 if not isinstance(listener, ASyncCommandListener): 859 raise TypeError("listener param must be an ASyncCommandListener instance") 860 return self.__eventBroadcaster.removeEventListener(AbstractSyncCommand.onCommandEndEVENT, listener) 861 862 def fireCommandEndEvent(self): 903 863 """ 904 864 Fires the onCommandEnd event to the listeners … … 906 866 @rtype: void 907 867 """ 908 self.__eventBroadcaster.broadcastEvent( self.__onCommandEnd)909 910 def execute( self, event=None):868 self.__eventBroadcaster.broadcastEvent(self.__onCommandEnd) 869 870 def execute(self, event=None): 911 871 """ 912 872 By default the implementation of the execute method … … 919 879 self.fireCommandEndEvent() 920 880 921 def run( self):881 def run(self): 922 882 """ 923 883 Implementation of the Runnable interface, … … 928 888 self.execute() 929 889 930 def isRunning( self):890 def isRunning(self): 931 891 """ 932 892 Returns true if this command is currently processing. … … 936 896 return self.__isRunning 937 897 938 def __str__( self):898 def __str__(self): 939 899 """ 940 900 Returns the string representation of this instance. 941 901 @rtype: String 942 902 """ 943 return pyxoo.utils.PyxooStringifier.stringify( self)903 return pyxoo.utils.PyxooStringifier.stringify(self) project/trunk/src/pyxoo/core.py
r29 r33 8 8 9 9 10 class Locator ( pyxoo.utils.Interface ):10 class Locator: 11 11 """A Locator is an entity that points to specific kind 12 12 of ressources within an application. All ressources stored by a … … 19 19 """ 20 20 21 def is Registered( self, key):21 def is_registered(self, key): 22 22 """ 23 23 Returns true is there is a ressource associated … … 31 31 """ 32 32 33 def locate( self, key):33 def locate(self, key): 34 34 """ 35 35 Returns the ressource associated with the passed-in key. … … 42 42 """ 43 43 44 def add( self, dictionnary):44 def add(self, dictionnary): 45 45 """ 46 46 Adds all ressources contained in the passed-in dictionnary … … 50 50 @rtype: void 51 51 """ 52 53 54 55 class AbstractLocator( Locator ): 56 __logger = logging.getLogger( "pyxoo.core.AbstractLocator" ) 57 def __init__( self, typeObject=None, typeListener=None ): 52 53 54 class AbstractLocator(Locator): 55 __logger = logging.getLogger("pyxoo.core.AbstractLocator") 56 def __init__(self, type_object=None): 58 57 """ 59 58 Creates a new locator instance. If the type … … 65 64 @type typeListener: Class or Type 66 65 """ 67 self.__type = typeObject68 self._elements = pyxoo.utils.HashMap( str, self.__type)69 self.__eventBroadcaster = pyxoo.event.EventBroadcaster( self, typeListener)70 71 def onRegister( self, name=None, object=None):66 self.__type_object = type_object 67 self._elements = dict() 68 self.__eventBroadcaster = pyxoo.event.EventBroadcaster(self) 69 70 de
