Class JavaScript.PortOrParameterProxy

  • Enclosing class:
    JavaScript

    public class JavaScript.PortOrParameterProxy
    extends java.lang.Object
    Proxy for a port or parameter. This is used to wrap ports and parameters for security reasons. If we expose the port or parameter to the JavaScript environment, then the script can access all aspects of the model containing this actor. E.g., it can call getContainer() on the object. This wrapper provides access to the port or parameter only via a protected method, which JavaScript cannot access.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<Token> _localInputTokens
      A list of tokens that this JavaScript actor has sent to its own input.
      protected Variable _parameter
      The parameter that is proxied, or null if it's a port.
      protected TypedIOPort _port
      The port that is proxied, or null if it's a parameter.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected PortOrParameterProxy​(NamedObj portOrParameter)
      Construct a proxy.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Token get​(int channelIndex)
      Get the current value of the input port or a parameter.
      boolean isJSON()
      Return true if the port or parameter value is required to be JSON.
      void send​(int channelIndex, Token data, java.lang.Object value)
      Expose the send() method of the port.
      void set​(Token token)
      Set the current value of the parameter.
      java.lang.String toString()
      Return the name of the proxied port or parameter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • _localInputTokens

        protected java.util.List<Token> _localInputTokens
        A list of tokens that this JavaScript actor has sent to its own input.
      • _parameter

        protected Variable _parameter
        The parameter that is proxied, or null if it's a port.
      • _port

        protected TypedIOPort _port
        The port that is proxied, or null if it's a parameter.
    • Constructor Detail

      • PortOrParameterProxy

        protected PortOrParameterProxy​(NamedObj portOrParameter)
                                throws IllegalActionException
        Construct a proxy.
        Parameters:
        portOrParameter - The object to be proxied.
        Throws:
        IllegalActionException - If the argument is neither a port nor a parameter.
    • Method Detail

      • isJSON

        public boolean isJSON()
        Return true if the port or parameter value is required to be JSON.
        Returns:
        True for JSON ports and parameters.
      • get

        public Token get​(int channelIndex)
                  throws IllegalActionException
        Get the current value of the input port or a parameter. If it is a ParameterPort, then retrieve the value from the corresponding parameter instead (the fire() method will have done update). This should now only be used by getParameter.
        Parameters:
        channelIndex - The channel index. This is ignored for parameters.
        Returns:
        The current value of the input or parameter, or null if there is none.
        Throws:
        IllegalActionException - If the port is not an input port or retrieving the value fails.
      • send

        public void send​(int channelIndex,
                         Token data,
                         java.lang.Object value)
                  throws NoRoomException,
                         IllegalActionException
        Expose the send() method of the port.
        Parameters:
        channelIndex - The channel index.
        data - The token to send.
        value - The JavaScript value to pass back when the send actually occurs.
        Throws:
        IllegalActionException - If this is a proxy for a parameter or if sending fails.
        NoRoomException - If there is no room at the destination.
      • toString

        public java.lang.String toString()
        Return the name of the proxied port or parameter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The name of the proxied port or parameter