[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager - IServiceConfiguration.py:1.4 ServiceConfiguration.py:1.4 ServiceManager.py:1.12
Jim Fulton
jim@zope.com
Thu, 5 Dec 2002 12:00:45 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv29329/ServiceManager
Modified Files:
IServiceConfiguration.py ServiceConfiguration.py
ServiceManager.py
Log Message:
Created SimpleConfiguration and ComponentConfiguration objects out of
ServiceConfiguration objects to make other component configurations
easier to develop
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceConfiguration.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceConfiguration.py:1.3 Tue Dec 3 13:15:30 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/IServiceConfiguration.py Thu Dec 5 12:00:44 2002
@@ -16,9 +16,10 @@
"""
from Interface.Attribute import Attribute
-from Zope.App.OFS.Services.ConfigurationInterfaces import IConfiguration
+from Zope.App.OFS.Services.ConfigurationInterfaces \
+ import IComponentConfiguration
-class IServiceConfiguration(IConfiguration):
+class IServiceConfiguration(IComponentConfiguration):
"""Service Configuration
Service configurations are dependent on the components that they
@@ -27,12 +28,6 @@
"""
serviceType = Attribute("The service type id")
-
- componentPath = Attribute("The physical path to the component")
-
- def getService():
- """Return the service component named in the directive.
- """
__doc__ = IServiceConfiguration.__doc__ + __doc__
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceConfiguration.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceConfiguration.py:1.3 Tue Dec 3 13:16:58 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceConfiguration.py Thu Dec 5 12:00:44 2002
@@ -15,134 +15,39 @@
$Id$
"""
-__metaclass__ = type
-
-from Persistence import Persistent
-from Zope.Security.Checker import CheckerPublic, InterfaceChecker
-from Zope.Security.Proxy import Proxy
-from Zope.App.DependencyFramework.Exceptions import DependencyError
-from Zope.App.Traversing import traverse
from IServiceConfiguration import IServiceConfiguration
-from Zope.Proxy.ProxyIntrospection import removeAllProxies
-from Zope.App.Traversing import getPhysicalRoot
-from Zope.ComponentArchitecture import getService, getServiceManager
-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
from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty
-from Zope.ContextWrapper import ContextProperty
from IBindingAware import IBindingAware
-from Zope.App.OFS.Services.ConfigurationInterfaces import Active
-from Zope.App.OFS.Services.ConfigurationInterfaces import Registered
-from Zope.App.OFS.Services.ConfigurationInterfaces import Unregistered
+from Zope.App.OFS.Services.Configuration import ComponentConfiguration
+from Zope.ContextWrapper import ContextMethod
-class ServiceConfiguration(Persistent):
+class ServiceConfiguration(ComponentConfiguration):
__doc__ = IServiceConfiguration.__doc__
- __implements__ = IServiceConfiguration, IAddNotifiable, IDeleteNotifiable
+ __implements__ = (IServiceConfiguration,
+ ComponentConfiguration.__implements__)
status = ConfigurationStatusProperty('Services')
- def __init__(self, service_type, component_path, permission=None):
+ def __init__(self, service_type, *args, **kw):
self.serviceType = service_type
- self.componentPath = component_path
- if permission == 'Zope.Public':
- permission = CheckerPublic
-
- self.permission = permission
-
- def __repr__(self):
- return "service(%s, %s)" % (self.serviceType, self.componentPath)
-
- ############################################################
- # Implementation methods for interface
- # Zope.App.OFS.Services.ServiceManager.IServiceConfiguration.
-
- def getService(self):
- service_manager = getServiceManager(self)
-
- service = getattr(self, '_v_service', None)
- if service is None:
-
- # We have to be clever here. We need to do an honest to
- # god unrestricted traveral, which means we have to
- # traverse from an unproxies object. But, it's not enough
- # for the service manager to be unproxies, because the
- # path is an absolute path. When absolute paths are
- # traversed, the traverser finds the physical root and
- # traverses from there, so we need to make sure the
- # physical root isn;t proxied.
-
- # get the root and unproxy it.
- root = removeAllProxies(getPhysicalRoot(service_manager))
- service = traverse(root, self.componentPath)
-
- if self.permission:
- if type(service) is Proxy:
- # XXX what is this?
- service = removeSecurityProxy(service)
-
- interface = service_manager.getInterfaceFor(self.serviceType)
-
- checker = InterfaceChecker(interface, self.permission)
-
- service = Proxy(service, checker)
-
-
- self._v_service = service
-
-
- return service
-
- getService.__doc__ = IServiceConfiguration['getService'].__doc__
-
- getService = ContextMethod(getService)
+ super(ServiceConfiguration, self).__init__(*args, **kw)
############################################################
def activated(self):
- service = self.getService()
+ service = self.getComponent()
if IBindingAware.isImplementedBy(service):
service.bound(self.serviceType)
activated = ContextMethod(activated)
def deactivated(self):
- service = self.getService()
+ service = self.getComponent()
if IBindingAware.isImplementedBy(service):
service.unbound(self.serviceType)
deactivated = ContextMethod(deactivated)
-
- def manage_afterAdd(self, configuration, container):
- "See Zope.App.OFS.Container.IAddNotifiable"
- sm = getServiceManager(configuration)
- service = configuration.getService()
- dependents = getAdapter(service, IDependable)
- objectpath = getPhysicalPathString(configuration)
- dependents.addDependent(objectpath)
-
- def manage_beforeDelete(self, configuration, container):
- "See Zope.App.OFS.Container.IDeleteNotifiable"
- assert self == configuration
- sm = getServiceManager(self)
- service = self.getService()
- objectstatus = self.status
- dependents = getAdapter(service, IDependable)
- objectpath = getPhysicalPathString(self)
-
- if objectstatus == Active:
- raise DependencyError("Can't delete active configurations")
- elif objectstatus == Registered:
- self.status = Unregistered
-
- dependents.removeDependent(objectpath)
-
- manage_beforeDelete = ContextMethod(manage_beforeDelete)
__doc__ = ServiceConfiguration.__doc__ + __doc__
=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py 1.11 => 1.12 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py:1.11 Tue Dec 3 12:45:20 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/ServiceManager.py Thu Dec 5 12:00:44 2002
@@ -163,7 +163,7 @@
if registry:
configuration = registry.active()
if configuration is not None:
- service = configuration.getService()
+ service = configuration.getComponent()
return service
return None