[Zope3-checkins] CVS: Zope3/lib/python/Zope/ObjectHub - HubEvent.py:1.1 IHubEvent.py:1.1 ObjectHub.py:1.8 IRuidObjectEvent.py:NONE RuidObjectEvent.py:NONE

Godefroid Chapelle gotcha@swing.be
Thu, 22 Aug 2002 13:05:25 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/ObjectHub
In directory cvs.zope.org:/tmp/cvs-serv11633

Modified Files:
	ObjectHub.py 
Added Files:
	HubEvent.py IHubEvent.py 
Removed Files:
	IRuidObjectEvent.py RuidObjectEvent.py 
Log Message:
Refactored inheritance of internal hub events.

Renamed from RuidObjectEvents to HubEvents.





=== Added File Zope3/lib/python/Zope/ObjectHub/HubEvent.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

Revision information:
$Id: HubEvent.py,v 1.1 2002/08/22 17:05:24 gotcha Exp $
"""

from IHubEvent import IObjectRegisteredHubEvent
from IHubEvent import IObjectAddedHubEvent
from IHubEvent import IObjectUnregisteredHubEvent
from IHubEvent import IObjectModifiedHubEvent
from IHubEvent import IObjectMovedHubEvent
from IHubEvent import IObjectRemovedHubEvent

class HubEvent:
    """Convenient mix-in for HubEvents"""
    
    def __init__(self, objecthub, ruid, location):
        # we keep all three, to avoid unnecessary lookups
        # and to give the objecthub an opportunity to do
        # caching of objects
        self.__objecthub = objecthub
        self.__ruid = ruid
        self.__location = location
        
    def getRuid(self):
        return self.__ruid
        
    def getLocation(self):
        return self.__location
        
    def getObject(self):
        if hasattr(self, '_v_object'):
            return self._v_object
        obj = self._v_object = self.__objecthub.getObject(self.__ruid)
        return obj


class ObjectRegisteredHubEvent(HubEvent):
    """An ruid has been freshly created and mapped against an object."""

    __implements__ = IObjectRegisteredHubEvent


class ObjectUnregisteredHubEvent(HubEvent):
    """We are no longer interested in this object."""

    __implements__ = IObjectUnregisteredHubEvent


class ObjectAddedHubEvent(HubEvent):
    """An ruid has been freshly created and mapped against an object.
       Also, implies the object has been newly added."""
    
    __implements__ = IObjectAddedHubEvent
    
    
class ObjectModifiedHubEvent(HubEvent):
    """An object with an ruid has been modified."""
    
    __implements__ = IObjectModifiedHubEvent
    
    
class ObjectMovedHubEvent(HubEvent):
    """An object with an ruid has had its context changed. Typically, this
       means that it has been moved."""
       
    __implements__ = IObjectMovedHubEvent


class ObjectRemovedHubEvent(HubEvent):
    """An object with an ruid has been removed."""

    __implements__ = IObjectRemovedHubEvent

    def __init__(self, obj, ruid, location):
        self.__object = obj
        self.__ruid = ruid
        self.__location = location

    def getRuid(self):
        return self.__ruid
        
    def getLocation(self):
        return self.__location

    def getObject(self):
        return self.__object


=== Added File Zope3/lib/python/Zope/ObjectHub/IHubEvent.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

Revision information:
$Id: IHubEvent.py,v 1.1 2002/08/22 17:05:24 gotcha Exp $
"""
from Zope.Event.IEvent import IEvent

class IHubEvent(IEvent):
    """Internal Object Hub Event : something has happened to an object for
       which there is an ruid.
       An ruid is a way of refering to an object independent of location.
    """

    def getRuid():
        """Returns the object's ruid."""
   
    def getLocation():
        """Returns the object's current location."""
   
    def getObject():
        """Returns the object."""
   

class IRegistrationHubEvent(IHubEvent):
    """Some work could be done on registration or deregistration of an object."""


class IObjectRegisteredHubEvent(IRegistrationHubEvent):
    """An ruid has been freshly created and mapped against an object."""


class IObjectUnregisteredHubEvent(IRegistrationHubEvent):
    """We are no longer interested in this object."""


class INotificationHubEvent(IHubEvent):
    """Some work has be done on a registrated object."""


class IObjectAddedHubEvent(INotificationHubEvent):
    """An ruid has been freshly created and mapped against an object.
       Also, implies the object has been newly added."""
    
    
class IObjectModifiedHubEvent(INotificationHubEvent):
    """An object with an ruid has been modified."""
    
    
class IObjectMovedHubEvent(INotificationHubEvent):
    """An object with an ruid has had its context changed. Typically, this
       means that it has been moved."""

   
class IObjectRemovedHubEvent(INotificationHubEvent):
    """An object with an ruid has been removed."""

    def getLocation():
        """Returns the object's location before it was removed."""

    def getObject():
        """Returns the object, or None if the object is unavailable."""


=== Zope3/lib/python/Zope/ObjectHub/ObjectHub.py 1.7 => 1.8 ===
--- Zope3/lib/python/Zope/ObjectHub/ObjectHub.py:1.7	Fri Jul 12 13:45:57 2002
+++ Zope3/lib/python/Zope/ObjectHub/ObjectHub.py	Thu Aug 22 13:05:24 2002
@@ -23,13 +23,13 @@
 from Zope.Event.IObjectEvent import IObjectRemovedEvent, IObjectMovedEvent
 from Zope.Event.IEvent import IEvent
 from Zope.Event.EventChannel import EventChannel
-from RuidObjectEvent import RuidObjectRegisteredEvent
-from RuidObjectEvent import RuidObjectUnregisteredEvent
-from RuidObjectEvent import RuidObjectAddedEvent
-from RuidObjectEvent import RuidObjectModifiedEvent
-from RuidObjectEvent import RuidObjectContextChangedEvent
-from RuidObjectEvent import RuidObjectRemovedEvent
-from IRuidObjectEvent import IRuidObjectEvent
+from HubEvent import ObjectRegisteredHubEvent
+from HubEvent import ObjectUnregisteredHubEvent
+from HubEvent import ObjectAddedHubEvent
+from HubEvent import ObjectModifiedHubEvent
+from HubEvent import ObjectMovedHubEvent
+from HubEvent import ObjectRemovedHubEvent
+from IHubEvent import IHubEvent
 
 from Zope.Exceptions import NotFoundError
 from Persistence import Persistent
@@ -85,13 +85,15 @@
 
     def notify(self, event):
         '''See interface ISubscriber'''
-        if IRuidObjectEvent.isImplementedBy(event):
+        if IHubEvent.isImplementedBy(event):
             self.__eventchannel.notify(event)
             return
 
         if IObjectEvent.isImplementedBy(event):
             self.__eventchannel.notify(event)
-            
+
+            # generate NotificationHubEvents only if object is known
+            # ie registered  
             if IObjectMovedEvent.isImplementedBy(event):
                 canonical_location = locationAsUnicode(event.getFromLocation())
                 ruid = self._lookupRuid(canonical_location)
@@ -142,13 +144,6 @@
         if location[0] != u'/':
             raise ValueError, "Location must be absolute"
         ruid = self._registerObject(canonical_location)
-
-        # send out to plugins IRuidObjectRegisteredEvent
-        event = RuidObjectRegisteredEvent(
-            self, 
-            ruid,
-            canonical_location)
-        self.__eventchannel.notify(event)
         return ruid
 
     def unregister(self, ruid_or_location):
@@ -161,12 +156,7 @@
         if ruid is None:
             raise NotFoundError, 'location %s is not in object hub' % \
                 canonical_location
-        event = RuidObjectUnregisteredEvent(
-            self, 
-            ruid,
-            canonical_location)
-        self.__eventchannel.notify(event)
-        
+  
     #
     ############################################################
 
@@ -190,24 +180,30 @@
                 canonical_location
         ruid = self._generateRuid(canonical_location)
         location_to_ruid[canonical_location] = ruid
+
+        # send out IObjectRegisteredHubEvent to plugins
+        event = ObjectRegisteredHubEvent(
+            self, 
+            ruid,
+            canonical_location)
+        self.__eventchannel.notify(event)
         return ruid
 
     def _objectAdded(self, canonical_location, ruid):
-        # send out to plugins IRuidObjectAddedEvent
-        event = RuidObjectAddedEvent(
+        # send out IObjectAddedHubEvent to plugins
+        event = ObjectAddedHubEvent(
             self, 
             ruid,
             canonical_location)
         self.__eventchannel.notify(event)
     
     def _objectModified(self, canonical_location, ruid):
-        # send out to plugins IRuidObjectModifiedEvent
-        event = RuidObjectModifiedEvent(
+        # send out IObjectModifiedHubEvent to plugins
+        event = ObjectModifiedHubEvent(
             self, 
             ruid,
             canonical_location)
         self.__eventchannel.notify(event)
-        
     
     def _objectMoved(self, old_location, new_location):
         location_to_ruid = self.__location_to_ruid
@@ -218,17 +214,17 @@
                 'Cannot move to location %s, '
                 'as there is already something there'
                 % canonical_new_location)
-        if not location_to_ruid.has_key(canonical_location):
-            # we're not interested in this event
-            return
+        # already tested before calling _objectMoved
+##        if not location_to_ruid.has_key(canonical_location):
+##            # we're not interested in this event
+##            return
 
         ruid = location_to_ruid[canonical_location]
         del location_to_ruid[canonical_location]
         location_to_ruid[canonical_new_location] = ruid
         self.__ruid_to_location[ruid] = canonical_new_location
-        
-        # send out to plugins IRuidObjectContextChangedEvent
-        event = RuidObjectContextChangedEvent(
+        # send out IObjectMovedHubEvent to plugins
+        event = ObjectMovedHubEvent(
             self, 
             ruid,
             canonical_new_location)
@@ -246,13 +242,17 @@
         else:
             del ruid_to_location[ruid]
             del location_to_ruid[canonical_location]
+            # send out IObjectUnregisteredHubEvent to plugins
+            event = ObjectUnregisteredHubEvent(
+                self, 
+                ruid,
+                canonical_location)
+            self.__eventchannel.notify(event)
             return ruid
-        
-            
+
     def _objectRemoved(self, canonical_location, ruid, obj):
-            
-        # send out to plugins IRuidObjectRemovedEvent
-        event = RuidObjectRemovedEvent(
+        # send out IObjectRemovedHubEvent to plugins
+        event = ObjectRemovedHubEvent(
             obj,
             ruid,
             canonical_location)

=== Removed File Zope3/lib/python/Zope/ObjectHub/IRuidObjectEvent.py ===

=== Removed File Zope3/lib/python/Zope/ObjectHub/RuidObjectEvent.py ===