[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Service - IServiceManager.py:1.1.2.1 ServiceManager.py:1.1.2.1 __init__.py:1.1.2.1
Kapil
k_vertigo@yahoo.com
Fri, 8 Feb 2002 15:56:00 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Service
In directory cvs.zope.org:/tmp/cvs-serv12657/Service
Added Files:
Tag: Zope-3x-branch
IServiceManager.py ServiceManager.py __init__.py
Log Message:
Added in interfaces and implementation for ServiceManagers in the
zodb instance space.
=== Added File Zope3/lib/python/Zope/App/Service/IServiceManager.py ===
##############################################################################
#
# Copyright (c) 2001 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: IServiceManager.py,v 1.1.2.1 2002/02/08 20:55:59 k_vertigo Exp $
"""
from Interface import Interface
from Zope.ComponentArchitecture.IServiceService import IServiceService
class IServiceManager(IServiceService):
"""
Service Managers act as containers for Services.
If a Service Manager is asked for a service it
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 the ComponentArchitecture ServiceManager which
contains file based services.
"""
=== Added File Zope3/lib/python/Zope/App/Service/ServiceManager.py ===
##############################################################################
#
# Copyright (c) 2001 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: ServiceManager.py,v 1.1.2.1 2002/02/08 20:55:59 k_vertigo Exp $
"""
from IServiceManager import IServiceManager
from Zope.ComponentArchitecture.IServiceManagerContainer \
import IServiceManagerContainer
from Zope.ComponentArchitecture import getService
from Zope.ComponentArchitecture.Service \
import UndefinedService, InvalidService
from Zope.Exceptions import DuplicationError, NotFoundError
from Zope.App.OFS.IContainer import IContainer
from Zope.App.OFS.Folder.Folder import Folder
from Zope.ContextWrapper import getinnercontext
class ServiceManager(Folder):
__implements__ = (
IServiceManager,
IContainer,
)
def __init__(self):
self.__defs = {}
Folder.__init__(self)
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 getService(self, object, name):
""" see IServiceManager Interface"""
service = self.getObject(name, None)
if service:
return service
while object is not None:
object = getinnercontext(object)
if IServiceManagerContainer.isImplementedBy(object):
sm = object.getServiceManager()
if sm:
return sm.getService(object, name)
# fallback to the ComponentArchitecture Service Manager
# XXX when this called the original object might no longer be
# the context
return getService(object, name)
def provideService(self, name, component):
""" see IServiceManager Interface"""
if name in self.objectIds():
raise DuplicationError(name)
if name not in self.__defs.keys():
raise UndefinedService(name)
if not self.__defs[name].isImplementedBy(component):
raise InvalidService(name, component, self.__defs[name])
self.setObject(name, component)
=== Added File Zope3/lib/python/Zope/App/Service/__init__.py ===
##############################################################################
#
# Copyright (c) 2001 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: __init__.py,v 1.1.2.1 2002/02/08 20:55:59 k_vertigo Exp $
"""