When you use an interface of type JavaObject, you often need to access a static method that creates an object at run time. This requirement is in effect because the EGL interface technology does not allow you to instantiate a Java™ object from within your EGL code.
package myInterfaces; Interface HelloWorld type JavaObject {javaName = "HelloWorld", packageName = "com.ibm.examples.helloWorld"} function sayHello(name String) returns (String); End
package com.ibm.examples.helloWorld; class HelloWorld { // Java class constructor public HelloWorld() { } // implementation of the function // that is referenced in the interface public String sayHello(String name) { return "Hello " + name; } }
package myInterfaces; Interface HelloWorldFactory {javaName = "HelloWorldFactory", packageName = "com.ibm.examples.helloWorld"} static function createHelloWorld() returns (HelloWorld); End
package com.ibm.examples.helloWorld; class HelloWorldFactory { // Java class constructor public HelloWorldFactory() { } // implementation of the function // that is referenced in the interface public static HelloWorld createHelloWorld() { return new HelloWorld; } }
package myDriver; import myInterfaces.*; program myProgram { } function myFunction() echo STRING; // create a variable of type HelloWorld; // this reference variable points to NIL hwVar HellowWorld; // assign a Java object to the variable hwVar = HelloWorldFactory.createHelloWorld(); // access any Java method that is in // the object of type HelloWorld // and has a corresponding // function description // in the EGL interface part echo = hwVar.sayHello("John Doe"); End End
When you are writing a pageHandler that interacts with the JSF component tree, you create variables that are based on EGL interface parts; however, you are not concerned with object creation because EGL handles the issue at run time. For an overview, see JSF component tree.
Related concepts
EGL interfaces
JSF component tree
Related tasks
Creating an EGL Interface part
Related reference
Interface part in EGL source format
Interfaces of type JavaObject