[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - DependencyChecker.py:1.2

Jim Fulton jim@zope.com
Mon, 18 Nov 2002 18:47:58 -0500


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

Added Files:
	DependencyChecker.py 
Log Message:
Provide a object removal subscriber that checks that we can't delete
objects with dependents.


=== Zope3/lib/python/Zope/App/OFS/Container/DependencyChecker.py 1.1 => 1.2 ===
--- /dev/null	Mon Nov 18 18:47:58 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/DependencyChecker.py	Mon Nov 18 18:47:58 2002
@@ -0,0 +1,43 @@
+##############################################################################
+#
+# 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.
+# 
+##############################################################################
+"""Objects that take care of annotating dublin core meta data times
+
+$Id$
+"""
+from Zope.ComponentArchitecture import queryAdapter
+from Zope.App.DependencyFramework.IDependable import IDependable
+from Zope.App.DependencyFramework.Exception import DependencyError
+from Zope.Event.ISubscriber import ISubscriber
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
+class DependencyChecker:
+    """Checking dependency  while deleting object
+    """
+    __implements__ = ISubscriber
+    
+    def __init__(self):
+        pass
+
+    def notify(self, event):
+        object = removeAllProxies(event.object)
+        dependency = queryAdapter(object, IDependable)
+        if dependency is not None:
+            if dependency.dependents():
+                raise DependencyError(" Removal of object dependable")
+            
+
+    
+CheckDependency = DependencyChecker() 
+    
+        
+