2013-03-15 71 views
1

我正在使用Windchill 10.0 M030。我創建了一個捕獲一些操作的Windchill服務。我完成了捕獲刪除,簽入和狀態更改事件,但我不知道如何捕獲對象的修訂事件。有人可以幫我嗎?如何捕獲WTObject的修訂事件?

一些示例代碼片段會很有幫助。可以正常工作的事件如下:

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

有沒有像這樣捕獲修改事件的單獨事件?我怎樣才能做到這一點?

謝謝。

回答

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命令行實用程序)