External Modules
- Create a Java class that implements the WSRunnable interface.
- Implement business logic in the required
run(…)method, which takes the WSContext as one of its arguments. Use the WSContext object to gain access to WorldServer services. - Use the WSContextManager class to execute your WSRunnable class.
run method that provides access to the WSContext object. The WSRunnable interface is not an object access interface. Unlike the object access interfaces, the SDK user is expected to implement this interface to create WorldServer SDK applications that can be executed outside of a hosted WorldServer environment. The WSRunnable interface is defined below:
public interface WSRunnable {
public boolean run(WSContext wsContext);
}
The WSContextManager class contains methods that allow you to run a WSRunnable class instance.
public static void runAsUser(String username, String password, WSRunnable runnable– requires that you provide the user name and password for authentication.public static void runAsUser(String username, String password, WSRunnable runnable, int retryCount)– requires that you provide the user name and password for authentication, and accepts a retry parameter telling the system how many times to retry this runnable process in the event of an exception.public static void run(WSContext context, WSRunnable runnable)– requires you to provide an existing context object from which credentials will be derived.
- Executing explicit class instances (executing via
mainmethod of WSRunnable class):public class MySample implements WSRunnable { public boolean run(WSContext wsContext) { { try { // TO-DO: Provide custom code } catch (Exception ex) { // handle exception } } public static void main(String[] args) { MySample sample = new MySample(); WSContextManager.runAsUser(“username”, “password”, sample); } } - Executing anonymous class instances:
public class MySample { public void doSDKProcess(WSContext wsContext) { { // creates an anonymous WSRunnable process that // is executed WSContextManager.run(“username”, “password”, new WSRunnable() { public boolean run(WSContext wsContext) { // TO-DO: Do something useful return true; } // close anonymous run method }); } }
Creating Command-Line Tools
Creating a stand-alone SDK application or an SDK utility class is essentially the same as writing any standard Java program in that you must implement the main() method.. You call the WSContextManager explicitly to execute your SDK-enabled code using either explicit or anonymous class models described above.
Alternatively, you can use the SDK command framework for creating new commands by extending the WSCommand class. This class provides some common utilities for processing command-line arguments, command usage information, and more. Refer to the Java Doc for more details on its usage. Several provided samples use this framework. You can use them as templates for your own implementations.