コード例 #1
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def __init__(self, *oargs, **nargs):
     """Initialise an OWL function.
     
         args: an argument list for auto-populating associations upon creation
             of an object.
     
     """
     # Some helper variables to make typing easier
     self._universe = OwlUniverse.get_universe()
     
     # If we are an abstract - then throw an exception
     if self.is_abstract() is True:
         raise Exception("Cannot instantiate an abstract class")
     
     # Prepare data stores
     self._references = dict()
     self._data = dict()
     for attr in self.associations():
         self._data[attr.id()] = None
         setattr(self, attr.id(), attr(self))
     
     # For each named argument, run its method
     for k,v in nargs.iteritems():
         self.association(k, v)
 
     # TODO: We should be mandating that objects are instantiated with
     #    mandatory associations provided as arguments at creation time.
     #    This involves some sort of positive validation I suppose.
 
     # And register the instance in the universe
     self._universe.add_object(self)
コード例 #2
0
    def __init__(self, *oargs, **nargs):
        """Initialise an OWL function.
        
            args: an argument list for auto-populating associations upon creation
                of an object.
        
        """
        # Some helper variables to make typing easier
        self._universe = OwlUniverse.get_universe()

        # If we are an abstract - then throw an exception
        if self.is_abstract() is True:
            raise Exception("Cannot instantiate an abstract class")

        # Prepare data stores
        self._references = dict()
        self._data = dict()
        for attr in self.associations():
            self._data[attr.id()] = None
            setattr(self, attr.id(), attr(self))

        # For each named argument, run its method
        for k, v in nargs.iteritems():
            self.association(k, v)

        # TODO: We should be mandating that objects are instantiated with
        #    mandatory associations provided as arguments at creation time.
        #    This involves some sort of positive validation I suppose.

        # And register the instance in the universe
        self._universe.add_object(self)
コード例 #3
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def class_type(cls):
     """Return the class that this association pertains to.
     
     """
     universe = OwlUniverse.get_universe()
     return universe.get_class(_model.association_attr(cls.classid(), 
         cls.id())['type'])
コード例 #4
0
 def class_type(cls):
     """Return the class that this association pertains to.
     
     """
     universe = OwlUniverse.get_universe()
     return universe.get_class(
         _model.association_attr(cls.classid(), cls.id())['type'])
コード例 #5
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def child_classes(cls):
     """Return a list of child classes.
     
     """
     universe = OwlUniverse.get_universe()
     children = list()
     for i in _model.class_children(cls.id()):
         children.append(universe.get_class(i))
         
     return children
コード例 #6
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def ref_classes(cls):
     """Return a list of classes that may reference this class.
     
     """
     universe = OwlUniverse.get_universe()
     refs = list()
     for i in _model.references(cls.id()):
         refs.append(universe.get_class(i))
         
     return refs
コード例 #7
0
    def child_classes(cls):
        """Return a list of child classes.
        
        """
        universe = OwlUniverse.get_universe()
        children = list()
        for i in _model.class_children(cls.id()):
            children.append(universe.get_class(i))

        return children
コード例 #8
0
    def ref_classes(cls):
        """Return a list of classes that may reference this class.
        
        """
        universe = OwlUniverse.get_universe()
        refs = list()
        for i in _model.references(cls.id()):
            refs.append(universe.get_class(i))

        return refs