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

Florent Guillaume fg@nuxeo.com
Fri, 25 Oct 2002 21:39:50 +0200


I know it's current work done in a branch, but pretty please could we
have those things named differently than "manage_afterAdd" and
"manage_beforeDelete"? Those raise bad memories, and aren't in sync with
the rest of the naming in Z3.

Also, is this IAddNotifiable framework going to stay? I would have
thought we'd use the Event Service instead of that, where someone would
register as a listener for the add and remove events and would act on
them to keep the invariants needed.

Florent


In article <200210211612.g9LGCel13573@cvs.baymountain.com> you write:
> 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__
>  
> 
> 
> _______________________________________________
> Zope3-Checkins mailing list
> Zope3-Checkins@zope.org
> http://lists.zope.org/mailman/listinfo/zope3-checkins
> 


-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com