[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager - ConfigurationManager.py:1.2.10.1 IServiceConfiguration.py:1.4.2.1 IServiceManager.py:1.6.2.1 ServiceConfiguration.py:1.4.2.1 ServiceManager.py:1.13.2.1 configure.zcml:1.8.10.1

Marius Gedminas mgedmin@codeworks.lt
Tue, 10 Dec 2002 14:16:33 -0500


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

Modified Files:
      Tag: named-component-configuration-branch
	ConfigurationManager.py IServiceConfiguration.py 
	IServiceManager.py ServiceConfiguration.py ServiceManager.py 
	configure.zcml 
Log Message:
Refactoring of configuration views:
  - new interfaces INamedComponentConfiguration, INameConfigurable,
    implemented in NamedComponentConfiguration, NameConfigurable, simplify
    the case where configurations are identified by a name (service types,
    connections, caches, queries, etc)
  - common views for INamedComponentConfiguration, INameConfigurable
  - refactored ServiceManager and ConnectionService to take advantage of the
    new infrastructure
  - incidentally wrote several unit tests for configuration classes
  - removed caching from ComponentConnection.getComponent; this exposed a bug
    in LocalEventService tests



=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ConfigurationManager.py 1.2 => 1.2.10.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ConfigurationManager.py:1.2	Sat Nov 30 13:39:16 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ConfigurationManager.py	Tue Dec 10 14:16:02 2002
@@ -2,14 +2,14 @@
 #
 # Copyright (c) 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$
@@ -25,7 +25,7 @@
 
     Manages configurations within a package.
     """
-    
+
     __implements__ = IConfigurationManager
 
     def __init__(self):
@@ -49,7 +49,7 @@
     def __contains__(self, key):
         "See Interface.Common.Mapping.IReadMapping"
         return self.get(key) is not None
-    
+
 
     def keys(self):
         "See Interface.Common.Mapping.IEnumerableMapping"
@@ -58,7 +58,7 @@
     def values(self):
         "See Interface.Common.Mapping.IEnumerableMapping"
         return [v for k, v in self._data]
-    
+
     def items(self):
         "See Interface.Common.Mapping.IEnumerableMapping"
         return self._data
@@ -73,7 +73,7 @@
         key = str(self._next)
         self._data += ((key, object), )
         return key
-        
+
     def __delitem__(self, key):
         "See Zope.App.OFS.Container.IContainer.IWriteContainer"
         if key not in self:
@@ -113,7 +113,7 @@
                 j = max(i + direction, 0)
                 while j in indexes:
                     j += 1
-                
+
                 indexes[j] = item
 
         # Fill in the rest where there's room.
@@ -134,7 +134,7 @@
 
     def moveDown(self, names):
         self._moveUpOrDown(names, 1)
-        
+
 
 
 __doc__ = ConfigurationManager.__doc__  + __doc__


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceConfiguration.py 1.4 => 1.4.2.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceConfiguration.py:1.4	Thu Dec  5 12:00:44 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceConfiguration.py	Tue Dec 10 14:16:02 2002
@@ -2,14 +2,14 @@
 #
 # Copyright (c) 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$
@@ -17,17 +17,17 @@
 
 from Interface.Attribute import Attribute
 from Zope.App.OFS.Services.ConfigurationInterfaces \
-     import IComponentConfiguration
+     import INamedComponentConfiguration
 
-class IServiceConfiguration(IComponentConfiguration):
+class IServiceConfiguration(INamedComponentConfiguration):
     """Service Configuration
 
     Service configurations are dependent on the components that they
     configure. They register themselves as component dependents.
-    
+
+    The name of a service configuration is used to determine the service
+    type.
     """
 
-    serviceType = Attribute("The service type id")
 
 __doc__ = IServiceConfiguration.__doc__ + __doc__
-


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceManager.py 1.6 => 1.6.2.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceManager.py:1.6	Mon Dec  9 10:16:35 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceManager.py	Tue Dec 10 14:16:02 2002
@@ -2,27 +2,27 @@
 #
 # 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$
 """
 from Zope.ComponentArchitecture.IServiceService import IServiceService
-from Zope.App.OFS.Services.ConfigurationInterfaces import IConfigurable
+from Zope.App.OFS.Services.ConfigurationInterfaces import INameConfigurable
 from IComponentManager import IComponentManager
 from Interface.Attribute import Attribute
 
-class IServiceManager(IServiceService, IComponentManager, IConfigurable):
+class IServiceManager(IServiceService, IComponentManager, INameConfigurable):
     """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
@@ -31,14 +31,6 @@
     """
 
     Packages = Attribute("""Package container""")
-    
-    def queryConfigurations(service_type):
-        """Return an IConfigurationRegistry for a service type
-        """
-
-    def createConfigurations(service_type):
-        """Create and return an IConfigurationRegistry for a service type
-        """
 
     def getBoundService(name):
         """Retrieve a bound service implementation.
@@ -48,7 +40,3 @@
 
         None is returned if the named service isn't bound locally.
         """
-
-    def getBoundServiceTypes():
-        """Get a sequence of the bound service types"""
-


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceConfiguration.py 1.4 => 1.4.2.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceConfiguration.py:1.4	Thu Dec  5 12:00:44 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceConfiguration.py	Tue Dec 10 14:16:02 2002
@@ -2,53 +2,60 @@
 #
 # Copyright (c) 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$
 """
 
 from IServiceConfiguration import IServiceConfiguration
-from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty
 from IBindingAware import IBindingAware
-from Zope.App.OFS.Services.Configuration import ComponentConfiguration
+from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty
+from Zope.App.OFS.Services.Configuration import NamedComponentConfiguration
 from Zope.ContextWrapper import ContextMethod
+from Zope.ComponentArchitecture import getServiceManager
+
+class ServiceConfiguration(NamedComponentConfiguration):
 
-class ServiceConfiguration(ComponentConfiguration):
     __doc__ = IServiceConfiguration.__doc__
-    
+
     __implements__ = (IServiceConfiguration,
-                      ComponentConfiguration.__implements__)
+                      NamedComponentConfiguration.__implements__)
 
     status = ConfigurationStatusProperty('Services')
 
-    def __init__(self, service_type, *args, **kw):
-        self.serviceType = service_type
+    label = "Service"
+
+    def __init__(self, *args, **kw):
         super(ServiceConfiguration, self).__init__(*args, **kw)
 
-    ############################################################
+    def getInterface(self):
+        service_manager = getServiceManager(self)
+        return service_manager.getInterfaceFor(self.name)
+
+    getInterface = ContextMethod(getInterface)
 
     def activated(self):
         service = self.getComponent()
         if IBindingAware.isImplementedBy(service):
-            service.bound(self.serviceType)
+            service.bound(self.name)
 
     activated = ContextMethod(activated)
 
     def deactivated(self):
         service = self.getComponent()
         if IBindingAware.isImplementedBy(service):
-            service.unbound(self.serviceType)
+            service.unbound(self.name)
 
     deactivated = ContextMethod(deactivated)
-    
+
 __doc__ = ServiceConfiguration.__doc__  + __doc__
 
-            
+


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py 1.13 => 1.13.2.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py:1.13	Mon Dec  9 10:22:20 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py	Tue Dec 10 14:16:02 2002
@@ -2,14 +2,14 @@
 #
 # 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.
-# 
+#
 ##############################################################################
 """XXX I need a summary line.
 
@@ -44,6 +44,7 @@
 from IServiceManager import IServiceManager
 
 from Zope.App.OFS.Services.Configuration import ConfigurationRegistry
+from Zope.App.OFS.Services.Configuration import NameConfigurable
 
 from Persistence.Module import PersistentModuleRegistry
 from Persistence.Module import PersistentModule
@@ -53,20 +54,16 @@
 ModuleType = ModuleType, PersistentModule
 
 
-class ServiceManager(PersistentModuleRegistry):
+class ServiceManager(PersistentModuleRegistry, NameConfigurable):
 
     __implements__ = (IServiceManager, ISimpleReadContainer,
                       PersistentModuleRegistry.__implements__,
+                      NameConfigurable.__implements__,
                       INameResolver)
 
     def __init__(self):
         super(ServiceManager, self).__init__()
-
-        self.__bindings = {}
-        # Bindings is of the form:
-        #
-        # {service_type -> ConfigurationRegistry}
-
+        NameConfigurable.__init__(self)
         self.Packages = Packages()
 
 
@@ -106,13 +103,13 @@
             return self # We are the service service
 
         if not getattr(self, '_v_calling', 0):
-            
+
             self._v_calling = 1
             try:
                 service = self.getBoundService(name)
                 if service is not None:
                     return service
-                    
+
             finally:
                 self._v_calling = 0
 
@@ -131,31 +128,6 @@
 
     getInterfaceFor = ContextMethod(getInterfaceFor)
 
-    def queryConfigurationsFor(self, configuration, default=None):
-        return self.queryConfigurations(configuration.serviceType, default)
-
-    queryConfigurationsFor = ContextMethod(queryConfigurationsFor)
-
-    def queryConfigurations(self, service_type, default=None):
-        registry = self.__bindings.get(service_type, default)
-        return ContextWrapper(registry, self)
-
-    queryConfigurations = ContextMethod(queryConfigurations)
-        
-
-    def createConfigurationsFor(self, configuration):
-        return self.createConfigurations(configuration.serviceType)
-
-    createConfigurationsFor = ContextMethod(createConfigurationsFor)
-
-    def createConfigurations(self, service_type):
-        registry = ConfigurationRegistry()
-        self.__bindings[service_type] = registry
-        self._p_changed = 1
-        return registry
-
-    createConfigurations = ContextMethod(createConfigurations)
-
     def getBoundService(self, name):
         "See Zope.App.OFS.Services.ServiceManager.IServiceManager."
 
@@ -165,17 +137,11 @@
             if configuration is not None:
                 service = configuration.getComponent()
                 return service
-            
+
         return None
 
     getBoundService = ContextMethod(getBoundService)
 
-    def getBoundServiceTypes(self):
-        "See "
-        "Zope.App.OFS.Services.ServiceManager.IServiceManager.IServiceManager"
-        
-        return  self.__bindings.keys()
-
     ############################################################
     # Implementation methods for interface
     # Zope.App.OFS.Services.ServiceManager.IComponentManager.
@@ -208,7 +174,7 @@
         if key == 'Packages':
             return self.Packages
 
-        directives = self.__bindings.get(key)
+        directives = self.queryConfigurations(key)
         if directives and directives[0] is not None:
             return self.queryService(key, default)
 
@@ -222,11 +188,11 @@
         return self.get(key) is not None
 
     def findModule(self, name):
-        # override to pass call up to next service manager 
+        # override to pass call up to next service manager
         mod = super(ServiceManager, removeAllProxies(self)).findModule(name)
         if mod is not None:
             return mod
-        
+
         sm = getNextServiceManager(self)
         try:
             findModule = sm.findModule
@@ -252,7 +218,7 @@
     __import = ContextMethod(__import)
 
     def resolve(self, name):
-        
+
         name = name.strip()
 
         if name.endswith('.') or name.endswith('+'):


=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/configure.zcml 1.8 => 1.8.10.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/configure.zcml:1.8	Sun Dec  1 05:28:22 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/configure.zcml	Tue Dec 10 14:16:02 2002
@@ -45,17 +45,17 @@
         interface="Zope.App.OFS.Container.IContainer.IWriteContainer" />
     <require
         permission="Zope.ManageServices"
-    	interface=".IConfigurationManager.IOrderedContainer" />
-    <factory 
-        id = "Zope.App.OFS.Services.ServiceManager.ConfigurationManager" 
-	permission = "Zope.ManageServices"
-	title = "Configuration Manager" />
+        interface=".IConfigurationManager.IOrderedContainer" />
+    <factory
+        id = "Zope.App.OFS.Services.ServiceManager.ConfigurationManager"
+        permission = "Zope.ManageServices"
+        title = "Configuration Manager" />
   </content>
 
   <content class=".Module.Manager.">
-    <require 
+    <require
         permission="Zope.ManageCode"
-	interface="Persistence.IPersistentModuleManager." />
+        interface="Persistence.IPersistentModuleManager." />
     <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
    </content>
 
@@ -78,7 +78,7 @@
         />
 
   </content>
-  
+
   <include package="Zope.App.OFS.Services.ServiceManager.Browser" />
 
 </zopeConfigure>