Changeset 33

Show
Ignore:
Timestamp:
08/16/08 07:57:59 (5 months ago)
Author:
skit
Message:

big refactoring :
changement des nom de methodes, variables
modification du système de singleton, multiton
suppression HashMap?, Interface

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • project/trunk/src/pyxoo/command.py

    r29 r33  
    1010 
    1111 
    12 class Command( pyxoo.utils.Interface ):     
     12class Command:     
    1313    """Encapsulate a request as an object, thereby letting you parameterize 
    1414    clients with different requests, queue or log requests,  
     
    2323    """ 
    2424     
    25     def execute( self, event=None ): 
     25    def execute(self, event=None): 
    2626        """ 
    2727        Execute the request according to the current command data. 
     
    3838 
    3939 
    40 class AbstractCommand( Command ): 
     40class AbstractCommand(Command): 
    4141    """AbstractCommand provides a skeleton for commands which 
    4242    might work within plugin's FrontController. Abstract command 
     
    5353    __owner = None 
    5454         
    55     def execute( self, event=None ): 
     55    def execute(self, event=None): 
    5656        """ 
    5757        Override the execute virtual method 
     
    6464        @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. 
    6565        """ 
    66         raise NotImplementedError( "%s.execute() must be implemented in concrete class."%self
    67          
    68     def getOwner( self ): 
     66        raise NotImplementedError("%s.execute() must be implemented in concrete class."%self
     67         
     68    def get_owner(self): 
    6969        """ 
    7070        Returns a reference to the owner of this command. 
     
    7474        return self.__owner 
    7575     
    76     def setOwner( self, owner ): 
     76    def set_owner(self, owner): 
    7777        """ 
    7878        Defines the plugin owner of this command. 
     
    8484        @rtype: void  
    8585        """ 
    86         if owner and not isinstance( owner, pyxoo.plugin.Plugin ): 
    87             raise TypeError( "owner param must be a Plugin object" ) 
    8886        self.__owner = owner 
    8987         
    90     def getModelLocator( self ): 
     88    def get_model_locator(self): 
    9189        """ 
    9290        Returns a reference to the owner ModelLocator. 
     
    9694        @return: a reference to the owner model locator 
    9795        """ 
    98         return self.getOwner().getModelLocator() 
    99      
    100     def getViewLocator( self ): 
     96        return self.get_owner().get_model_locator() 
     97     
     98    def get_view_locator(self): 
    10199        """ 
    102100        Returns a reference to the owner ViewLocator. 
     
    106104        @return: a reference to the owner view locator 
    107105        """ 
    108         return self.getOwner().getViewLocator() 
    109      
    110     def _firePrivateEvent( self, event ): 
     106        return self.get_owner().get_view_locator() 
     107     
     108    def _fire_private_event(self, event): 
    111109        """ 
    112110        Fires a private event directly on this command's owner. 
     
    114112        @rtype: void  
    115113        """ 
    116         self.getOwner().firePrivateEvent( event
    117      
    118     def __str__( self ): 
     114        self.get_owner().fire_private_event(event
     115     
     116    def __str__(self): 
    119117        """ 
    120118        Returns the string representation of this instance. 
    121119        @rtype: String 
    122120        """ 
    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 
     124class MacroCommand(Command):   
    127125    """A macro command wraps many commands execution in a single  
    128126    execute call. The MacroCommand 
     
    142140    interface to provide a feedback for its execution end. 
    143141    """  
    144     def addCommand( self, command ): 
     142    def add_command(self, command): 
    145143        """ 
    146144        Adds the passed-in command to this macro command. 
     
    151149        """ 
    152150     
    153     def removeCommand( self, command ): 
     151    def remove_command(self, command): 
    154152        """ 
    155153        Removes the passed-in command from this macro command. 
     
    161159 
    162160 
    163  
    164 class Batch( MacroCommand, AbstractCommand ): 
     161class Batch(AbstractCommand, MacroCommand): 
    165162    """Batch object encapsulate a set of Commands 
    166163    to execute at the same time. 
     
    173170    """ 
    174171     
    175     def __init__( self ): 
     172    def __init__(self): 
    176173        """ 
    177174        Constructs a MacroCommand implementation. 
     
    179176        self.__commands = list() 
    180177         
    181     def addCommand( self, command ): 
     178    def add_command(self, command): 
    182179        """ 
    183180        Adds a command in the batch stack. 
     
    194191        """ 
    195192        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
    198195        return True 
    199196     
    200     def removeCommand( self, command ): 
     197    def remove_command(self, command): 
    201198        """ 
    202199        Removes all references to the passed-in command. 
     
    210207        """ 
    211208        if command in self.__commands: 
    212             self.__commands.remove( command
     209            self.__commands.remove(command
    213210            return True 
    214211        return False 
    215212     
    216     def setOwner( self, owner ): 
     213    def set_owner(self, owner): 
    217214        """ 
    218215        Defines the plugin owner of this command. 
     
    224221        @rtype: void  
    225222        """ 
    226         AbstractCommand.setOwner( self, owner
     223        AbstractCommand.set_owner(self, owner
    227224        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): 
    231228        """ 
    232229        Executes the whole set of commands in the order they were 
     
    240237        """ 
    241238        for command in self.__commands: 
    242             command.execute( event
     239            command.execute(event
    243240             
    244     def contains( self, command ): 
     241    def contains(self, command): 
    245242        """ 
    246243        Returns true if the passed-in command is stored 
     
    253250        return command in self.__commands 
    254251 
    255     def removeAll( self ): 
     252    def remove_all(self): 
    256253        """ 
    257254        Removes all commands. 
     
    261258        self.__commands = list() 
    262259         
    263     def size( self ): 
     260    def size(self): 
    264261        """ 
    265262        Returns the number of commands stored in this batch. 
     
    267264        @rtype: Integer 
    268265        """ 
    269         return len( self.__commands
    270          
    271  
    272 class ReversedBatch( Batch ): 
     266        return len(self.__commands
     267         
     268 
     269class ReversedBatch(Batch): 
    273270    """ReversedBatch is a concrete implementation of MacroCommand interface but execution is reversed""" 
    274     def execute( self, event=None ): 
     271    def execute(self, event=None): 
    275272        """ 
    276273        Executes the whole set of commands in the reversed order 
     
    286283        commands = self.getCommands() 
    287284        while index > -1: 
    288             commands[index].execute( event
     285            commands[index].execute(event
    289286            index -= 1 
    290287 
    291288 
    292289 
    293 class Delegate( Command ):     
    294     __logger = logging.getLogger( "pyxoo.command.Delegate"
     290class Delegate(Command):     
     291    __logger = logging.getLogger("pyxoo.command.Delegate"
    295292     
    296293    @classmethod 
    297     def create( cls, method, *args ): 
     294    def create(cls, method, *args): 
    298295        """ 
    299296        @param method: 
     
    303300        @rtype: Function 
    304301        """ 
    305         def function( *rest ): 
     302        def function(*rest): 
    306303            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
    312309        return function 
    313310     
    314     def __init__( self, function, *args ): 
     311    def __init__(self, function, *args): 
    315312        """ 
    316313        @param function: 
     
    320317        """ 
    321318        self.__function = function 
    322         self.__args     = list( args
    323          
    324     def getArguments( self ): 
     319        self.__args     = list(args
     320         
     321    def get_arguments(self): 
    325322        """ 
    326323        @return:  
     
    329326        return self.__args 
    330327         
    331     def setArguments( self, *args ): 
     328    def set_arguments(self, *args): 
    332329        """ 
    333330        @param *args: 
     
    335332        @rtype: void 
    336333        """ 
    337         self.setArgumentsArray( list( args )
    338          
    339     def setArgumentsArray( self, array ): 
     334        self.set_arguments_array(list(args)
     335         
     336    def set_arguments_array(self, array): 
    340337        """ 
    341338        @param array: 
     
    343340        @rtype: void  
    344341        """ 
    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: 
    348343            self.__args = array 
    349344             
    350     def addArguments( self, *args ): 
     345    def add_arguments(self, *args): 
    351346        """ 
    352347        @param *args:  
     
    354349        @rtype: void 
    355350        """ 
    356         self.addArgumentsArray( list( args )
     351        self.add_arguments_array(list(args)
    357352             
    358     def addArgumentsArray( self, array ): 
     353    def add_arguments_array(self, array): 
    359354        """ 
    360355        @param array: 
     
    362357        @rtype: void 
    363358        """ 
    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: 
    367360            self.__args += array 
    368361         
    369     def execute( self, event=None ): 
     362    def execute(self, event=None): 
    370363        """ 
    371364        @param event: Can be None 
    372         @type event: pyxoo.event.IEvent 
     365        @type event: pyxoo.event.Event 
    373366        @rtype: void          
    374367        """ 
    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." ) 
    377368        args = list() 
    378         if event is not None:args.append( event
     369        if event is not None:args.append(event
    379370        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 handleEvent( 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): 
    387378        """ 
    388379        @param event: 
    389         @type event: pyxoo.event.IEvent 
    390         @rtype: void 
    391         """ 
    392         self.execute( event
    393          
    394     def callFunction( self ): 
     380        @type event: pyxoo.event.Event 
     381        @rtype: void 
     382        """ 
     383        self.execute(event
     384         
     385    def call_function(self): 
    395386        """ 
    396387        @rtype: Object 
    397388        """ 
    398         return apply( self.__function, self.__args
    399          
    400     def __str__( self ): 
     389        return apply(self.__function, self.__args
     390         
     391    def __str__(self): 
    401392        """ 
    402393        Returns the string representation of this instance. 
    403394        @rtype: String 
    404395        """ 
    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 
     399class FrontController(pyxoo.core.AbstractLocator): 
    423400    """ 
    424401    A base class for an application specific front controller, 
     
    444421    plugin's MVC components. 
    445422    """ 
    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): 
    449426        """ 
    450427        Creates a new Front Controller instance for the passed-in 
     
    454431        @type owner: pyxoo.plugin.Plugin  
    455432        """ 
    456         pyxoo.core.AbstractLocator.__init__( self, None, None
     433        pyxoo.core.AbstractLocator.__init__(self, None
    457434        if owner: 
    458             if not isinstance( owner, pyxoo.plugin.Plugin ): 
    459                 raise TypeError( "owner param must be a Plugin instance" ) 
    460435            self.__owner = owner 
    461436        else: 
    462             self.__owner = pyxoo.plugin.NullPlugin.getInstance() 
    463             pyxoo.event.EventBroadcaster.getInstance().addListener( self )         
    464         self.__aSyncCommands = pyxoo.utils.HashMap() 
    465      
    466     def getOwner( 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): 
    467442        """ 
    468443        Returns the owner plugin of this controller 
     
    472447        return self.__owner 
    473448     
    474     def register( self, eventName, object ): 
     449    def register(self, event_type, object): 
    475450        try: 
    476             if pyxoo.utils.Type.isClass( object ): 
    477                 self.pushCommandClass( eventName, object
     451            if pyxoo.utils.Type.isClass(object): 
     452                self.push_command_class(event_type, object
    478453            else: 
    479                 self.pushCommandInstance( eventName, object
     454                self.push_command_instance(event_type, object
    480455        except Exception, e: 
    481             self.__logger.fatal( e.message
     456            self.__logger.fatal(e.message
    482457            raise e 
    483458         
    484     def pushCommandClass( self, eventName, commandClass ): 
     459    def push_command_class(self, event_type, command_class): 
    485460        """ 
    486461        Registers the passed-in command class to be triggered at each time 
     
    493468        If there is already a command or a class associated with the passed-in event, 
    494469        the association failed and an exception is throw. 
    495         @param eventName: name of the event type with which the command will be registered 
    496         @param commandClass: class to associate with the passed-in event type 
    497         @type eventName: String 
    498         @type commandClass: Class 
     470        @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 
    499474        @return: true if the command class have been succesfully registered with the passed-in event type 
    500475        @rtype: Boolean 
    501476        @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) 
    514482        else: 
    515             self._elements.put( eventName, commandClass ) 
    516          
    517     def pushCommandInstance( self, eventName, command ): 
     483            self._elements[event_type] = command_class 
     484         
     485    def push_command_instance(self, event_type, command): 
    518486        """ 
    519487        Registers the passed-in command to be triggered at each time 
     
    522490        If there is already a class or a command associated with the passed-in 
    523491        event, the association failed and an exception is throw. 
    524         @param eventName: name of the event type with which the command will be registered 
     492        @param event_type: name of the event type with which the command will be registered 
    525493        @param command: command to associate with the passed-in event type 
    526         @type eventName: String 
     494        @type event_type: String 
    527495        @type command: Command 
    528496        @return: true if the command have been succesfully registered with the passed-in event type 
     
    530498        @raise IllegalArgumentException: There is already a command or class registered with the specified key. 
    531499        """ 
    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) 
    540504        else: 
    541             self._elements.put( eventName, command ) 
     505            self._elements[event_type] = command 
    542506             
    543     def remove( self, eventName ): 
     507    def remove(self, event_type): 
    544508        """ 
    545509        Removes the class or the command registered with the 
     
    549513        @rtype: void 
    550514        """ 
    551         self._elements.remove( eventName ) 
    552          
    553     def handleEvent( self, event ): 
     515        del self._elements[event_type] 
     516         
     517    def handle_event(self, event): 
    554518        """ 
    555519        Handles all events received by this object. 
     
    569533        @rtype: void         
    570534        """ 
    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 
    574536        command = None 
    575537        try: 
    576             command = self.locate( type
     538            command = self.locate(type
    577539        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)
    579541        if command: 
    580             if isinstance( command, ASyncCommand ): 
    581                 self.__aSyncCommands.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
    584546             
    585     def onCommandEnd( self, event ): 
     547    def onCommandEnd(self, event): 
    586548        """ 
    587549        Catch callback events from asynchronous commands thiggered 
     
    593555        @rtype: void 
    594556        """ 
    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): 
    600560        """ 
    601561        Returns the command located at the specified key 
     
    613573        """ 
    614574        try: 
    615             object = pyxoo.core.AbstractLocator.locate( self, key
     575            object = pyxoo.core.AbstractLocator.locate(self, key
    616576        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): 
    621581            command = object 
    622582        else: 
    623583            command = object()         
    624         if isinstance( command, AbstractCommand ): 
     584        if isinstance(command, AbstractCommand): 
    625585            if not command.getOwner(): 
    626                 command.setOwner( self.getOwner()
     586                command.setOwner(self.getOwner()
    627587        return command 
    628588     
    629     def add( self, dictionnary ): 
     589    def add(self, dictionnary): 
    630590        """ 
    631591        Adds all key/commands associations within the passed-in 
     
    644604            try: 
    645605                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
    649609                else: 
    650                     self.pushCommandInstance( name, command
     610                    self.pushCommandInstance(name, command
    651611            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
    654614                raise e 
    655615 
     
    657617         
    658618 
    659 class Runnable( pyxoo.utils.Interface )
     619class Runnable
    660620    """ 
    661621    The Runnable interface should be implemented by any 
     
    692652    extends the Runnable interface to define process ending rules. 
    693653    """ 
    694     def run( self ): 
     654    def run(self): 
    695655        """ 
    696656        Starts the asynchronous process of this runnable object. 
     
    703663        """      
    704664            
    705     def isRunning( self ): 
     665    def isRunning(self): 
    706666        """ 
    707667        Returns true if this object is running. 
     
    711671 
    712672 
    713 class Suspendable( Runnable, pyxoo.utils.Interface ): 
     673class Suspendable(Runnable): 
    714674    """ 
    715675    Suspendable defines rules for Runnable 
     
    734694    and Cancelable interfaces. 
    735695    """ 
    736     def start( self ): 
     696    def start(self): 
    737697        """         
    738698        Starts the operation of this suspendable operation. 
     
    743703        """ 
    744704         
    745     def stop( self ): 
     705    def stop(self): 
    746706        """         
    747707        Stops the operation in process. If a call to the 
     
    751711        """ 
    752712         
    753     def reset( self ): 
     713    def reset(self): 
    754714        """         
    755715        Resets the state of this object. The state of an operation 
     
    761721        """ 
    762722 
    763 class Cancelable( Runnable, pyxoo.utils.Interface ): 
     723class Cancelable(Runnable): 
    764724    """ 
    765725    Cancelable defines rules for Runnable 
     
    780740    """ 
    781741     
    782     def cancel( self ): 
     742    def cancel(self): 
    783743        """         
    784744        Attempts to cancel execution of this task. 
     
    796756        """ 
    797757 
    798     def isCancelled( self ): 
     758    def isCancelled(self): 
    799759        """ 
    800760        Returns true if the operation have been stopped 
     
    804764        """ 
    805765 
    806 class ASyncCommand( Command, Runnable, pyxoo.utils.Interface ): 
     766class ASyncCommand(Command, Runnable): 
    807767    """ 
    808768    An asynchronous command is a runnable command, which is not terminated 
     
    813773    command dispatch an onCommandEnd event at the end of its process. 
    814774    """ 
    815     def addASyncCommandListener( self, listener, *args ): 
     775    def addASyncCommandListener(self, listener, *args): 
    816776        """ 
    817777        Adds the passed-in command listener object as listener 
     
    828788        """ 
    829789         
    830     def removeASyncCommandListener( self, listener ): 
     790    def removeASyncCommandListener(self, listener): 
    831791        """ 
    832792        Removes the passed-in command listener object as listener 
     
    838798        """ 
    839799          
    840     def fireCommandEndEvent( self ): 
     800    def fireCommandEndEvent(self): 
    841801        """ 
    842802        Fires the onCommandEnd event to the listeners of this command.  
     
    847807 
    848808         
    849 class AbstractSyncCommand( AbstractCommand, ASyncCommand ): 
     809class AbstractSyncCommand(AbstractCommand, ASyncCommand): 
    850810    """ 
    851811    AbstractSyncCommand provides a skeleton to create 
     
    867827    onCommandEndEVENT = "onCommandEnd" 
    868828     
    869     def __init__( self ): 
     829    def __init__(self): 
    870830        """ 
    871831        Initializes event dispatching behavior and Runnable implementation 
    872832        """ 
    873833        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): 
    878838        """ 
    879839        Adds the passed-in listener as listener for the onCommandEnd event of this command. 
     
    884844        @rtype: Boolean 
    885845        """ 
    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): 
    891851        """ 
    892852        Removes the passed-in listener for listening 
     
    896856        @rtype: Boolean 
    897857        """ 
    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): 
    903863        """ 
    904864        Fires the onCommandEnd event to the listeners 
     
    906866        @rtype: void  
    907867        """ 
    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): 
    911871        """ 
    912872        By default the implementation of the execute method 
     
    919879        self.fireCommandEndEvent() 
    920880         
    921     def run( self ): 
     881    def run(self): 
    922882        """ 
    923883        Implementation of the Runnable interface,  
     
    928888        self.execute() 
    929889         
    930     def isRunning( self ): 
     890    def isRunning(self): 
    931891        """ 
    932892        Returns true if this command is currently processing.  
     
    936896        return self.__isRunning 
    937897 
    938     def __str__( self ): 
     898    def __str__(self): 
    939899        """ 
    940900        Returns the string representation of this instance. 
    941901        @rtype: String 
    942902        """ 
    943         return pyxoo.utils.PyxooStringifier.stringify( self
     903        return pyxoo.utils.PyxooStringifier.stringify(self
  • project/trunk/src/pyxoo/core.py

    r29 r33  
    88 
    99 
    10 class Locator( pyxoo.utils.Interface )
     10class Locator
    1111    """A Locator is an entity that points to specific kind 
    1212    of ressources within an application. All ressources stored by a 
     
    1919    """ 
    2020     
    21     def isRegistered( self, key ): 
     21    def is_registered(self, key): 
    2222        """ 
    2323        Returns true is there is a ressource associated 
     
    3131        """ 
    3232     
    33     def locate( self, key ): 
     33    def locate(self, key): 
    3434        """ 
    3535        Returns the ressource associated with the passed-in key. 
     
    4242        """ 
    4343         
    44     def add( self, dictionnary ): 
     44    def add(self, dictionnary): 
    4545        """ 
    4646        Adds all ressources contained in the passed-in dictionnary 
     
    5050        @rtype: void 
    5151        """ 
    52  
    53  
    54  
    55 class AbstractLocator( Locator ): 
    56     __logger = logging.getLogger( "pyxoo.core.AbstractLocator" ) 
    57     def __init__( self, typeObject=None, typeListener=None ): 
     52         
     53         
     54class AbstractLocator(Locator): 
     55    __logger = logging.getLogger("pyxoo.core.AbstractLocator") 
     56    def __init__(self, type_object=None): 
    5857        """ 
    5958        Creates a new locator instance. If the type 
     
    6564        @type typeListener: Class or Type 
    6665        """ 
    67         self.__type = typeObject 
    68         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