org.wso2.mashup.hostobjects.system
Class SystemHostObject

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by org.wso2.mashup.hostobjects.system.SystemHostObject
All Implemented Interfaces:
java.io.Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable

public class SystemHostObject
extends org.mozilla.javascript.ScriptableObject

This is a JavaScript Rhino host object aimed to provide a set of system specific utility functions to the javascript service developers.

For more information refer to JavaScript System Host Object.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
SystemHostObject()
           
 
Method Summary
 java.lang.String getClassName()
          Type to be used for this object inside the javascript.
 void jsConstructor()
           
static void jsFunction_clearInterval(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          

Removes a JavaScript function scheduled for periodic execution using the job id

system.clearInterval(id);

static void jsFunction_include(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          

Imports the external scripts given as the arguments, to the java script run time.

static void jsFunction_notifyMonitor(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
           Sends notification to a monitoring software via JMX.
static java.lang.String jsFunction_setInterval(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          

This method allows the scheduling of a JavaScript function periodically.

static void jsFunction_wait(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          

Waits the execution of the script for the given time in miliseconds or waits for 10 miliseconds when the time is not given.

 java.lang.String jsGet_localHostName()
          

Get the string defining the hostname of the system.

 
Methods inherited from class org.mozilla.javascript.ScriptableObject
associateValue, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, get, get, getAllIds, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, has, has, hasInstance, hasProperty, hasProperty, isConst, isSealed, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SystemHostObject

public SystemHostObject()
Method Detail

jsConstructor

public void jsConstructor()

getClassName

public java.lang.String getClassName()
Type to be used for this object inside the javascript.

Specified by:
getClassName in interface org.mozilla.javascript.Scriptable
Specified by:
getClassName in class org.mozilla.javascript.ScriptableObject

jsFunction_wait

public static void jsFunction_wait(org.mozilla.javascript.Context cx,
                                   org.mozilla.javascript.Scriptable thisObj,
                                   java.lang.Object[] arguments,
                                   org.mozilla.javascript.Function funObj)
                            throws org.apache.axis2.AxisFault

Waits the execution of the script for the given time in miliseconds or waits for 10 miliseconds when the time is not given.

 system.wait();
 system.wait(1000);
 

Throws:
org.apache.axis2.AxisFault

jsGet_localHostName

public java.lang.String jsGet_localHostName()
                                     throws org.wso2.mashup.MashupFault

Get the string defining the hostname of the system.

 var hostname = system.localhostname;
 

Throws:
org.wso2.mashup.MashupFault

jsFunction_include

public static void jsFunction_include(org.mozilla.javascript.Context cx,
                                      org.mozilla.javascript.Scriptable thisObj,
                                      java.lang.Object[] arguments,
                                      org.mozilla.javascript.Function funObj)
                               throws java.io.IOException

Imports the external scripts given as the arguments, to the java script run time. Paths of the scripts to be imported can be given using a comma separated list as arguments. Imported script files needs to be placed in the {service_file_name}.resources directory of the mashup service. If the path represents a file it should be given relative to the {service_file_name}.resources directory. If a file is not found at this location, the path is treated as an URL. The URL can be given relative to the services context root (eg: http://127.0.0.1:7762/services) or it can also be an absolute URL.

 system.include("include.js");
 system.include("version?stub&lang=e4x", "lib2.js");
 system.include("http://tempuri.org/js/temp.js");
 

Throws:
java.io.IOException

jsFunction_setInterval

public static java.lang.String jsFunction_setInterval(org.mozilla.javascript.Context cx,
                                                      org.mozilla.javascript.Scriptable thisObj,
                                                      java.lang.Object[] arguments,
                                                      org.mozilla.javascript.Function funObj)
                                               throws java.io.IOException

This method allows the scheduling of a JavaScript function periodically. There are 2 mandatory parameters. A javascript function (or a javascript expression) and the time interval between two consecutive executions. Optionally one can specify a start time, indicating when to begin the function execution (after given number of milliseconds in the frequency parameter by default). It is also possible to give a start time and an end time.

The method returns a String UUID, which can be used to refer to this function scheduling instance.

Imagine you have a javascript function in your service as follows

 function myJavaScriptFunction(function-parameter)
 {
      print("The parameter value is " + function-parameter);
 }
 

example 1:

    //Setting up 'myJavaScriptFunction' to be executed in 2000 millisecond intervals, starting now and continuing forever.
    var id = system.setInterval(myJavaScriptFunction, 2000, 'I am a parameter value');
 

example 2:

    //Setting up 'myJavaScriptFunction' to be executed in 2000 millisecond intervals, starting now and continuing forever.
    //But passing the function as a javascript expression.
    var id = system.setInterval('myJavaScriptFunction("I am a parameter value");', 2000);
 

example 3:

    //Setting to start in 2 minutes from now
    var startTime = new Date();
    startTime.setMinutes(startTime.getMinutes() + 2);
 

var id = system.setInterval(myJavaScriptFunction, 2000, 'I am a parameter value', startTime); or var id = system.setInterval('myJavaScriptFunction("I am a parameter value");', 2000, null, startTime);

example 4:

    //Setting to start in 2 minutes from now
    var startTime = new Date();
    startTime.setMinutes(startTime.getMinutes() + 2);
 

//Setting to end in 4 minutes after starting var endtime = new Date(); endtime.setMinutes(startTime.getMinutes() + 4);

var id = system.setInterval(myJavaScriptFunction, 2000, 'I am a parameter value', startTime, endtime); or var id = system.setInterval('myJavaScriptFunction("I am a parameter value");', 2000, null, startTime, endtime);

Parameters:
cx - - The Rhino context which is created for each invocation of a function
thisObj -
arguments - The expected arguments are; the JavaScript function to execute and the frequency of execution. Optionally you can provide a start and end time. The default start time is 'after given number of milliseconds in the frequency parameter' and end time is 'indefinitely'.
funObj -
Returns:
String - An id representing a handle to the timer
Throws:
java.io.IOException

jsFunction_clearInterval

public static void jsFunction_clearInterval(org.mozilla.javascript.Context cx,
                                            org.mozilla.javascript.Scriptable thisObj,
                                            java.lang.Object[] arguments,
                                            org.mozilla.javascript.Function funObj)
                                     throws java.io.IOException

Removes a JavaScript function scheduled for periodic execution using the job id

   system.clearInterval(id);
 

Parameters:
cx -
thisObj -
arguments - The expected argument is a string representing the ID of the scheduled function
funObj -
Throws:
java.io.IOException

jsFunction_notifyMonitor

public static void jsFunction_notifyMonitor(org.mozilla.javascript.Context cx,
                                            org.mozilla.javascript.Scriptable thisObj,
                                            java.lang.Object[] arguments,
                                            org.mozilla.javascript.Function funObj)
                                     throws org.apache.axis2.AxisFault

Sends notification to a monitoring software via JMX. A single parameter is assumed to be the message, while if another string is provided it is the title. A third parameter , if integer, is assumed to be the message severity (info = 0, error = 1, warning = 2 and none = 3).

 system.notifyMonitor("Message");
 system.notifyMonitor("Title", "Message");
 system.notifyMonitor("Title", "Message", 3);
 

Throws:
org.apache.axis2.AxisFault