package gw.contact uses gw.lang.reflect.IType uses java.lang.ThreadLocal uses java.util.Set uses java.util.HashSet uses java.lang.IllegalArgumentException /** * Contact Tokens provide information about calls made into the contact system integration stored within a TheadLocal. * Note, it is important that any process using these methods should set and clear the thread-local tokens within the * scope of a single web service call. * * This class replaces ExternalAppThreadLocal */ @ReadOnly class ContactTokenThreadLocal { static var _threadLocal = new ThreadLocal>(){ override function initialValue() : Set{ return new HashSet() } } var _externalApp : String as readonly ExternalApp var _linkId : String as readonly LinkId var _type : Type as readonly TokenType protected construct(theExternalApp : String, theLinkId : String, aType : IType){ _externalApp = theExternalApp _linkId = theLinkId _type = aType } static function setToken(appStr : String, link : String, aType : IType){ if (link == null){ throw new IllegalArgumentException("Must have a non-null link id to create a contact token") } var token = new ContactTokenThreadLocal(appStr, link, aType) var tokenSet = _threadLocal.get() tokenSet.add(token) } static function isTokenSet(appStr : String, link : String, aType : IType): boolean { var token = new ContactTokenThreadLocal(appStr, link, aType) var tokenSet = _threadLocal.get() return tokenSet.contains(token) } static function areTokensEmpty(): boolean { return _threadLocal.get().Empty } static function clearAllTokens(){ _threadLocal.get().clear() } static protected function getSet() : Set{ return _threadLocal.get() } override function toString() : String { return "ExternalApp:${ExternalApp} LinkId:${LinkId} TokenType:${TokenType}" } override function equals(o : Object) : boolean { if (this === o) { return true; } if (typeof o != ContactTokenThreadLocal) { return false; } var contactToken = o as ContactTokenThreadLocal; if (ExternalApp != null ? !ExternalApp.equals(contactToken.ExternalApp) : contactToken.ExternalApp != null) { return false; } if (LinkId != null ? !LinkId.equals(contactToken.LinkId) : contactToken.LinkId != null) { return false; } if (TokenType != null ? !TokenType.equals(contactToken.TokenType) : contactToken.TokenType != null) { return false; } return true; } override function hashCode() : int { var result = 17 result = 31 * result + (ExternalApp != null ? ExternalApp.hashCode() : 0); result = 31 * result + (LinkId != null ? LinkId.hashCode() : 0); result = 31 * result + (TokenType != null ? TokenType.hashCode() : 0); return result; } }