Windchill 中的业务逻辑方法,可以让其运行在MethodServer上,9.1 版本的系统通过反射调用来实现在MethodServer上运行。10.0版本是通过java annotation实现。为什么会出现这样的方式调用方法呢?经过仔细分析,以及和PTC技术支持多次沟通,确定如下原因:
1 代码是跨越methodServer运行,要去访问缓存数据,或者数据库,那么就需要实现service方法。最典型的使用场景就是jsp中的java代码要查找windchill系统的数据,就需要使用service方法来跨越methodserver运行。
2 第二种典型使用场景就是,需要设置当前用户的用户名和密码等信息。
RemoteMethodServer rms = RemoteMethodServer.getDefault();
rms.setUserName("");
rms.setPassword("");
现在来看看实现service方法的具体过程:
1 设计服务类的接口
import wt.method.RemoteInterface;
import wt.part.WTPart;
import wt.util.WTException;
@RemoteInterface
public interface TrainingService {
WTPart createFatherOf(final String name) throws WTException;
}
2 接口的实现
import wt.fc.PersistenceHelper;
import wt.part.WTPart;
import wt.services.StandardManager;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
public class StandardTrainingService extends StandardManager implements TrainingService{
private static final long serialVersionUID = 1L;
public static StandardTrainingService newStandardTrainingService() throws WTException{
final StandardTrainingService service = new StandardTrainingService();
service.initialize();
return service;
}
public WTPart createFatherOf(String name) throws WTException {
final WTPart part = WTPart.newWTPart();
try {
part.setName("I am you father, "+name);
} catch (WTPropertyVetoException e) {
throw new WTException(e);
}
return (WTPart)PersistenceHelper.manager.store(part);
}
}
3 Helper类的实现
import wt.services.ServiceFactory;
public class TrainingHelper {
public static final TrainingService service = ServiceFactory.getService(TrainingService.class);
}