[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager - hooks.py:1.1.2.1 service-manager.zcml:1.1.2.2

Gary Poster garyposter@earthlink.net
Sun, 14 Apr 2002 23:32:29 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	service-manager.zcml 
Added Files:
      Tag: Zope-3x-branch
	hooks.py 
Log Message:
This commit sets up the hook tag so that it actually works, and uses the new functionality to better divide up the labor of the ComponentArchitecture.  The placeless ComponentArchitecture code for getService is still there, but the placeful code has been moved to the ServiceManager section.  A few other hooks are also set up in ComponentArchitecture, and a few changes made in preparation for a later update of some placeful services.

The ServiceManager test was altered to use the newly moved placeful getService code.

Other hooks can now be set up and used using this hopefully helpful mechanism.



=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/hooks.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.
# 
##############################################################################
"""

$Id: hooks.py,v 1.1.2.1 2002/04/15 03:31:59 poster Exp $
"""
from Zope.ComponentArchitecture.IServiceService import IServiceService
from Zope.ComponentArchitecture.IServiceManagerContainer import IServiceManagerContainer
from Zope.ContextWrapper import getinnercontext
from Zope.ComponentArchitecture import getGlobalServiceManager

def _getService(context, name):
    """
    context based lookup
    """
    return _getServiceManager(context).getService(context, name)

def _getServiceManager(context):
    """
    context based lookup, with fallback to component architecture
    service manager if no service manager found within context
    """
    while context is not None:
        # if the context is actually a service or service manager...
        if IServiceService.isImplementedBy(context): return context
        if IServiceManagerContainer.isImplementedBy(context):
            sm = context.getServiceManager()
            if sm is not None:
                return sm
        context = getinnercontext(context)
    return getGlobalServiceManager()
    

def _getServiceDefinitions(context): # needed? not hooked in now
    """
    context based lookup to get service defintions
    """
    return _getServiceManager(context).getServiceDefinitions()

=== Zope3/lib/python/Zope/App/OFS/ServiceManager/service-manager.zcml 1.1.2.1 => 1.1.2.2 ===
 <include package="Zope.App.OFS.ServiceManager.Views" file="views.zcml" />
 
+<hook module="Zope.ComponentArchitecture" name="getServiceManager"
+   implementation=".hooks._getServiceManager" />
+
+<hook module="Zope.ComponentArchitecture" name="getService"
+   implementation=".hooks._getService" />
+
+<!--hook module="Zope.ComponentArchitecture" name="getServiceDefinitions"
+   implementation=".hooks._getServiceDefinitions" /-->
+
 </zopeConfigure>