Class State

  • All Implemented Interfaces:
    QDLConstants, edu.uiuc.ncsa.security.core.Logable, edu.uiuc.ncsa.security.util.scripting.StateInterface, Serializable

    public class State
    extends FunctionState
    implements QDLConstants
    This is a facade for the various stateful components we have to track. Represents the internal state of the system.

    Created by Jeff Gaynor
    on 1/21/20 at 7:25 AM

    See Also:
    Serialized Form
    • Field Detail

      • extrinsicVars

        public static VStack extrinsicVars
    • Constructor Detail

      • State

        public State()
        This is needed for XML deserialization and makes dummy state for everything, assuming the deserializer will replace it all. Generally do not use outside of XML deserialization.
    • Method Detail

      • getInternalID

        public String getInternalID()
        The internal id of the state object is needed in serialization and other operations. Every instance of a state object has a unique id.
        Returns:
      • getStateID

        public int getStateID()
        This is used in the debugger and refers to paused vs running processes. It does not refer to process ids or the internal id of the state object.
        Returns:
      • setStateID

        public void setStateID​(int pid)
      • newInstance

        public State newInstance()
        A new instance with the default components.
        Returns:
      • getFactory

        public static State getFactory()
      • setFactory

        public static void setFactory​(State factory)
      • newInstance

        public State newInstance​(VStack symbolStack,
                                 OpEvaluator opEvaluator,
                                 MetaEvaluator metaEvaluator,
                                 FStack<? extends FTable<? extends FKey,​? extends FunctionRecordInterface>> ftStack,
                                 MTStack mtStack,
                                 MIStack miStack,
                                 edu.uiuc.ncsa.security.core.util.MyLoggingFacade myLoggingFacade,
                                 boolean isServerMode,
                                 boolean isRestrictedIO,
                                 boolean assertionsOn)
        If you extend this class, you must override this method to return a new instance of your state with everything in it you want or need. Then set your setFactory(State)
        Parameters:
        opEvaluator -
        metaEvaluator -
        ftStack -
        mtStack -
        miStack -
        myLoggingFacade -
        isServerMode -
        isRestrictedIO -
        assertionsOn -
        Returns:
      • getSystemConstants

        public QDLStem getSystemConstants()
      • setSystemConstants

        public void setSystemConstants​(QDLStem systemConstants)
      • getSystemInfo

        public QDLStem getSystemInfo()
      • setSystemInfo

        public void setSystemInfo​(QDLStem systemInfo)
      • createSystemInfo

        public void createSystemInfo​(QDLEnvironment qe)
      • addLibEntries

        public void addLibEntries​(String libraryKey,
                                  QDLStem classPaths)
        Adds a list of classpath to the info().lib key entry. This allows modules to add their classes to the library so users can find them. The argument is a stem with key values pairs:
        name : classpath

        and will be added to an existing entry with the same key or a new one.

        E.g. calling

        addLibEntries("oa2", {"store":"path.to.store"})

        would result in the entry info().'lib'.'oa2'.'store'
        returning the path.to.store

        Parameters:
        libraryKey -
        classPaths -
      • addLibEntry

        public void addLibEntry​(String libraryKey,
                                String moduleKey,
                                String className)
        Add a single entry to a given library
        Parameters:
        libraryKey -
        moduleKey -
        className -
      • getLibMap

        public QDLStem getLibMap()
      • createSystemConstants

        public void createSystemConstants()
      • getQDLReservedNames

        protected QDLStem getQDLReservedNames()
        Get a listing of all the functions, operators and keywords for QDL.
        Returns:
      • getDebugUtil

        public edu.uiuc.ncsa.security.core.util.MetaDebugUtil getDebugUtil()
        Debug utility for QDL. Note that this is completely independent of the DebugUtil for the JVM, which can be toggled with the WS variable 'debug'
        Returns:
      • setDebugUtil

        public void setDebugUtil​(edu.uiuc.ncsa.security.core.util.MetaDebugUtil debugUtil)
      • addManifestConstants

        protected QDLStem addManifestConstants​(String path)
        If this is packaged in a jar, read off the information from the manifest file. If no manifest, skip this.
        Returns:
      • isServerMode

        public boolean isServerMode()
      • setServerMode

        public void setServerMode​(boolean serverMode)
      • isRestrictedIO

        public boolean isRestrictedIO()
        In server mode, some IO for debugging with debugger is still be allowed. If this flag is set true, then printing is not allowed nor is saving the workspace.
        Returns:
      • setRestrictedIO

        public void setRestrictedIO​(boolean restrictedIO)
      • addVFSProvider

        public void addVFSProvider​(VFSFileProvider scriptProvider)
      • hasMountPoint

        public boolean hasMountPoint​(String mountPoint)
      • removeVFSProvider

        public void removeVFSProvider​(String mountPoint)
      • removeScriptProvider

        public void removeScriptProvider​(String scheme)
      • getScriptFromVFS

        public QDLScript getScriptFromVFS​(String fqName)
                                   throws Throwable
        Convenience to get a script from the VFS. This takes any file and tries to turn it in to a script, so the "onus is on the app" to make sure this is a script.
        Parameters:
        fqName -
        Returns:
        Throws:
        Throwable
      • getVFS

        public VFSFileProvider getVFS​(String fqName)
                               throws Throwable
        Given a fully qualified path, find the VFS corresponding to the mount point and return it or null if no such mount point exists
        Parameters:
        fqName -
        Returns:
        Throws:
        Throwable
      • hasVFSProviders

        public boolean hasVFSProviders()
      • isVFSFile

        public boolean isVFSFile​(String path)
      • newLocalState

        public State newLocalState()
        Convenience method for newLocalState(State) with a null argument
        Returns:
        State
      • newLocalState

        public State newLocalState​(State moduleState)
        Creates a new state object and pushes the moduleState's stacks onto the current one. This means the resulting state inherits everything.
        Parameters:
        moduleState -
        Returns:
      • newSelectiveState

        public State newSelectiveState​(State moduleState)
      • newSelectiveState

        public State newSelectiveState​(State moduleState,
                                       boolean inheritVariables)
        Create a clean state, taking the old modules from moduleState, all the functions and allowing inheritance of the current variable stack
        Parameters:
        moduleState -
        inheritVariables -
        Returns:
      • newSelectiveState

        public State newSelectiveState​(State moduleState,
                                       boolean inheritFunctions,
                                       boolean inheritVariables)
        This will clone the current state and will add the modules (templates and instances -- old modules) from moduleState. If pushFunctions is
        Parameters:
        moduleState -
        inheritFunctions -
        inheritVariables -
        Returns:
      • newSelectiveState

        public State newSelectiveState​(State moduleState,
                                       boolean inheritModules,
                                       boolean inheritFunctions,
                                       boolean inheritVariables)
        Create a new state based on the current state and choosing what to inherit. In this case, inherited objects come first, items in current state are appended. This allows for overrides in Statement.evaluate(State) calls.
        Parameters:
        moduleState -
        inheritModules -
        inheritFunctions -
        inheritVariables -
        Returns:
      • injectTransientFields

        public void injectTransientFields​(State oldState)
        For the case the this has been deserialized and needs to have its transient fields initialized. These are things like the MetaEvaluator that should not be serialized or current mount points (which can't be serialized because you'd have to serialize the entire backing file system to satisfy the contract of serialization!)
        Parameters:
        oldState -
      • newCleanState

        public State newCleanState()
        This creates a completely clean state, using the current environment (so modules and script paths, but not variables, modules etc.) and preserves debugging
        Returns:
      • newFunctionState

        public State newFunctionState()
        Carries over modules and functions, but not variables.
        Returns:
      • addModule

        public void addModule​(Module module)
        Add the module under the default alias
        Parameters:
        module -
      • getStackSize

        public int getStackSize()
      • writeExtraXMLElements

        public void writeExtraXMLElements​(XMLStreamWriter xsr)
                                   throws XMLStreamException
        This is invoked at the end of the serialization and lets you add additional things to be serialized in the State. All new elements are added right before the final closing tag for the state object.
        Parameters:
        xsr -
        Throws:
        XMLStreamException
      • createConstants

        protected net.sf.json.JSONObject createConstants()
      • readExtraXMLElements

        public void readExtraXMLElements​(XMLEvent xe,
                                         XMLEventReader xer)
                                  throws XMLStreamException
        This passes in the current start event so you can add your own event loop and cases. Note you need have only a switch on the tag names you want.
        Parameters:
        xe -
        xer -
        Throws:
        XMLStreamException
      • readConstantsFromJSON

        protected void readConstantsFromJSON​(net.sf.json.JSONObject json)
      • getTempVariableName

        public String getTempVariableName()
        Returns an unused variable name.
        Returns:
      • isAssertionsOn

        public boolean isAssertionsOn()
      • setAssertionsOn

        public void setAssertionsOn​(boolean assertionsOn)
      • getWorkspaceCommands

        public WorkspaceCommands getWorkspaceCommands()
        Allows back reference to workspace to run macros.
        Returns:
      • setWorkspaceCommands

        public void setWorkspaceCommands​(WorkspaceCommands workspaceCommands)
      • buildSO

        public void buildSO​(SerializationState SerializationState)
        Recurse through the modules and collects templates and state objects from instances. Now that templates and instances are handled as stacks with local state, old form of serialization fails due to recursion.

        These are serialized into a flat list and references to them are used. This also checks for cycles.
        Parameters:
        SerializationState -
      • setExtrinsicVars

        public void setExtrinsicVars​(VStack extrinsicVars)
      • isAllowBaseFunctionOverrides

        public boolean isAllowBaseFunctionOverrides()
      • setAllowBaseFunctionOverrides

        public void setAllowBaseFunctionOverrides​(boolean allowBaseFunctionOverrides)
      • getTargetState

        public State getTargetState()
        The target state is used in cases where argument lists are processed. This allows for the ANode2 assignment to a different state that the calling state, in particular, this is how functions can assign variables in their argument list only for the duration of the function.
        Returns:
      • setTargetState

        public void setTargetState​(State targetState)
      • getRootState

        public static State getRootState()
        At system startup this is set to be the top-level state object for the system. It is used, e.g. in resolving default namepsace requests everywhere and should be set exactly once on startup by the system.
        Returns:
      • setRootState

        public static void setRootState​(State newRoot)
      • serializeLocalStateToJSON

        public net.sf.json.JSONObject serializeLocalStateToJSON​(SerializationState serializationState)
                                                         throws Throwable
        Only serialize the local part of the state. This is used by e.g., modules that have shared state and should never overwrite shared state on deserialization.
        Parameters:
        serializationState -
        Returns:
        Throws:
        Throwable
      • main

        public static void main​(String[] args)