Example 2: Methods

If you can't play the video, make sure that you are logged in at Wex Solutions.

This example illustrates the basics regarding method-calling across different Windchill Extensions through the WexInvoker.invoke method.

You can find the code for this example in our Git-Hub repository.

Implementation

The methods are defined as Features in the ExampleMethods.java file.

image-20220815174416781

As seen in the Development section of the Developer's Guide, a Method Feature is declared with the use of the @WexComponent and @WexMethod annotations. This will make the WEX Kernel expose the method to Windchill, which will make it callable by other entities in the system.

image-20230426175023311

Execution

To execute the test, deploy the extension to a Windchill server from the Extension Manager. Then go to the extension's User Guide and click the link:

1617642608083

Clicking the link will run the JSP located at wex\jsp\test.jsp which calls the abovementioned methods through the WexInvoker.invoke command. Said JSP file contains the following code:

<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="com.wincomplm.wex.kernel.api.invoke.WexInvoker"%>
<html>
    <body style="font-family: Arial, Helvetica, sans-serif;">
        <h1>Sample method examples</h1>
        <table>
            <tr><td><b>Simple call</b></td><td><%= (String) WexInvoker.invoke("com.wincomplm.wex-example-method","methods.example") %></td></tr>
            <tr><td><b>Call with argument</b></td><td><%= (String) WexInvoker.invoke("com.wincomplm.wex-example-method","methods.argName","Bob") %></td></tr>
            <tr><td><b>Windchill user name</b></td><td><%= (String) WexInvoker.invoke("com.wincomplm.wex-example-method","methods.userName") %></td></tr>
        </table>
    </body>
</html>

The following pop-up window will appear after clicking on the link:

1617642666605

What is displayed in the window is the result of the three calls made in the JSP file. They are, as you can see by reviewing the code:

These are the Features that were defined with the use of the annotations, which can be seen from the Extension Manager:

1617642854823

Command Line

Any command line methods must be implemented as a Feature, due to the code within the WEX being isolated and not available to the Windchill system. If you'd like to learn more about the system's architecture, there's an explanation on it on the Developer Guide.

The following Command Line example, even though basic, covers the general aspects of the implementation process.

First, let's take a look at the code:

image-20220815194709801

  1. As in any regular .java file, we start declaring the package name.
  2. The following six imports are necessary for the implementation of the Command Line feature, since they bring in the dependencies and annotations that make the declaration of the Feature and the Command Line parameters possible.
  3. The class CmdLineParser only needs to be brought in when we need to pass arguments to the Command Line, as in this example we did with the variable msg.
  4. Notice how there are two implementations of the execute() method. In the public void execute() we define the actions to be executed by the command; the naming for this one is optional and can be done to taste. public int execute(String[] args), on the other hand, is mandatory, since it needs to @Override the method with the same name that's declared in the IWexCommandLine Interface. The purpose of this second method will be to parse the input arguments, when needed, and call the other one.