[Zope3-dev] Containment constraints

Jim Fulton jim@zope.com
Thu, 12 Jun 2003 06:19:00 -0400


Containers often have constrains on the items they contain. For
example:

* Regular folders should only contain regular content.

* Site management folders should only contain "meta" content.

* Site managers only contain site-management folders.

* Page folders only contain ZPT templates and registration
   managers.

* Site-management folders and page folders must contain exactly
   one registration manager.

Similarly, objects may have constraints on the containers that
they can be contained in.

Some of these constraints can, and perhaps should, be handled by
code in container setObject methods, however:

* We may want to impose containment constraints externally to a
   container. For example, we may use a marker interface to
   identify specialized containers according to use. Imagine a "news
   folder" that is a specialized use of a folder. We want to constrain
   news folders to contain only news items.

* A container's setObject method has no way to check constraints
   that items may place on their containers.

We currently rely on add-meny registration to constrain adding
objects to containers.  This works reasonably well for adding
objects.

The adding menu approach doesn't help with copy and move, however.  We
can embed constraints in the various adapters used for copy and
move. For example, IObjectCopier and IObjectMover adapters could check
constraints on an object's container. IPasteTarget adapters can check
constraints on a container's items.

Alternatively, we could provide IObjectAddedEvent subscribers that
veto inappropriate combinations of containers and items.

It might be useful to abstract the containment constraints into some
separate specification and registry. This would allow the constraints
to be shared among adding, copying and moving. Possibly, it would be
simpler to express abstract constraints than to write constraining
code in the various adapters.  We would need to come up with some ways
to express these constraints.

Here are some example constraints:

- Folders can contain only ordinary content.

   Ordinary content is content that has a content type.

- Site-management folders can only contain meta content.

   Meta content is content that has a meta-content type.

- Site-management folders can only contain: IUseConfigurable,
   IConfigurationManagerContainer, or IConfigurationManager objects.

- IUseConfigurable and IConfigurationManager objects can only be
   contained in IConfigurationManagerContainers.

- IConfigurationManagerContainers can only be contained in sites or in
   IConfigurationManagerContainers.

- Sites can only IConfigurationManagerContainers.  Maybe sites can
   only contain site-management folders and bundles.

- (Future) Pluggable authentication services can only contain principal
   sources. Principal sources can only be contained in pluggable
   authentication services.  A user folder (a simple principal source)
   can only contain users.

Note that most of these constraints are expressed as allowable
combinations of interfaces. Also, we'll often want to add constraints
to sub-types.

Thoughts? Suggestions? :)

Jim

-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (703) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org