Hi!

In Zope there are two ways to register content classes and factories:

Oldstyle::

    class Foo:
        meta_type = 'Foo Type'

    def manage_addFoo(folder, id):
        ob = Foo(id)
        folder._setObject(id, ob)

    context.registerClass(
        Foo,
        constructors=('manage_addFoo',),
        permission=AddFoo,
        )

Newstyle::

    class Foo:
        # the meta_type attribute is added by registerClass

    FooFactory = Factory(Foo)

    <five:registerClass
        class=".Foo"
        meta_type="Foo Type"
        permission="fooproduct.AddFoo"
        />

    <factory
        component=".FooFactory"
        id="fooproduct.foo"
        />


Oldstyle factories are used this way::

    dispatcher = folder.manage_addProduct['FooProduct']
    dispatcher.manage_addFoo('foo')

And newstyle factories like this::

    factory = getUtility(IFactory, 'fooproduct.foo')
    ob = factory(id)
    folder._setObject(id, obj)

FactoryTypeInformation currently just supports oldstyle factories.


Proposal
========

If the 'product' property of a type info instance is empty the 'factory' property is interpreted as a newstyle factory ID.


Risks
=====

Newstyle factories are placeless, they know nothing about the container and can't add the objects themselves to the container. There are many complex factories out there that can't be easily replaced by newstyle factories. So we can't deprecate the old way - at least for now.


Any feedback is welcome. If there are no objections I'll check in the proposed change on the trunk.


Cheers,

        Yuppie

_______________________________________________
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to