当前位置:文档之家› Windchill客制化服务

Windchill客制化服务

Windchill客制化服务
Windchill客制化服务

Windchill客制化服务(转载)

通过添加Windchill客制化服务,可以让自己业务相关的对象在Windchill启动时进行初始化。如定制数据缓存,初始化静态变量,从而减少用户访问数据库的频率,提高访问相关数据的速度。

废话不多说,直接上代码,照着下面的步骤一步步来就ok。

/*************************************************************/

第一步:定义自己的业务接口ServiceInterface ,用来存放一些静态变量,方便其实现类的使用,我在这里将静态变量定义到了实现类中,所以只需写一个空的接口即可,代码如下:

Java代码

1.package com.wcservice;

2./**

3.*

4.*

Description:

5.* @author:

6.* @time: 2010-4-30 下午05:03:35

7.* @version 1.0

8.*/

9.public interface ServiceInterface {

10.

11.//##begin user.attributes preserve=yes

12.//##end user.attributes

13.

14.//##begin static.initialization preserve=yes

15.//##end static.initialization

16.

17.//##begin user.operations preserve=yes

18.//##end user.operations

19.}

/*************************************************************/

第二步,定义该接口的第一个实现类ServiceInterfaceImp ,同时需要实现wt.method.RemoteAccess类,这个类里的相关代码是无需修改的。

Java代码

1.package com.wcservice;

2.

3.import java.io.Serializable;

4.import https://www.doczj.com/doc/647828442.html,ng.String;

5.import wt.method.RemoteMethodServer;

6.import wt.services.Manager;

7.import wt.services.ManagerServiceFactory;

8.import wt.util.WTException;

9.

10./**

11.*

12.*

Description:

13.* @author:

14.* @time: 2010-4-30 下午04:57:53

15.* @version 1.0

16.*/

17.public class ServiceInterfaceImp implements

wt.method.RemoteAccess,

18.ServiceInterface, Serializable {

19.

20.// --- Attribute Section ---

21.

22.static final boolean SERVER = RemoteMethodServer.ServerFlag;

23.

24.private static final String FC_RESOURCE = "wt.fc.fcResource";

25.

26.private static final String CLASSNAME =

ServiceInterfaceImp.class.getName();

27.

28.// --- Operation Section ---

29./**

30.* @return Manager

31.* @exception wt.util.WTException

32.*/

33.private static Manager getManager() throws WTException {

34.Manager manager = ManagerServiceFactory.getDefault().getManager(

35.ServiceInterface.class);

36.if (manager == null) {

37.Object[] param = {CLASSNAME};

38.throw new WTException(FC_RESOURCE,

39.wt.fc.fcResource.UNREGISTERED_SERVICE, param);

40.}

41.return manager;

42.}

43.}

第三步,定义客制化服务启动和关闭的类MyService。

//该类需要继承wt.services.StandardManager类,并实现我们刚才定义的接口ServiceInterface,详细注释见代码:

Java代码

1.package com.wcservice;

2.

3.import java.io.Serializable;

4.

5.import wt.services.ManagerException;

6.import wt.services.StandardManager;

7.import wt.util.WTException;

8./**

9.*

10.*

Description: 定义windchill客制化服务启动和停止的方法,同时

定义创建该类对象的方法

11.* @author:

12.* @time: 2010-4-30 下午05:18:26

13.* @version 1.0

14.*/

15.public class MyBusiness extends StandardManager implements

ServiceInterface,Serializable {

16.

17.// --- Operation Section ---

18.

19./**

20.* 返回MyBusiness的对象,并调用父类StandardManager的initialize()

方法进行初始化,该方法内容无需修改,方法名格式为new+你的类名

21.*/

22.public static MyBusiness newMyBusiness() throws WTException {

23.System.out.println(MyBusiness.class.getName()+".newMyBusiness()

,MyBusiness对象初始化完毕。");

24.MyBusiness instance = new MyBusiness();

25.instance.initialize();

26.return instance;

27.}

28.

29.// ##begin user.operations preserve=yes

30.protected void performStartupProcess() throws ManagerException {

31.//write your business here,while windchill start,it execute

32.System.out.println(MyBusiness.class.getName()+".performStartupP

rocess()方法执行,windchill服务正在启动!");

33.}

34.

35.protected void performShutdownProcess() throws ManagerException {

36.//write your business here,while windchill stop,it execute

37.System.out.println(MyBusiness.class.getName()+".performShutdown

Process()方法执行,windchill服务正在停止!");

38.}

39.}

第四步,将class文件copy到codebase对应目录下,然后打开

/site.xconf增加如下内容:

Xml代码

1.

2.

3.

4.targetFile="codebase/wt.properties"

5.value="com.wcservice.ServiceInterface/com.wcservice.MyBusiness"

/>

修改完site.xconf文件,windchill shell中执行如下命令:

Java代码

1.xconfmanager -p

第五步,重启windchill MethodServer,观察MethodServer窗口,可以看到:先执行MyBusiness类的初始化方法newMyBusiness(),后执行performStartupProcess()方法。

然后关闭MethodServer的时候,可以看到MyBusiness类的performShutdownProcess()方法执行。

按照我的上述步骤进行,就算你是个windchill超级新手,也会成功。原理我就

不在这里说了,大家有空可以多看看windchill的api。

相关主题
文本预览
相关文档 最新文档