Class PtalonActor

    • Field Detail

      • ptalonCodeLocation

        public FileParameter ptalonCodeLocation
        The location of the Ptalon code.
    • Constructor Detail

      • PtalonActor

        public PtalonActor​(CompositeEntity container,
                           java.lang.String name)
                    throws IllegalActionException,
                           NameDuplicationException
        Construct a PtalonActor with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace. This actor will have no local director initially, and its executive director will be simply the director of the container.
        Parameters:
        container - The container.
        name - The name of this actor.
        Throws:
        IllegalActionException - If the container is incompatible with this actor.
        NameDuplicationException - If the name coincides with an actor already in the container.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        React to a change in an attribute. This method is called by a contained attribute when its value changes. This initially responds to changes in the ptalonCodeLocation parameter by calling a method which starts the parsing of the Ptalon code. Later, this method responds to changes in parameters specified in the Ptalon code itself: (1) If the parameter was not previously assigned, then update the internal variables; (2) If the parameter was previously assigned, then update the internal variables, and also update the rest of the PtalonActor based on the new value of the parameter (we currently choose the reparse and regenerate the entire PtalonActor from scratch).

        We choose to implement this in attributeChanged() instead if preinitialize() because we want changes to be reflected immediately, since preinitialize() is only processed after the model starts to run.

        Overrides:
        attributeChanged in class TypedCompositeActor
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If the change is not acceptable to this container (not thrown in this base class).
      • configure

        public void configure​(java.net.URL base,
                              java.lang.String source,
                              java.lang.String text)
                       throws java.lang.Exception
        Read the saved XML for this PtalonActor.
        Specified by:
        configure in interface Configurable
        Parameters:
        base - The base relative to which references within the input are found, or null if this is not known, or there is none.
        source - The input source, which specifies a URL, or null if none.
        text - Configuration information given as text, or null if none.
        Throws:
        java.lang.Exception - If something goes wrong.
      • 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
        Returns:
        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()
        Override the default behavior to always return null.
        Specified by:
        getConfigureText in interface Configurable
        Returns:
        null.
      • getMappedName

        public java.lang.String getMappedName​(java.lang.String ptalonName)
                                       throws PtalonRuntimeException
        Get the stored unique name for a symbol in the PtalonActor. The unique name comes from a call to uniqueName().
        Parameters:
        ptalonName - The symbol.
        Returns:
        The unique name.
        Throws:
        PtalonRuntimeException - If no such symbol exists.
      • getNestedDepth

        public int getNestedDepth()
        Return the depth of this PtalonActor declaration with respect to its creator. If this PtalonActor is not created by another PtalonActor's code, then the depth is zero. If, however, this PtalonActor is named Bar in some PtalonCode, and it is created with Foo(actorparameter0 := Bar()), then its depth will be 2, and the corresponding Foo container will have depth 1.
        Returns:
        The depth of this actor declaration with respect to its creator.
        See Also:
        setNestedDepth(int)
      • getPtalonParameter

        public PtalonParameter getPtalonParameter​(java.lang.String name)
                                           throws PtalonRuntimeException
        Find the parameter in the Ptalon code with the specified name, and return the Ptolemy parameter (java) that was created.
        Parameters:
        name - The name of the parameter in the Ptalon code, which may be a prefix of the actual parameter's name.
        Returns:
        The PtalonParameter.
        Throws:
        PtalonRuntimeException - If no such PtalonParameter exists.
      • setNestedDepth

        public void setNestedDepth​(int depth)
        Set the depth of this PtalonActor declaration with respect to its creator. If this PtalonActor is not created by another PtalonActor's code, then the depth will be zero. If, however, this PtalonActor is named Bar in some PtalonCode, and it is created with Foo(actorparameter0 := Bar()), then it's depth will be 2, and the corresponding Foo container will have depth 1.
        Parameters:
        depth - The of this actor declaration with respect to its creator.
        See Also:
        getNestedDepth()
      • uniqueName

        public java.lang.String uniqueName​(java.lang.String prefix)
        Return a name that is guaranteed to not be the name of any contained attribute, port, class, entity, or relation. In this implementation, the argument is stripped of any numeric suffix, and then a numeric suffix is appended and incremented until a name is found that does not conflict with a contained attribute, port, class, entity, or relation. If this composite entity or any composite entity that it contains defers its MoML definition (i.e., it is an instance of a class or a subclass), then the prefix gets appended with "_n_", where n is the depth of this deferral. That is, if the object deferred to also defers, then n is incremented. This differs from the superclass in that a number is always appended in this class. This is mainly important for visualization of the created actors and their displayed names.
        Overrides:
        uniqueName in class CompositeEntity
        Parameters:
        prefix - A prefix for the name.
        Returns:
        A unique name.
      • _createPtalonPopulator

        protected PtalonPopulator _createPtalonPopulator()
      • _createPtalonRecognizer

        protected PtalonRecognizer _createPtalonRecognizer​(PtalonLexer lexer)
        Create Ptalon parser. This function simply constructs a PtalonRecognizer instance with the given lexer. Subclasses may override this function to return a customized parser.
        Parameters:
        lexer - The lexer.
        Returns:
        The Ptalon parser.
      • _exportMoMLContents

        protected void _exportMoMLContents​(java.io.Writer output,
                                           int depth)
                                    throws java.io.IOException
        Write a MoML description of the contents of this object, which in this class is the configuration information. This method is called by exportMoML(). Each description is indented according to the specified depth and terminated with a newline character. Note that this only saves the values of the Ptalon parameters; it does not save other entities generated as a result of parsing the Ptalon file.
        Overrides:
        _exportMoMLContents in class CompositeEntity
        Parameters:
        output - The output stream for writing.
        depth - The depth in the hierarchy, to determine indenting.
        Throws:
        java.io.IOException - If an I/O error occurs.
        See Also:
        NamedObj.exportMoML(Writer, int)
      • _initializePtalonActor

        protected void _initializePtalonActor()
        Initialize this PtalonActor. This method may be called when the PtalonActor is first constructed or if any of its parameter values are changed, so we only initialize variables that do not need to be saved when reparsing the Ptalon file.
      • _initializePtalonCodeLocation

        protected void _initializePtalonCodeLocation()
                                              throws IllegalActionException
        This helper method is used to begin the Ptalon compiler if the ptalonCodeLocation attribute has been updated.
        Throws:
        IllegalActionException - If any exception is thrown.
      • _removeContents

        protected void _removeContents()