Advanced Customization > Services and Infrastructure Customization > System Generation > Modeling Business Objects > Services
  
Services
Windchill services provide APIs and logic to manage modeled business objects. They consist of:
An (optional) helper consisting of static fields and methods, including a static field (generally named service or manager) referring to a service
A service interface consisting of remotely-invocable method declarations
A standard service which implements the service and is registered to run as a service in the Method Server.
Services are covered elsewhere in this document. However, this is the basic pattern.
Listing 17: ExampleHelper.java
01 package com.acme.example;
02
03 import wt.services.ServiceFactory;
04
05 /** Helpers are not instantiated and should consist of only static
fields/methods **/
06 public final class ExampleHelper {
07 /** Use the ServiceFactory to acquire an instance of the service. **/
08 public static final ExampleService service = ServiceFactory.
getService(ExampleService.class);
09 }
Listing 18: ExampleService.java
01 package com.acme.example;
02
03 import wt.method.RemoteInterface;
04 import wt.util.WTException;
05
06 /** RemoteInterface annotation is required for all service interfaces **/
07 @RemoteInterface
08 public interface ExampleService {
09 /** All interface methods are callable via RMI and must
throw WTException **/
10 SimpleExample createSimpleExampleByName(final String name)
throws WTException;
11 }
Listing 19: StandardExampleService.java
01 package com.acme.example;
02
03 import wt.fc.PersistenceHelper;
04 import wt.services.StandardManager;
05 import wt.util.WTException;
06 import wt.util.WTPropertyVetoException;
07
08 /** service must extend StandardManager, implement service interface **/
09 public class StandardExampleService extends StandardManager implements
ExampleService {
10 /** MethodServer refectively calls this API during startup **/
11 public static StandardExampleService newStandardExampleService()
throws WTException {
12 final StandardExampleService instance = new StandardExampleService();
13 instance.initialize();
14 return instance;
15 }
16
17 @Override
18 public SimpleExample createSimpleExampleByName(final String name)
throws WTException {
19 final SimpleExample example = SimpleExample.newSimpleExample();
20 try {
21 example.setName(name);
22 }
23 catch (WTPropertyVetoException wtpve) {
24 throw new WTException(wtpve);
25 }
26 return (SimpleExample) PersistenceHelper.manager.store(example);
27 }
28 }
The service must be registered in site.xconf; the number 99999 must be unique so as not to replace an existing service. Note that changes to site.xconf must be propagated using xconfmanager. All customization services must be registered in site.xconf.
Listing 20: site.xconf fragment
01 <Property name="wt.services.service.99999"
02 targetFile="codebase/wt.properties"
03 value="com.acme.training.MyService/com.acme.
training.StandardMyService"/>
With this service, we could reduce our Jython example to persist a SimpleExample to the following:
Listing 21: Persisting SimpleExample with service
01 from com. acme . example import
02
03 se = ExampleHelper.service.createSimpleExampleByName(’test’)