definePublicObject function

In z/OSMF, a public object is a Dojo AMD class that IBM, you, or a vendor defined that has been instantiated and stored in z/OSMF core, making the class accessible to any vendor and any z/OSMF task. If your plug-in contains multiple tasks and you want to pass data between those tasks, consider creating a public object for the tasks to share. To do so, call the definePublicObject function.

Invoking the function

To call the definePublicObject function, use the syntax shown in Figure 1.

Figure 1. Syntax to use to call the definePublicObject function
win.global.zosmfExternalTools.definePublicObject(class,handle,callback[,
    dojoPackageAlias,dojoPackageLocation]);
where,
class
Specify either the path to the Dojo class or the object of the Dojo class that you want to publicly store in z/OSMF core. When specifying the path, you can specify a path that is relative to the Dojo package location, or you can specify the absolute path. The class is required.
handle
Specify the name you want z/OSMF core to assign to the public object. The handle is required.
callback
Specify the function you want z/OSMF core to call when the object is available for your plug-in to use. The callback function is required.
dojoPackageAlias
Specify the shortcut or alias to use when referring to the location of the package that contains the Dojo classes. z/OSMF core will map the alias to the actual location of the package. The Dojo package alias is required only if you specify a path for the class parameter.
dojoPackageLocation
Specify the absolute path to the Dojo package. z/OSMF core will map this path to the Dojo package alias you specified. The Dojo package location is required only if you specify a path for the class parameter.
When your plug-in calls the definePublicObject function, if a path is specified for the class parameter, z/OSMF core:
  1. Resolves the alias, and locates the Dojo package.
  2. Instantiates the Dojo class, turning it into an object.
  3. Stores the object in z/OSMF core under the specified handle.
  4. Calls the callback function, which you provided, and passes the object to the function for your plug-in to use.
When your plug-in calls the definePublicObject function, if an object of the Dojo class is specified for the class parameter, z/OSMF core:
  1. Stores the object in z/OSMF core under the specified handle.
  2. Calls the callback function, which you provided, and passes the object to the function for your plug-in to use.

Example

In the following example, the path to the Dojo package is /zosmf/IzuUICommon/externalfiles/util/js. The alias for this path is zosmfUtil.

The path to the class that will be defined as a public object is /zosmf/IzuUICommon/externalfiles/util/js/UtilConstants. With the alias, the path to the class becomes zosmfUtil/UtilConstants. The public object will be called utilGlobal.

After z/OSMF core creates a new instance of the public object, z/OSMF core calls the testCallback function and supplies the handle for the object.

Figure 2. Sample code for the definePublicObject function
var testCallback = function(obj){
   console.log("callback called!");
   console.log("with object "+obj);
}

function init(){
win.global.zosmfExternalTools.definePublicObject(
   "zosmfUtil/UtilConstants","utilGlobal",testCallback,
   "zosmfUtil","/zosmf/IzuUICommon/externalfiles/util/js");
}