Class RhinoCore

  • All Implemented Interfaces:
    org.mozilla.javascript.tools.debugger.ScopeProvider

    public final class RhinoCore
    extends java.lang.Object
    implements org.mozilla.javascript.tools.debugger.ScopeProvider
    This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      Application app  
    • Constructor Summary

      Constructors 
      Constructor Description
      RhinoCore​(Application app)
      Create a Rhino evaluator for the given application and request evaluator.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Application getApplication()
      Return the application we're running in
      static RhinoCore getCore()
      Get the RhinoCore instance associated with the current thread, or null
      org.mozilla.javascript.Scriptable getElementWrapper​(java.lang.Object e)
      Get a Script wrapper for any given object.
      org.mozilla.javascript.Scriptable getNodeWrapper​(NodeHandle handle)
      Get a node wrapper for a node that may not have been fetched yet
      org.mozilla.javascript.Scriptable getNodeWrapper​(INode node)
      Get a script wrapper for an instance of helma.objectmodel.INode
      org.mozilla.javascript.Scriptable getPrototype​(java.lang.String protoName)
      Get the object prototype for a prototype name and initialize/update it if necessary.
      java.util.Map getPrototypeProperties​(java.lang.String protoName)
      Get an array containing the property ids of all properties that were compiled from scripts for the given prototype.
      org.mozilla.javascript.Scriptable getScope()
      Return the global scope of this RhinoCore.
      org.mozilla.javascript.Scriptable getValidPrototype​(java.lang.String protoName)
      A version of getPrototype() that retrieves a prototype and checks if it is valid, i.e.
      boolean hasFunction​(java.lang.String protoname, java.lang.String fname)
      Check if an object has a function property (public method if it is a java object) with that name.
      protected void initialize()
      Initialize the evaluator, making sure the minimum type information necessary to bootstrap the rest is parsed.
      protected helma.scripting.rhino.RhinoCore.TypeInfo initPrototype​(Prototype prototype)
      Initialize a prototype info without compiling its script files.
      void injectCodeResource​(java.lang.String typename, Resource code)
      Add a code resource to a given prototype by immediately compiling and evaluating it.
      protected java.lang.String postProcessHref​(java.lang.Object obj, java.lang.String protoName, java.lang.String href)  
      java.lang.Object processXmlRpcArgument​(java.lang.Object arg)
      Convert an input argument from Java to the scripting runtime representation.
      java.lang.Object processXmlRpcResponse​(java.lang.Object arg)
      convert a JavaScript Object object to a generic Java object stucture.
      protected void setParentPrototype​(Prototype prototype, helma.scripting.rhino.RhinoCore.TypeInfo type)
      Set the parent prototype on the ObjectPrototype.
      void shutdown()  
      protected static java.lang.Object[] unwrapSkinpath​(java.lang.Object[] skinpath)  
      void updatePrototypes()
      This method is called before an execution context is entered to let the engine know it should update its prototype information.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RhinoCore

        public RhinoCore​(Application app)
        Create a Rhino evaluator for the given application and request evaluator.
    • Method Detail

      • initialize

        protected void initialize()
        Initialize the evaluator, making sure the minimum type information necessary to bootstrap the rest is parsed.
      • shutdown

        public void shutdown()
      • initPrototype

        protected helma.scripting.rhino.RhinoCore.TypeInfo initPrototype​(Prototype prototype)
        Initialize a prototype info without compiling its script files.
        Parameters:
        prototype - the prototype to be created
      • setParentPrototype

        protected void setParentPrototype​(Prototype prototype,
                                          helma.scripting.rhino.RhinoCore.TypeInfo type)
        Set the parent prototype on the ObjectPrototype.
        Parameters:
        prototype - the prototype spec
        type - the prototype object info
      • updatePrototypes

        public void updatePrototypes()
                              throws java.io.IOException
        This method is called before an execution context is entered to let the engine know it should update its prototype information. The update policy here is to check for update those prototypes which already have been compiled before. Others will be updated/compiled on demand.
        Throws:
        java.io.IOException
      • getValidPrototype

        public org.mozilla.javascript.Scriptable getValidPrototype​(java.lang.String protoName)
        A version of getPrototype() that retrieves a prototype and checks if it is valid, i.e. there were no errors when compiling it. If invalid, a ScriptingException is thrown.
      • getPrototype

        public org.mozilla.javascript.Scriptable getPrototype​(java.lang.String protoName)
        Get the object prototype for a prototype name and initialize/update it if necessary. The policy here is to update the prototype only if it hasn't been updated before, otherwise we assume it already was updated by updatePrototypes(), which is called for each request.
      • getPrototypeProperties

        public java.util.Map getPrototypeProperties​(java.lang.String protoName)
        Get an array containing the property ids of all properties that were compiled from scripts for the given prototype.
        Parameters:
        protoName - the name of the prototype
        Returns:
        an array containing all compiled properties of the given prototype
      • hasFunction

        public boolean hasFunction​(java.lang.String protoname,
                                   java.lang.String fname)
        Check if an object has a function property (public method if it is a java object) with that name.
      • processXmlRpcArgument

        public java.lang.Object processXmlRpcArgument​(java.lang.Object arg)
        Convert an input argument from Java to the scripting runtime representation.
      • processXmlRpcResponse

        public java.lang.Object processXmlRpcResponse​(java.lang.Object arg)
        convert a JavaScript Object object to a generic Java object stucture.
      • getApplication

        public Application getApplication()
        Return the application we're running in
      • getElementWrapper

        public org.mozilla.javascript.Scriptable getElementWrapper​(java.lang.Object e)
        Get a Script wrapper for any given object. If the object implements the IPathElement interface, the getPrototype method will be used to retrieve the name of the prototype to use. Otherwise, a Java-Class-to-Script-Prototype mapping is consulted.
      • getNodeWrapper

        public org.mozilla.javascript.Scriptable getNodeWrapper​(INode node)
        Get a script wrapper for an instance of helma.objectmodel.INode
      • getNodeWrapper

        public org.mozilla.javascript.Scriptable getNodeWrapper​(NodeHandle handle)
        Get a node wrapper for a node that may not have been fetched yet
        Parameters:
        handle - a node handle
        Returns:
        a wrapper for the node
      • postProcessHref

        protected java.lang.String postProcessHref​(java.lang.Object obj,
                                                   java.lang.String protoName,
                                                   java.lang.String href)
                                            throws java.io.UnsupportedEncodingException,
                                                   java.io.IOException
        Throws:
        java.io.UnsupportedEncodingException
        java.io.IOException
      • getCore

        public static RhinoCore getCore()
        Get the RhinoCore instance associated with the current thread, or null
        Returns:
        the RhinoCore instance associated with the current thread
      • unwrapSkinpath

        protected static java.lang.Object[] unwrapSkinpath​(java.lang.Object[] skinpath)
      • injectCodeResource

        public void injectCodeResource​(java.lang.String typename,
                                       Resource code)
        Add a code resource to a given prototype by immediately compiling and evaluating it.
        Parameters:
        typename - the type this resource belongs to
        code - a code resource
      • getScope

        public org.mozilla.javascript.Scriptable getScope()
        Return the global scope of this RhinoCore.
        Specified by:
        getScope in interface org.mozilla.javascript.tools.debugger.ScopeProvider