[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager - IServiceManager.py:1.1.2.3 ServiceManager.py:1.1.2.4
Steve Alexander
steve@cat-box.net
Mon, 4 Mar 2002 18:52:17 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv1579
Modified Files:
Tag: Zope-3x-branch
IServiceManager.py ServiceManager.py
Log Message:
Working TTW service manager + tests.
=== Zope3/lib/python/Zope/App/OFS/ServiceManager/IServiceManager.py 1.1.2.2 => 1.1.2.3 ===
checks for those it contains, before using a context
based lookup to find another service manager to delegate
- to. if no other service manager is found they defer
+ to. If no other service manager is found they defer
to the ComponentArchitecture ServiceManager which
contains file based services.
"""
@@ -33,6 +33,8 @@
def bindService(serviceName, serviceComponentName):
"""provide a service implementation"""
+ def unbindService(serviceName):
+ """no longer provide a service implementation"""
def getBoundService(name):
"""retrieve a bound service implimentation
@@ -41,5 +43,3 @@
in this ServiceService. Does not search context.
"""
- def getServiceDefinitions():
- """returns the dictionary of service definitions"""
=== Zope3/lib/python/Zope/App/OFS/ServiceManager/ServiceManager.py 1.1.2.3 => 1.1.2.4 ===
from Zope.ComponentArchitecture.Service import UndefinedService
from Zope.ComponentArchitecture.Service import InvalidService
-from Zope.Exceptions import DuplicationError, NotFoundError
+from Zope.Exceptions import NotFoundError, ZopeError
from Zope.App.OFS.Folder.Folder import Folder
from Zope.ContextWrapper import getinnercontext
from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
@@ -31,31 +31,22 @@
__implements__ = IServiceManager
def __init__(self):
- self.__defs = {}
self.__bindings = {}
super(ServiceManager, self).__init__()
- def defineService(self, name, interface):
- """ see ServiceManager Interface """
-
- if name in self.__defs:
- raise DuplicationError(name)
-
- # trigger p machinery
- self.__defs == self.__defs
-
- self.__defs[name] = interface
def getServiceDefinitions(self):
- serviceDefs = self.__defs.items()
+ """ see IServiceService Interface """
# Get the services defined above us
- parentSM = self._findParentServiceManager()
- if parentSM is not None:
- serviceDefs = serviceDefs + parentSM.getServiceDefinitions()
- else:
- serviceDefs = serviceDefs + getServiceDefinitions()
-
- return serviceDefs
+ #serviceDefs = []
+ #parentSM = self._findParentServiceManager()
+ #if parentSM is not None:
+ # serviceDefs += parentSM.getServiceDefinitions()
+ #else:
+ # serviceDefs += getServiceDefinitions()
+ #
+ #return serviceDefs
+ return getServiceDefinitions()
def _findParentServiceManager(self):
parent = getinnercontext(self)
@@ -65,7 +56,7 @@
return sm
def getService(self, object, name):
- """ see IServiceManager Interface"""
+ """ see IServiceService Interface"""
service = self.__bindings.get(name)
@@ -98,19 +89,36 @@
# This could raise a KeyError if we don't have this component
serviceComponent = self.getObject(serviceComponentName)
- if serviceName not in self.__defs.keys():
- raise UndefinedService(serviceName)
-
- if not self.__defs[serviceName].isImplementedBy(serviceComponent):
- raise InvalidService(serviceName, serviceComponentName,
- self.__defs[serviceName])
+ for name,interface in self.getServiceDefinitions():
+ if name == serviceName:
+ if not interface.isImplementedBy(serviceComponent):
+ raise InvalidService(serviceName,
+ serviceComponentName,
+ interface)
+ break
# Services are added to the Manager through the Folder interface
# self.setObject(name, component)
+
+ # trigger persistence
+ self.__bindings = self.__bindings
+
self.__bindings[serviceName] = serviceComponentName
- def getServiceDefinitions(self):
- """ see IServiceManager Interface"""
+ def unbindService(self, serviceName):
+ """ see IServiceManager Interface """
+
+ # trigger persistence
+ self.__bindings = self.__bindings
+
+ del self.__bindings[serviceName]
- return self.__defs.items()
+ def delObject(self, name):
+ '''See interface IWriteContainer'''
+ if name in self.__bindings.values():
+ # Should we silently unbind the service?
+ # self.unbindService(name)
+ # No, let's raise an exception
+ raise ZopeError("Cannot remove a bound service. Unbind it first.")
+ BTreeContainer.delObject(self, name)