com.ibm.itim.script

Class ContextItem

  • java.lang.Object
    • com.ibm.itim.script.ContextItem


  • public abstract class ContextItem
    extends java.lang.Object
    Wrapper class that holds all the information about an object that is needed to load the object into a scripting framework.
    Since:
    ITIM 5.0
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      static ContextItem createConstructor(java.lang.String name, java.lang.Class prototype)
      Get a ContextItem that represents a constructor in the scripting environment.
      static ContextItem createGlobalFunction(java.lang.String name, GlobalFunction function)
      Get a ContextItem that represents a global function in the scripting environment.
      static ContextItem createItem(java.lang.String name)
      Get a ContextItem object with the given name.
      static ContextItem createItem(java.lang.String name, java.lang.Object contextItem)
      Get a ContextItem object with the given name and set to contextItem.
      java.lang.Object getContextObject()
      Get a reference to the contextObject.
      java.lang.String getName()
      Get the name of the ContextItem.
      java.lang.String getType()
      Get the type of the contextObject in the ContextItem.
      abstract void setContextObject(java.lang.Object obj)
      Sets the context object (the object to put into the scripting environment) to obj.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createItem

        public static ContextItem createItem(java.lang.String name)
        Get a ContextItem object with the given name. The contextObject can be set later with setContextObject(), and type will be automatically set to contextObject.getClass().getName().
        Parameters:
        name - The name for the new ContextItem. The name cannot be changed later.
        Returns:
        A new ContextItem with name set to the parameter.
      • createItem

        public static ContextItem createItem(java.lang.String name,
                                             java.lang.Object contextItem)
        Get a ContextItem object with the given name and set to contextItem. contextObject can be changed later with setContextObject().
        Parameters:
        name - The name for the new ContextTime. The name cannot be changed later.
        contextItem - The item to set contextObject to.
        Returns:
        A new ContextItem with name set to name and contextObject set to contextItem.
      • createConstructor

        public static ContextItem createConstructor(java.lang.String name,
                                                    java.lang.Class prototype)
        Get a ContextItem that represents a constructor in the scripting environment. If the name of the ContextItem is "Person" then a script can have the command:
        var person = new Person();
        All constructor ContextItem object must have a default constructor.
        Parameters:
        name - The name for the new ContextItem.
        prototype - The class that acts a prototype for creating new Objects of the same type. prototype must have a default constructor.
        Returns:
        A new ContextItem that represents a JavaScript constructor.
      • createGlobalFunction

        public static ContextItem createGlobalFunction(java.lang.String name,
                                                       GlobalFunction function)
        Get a ContextItem that represents a global function in the scripting environment. If the name of the ContextItem is "increment" then a script can have the command:
        increment();
        Parameters:
        name - The name of the new ContextItem.
        function - The GlobalFunction object on which to call call() whenever a script calls the function.
        Returns:
        A new ContextItem that represents the global function.
      • getContextObject

        public java.lang.Object getContextObject()
        Get a reference to the contextObject.
      • setContextObject

        public abstract void setContextObject(java.lang.Object obj)
        Sets the context object (the object to put into the scripting environment) to obj. If the ContextItem was created with a call to createConstructor() then this method has absolutly no effect. No error or warning is reported, the context object just does not change. Allowing users to call setContextObject() on non-constructor objects is for performance reasons; it allows users to not need to be constantly creating new ContextItem objects. This saves time on memory allocation and garbage collection operations. This seems like a win even though it introduces a slight inconsistency into the APIs between constructor and non-constructor ContextItems.
        Parameters:
        obj - The Object to use as the context object.
      • getName

        public java.lang.String getName()
        Get the name of the ContextItem.
      • getType

        public java.lang.String getType()
        Get the type of the contextObject in the ContextItem.