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

Jim Fulton jim@zope.com
Thu, 5 Dec 2002 11:20:59 -0500


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

Modified Files:
      Tag: ComponentConfiguration-branch
	Configuration.py ConfigurationInterfaces.py 
Log Message:
Commiting code on branch so I can work on a different ws

=== Zope3/lib/python/Zope/App/OFS/Services/Configuration.py 1.2 => 1.2.8.1 ===
--- 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 11:20:28 2002
@@ -238,3 +238,101 @@
         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:
+            configurations.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.2.8.1 ===
--- 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 11:20:28 2002
@@ -68,6 +68,14 @@
         """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.
+        """
+
 
 class IConfigurationRegistry(Interface):
     """A registry of configurations for a set of parameters