RE: [Zope-dev] The Application object
I'm not sure I understand. What is AppSingleton? What does the Instance() method do?
-----Original Message----- From: Jeff K. Hoffman [mailto:jeff.hoffman@goingv.com] Sent: Monday, July 17, 2000 11:54 AM To: zope-dev@zope.org Subject: [Zope-dev] The Application object
Hello,
What is the easiest way for me to get ahold of the Application object at run-time?
I am writing a Product that needs to access some things in the Control_Panel, and need the app object to get there.
I know how to do it given a reference to an object in the ZODB (getPhysicalRoot(), etc.), but need a way to do it given no references. I need something like:
import AppSingleton
app = AppSingleton.Instance() app.Control_Panel.blah
--Jeff
--- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff.hoffman@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
On Mon, 17 Jul 2000, Chris McDonough wrote:
I'm not sure I understand. What is AppSingleton? What does the Instance() method do?
Sorry I wasn't clear enough. The Singleton is a design pattern from the Gang of Four book that fits this situation well. It is a class that is meant to control access to the one and only instance of a global variable. I was just using that as a frame of reference, though; Zope has no such class for the Application object, or I wouldn't be writing this message. I just need some way of getting at the one and only Application object at run-time. Something like: from Globals import app myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') ... Given a reference to an object in the ZODB, I can do this via: app = self.getPhysicalRoot() myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') But, this does not work from methods like __init__, or __setstate__, where we do not have a physical location in the ZODB, yet. I just need a reference to the app object. I know the answer has to be simple, but I can't find it. --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff.hoffman@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
On Mon, Jul 17, 2000 at 12:21:42PM -0400, Jeff K. Hoffman wrote:
On Mon, 17 Jul 2000, Chris McDonough wrote:
I'm not sure I understand. What is AppSingleton? What does the Instance() method do?
Sorry I wasn't clear enough. The Singleton is a design pattern from the Gang of Four book that fits this situation well. It is a class that is meant to control access to the one and only instance of a global variable. I was just using that as a frame of reference, though; Zope has no such class for the Application object, or I wouldn't be writing this message.
I just need some way of getting at the one and only Application object at run-time. Something like:
from Globals import app myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') ...
Given a reference to an object in the ZODB, I can do this via:
app = self.getPhysicalRoot() myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo')
But, this does not work from methods like __init__, or __setstate__, where we do not have a physical location in the ZODB, yet.
I just need a reference to the app object. I know the answer has to be simple, but I can't find it.
See the __init__.py method of ZScheduler, which can be found on Zope.org. ZScheduler uses a Singleton as well. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | ZopeStudio: http://www.zope.org/Products/ZopeStudio -----------------------------------------------------
participants (3)
-
Chris McDonough -
Jeff K. Hoffman -
Martijn Pieters