def for_class(digobj, repo):
        '''Generate a ContentModel object for the specified
        :class:`DigitalObject` class.  Content model object is saved
        in the specified repository if it doesn't already exist.'''
        full_name = '%s.%s' % (digobj.__module__, digobj.__name__)
        cmodels = getattr(digobj, 'CONTENT_MODELS', None)
        if not cmodels:
            logger.debug('%s has no content models', full_name)
            return None
        if len(cmodels) > 1:
            logger.debug('%s has %d content models', full_name, len(cmodels))
            raise ValueError(('Cannot construct ContentModel object for ' +
                              '%s, which has %d CONTENT_MODELS (only 1 is ' +
                              'supported)') %
                             (full_name, len(cmodels)))

        cmodel_uri = cmodels[0]
        logger.debug('cmodel for %s is %s', full_name, cmodel_uri)
        cmodel_obj = repo.get_object(cmodel_uri, type=ContentModel,
                                     create=False)
        if cmodel_obj.exists:
            logger.debug('%s already exists', cmodel_uri)
            return cmodel_obj

        # otherwise the cmodel doesn't exist. let's create it.
        logger.debug('creating %s from %s', cmodel_uri, full_name)
        cmodel_obj = repo.get_object(cmodel_uri, type=ContentModel,
                                     create=True)
        # XXX: should this use _defined_datastreams instead?
        for ds in digobj._local_datastreams.values():
            ds_composite_model = cmodel_obj.ds_composite_model.content
            type_model = ds_composite_model.get_type_model(ds.id, create=True)
            type_model.mimetype = ds.default_mimetype
            if ds.default_format_uri:
                type_model.format_uri = ds.default_format_uri
        cmodel_obj.save()
        return cmodel_obj