libSBML Python API  5.11.0
libsbml.SBasePlugin Class Reference
Inheritance diagram for libsbml.SBasePlugin:
[legend]

Detailed Description

Base class for extending SBML objects in packages.

This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.

The SBasePlugin class is libSBML's base class for extensions of core SBML component objects. SBasePlugin defines basic virtual methods for reading/writing/checking additional attributes and/or subobjects; these methods should be overridden by subclasses to implement the necessary features of an extended SBML object.

Perhaps the easiest way to explain and motivate the role of SBasePlugin is through an example. The SBML Layout package specifies the existence of an element, <listOfLayouts>, contained inside an SBML <model> element. In terms of libSBML components, this means a new ListOfLayouts class of objects must be defined, and this object placed in an extended class of Model (because Model in plain/core SBML does not allow the inclusion of a ListOfLayouts subobject). This extended class of Model is LayoutModelPlugin, and it is derived from SBasePlugin.

How to extend SBasePlugin for a package implementation

LibSBML package extensions can extend existing libSBML objects such as Model using SBasePlugin as a base class, to hold attributes and/or subcomponents necessary for the SBML package being implemented. Package developers must implement an SBasePlugin extended class for each element to be extended (e.g., Model, Reaction, and others) where additional attributes and/or top-level objects of the package extension are directly contained. The following subsections detail the basic steps necessary to use SBasePlugin for the implementation of a class extension.

1. Identify the SBML components that need to be extended

The specification for a SBML Level 3 package will define the attributes and subojects that make up the package constructs. Those constructs that modify existing SBML components such as Model, Reaction, etc., will be the ones that need to be extended using SBasePlugin.

For example, the Layout package makes additions to Model, SpeciesReference, and the <sbml> element (which is represented in libSBML by SBMLDocument). This means that the Layout package extension in libSBML needs to define extended versions of Model, SpeciesReference and SBMLDocument. Elements other than the SBML document need to be implemented using SBasePlugin; the document component must be implemented using SBMLDocumentPlugin instead.

2. Create a SBasePlugin subclass for each extended SBML component

A new class definition that subclasses SBasePlugin needs to be created for each SBML component to be extended by the package. For instance, the Layout package needs LayoutModelPlugin and LayoutSpeciesReferencePlugin. (As mentioned above, the Layout class also needs LayoutSBMLDocumentPlugin, but this one is implemented using SBMLDocumentPlugin instead of SBasePlugin.) Below, we describe in detail the different parts of an SBasePlugin subclass definition.

2.1 Define protected data members

Data attributes on each extended class in an SBML package will have one of the data types string, double, int, or bool. Subelements/subobjects will normally be derived from the ListOf class or from SBase.

The additional data members must be properly initialized in the class constructor, and must be properly copied in the copy constructor and assignment operator. For example, the following data member is defined in the GroupsModelPlugin class (in the file GroupsModelPlugin.h):

ListOfGroups mGroups;

2.2 Override SBasePlugin class-related methods

The derived class must override the constructor, copy constructor, assignment operator (operator=) and clone() methods from SBasePlugin.

2.3 Override SBasePlugin virtual methods for attributes

If the extended component is defined by the SBML Level 3 package to have attributes, then the extended class definition needs to override the following internal methods on SBasePlugin and provide appropriate implementations:

  • addExpectedAttributes(ExpectedAttributes& attributes): This method should add the attributes that are expected to be found on this kind of extended component in an SBML file or data stream.
  • readAttributes(XMLAttributes attributes, ExpectedAttributes& expectedAttributes): This method should read the attributes expected to be found on this kind of extended component in an SBML file or data stream.
  • hasRequiredAttributes(): This method should return True if all of the required attribute for this extended component are present on instance of the object.
  • writeAttributes(XMLOutputStream stream): This method should write out the attributes of an extended component. The implementation should use the different kinds of writeAttribute methods defined by XMLOutputStream to achieve this.

2.4 Override SBasePlugin virtual methods for subcomponents

If the extended component is defined by the Level 3 package to have subcomponents (i.e., full XML elements rather than mere attributes), then the extended class definition needs to override the following internal SBasePlugin methods and provide appropriate implementations:

  • createObject(XMLInputStream stream): Subclasses must override this method to create, store, and then return an SBML object corresponding to the next XMLToken in the XMLInputStream. To do this, implementations can use methods like peek() on XMLInputStream to test if the next object in the stream is something expected for the package. For example, LayoutModelPlugin uses peek() to examine the next element in the input stream, then tests that element against the Layout namespace and the element name 'listOfLayouts' to see if it's the single subcomponent (ListOfLayouts) permitted on a Model object using the Layout package. If it is, it returns the appropriate object.
  • connectToParent(SBase sbase): This creates a parent-child relationship between a given extended component and its subcomponent(s).
  • setSBMLDocument(SBMLDocument d): This method should set the parent SBMLDocument object on the subcomponent object instances, so that the subcomponent instances know which SBMLDocument contains them.
  • enablePackageInternal(string& pkgURI, string& pkgPrefix, bool flag): This method should enable or disable the subcomponent based on whether a given XML namespace is active.
  • writeElements(XMLOutputStream stream): This method must be overridden to provide an implementation that will write out the expected subcomponents/subelements to the XML output stream.
  • readOtherXML(SBase parentObject, XMLInputStream stream): This function should be overridden if elements of annotation, notes, MathML content, etc., need to be directly parsed from the given XMLInputStream object.
  • hasRequiredElements(): This method should return True if a given object contains all the required subcomponents defined by the specification for that SBML Level 3 package.

2.5 Override SBasePlugin virtual methods for XML namespaces

If the package needs to add additional xmlns attributes to declare additional XML namespace URIs, the extended class should override the following method:

  • writeXMLNS(XMLOutputStream stream): This method should write out any additional XML namespaces that might be needed by a package implementation.

2.6 Implement additional methods as needed

Extended component implementations can add whatever additional utility methods are useful for their implementation.

Public Member Functions

def clone (self)
 Creates and returns a deep copy of this SBasePlugin object. More...
 
def getElementByMetaId (self, metaid)
 Return the first child object found with a given meta identifier. More...
 
def getElementBySId (self, id)
 Return the first child object found with a given identifier. More...
 
def getElementNamespace (self)
  Base class for extending SBML objects in packages. More...
 
def getLevel (self)
 Returns the SBML Level of the package extension of this plugin object. More...
 
def getListOfAllElements
 Returns an SBaseList of all child SBase objects, including those nested to an arbitrary depth. More...
 
def getPackageName (self)
 Returns the short-form name of the package to which this plugin object belongs. More...
 
def getPackageVersion (self)
 Returns the package version of the package extension of this plugin object. More...
 
def getParentSBMLObject (self, args)
 Returns the parent object to which this plugin object is connected. More...
 
def getPrefix (self)
 Returns the XML namespace prefix of the package to which this plugin object belongs. More...
 
def getSBMLDocument (self, args)
 Returns the SBMLDocument object containing this object instance. More...
 
def getURI (self)
 Returns the XML namespace URI for the package to which this object belongs. More...
 
def getVersion (self)
 Returns the Version within the SBML Level of the package extension of this plugin object. More...
 
def setElementNamespace (self, uri)
 Sets the XML namespace to which this object belongs. More...
 

Member Function Documentation

def libsbml.SBasePlugin.clone (   self)

Creates and returns a deep copy of this SBasePlugin object.

clone()   SBasePlugin
Returns
the (deep) copy of this SBasePlugin object.
def libsbml.SBasePlugin.getElementByMetaId (   self,
  metaid 
)

Return the first child object found with a given meta identifier.

getElementByMetaId(string metaid)   SBase

This method searches all the subobjects under this one, compares their meta identifiers to metaid, and returns the first one that machines.

Parameters
metaidstring, the metaid of the object to find.
Returns
pointer to the first object found with the given metaid.
def libsbml.SBasePlugin.getElementBySId (   self,
  id 
)

Return the first child object found with a given identifier.

getElementBySId(string id)   SBase

This method searches all the subobjects under this one, compares their identifiers to id, and returns the first one that machines.

Normally, SId type identifier values are unique across a model in SBML. However, in some circumstances they may not be, such as if a model is invalid because of multiple objects having the same identifier.

Parameters
idstring representing the identifier of the object to find
Returns
pointer to the first object with the given id.
def libsbml.SBasePlugin.getLevel (   self)

Returns the SBML Level of the package extension of this plugin object.

getLevel()   long
Returns
the SBML Level.
See also
getVersion()
def libsbml.SBasePlugin.getListOfAllElements (   self,
  filter = None 
)

Returns an SBaseList of all child SBase objects, including those nested to an arbitrary depth.

getListOfAllElements(ElementFilter filter=None)   SBaseList
getListOfAllElements()   SBaseList
Returns
a list of all objects that are children of this object.
def libsbml.SBasePlugin.getPackageName (   self)

Returns the short-form name of the package to which this plugin object belongs.

getPackageName()   string
Returns
the short-form package name (or nickname) of the SBML package implemented by this package extension.
def libsbml.SBasePlugin.getPackageVersion (   self)

Returns the package version of the package extension of this plugin object.

getPackageVersion()   long
Returns
the package version of the package extension of this plugin object.
See also
getLevel()
getVersion()
def libsbml.SBasePlugin.getParentSBMLObject (   self,
  args 
)

Returns the parent object to which this plugin object is connected.

getParentSBMLObject()   SBase
Returns
the parent object of this object.
def libsbml.SBasePlugin.getPrefix (   self)

Returns the XML namespace prefix of the package to which this plugin object belongs.

getPrefix()   string
Returns
the XML namespace prefix of the SBML Level 3 package implemented by this libSBML package extension.
def libsbml.SBasePlugin.getSBMLDocument (   self,
  args 
)

Returns the SBMLDocument object containing this object instance.

getSBMLDocument()   SBMLDocument
LibSBML uses the class SBMLDocument as a top-level container for storing SBML content and data associated with it (such as warnings and error messages). An SBML model in libSBML is contained inside an SBMLDocument object. SBMLDocument corresponds roughly to the class SBML defined in the SBML Level 3 and Level 2 specifications, but it does not have a direct correspondence in SBML Level 1. (But, it is created by libSBML no matter whether the model is Level 1, Level 2 or Level 3.)

This method allows the caller to obtain the SBMLDocument for the current object.

Returns
the parent SBMLDocument object of this plugin object.
See also
getParentSBMLObject()
def libsbml.SBasePlugin.getURI (   self)

Returns the XML namespace URI for the package to which this object belongs.

getURI()   string
In the XML representation of an SBML document, XML namespaces are used to identify the origin of each XML construct used. XML namespaces are identified by their unique resource identifiers (URIs). The core SBML specifications stipulate the namespaces that must be used for core SBML constructs; for example, all XML elements that belong to SBML Level 3 Version 1 Core must be placed in the XML namespace identified by the URI 'http://www.sbml.org/sbml/level3/version1/core'. Individual SBML Level 3 packages define their own XML namespaces; for example, all elements belonging to the SBML Level 3 Layout Version 1 package must be placed in the XML namespace 'http://www.sbml.org/sbml/level3/version1/layout/version1/'.

This method first looks into the SBMLNamespaces object possessed by the parent SBMLDocument object of the current object. If this cannot be found, this method returns the result of getElementNamespace().

Returns
a string, the URI of the XML namespace to which this object belongs.
See also
getPackageName()
getElementNamespace()
SBMLDocument.getSBMLNamespaces()
getSBMLDocument()
def libsbml.SBasePlugin.getVersion (   self)

Returns the Version within the SBML Level of the package extension of this plugin object.

getVersion()   long
Returns
the SBML Version.
See also
getLevel()
def libsbml.SBasePlugin.setElementNamespace (   self,
  uri 
)

Sets the XML namespace to which this object belongs.

setElementNamespace(string uri)   int
In the XML representation of an SBML document, XML namespaces are used to identify the origin of each XML construct used. XML namespaces are identified by their unique resource identifiers (URIs). The core SBML specifications stipulate the namespaces that must be used for core SBML constructs; for example, all XML elements that belong to SBML Level 3 Version 1 Core must be placed in the XML namespace identified by the URI 'http://www.sbml.org/sbml/level3/version1/core'. Individual SBML Level 3 packages define their own XML namespaces; for example, all elements belonging to the SBML Level 3 Layout Version 1 package must be placed in the XML namespace 'http://www.sbml.org/sbml/level3/version1/layout/version1/'.
Parameters
urithe URI to assign to this object.
Returns
integer value indicating success/failure of the function. The possible values returned by this function are:
See also
getElementNamespace()