[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager - ServiceDirective.py:1.3.6.1

Suresh Babu Eddala sbabu@zeomega.com
Mon, 21 Oct 2002 12:12:40 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv13324/lib/python/Zope/App/OFS/Services/ServiceManager

Modified Files:
      Tag: Zope3-Bangalore-TTW-Branch
	ServiceDirective.py 
Log Message:
Implemented the methods(manage_afterAdd, manage_beforeDelete) for 
adding and deleting the dependency of the object. 


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceDirective.py 1.3 => 1.3.6.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceDirective.py:1.3	Thu Jul 18 11:08:08 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceDirective.py	Mon Oct 21 12:12:39 2002
@@ -24,11 +24,20 @@
 from IServiceDirective import IServiceDirective
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
 from Zope.App.Traversing import getPhysicalRoot
+from Zope.ComponentArchitecture import getService
+from Zope.App.Traversing import getPhysicalPathString
+from ServiceManager import ServiceManager
+from Zope.App.OFS.Container.IAddNotifiable import IAddNotifiable
+from Zope.App.OFS.Container.IDeleteNotifiable import IDeleteNotifiable
+from Zope.App.DependencyFramework.IDependable import IDependable
+from Zope.ComponentArchitecture import getServiceManager, getAdapter
+from Zope.ContextWrapper import ContextMethod
 
 class ServiceDirective(Persistent):
     __doc__ = IServiceDirective.__doc__
     
-    __implements__ = IServiceDirective
+    __implements__ = IServiceDirective, IAddNotifiable, \
+                     IDeleteNotifiable
 
     def __init__(self, service_type, component_path, permission=None):
         self.service_type = service_type
@@ -82,9 +91,38 @@
 
     getService.__doc__ = IServiceDirective['getService'].__doc__
 
-    #
     ############################################################
 
+    def manage_afterAdd(self, directive, container):
+        "See Zope.App.OFS.Container.IAddNotifiable"
+        sm = getServiceManager(directive)
+        service = directive.getService(sm)
+        dependents = getAdapter(service, IDependable)
+        objectpath = getPhysicalPathString(directive)
+        dependents.addDependent(objectpath)
+        
+    def manage_beforeDelete(self, directive, container):
+        "See Zope.App.OFS.Container.IDeleteNotifiable"
+        directive = self
+        service_type = directive.service_type
+        sm = getServiceManager(directive)
+        service = directive.getService(sm)
+        objectstatus = sm.getRegistrationState(directive, service_type)
+        dependents = getAdapter(service, IDependable)
+        objectpath = getPhysicalPathString(directive)
+        
+        if objectstatus == 'Active':
+            raise "Object is active"
+        elif objectstatus == 'Registered':
+            sm.unbindService(directive)
+            dependents.removeDependent(objectpath)
+        else:
+            dependents.removeDependent(objectpath)
+
+
+            
+
+    manage_beforeDelete = ContextMethod(manage_beforeDelete)
     
 __doc__ = ServiceDirective.__doc__  + __doc__