[Dev] More content model changes

Morgen Sagen morgen at osafoundation.org
Wed Dec 15 11:06:04 PST 2004

While working on the content model I noticed there was *lots* of 
boilerplate code for looking up the kinds corresponding to the various 
classes, and thought it could be simplified by adding a new base class 
(between Item and ContentItem) which would supply methods for doing 
kind lookups (with UUID caching) and also for setting a new item's 
parent automatically.  I was able to remove all the _setUUIDs( ) 
methods as well as all of the getXXXKind( ) -type methods.  Now, each 
class within the content model should inherit (directly or indirectly) 
from ChandlerItem if it is going to have an associated kind -- 
ContentItem already does this -- and define two class attributes: 
myKindID (initialized to None) and myKindPath (initialized to the 
repository path of the corresponding kind).  You can then ask any 
ChandlerItem subclass for its Kind via cls.getKind( ), and when 
creating an instance of a ChandlerItem, you don't need to pass in kind 
or parent (by default the kind will be looked up, and the parent will 
be //userdata/contentitems).

Better name suggestions for this new class are welcome.  I ended up 
defining the ChandlerItem class because this is behavior that doesn't 
belong in Item and not all content model items are ContentItems.

Here is an example of the boilerplate code that will disappear in each 
content model parcel:

     def _setUUIDs(self):
         calendarEventKind = self['CalendarEvent']
         CalendarParcel.calendarEventKindID = calendarEventKind.itsUUID

         locationKind = self['Location']
         CalendarParcel.locationKindID = locationKind.itsUUID

         calendarKind = self['Calendar']
         CalendarParcel.calendarKindID = calendarKind.itsUUID

         recurrenceKind = self['RecurrencePattern']
         CalendarParcel.recurrencePatternKindID = recurrenceKind.itsUUID

         calendarEventMixinKind = self['CalendarEventMixin']
         CalendarParcel.calendarEventMixinKindID = 

     def onItemLoad(self):
         super(CalendarParcel, self).onItemLoad()

     def startupParcel(self):
         super(CalendarParcel, self).startupParcel()

     def getCalendarEventKind(cls):
         assert cls.calendarEventKindID, "CalendarParcel not yet loaded"
         return Globals.repository[cls.calendarEventKindID]

     getCalendarEventKind = classmethod(getCalendarEventKind)

     def getCalendarEventMixinKind(cls):
         assert cls.calendarEventMixinKindID, "CalendarParcel not yet 
         return Globals.repository[cls.calendarEventMixinKindID]

     getCalendarEventMixinKind = classmethod(getCalendarEventMixinKind)

     def getLocationKind(cls):
         assert cls.locationKindID, "CalendarParcel not yet loaded"
         return Globals.repository[cls.locationKindID]

     getLocationKind = classmethod(getLocationKind)

     def getCalendarKind(cls):
         assert cls.calendarKindID, "CalendarParcel not yet loaded"
         return Globals.repository[cls.calendarKindID]

     getCalendarKind = classmethod(getCalendarKind)

     def getRecurrencePatternKind(cls):
         assert cls.recurrencePatternKindID, "CalendarParcel not yet 
         return Globals.repository[cls.recurrencePatternKindID]

     getRecurrencePatternKind = classmethod(getRecurrencePatternKind)

     # The parcel knows the UUIDs for the Kinds, once the parcel is 
     calendarEventKindID = None
     calendarEventMixinKindID = None
     locationKindID = None
     calendarKindID = None
     recurrencePatternKindID = None

More information about the Dev mailing list