Author: jmorliaguet
Date: Thu Dec 15 00:14:58 2005
New Revision: 2032

Modified:
   cpsskins/branches/jmo-perspectives/elements/format.py
   cpsskins/branches/jmo-perspectives/engines/authoring/jsonrpc.py
   cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py
   cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py
   cpsskins/branches/jmo-perspectives/engines/default/formats/style.py
   cpsskins/branches/jmo-perspectives/engines/default/formats/widget.py
   cpsskins/branches/jmo-perspectives/perspectives/perspective.py
   cpsskins/branches/jmo-perspectives/setup/registration.py
Log:

- simpler registration of factories

- we use the component architecture API to create objects



Modified: cpsskins/branches/jmo-perspectives/elements/format.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/format.py       (original)
+++ cpsskins/branches/jmo-perspectives/elements/format.py       Thu Dec 15 
00:14:58 2005
@@ -19,8 +19,7 @@
 
 from zope.app.location.pickling import locationCopy
 from zope.app.traversing.interfaces import IPathAdapter, ITraversable
-from zope.component import getUtility, queryUtility
-from zope.component.interfaces import IFactory
+from zope.component import getUtility, queryUtility, createObject
 from zope.interface import implements
 from zope.security.proxy import removeSecurityProxy
 
@@ -135,8 +134,7 @@
         return names
 
     def addFormat(self, name=u'', type=u''):
-        factory = getUtility(IFactory, name)
-        format = factory()
+        format = createObject(name)
         format.type = type
         self.storeFormat(format)
         return self.setFormat(format)

Modified: cpsskins/branches/jmo-perspectives/engines/authoring/jsonrpc.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/authoring/jsonrpc.py     
(original)
+++ cpsskins/branches/jmo-perspectives/engines/authoring/jsonrpc.py     Thu Dec 
15 00:14:58 2005
@@ -22,7 +22,7 @@
 from zope.app.event.objectevent import ObjectCreatedEvent
 from zope.app.traversing.api import getParent
 from zope.app.zapi import getMultiAdapter
-from zope.component.interfaces import IFactory
+from zope.component import createObject
 from zope.event import notify
 from zope.interface import implements
 
@@ -91,8 +91,7 @@
         request = self.request
         container = self._getElementById(id)
 
-        factory = zapi.getUtility(IFactory, type_name)
-        content = factory()
+        content = createObject(type_name)
         notify(ObjectCreatedEvent(content))
 
         adding = getMultiAdapter((container, request), INodeAdding)

Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py        
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py        
Thu Dec 15 00:14:58 2005
@@ -18,7 +18,7 @@
 __docformat__ = "reStructuredText"
 
 from persistent import Persistent
-from zope.component.interfaces import IFactory
+from zope.component.factory import Factory
 from zope.interface import implements, implementedBy
 from zope.i18nmessageid import MessageFactory
 from zope.schema import Choice, Int, Bool
@@ -79,18 +79,6 @@
     def __repr__(self):
         return "<Effect of type: %s>" % self.type
 
-class EffectFactory(object):
-
-    implements(IFactory)
-
-    title = "Effect Factory"
-    description = "A Factory that creates Effects"
-
-    def __call__(self):
-        return Effect()
-
-    def getInterfaces(self):
-        return implementedBy(Effect)
-
-EffectFactory = EffectFactory()
+EffectFactory = Factory(Effect, "Effect Factory",
+                        "A Factory that creates Effects")
 

Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py        
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py        
Thu Dec 15 00:14:58 2005
@@ -21,7 +21,7 @@
 from persistent import Persistent
 
 from zope.app.traversing.interfaces import ITraversable
-from zope.component.interfaces import IFactory
+from zope.component.factory import Factory
 from zope.interface import implements, implementedBy
 from zope.interface.common.mapping import IMapping
 
@@ -87,18 +87,6 @@
 
     has_key = __contains__
 
-class LayoutFactory(object):
-
-    implements(IFactory)
-
-    title = "Layout Factory"
-    description = "A Factory that creates Layouts"
-
-    def __call__(self):
-        return Layout()
-
-    def getInterfaces(self):
-        return implementedBy(Layout)
-
-LayoutFactory = LayoutFactory()
+LayoutFactory = Factory(Layout, "Layout Factory",
+                        "A Factory that creates Layouts")
 

Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/style.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/style.py 
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/style.py Thu Dec 
15 00:14:58 2005
@@ -20,7 +20,7 @@
 from BTrees.OOBTree import OOBTree
 from persistent import Persistent
 
-from zope.component.interfaces import IFactory
+from zope.component.factory import Factory
 from zope.interface import implements, implementedBy
 from zope.interface.common.mapping import IMapping
 from zope.i18nmessageid import MessageFactory
@@ -152,19 +152,5 @@
 
     __contains__ = has_key
 
-
-class StyleFactory(object):
-
-    implements(IFactory)
-
-    title = "Style Factory"
-    description = "A Factory that creates Styles"
-
-    def __call__(self):
-        return Style()
-
-    def getInterfaces(self):
-        return implementedBy(Style)
-
-StyleFactory = StyleFactory()
+StyleFactory = Factory(Style, "Style Factory", "A Factory that creates Styles")
 

Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/widget.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/widget.py        
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/widget.py        
Thu Dec 15 00:14:58 2005
@@ -19,7 +19,7 @@
 
 from persistent import Persistent
 from zope.component import getUtilitiesFor
-from zope.component.interfaces import IFactory
+from zope.component.factory import Factory
 from zope.interface import implements, implementedBy
 from zope.i18nmessageid import MessageFactory
 from zope.schema.vocabulary import SimpleVocabulary
@@ -60,20 +60,8 @@
     def __repr__(self):
         return "Widget('%s')" % self.type
 
-class WidgetFactory(object):
-
-    implements(IFactory)
-
-    title = "Widget Factory"
-    description = "A Factory that creates Widgets"
-
-    def __call__(self):
-        return Widget()
-
-    def getInterfaces(self):
-        return implementedBy(Widget)
-
-WidgetFactory = WidgetFactory()
+WidgetFactory = Factory(Widget, "Widget Factory",
+                        "A Factory that creates Widgets")
 
 def WidgetsVocabulary(context):
     """A vocabulary that contains the list of widgets in a given category.

Modified: cpsskins/branches/jmo-perspectives/perspectives/perspective.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/perspectives/perspective.py      
(original)
+++ cpsskins/branches/jmo-perspectives/perspectives/perspective.py      Thu Dec 
15 00:14:58 2005
@@ -21,7 +21,7 @@
 
 from zope.app.publisher.browser import BrowserView
 from zope.component import adapts
-from zope.component.interfaces import IFactory
+from zope.component.factory import Factory
 from zope.interface import implements, implementedBy
 
 from cpsskins.perspectives.interfaces import IPerspective
@@ -50,20 +50,8 @@
     def __eq__(self, other):
         return str(self) == other
 
-class PerspectiveFactory(object):
-
-    implements(IFactory)
-
-    title = "Perspective Factory"
-    description = "A Factory that creates Perspectives"
-
-    def __call__(self):
-        return Perspective()
-
-    def getInterfaces(self):
-        return implementedBy(Perspective)
-
-PerspectiveFactory = PerspectiveFactory()
+PerspectiveFactory = Factory(Perspective, "Perspective Factory",
+                             "Factory that creates Perspectives")
 
 class Relatable(object):
     """This adapter makes perspectives relatable.

Modified: cpsskins/branches/jmo-perspectives/setup/registration.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/setup/registration.py    (original)
+++ cpsskins/branches/jmo-perspectives/setup/registration.py    Thu Dec 15 
00:14:58 2005
@@ -25,8 +25,7 @@
 from xml.dom.minidom import parse
 from xml.parsers.expat import ExpatError
 
-from zope.component import queryUtility, getUtility
-from zope.component.interfaces import IFactory
+from zope.component import getUtility, createObject
 
 from cpsskins.io.interfaces import IDataImporter
 from cpsskins.setup.interfaces import IResourceManager
@@ -65,12 +64,9 @@
                 logger.debug("no resource found for %s" % name)
                 continue
             resource = resource[0]
-            factory = queryUtility(IFactory, resource.tagName)
-            if factory is None:
-                continue
 
             # create the resource
-            resource_object = factory()
+            resource_object = createObject(resource.tagName)
 
             # load the data
             IDataImporter(resource_object).load(resource.toxml())
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to