Windchill Service方法實現

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);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章