1

我正在尝试使用 Java(和 Eclipse)从 Teamcenter 8 富客户端中的登录会话中获取会话参数,例如用户名。

public class SampleHandler extends AbstractHandler
{
    public Object execute(ExecutionEvent event) throws ExecutionException
    {
        // good, but useless
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    
        // wrong
        AbstractAIFSession a = AIFUtility.getSessionManager().getDefaultSession();
    
        // wrong
        AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
        TCSession session = (TCSession)app.getSession();

        // wrong
        ISessionService iss = AifrcpPlugin.getSessionService();
        session = (TCSession)iss.getSession("com.teamcenter.rac.kernel.TCSession");

        return null;
    }
}

该片段取自已编译的代码,当我运行我的插件并尝试调用AIFUtility类中的某些方法时,AifrcpPlugin会引发异常。

有谁知道如何获取当前会话的用户名?

4

1 回答 1

2

您可以使用AIFUtility.getCurrentApplication().getSession()获取当前会话,并session.getUserName()获取当前登录用户的用户名。

AbstractAIFSession session = AIFUtility.getCurrentApplication().getSession();
String username = session.getUserName();
String registry = session.getRegistry();
于 2014-02-12T14:10:28.890 回答