Scripting Server

GPSystem - Reference Documentation

Class implementing the Global Platform GPSystem class

Index of Methods

Constructor

Prototype

None

Description

The GPSystem class only provides class functions. No objects can be instantiated.

Exceptions

Name Value Description

Example


getVersion()

Prototype

String getVersion()

Description

Retrieve the version of the Global Platform Scripting specification implemented by the runtime.

Return

String String containing the version number

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


version = GPSystem.getVersion();

assert(version == "1.1.0");

wait()

Prototype

wait(Number ms)

Description

Wait for a specified period

Arguments

Type Name Description
Number ms The time to wait in milliseconds

Return

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_DATA The argument stringValue contains characters not compatible with the encoding format
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


start = new Date().valueOf();
waitingTime = 1000;

GPSystem.wait(waitingTime);

stop = new Date().valueOf();
elapsed = stop - start;

// Allow a tolerance of 10 ms
print("Wait: " + waitingTime + " ms / Elapsed: " + elapsed + " ms");
assert(((elapsed - 50) <= waitingTime) && ((elapsed + 50) >= waitingTime));

trace()

Prototype

boolean trace(Object o)

Description

Append data to the trace file by calling the objects "toString()" method.

Arguments

Type Name Description
Object o The object to trace

Return

Boolean Boolean value indicating the success (true) or failure (false) of the tracing

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_DATA The argument stringValue contains characters not compatible with the encoding format
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


rval = GPSystem.trace("Testoutput from GPSystem.trace()");
// assert(rval == true);

try {
	GPSystem.trace(null);
}
catch (e) {
	assert(e instanceof GPError);
	assert(e.error == GPError.INVALID_TYPE);
}

isTraceOn()

Prototype

boolean isTraceOn()

Description

Return true if the trace is enabled.

Return

Boolean Boolean value indicating if tracing is enabled

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


assert(typeof(GPSystem.isTraceOn()) == "boolean");

log()

Prototype

boolean log(Number level, String class, Object o)

Description

Log information for class at level by calling the objects "toString()" method.

Arguments

Type Name Description
Number level The log level, which is one of GPSystem.[DEBUG, INFO, WARN, ERROR, FATAL]
Object o The object to log

Return

Boolean Boolean value indicating the success (true) or failure (false) of the tracing

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_DATA The argument stringValue contains characters not compatible with the encoding format
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


GPSystem.log(GPSystem.DEBUG, "ClassName", "Output at DEBUG log level");
GPSystem.log(GPSystem.INFO,  "ClassName", "Output at INFO log level");
GPSystem.log(GPSystem.WARN,  "ClassName", "Output at WARN log level");
GPSystem.log(GPSystem.ERROR, "ClassName", "Output at ERROR log level");
GPSystem.log(GPSystem.FATAL, "ClassName", "Output at FATAL log level");
GPSystem.log(GPSystem.FATAL, "ClassName", null);

markTrace()

Prototype

markTrace()

Description

Mark the current position in the trace output for later retrieval of trace output using the copyTrace() method.

Return

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


GPSystem.markTrace();

copyTrace()

Prototype

String copyTrace()

Description

Return the trace starting with the position marked with the markTrace() method up to the very last entry.

Return

String Copy of the recent trace entries or null if unsupported

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


var msg ="Hello World"; 
GPSystem.trace(msg);
var t = GPSystem.copyTrace();

if (t != null) {
	assert(t == msg + "\n");
}


getVendorObject()

Prototype

getVendorObject(String objectName)

Description

Retrieve a vendor specific object

Arguments

Type Name Description
String objectName The name of the object

Return

Object The created object

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call
GPError GPError.OBJECTCREATIONFAILED The desired object could not be created

Example


try {
	obj = GPSystem.getVendorObject("myObject");
}
catch (e) {
	assert(e instanceof GPError);
	assert(e.error == GPError.OBJECTCREATIONFAILED);
}

getSystemID()

Prototype

getSystemID()

Description

Get the ID of the system.

For the smart card development platform a unique object identifier is returned.

It has the following components: OpenSCDP.Runtime.MajorVersion.MinorVersion.Build.SerialNumber.

Return

ByteString The ID of the system or null if none available

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


var id = GPSystem.getSystemID();
print(id);
var s = id.toString(OID).split(".");

print("Runtime : " + s[s.length - 5]);
print("Major   : " + s[s.length - 4]);
print("Minor   : " + s[s.length - 3]);
print("Build   : " + s[s.length - 2]);
print("Serial  : " + s[s.length - 1]);


dateTimeByteString()

Prototype

dateTimeByteString()

Description

Return a ByteString containing the current date and time

Return

ByteString The current date and time

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


time = GPSystem.dateTimeByteString();
assert(time != null);
assert(time instanceof ByteString);

mapFilename()

Prototype

mapFilename(String filename, Number location)

mapFilename(String filename)

Description

Searches for a file at the given location and maps the filename to the system specific absolute path.

If no location is specified the function uses the default location identifier GPSystem.AUTO.

Arguments

Type Name Description
String filename Filename
Number location Location indicator (GPSystem.CWD, GPSystem.USR, GPSystem.SYS, GPSystem.AUTO)

Return

String Absolute path of the file. Null if the file was not found.

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


absFilename = GPSystem.mapFilename("config.js", GPSystem.SYS);
assert(absFilename != null);

absFilename = GPSystem.mapFilename("config.js");
assert(absFilename != null);

absFilename = GPSystem.mapFilename("novalidfile.js");
assert(absFilename == null);