Class NamedObjVariable

    • Field Detail

      • NAME_PREFIX

        public static final java.lang.String NAME_PREFIX
        Prefix of the names of any automatically generated NamedObjVariable.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NamedObjVariable

        public NamedObjVariable​(NamedObj container)
                         throws IllegalActionException,
                                NameDuplicationException
        Construct a variable with a generated name as an attribute of the given container. The container argument must not be null, otherwise a NullPointerException will be thrown. This variable 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 number of the workspace.
        Parameters:
        container - The container.
        Throws:
        IllegalActionException - If the container does not accept a variable as its attribute.
        NameDuplicationException - If the name coincides with a variable already in the container.
      • NamedObjVariable

        public NamedObjVariable​(NamedObj container,
                                java.lang.String name)
                         throws IllegalActionException,
                                NameDuplicationException
        Construct a variable with the given name as an attribute of the given container. The container argument must not be null, otherwise a NullPointerException will be thrown. This variable 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 number of the workspace.
        Parameters:
        container - The container.
        name - The name of the variable.
        Throws:
        IllegalActionException - If the container does not accept a variable as its attribute.
        NameDuplicationException - If the name coincides with a variable already in the container.
    • Method Detail

      • getNamedObjVariable

        public static NamedObjVariable getNamedObjVariable​(NamedObj container,
                                                           boolean autoCreate)
                                                    throws IllegalActionException
        Get the NamedObjVariable contained in the container, and create a new one if none is found in the container and autoCreate is true.
        Parameters:
        container - The container.
        autoCreate - Whether a NamedObjVariable should be created if none is found.
        Returns:
        The NamedObjVariable, or null if none is found and autoCreate is false.
        Throws:
        IllegalActionException - If variable of the container cannot be retrieved, or a new one cannot be created.
      • setContainer

        public void setContainer​(NamedObj container)
                          throws IllegalActionException,
                                 NameDuplicationException
        Specify the container, and add this variable to the list of attributes in the container. If this variable already has a container, remove this variable from the attribute list of the current container first. Otherwise, remove it from the directory of the workspace, if it is there. If the specified container is null, remove this variable from the list of attributes of the current container. If the specified container already contains an attribute with the same name, then throw an exception and do not make any changes. Similarly, if the container is not in the same workspace as this variable, throw an exception. If this variable is already contained by the specified container, do nothing.

        If this method results in a change of container (which it usually does), then remove this variable from the scope of any scope dependent of this variable.

        This method is write-synchronized on the workspace and increments its version number.

        Overrides:
        setContainer in class Variable
        Parameters:
        container - The proposed container of this variable.
        Throws:
        IllegalActionException - If the container will not accept a variable as its attribute, or this variable and the container are not in the same workspace, or the proposed container would result in recursive containment.
        NameDuplicationException - If the container already has an attribute with the name of this variable.
        See Also:
        Attribute.getContainer()
      • setToken

        public void setToken​(Token token)
                      throws IllegalActionException
        Put a new token in this variable and notify the container and and value listeners. The token must be an ObjectToken containing the container of this variable. If an expression had been previously given using setExpression(), then that expression is forgotten. If the type of this variable has been set with setTypeEquals(), then convert the specified token into that type, if possible, or throw an exception, if not. If setTypeAtMost() has been called, then verify that its type constraint is satisfied, and if not, throw an exception.
        Note that you can call this with a null argument regardless of type constraints, unless there are other variables that depend on its value.
        Note that setPersistent(true} may need to be called so that the change to the token is marked as persistent and is exported. to the token is expor
        Overrides:
        setToken in class Variable
        Parameters:
        token - The new token to be stored in this variable.
        Throws:
        IllegalActionException - If the token type is not compatible with specified constraints, or if you are attempting to set to null a variable that has value dependents, or if the container rejects the change.
        See Also:
        Variable.getToken()