[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services - Configuration.py:1.3 ConfigurationInterfaces.py:1.3

Jim Fulton jim@zope.com
Thu, 5 Dec 2002 12:01:14 -0500


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

Modified Files:
	Configuration.py ConfigurationInterfaces.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/Configuration.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Services/Configuration.py:1.2	Sat Nov 30 13:35:55 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Configuration.py	Thu Dec  5 12:00:44 2002
@@ -21,7 +21,7 @@
 __metaclass__ = type
 
 from Persistence import Persistent
-from ConfigurationInterfaces import IConfigurationRegistry
+from ConfigurationInterfaces import IConfigurationRegistry, IConfiguration
 from Zope.Schema import Text
 from Zope.ComponentArchitecture import getService, getServiceManager
 from Zope.App.Traversing import getPhysicalPathString, traverse
@@ -29,6 +29,13 @@
      import Unregistered, Registered, Active
 from Zope.Proxy.ContextWrapper import ContextWrapper
 from Zope.ContextWrapper import ContextMethod
+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.App.DependencyFramework.Exceptions import DependencyError
+from Zope.ComponentArchitecture import getServiceManager, getAdapter
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
+from Zope.App.Traversing import getPhysicalRoot, traverse
 
 class ConfigurationStatusProperty:
 
@@ -238,3 +245,100 @@
         return result
 
     info = ContextMethod(info)
+
+class SimpleConfiguration(Persistent):
+    """Configutaion objects that just contain configuration data
+    """
+    
+    __implements__ = IConfiguration, IDeleteNotifiable
+
+    title = description = u''
+
+    def activated(self):
+        pass
+
+    def deactivated(self):
+        pass
+        
+    def manage_beforeDelete(self, configuration, container):
+        "See Zope.App.OFS.Container.IDeleteNotifiable"
+        
+        objectstatus = configuration.status
+        
+        if objectstatus == Active:
+            raise DependencyError("Can't delete active configurations")
+        elif objectstatus == Registered:
+            configuration.status = Unregistered
+
+class ComponentConfiguration(SimpleConfiguration):
+    """Component configuration
+    """
+
+    __implements__ = SimpleConfiguration.__implements__, IAddNotifiable
+
+    def __init__(self, component_path, permission=None):
+        self.componentPath = component_path
+        if permission == 'Zope.Public':
+            permission = CheckerPublic
+            
+        self.permission = permission
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.OFS.Services.ServiceManager.IServiceConfiguration.
+
+    def getComponent(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 unproxied 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
+
+    getComponent = ContextMethod(getComponent)
+
+    ############################################################
+
+    def manage_afterAdd(self, configuration, container):
+        "See Zope.App.OFS.Container.IAddNotifiable"
+        component = configuration.getComponent()
+        dependents = getAdapter(component, IDependable)
+        objectpath = getPhysicalPathString(configuration)
+        dependents.addDependent(objectpath)
+        
+    def manage_beforeDelete(self, configuration, container):
+        "See Zope.App.OFS.Container.IDeleteNotifiable"
+        super(ComponentConfiguration, self
+              ).manage_beforeDelete(configuration, container)        
+        component = configuration.getComponent()
+        dependents = getAdapter(component, IDependable)
+        objectpath = getPhysicalPathString(configuration)
+        dependents.removeDependent(objectpath)


=== Zope3/lib/python/Zope/App/OFS/Services/ConfigurationInterfaces.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConfigurationInterfaces.py:1.2	Sat Nov 30 13:35:55 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConfigurationInterfaces.py	Thu Dec  5 12:00:44 2002
@@ -17,6 +17,7 @@
 """
 
 from Interface import Interface
+from Interface.Attribute import Attribute
 from Zope.Schema import Text, TextLine
 from Zope.Schema.IField import ITextLine
 
@@ -66,6 +67,14 @@
 
     def deactivated():
         """Method called when a configuration is made inactive
+        """
+
+class IComponentConfiguration(IConfiguration):
+
+    componentPath = Attribute("The physical path to the component")
+
+    def getComponent():
+        """Return the component named in the configuration.
         """