[Bio] / CatalogServices / CatalogEntry.py Repository:
ViewVC logotype

View of /CatalogServices/CatalogEntry.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (download) (as text) (annotate)
Fri Mar 11 21:33:12 2005 UTC (15 years, 2 months ago) by efrank
Branch: MAIN
CVS Tags: before-dynamics-persistence, lwc, treatman-lastDay-0, preTreatmanDyn, HEAD
Changes since 1.13: +13 -14 lines
1. introduce Model as king of the hill rather than RecoElem.
2. migrations to follow
3. new modules for by-peg filtering
4. first stab at externalized app fwk
5. moved seed data factory

bunch of timing code still in this ...need to take out

#-----------------------------------------------------------------------------
# Name:        CatalogEntry.py
# Purpose:     An entry in the catalog: think of it like a directory
#              or like a file (depending upon isTerminal value).
#              You can move down to subdirectories, but if isTerminal() is
#              ture, then this is a terminal node in the catalog tree
#
# History:
#              02Feb04 efrank      First version
#
# Bugs:
#
# RCS-ID:      $Id: CatalogEntry.py,v 1.14 2005/03/11 21:33:12 efrank Exp $
# Copyright:   (c) 2004
# Licence:     See COPYING.TXT
#-----------------------------------------------------------------------------
"""
"""
__revision__ = "$Id: CatalogEntry.py,v 1.14 2005/03/11 21:33:12 efrank Exp $"
__docformat__ = "restructuredtext en"

from KahOM.Model                      import Model
from CatalogServices.Catalog          import Catalog
from CatalogServices.CatalogEntryBase import CatalogEntryBase

#import logging
#log = logging.getLogger("AG.toolkit")




#------------------------------------------------------------------
class CatalogEntry( CatalogEntryBase):
#------------------------------------------------------------------
    """
    An entry in the catalog: think of it like a directory. You can move
    down to subdirectories, but if isTerminal() is true, then this is a 
    terminal node in the tree.
    """

    #------------------------------------------------------------------
    def __init__(self, aFactory,  path, name, isTerminal):
    #------------------------------------------------------------------
        """
            @type aFactory: aFactory 
            @type path:   string.  full path, including node name
            @type name:   string
            @type isTerminal:  0 (is not terminal) or 1 (is terminal)
            this is dumb..should pull name off the end of path!
        """

        CatalogEntryBase.__init__(self, path, name, isTerminal)

        # will be set when data are associated with this CatalogEntry

        self.factory = aFactory
        """
        The factory for the associated with this catEntry.
        This is a shortcut for going back to the catalog.        
        Value is type set in __init__ of derived class and protected
        from change thereafter
        """

        return


    #------------------------------------------------------------------
    def entries(self):
    #------------------------------------------------------------------
        """ 
        Implement in derivative classes.  Returns list of CatalogEntries
        that are children of this CatalogEntry. Throws except if isTerminal is
        true. Note that some "children" are terminal, some are not.
        """

        raise Exception, "CatalogEntry: entries() not implemented in derivative.", self.__class__
        return

    #------------------------------------------------------------------
    def read(self, versionNumber=None):
    #------------------------------------------------------------------
        """
        Read the data associated with this catalogEntry for the specified
        verions number.  If no version number is specified, then return the
        biggest.

        @type version Number: int
        @rtype              : KahOM.Model
        """

        if (not self.isTerminal() ):
            raise Exception, "Invalid operation on directory"
    
        foundryItemKey = self.getFoundryItem( versionNumber )
        if (None == foundryItemKey):
            # why do we do this??
            model = Model( self.name())
        else:
            model = self.factory.getModelByFoundryItemKey( foundryItemKey)

        return model
         
    #------------------------------------------------------------------
    def write(self, model):
    #------------------------------------------------------------------
        """
        Write the passed item to the database, create a new version of
        this catEntry and associate them.
        @type model :  KahOM.Model
        @rtype      :  FoundryServices.FoundryItemKey
        
        """

        if (not self.isTerminal() ):
            raise Exception, "Can only write to terminal catalog entry"

        fik = self.factory.write( model, commit=1 )

        # update the CatalogEntry if write succeeded.  shouldn't have
        # None at this point ???
       
        if ((not fik == None ) and (not fik.getFoundryIdVal() == "Memory" ) ):
            self.setFoundryItem( fik )

        return fik

    #------------------------------------------------------------------
    def versions(self):
    #------------------------------------------------------------------
        """ 
        Implement in derivative classes.
        Returns list of integers.
        CatalogEntries are associated with FoundryItems. That association
        is versioned (which we interpret as versioning of the FoundryItem).
        This method returns a list of avail version numbers. This list may be
        empty, meaning nothing has been assoicated.  CatalogEntry derivatives
        corresponding to DataFactories that do *not* support versioning must
        implement this method anyway: such factories act as if there is a
        single version associated, named version 0, and they throw and
        exception in setFoundryItem if there is ever an attempt to associate
        a foundry item with a catalogentry for a second time (no re-assigns).

        @rtype: empty list
        """

        raise Exception, "CatalogEntry: listFoundryItemVersrions() not implemented in derivative", self.__class__

        return []

    #------------------------------------------------------------------
    def setFoundryItem(self, theItem):
    #------------------------------------------------------------------
        """ 
        Implement in derivative classes.  theItem is an instance of FoundryItemKey.
        A CatalogEntry locates an instance of the object model. That instance
        is located via a FoundryItemKey. setFoundryItem() makes a
        CatalogEntry "point at" data by recording the FoundryItemKey.  This
        assoication is versioned and is an "owns" relationship. Versioned means
        that, if setFoundryItem is called when there's already an item associated,
        the implementation must either a) fault b) store the new and differentiate
        new/old with an integral version number.

        @type theItem: FoundryItemKey

        """

        raise Exception, "CatalogEntry: setFoundryItem() not implemented in derivative", self.__class__

        return
    
    #------------------------------------------------------------------
    def getFoundryItem(self, versionNumber=None):
    #------------------------------------------------------------------
        """ 
        Implement in derivative classes.  
        A CatalogEntry locates an instance of the object model. That instance
        is located via a FoundryItemKey. getFoundryItemKey returns the FoundryItemKey
        of the associated object.  If there isn't one, None is returned.  You
        can pass in an optional version number.  Lacking a version number, you get
        the default version.  The default need not be the most recent!

        @type versionNumber: None
        """

        raise Exception, "CatalogEntry: getFoundryItem() not implemented in derivative", self.__class__
    
        return

    #------------------------------------------------------------------
    def mkDir(self, name):
    #------------------------------------------------------------------
        """
        Makes a new CatalogEntry that is a child of the present one that is
        intended to hold other CatlogEntries (not data).

        @type name: string
        """

        raise Exception, "CatalogEntry: mkDir() not implemented in derivative", self.__class__
    

        return

    #------------------------------------------------------------------
    def mkItem(self, name):
    #------------------------------------------------------------------
        """
        Makes a new CatalogEntry that is a child of the present one that
        is intended to be a leaf in the hierarchy, i.e., it will have data
        associated with it at some point.  The CatalogEntry is returned.

        @type name: string
        """

        raise Exception, "CatalogEntry: mkItem() not implemented in derivative", self.__class__
    
        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3