如何捕获WTObject的修订事件?

时间:2013-03-15 09:44:21

标签: java events ptc-windchill

我使用的是Windchill 10.0 M030。我创建了一个捕获一些操作的windchill服务。我完成了捕获删除,签入和状态更改事件,但我不知道如何捕获对象的修订事件。有人可以帮助我吗?

一些示例代码段会很有帮助。工作正常的事件如下:

public void notifyEvent(KeyedEvent event) throws RemoteException,
            WTException {


        if (event instanceof PersistenceManagerEvent) {
            notifyEvent((PersistenceManagerEvent) event);
        }
        if (event instanceof WorkInProgressServiceEvent) {
            notifyEvent((WorkInProgressServiceEvent) event);
        }
        if (event instanceof EPMWorkspaceManagerEvent) {
            notifyEvent((EPMWorkspaceManagerEvent) event);
        }

        if (event instanceof LifeCycleServiceEvent) {
            notifyEvent((LifeCycleServiceEvent) event);
        }
    }

是否有任何单独的事件,例如以这种方式捕获的Revise事件?我怎么能这样做?

谢谢。

1 个答案:

答案 0 :(得分:3)

以下是ListenerAdapter的代码:

public class VersionEventListenerAdapter extends ServiceEventListenerAdapter {

public VersionEventListenerAdapter(String serviceId) {
    super(serviceId);
}

public void notifyVetoableEvent(Object event) throws WTException, WTPropertyVetoException {
    if (!(event instanceof KeyedEvent)) {
        return;
    }

    Object target = ((KeyedEvent) event).getEventTarget();
    Object eventType = ((KeyedEvent) event).getEventType();

    if (eventType.equals(VersionControlServiceEvent.NEW_VERSION)
    {
       /** Call your business code here 
           example : yourMethod(target);
        **/
    }
}

然后注册监听器的服务

public class MyStandardListenerService extends StandardManager implements MyListenerServiceInterface {

private static final long serialVersionUID = 1L;

protected synchronized void performStartupProcess() throws ManagerException {

    VersionEventListenerAdapter versionEventListenerAdapter = new VersionEventListenerAdapter(getName());
    getManagerService().addEventListener(versionEventListenerAdapter, VersionControlServiceEvent.generateEventKey(VersionControlServiceEvent.NEW_VERSION));

}

public static MyStandardListenerService newMyStandardListenerService() throws WTException {
    MyStandardListenerService instance = new MyStandardListenerService();
    instance.initialize();
    return instance;
}

这项新服务需要在wt.properties中注册。有关如何注册它的更多详细信息,请参阅定制程序指南(使用xconfmanager命令行实用程序)