Package ptolemy.moml

Class MoMLModelAttribute

  • All Implemented Interfaces:
    java.lang.Cloneable, Changeable, Configurable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    ExceptionManager, OntologySolverBase

    public class MoMLModelAttribute
    extends Attribute
    implements Configurable
    An attribute that has a model described in MoML. The MoML is specified by calling configure(URL, String, String), or by including the MoML within <configure> tags in a MoML file. The MoML is returned by the getConfigureText() method. The getContainedModel() method returns the model specified by the MoML.

    When an instance of this attribute is exported to MoML, the MoML description above will be included in the exported MoML within <configure> tags.

    An instance of this attribute may wish to override the default "Look Inside" behavior by including an instance of ptolemy.vergil.toolbox.MoMLModelAttributeControllerFactory as an attribute contained by this instance. Instead of having an explicit compile-time dependency between this class and MoMLModelAttributeControllerFactory, derived classes should use MoML to set up the containment relationship. For example,

     <property name="MyAttribute" class="ptolemy.moml.MoMLModelAttribute">
         <property name="_controllerFactory" class="ptolemy.vergil.toolbox.MoMLModelAttributeControllerFactory">
            ... my MoML text here ...
    Ptolemy II 8.0
    Dai Bui, Edward Lee, Ben Lickly, Charles Shelton
    Red (tfeng)
    Red (tfeng)
    • Field Detail

      • modelURL

        public FileParameter modelURL
        URL from which to get the model. If this is specified, then the URL will be referenced in the exported configure tag rather than including the MoML for the model in the configure tag. This parameter is a string that defaults to empty. This string can either be an absolute, fully-qualified URL, or a URL relative to the container model's file location. A URL relative to the system's classpath can also be specified by a string starting with $CLASSPATH/{relative URL}.
      • _model

        protected NamedObj _model
        The contained model. This is protected so that derived classes can provide a default model.
    • Constructor Detail

      • MoMLModelAttribute

        public MoMLModelAttribute​(NamedObj container,
                                  java.lang.String name)
                           throws NameDuplicationException,
        Create a model attribute with the specified container and name.
        container - The specified container.
        name - The specified name.
        IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
        NameDuplicationException - If the name coincides with an attribute already in the container.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        React to a change in an attribute. If the modelURL attribute changes, reconfigure the MoML model with the new URL string.
        attributeChanged in class NamedObj
        attribute - The attribute that changed.
        IllegalActionException - Thrown if the URL string contained in the modelURL attribute is not valid.
      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Return a clone of this model attribute. This also creates a clone for the contained model.
        clone in class Attribute
        workspace - The workspace for the cloned object.
        A clone.
        java.lang.CloneNotSupportedException - Thrown if an error occurs while cloning the attribute or the contained model.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • configure

        public void configure​( base,
                              java.lang.String source,
                              java.lang.String text)
                       throws java.lang.Exception
        Construct and configure the contained model with the specified source and text. This parses the specified MoML text.
        Specified by:
        configure in interface Configurable
        base - The base URL for relative references, or null if not known.
        source - The URI of a document providing source, which if specified, will be used to obtain the text. In that case, the text argument will be ignored.
        text - The MoML description.
        java.lang.Exception - If the parsing fails.
      • getConfigureSource

        public java.lang.String getConfigureSource()
        Return the input source that was specified the last time the configure method was called.
        Specified by:
        getConfigureSource in interface Configurable
        The string representation of the input URL, or null if the no source has been used to configure this object, or null if no external source need be used to configure this object.
      • getConfigureText

        public java.lang.String getConfigureText()
        Return the MoML description of the model, if there is one, and null otherwise.
        Specified by:
        getConfigureText in interface Configurable
        The text to include in a configure tag.
      • getContainedModel

        public NamedObj getContainedModel()
        Return the contained model.
        The contained model.
      • _exportMoMLContents

        protected void _exportMoMLContents​( output,
                                           int depth)
        Write a MoML description this object, which includes a MoML description of the contained model within the <configure> tag. If the source URL is specified, do not write the MoML description.
        _exportMoMLContents in class NamedObj
        output - The output stream to write to.
        depth - The depth in the hierarchy, to determine indenting.
        Throws: - If an I/O error occurs.
        See Also:
        NamedObj.exportMoML(Writer, int)