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.
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_clearTimeout(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          Sometimes it's useful to be able to cancel a timer before it goes off.
static java.lang.Object jsFunction_getXML(org.mozilla.javascript.Context context, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
           Utility function to get an XML file over the network var history = system.getXML('http://wso2.org/repos/wso2/trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/history.xml'); You can also do basic authentication by giving a username/password var history = system.getXML('http://wso2.org/repos/wso2/trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/history.xml', 'username', 'password');
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_log(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          Allows printing to the system log from a Mashup.
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 java.lang.String jsFunction_setTimeout(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          setTimeout() allows you to specify that a piece of JavaScript code (called an expression) will be run a specified number of milliseconds from when the setTimeout() method was called.
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.wso2.mashup.MashupFault
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.wso2.mashup.MashupFault - Thrown in case any exceptions occur

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 - Thrown in case any exceptions occur

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 org.wso2.mashup.MashupFault
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:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur

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 org.wso2.mashup.MashupFault
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);
 
Throws:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur

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 org.wso2.mashup.MashupFault
Removes a JavaScript function scheduled for periodic execution using the job id
   system.clearInterval(id);
 
Throws:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur

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.wso2.mashup.MashupFault

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.wso2.mashup.MashupFault - Thrown in case any exceptions occur

jsFunction_getXML

public static java.lang.Object jsFunction_getXML(org.mozilla.javascript.Context context,
                                                 org.mozilla.javascript.Scriptable thisObj,
                                                 java.lang.Object[] arguments,
                                                 org.mozilla.javascript.Function funObj)
                                          throws org.wso2.mashup.MashupFault

Utility function to get an XML file over the network

 var history = system.getXML('http://wso2.org/repos/wso2/trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/history.xml');

 You can also do basic authentication by giving a username/password

 var history = system.getXML('http://wso2.org/repos/wso2/trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/history.xml', 'username', 'password');
 
Throws:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur

jsFunction_setTimeout

public static java.lang.String jsFunction_setTimeout(org.mozilla.javascript.Context cx,
                                                     org.mozilla.javascript.Scriptable thisObj,
                                                     java.lang.Object[] arguments,
                                                     org.mozilla.javascript.Function funObj)
                                              throws org.wso2.mashup.MashupFault
setTimeout() allows you to specify that a piece of JavaScript code (called an expression) will be run a specified number of milliseconds from when the setTimeout() method was called.
    ex: setTimeout (expression, timeout);
 
where expression is the JavaScript code to run after timeout milliseconds have elapsed. setTimeout() also returns a numeric timeout ID that can be used to track the timeout. This is most commonly used with the clearTimeout() method
Throws:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur

jsFunction_clearTimeout

public static void jsFunction_clearTimeout(org.mozilla.javascript.Context cx,
                                           org.mozilla.javascript.Scriptable thisObj,
                                           java.lang.Object[] arguments,
                                           org.mozilla.javascript.Function funObj)
                                    throws org.wso2.mashup.MashupFault
Sometimes it's useful to be able to cancel a timer before it goes off. The clearTimeout() method lets us do exactly that.
    ex: clearTimeout ( timeoutId );
 
where timeoutId is the ID of the timeout as returned from the setTimeout() method call.
Throws:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur

jsFunction_log

public static void jsFunction_log(org.mozilla.javascript.Context cx,
                                  org.mozilla.javascript.Scriptable thisObj,
                                  java.lang.Object[] arguments,
                                  org.mozilla.javascript.Function funObj)
                           throws org.wso2.mashup.MashupFault
Allows printing to the system log from a Mashup.
    ex: system.log(logmessage, loglevel);
 
Where logmessage contains a string to be written to the system log and (optional) loglevel indicates the logging level as 'info', 'warn', 'debug', 'error' or 'fatal'. The logging level defaults to 'info' when one is not provided.
Throws:
org.wso2.mashup.MashupFault - Thrown in case any exceptions occur