Exportfile for AOT version 1.0 or later Formatversion: 1 ***Element: CLS ; Microsoft Dynamics AX Class: SysDictClass unloaded ; -------------------------------------------------------------------------------- CLSVERSION 1 CLASS #SysDictClass PROPERTIES Name #SysDictClass Extends #DictClass RunOn #Called from ENDPROPERTIES METHODS Version: 3 SOURCE #allowMakeObject #/* # This methods will return false, if: # * The class is abstract # * The class doesn't implement required abstract methods # * The new method has parameters #*/ #public boolean allowMakeObject() #{ # str text; # XppCompiler compiler; # ExecutePermission permission; # ; # # if (this.isAbstract()) # return false; # # permission = new ExecutePermission(); # permission.assert(); # # // BP deviation documented # compiler = new XppCompiler(); # text = strfmt('%1 test(){return new %1();}',this.name()); # # return compiler.compile(text); #} ENDSOURCE SOURCE #classDeclaration #// This is a framework class. Customizing this class may cause problems with future upgrades to the software. #public class SysDictClass extends DictClass implements SysDictXmlReflectionProvider, SysDictXmlDocumentationProvider #{ # #XmlDocumentation #} ENDSOURCE SOURCE #hasObjectMethod #boolean hasObjectMethod( # identifiername methodName # ) #{ # SysDictMethod dictMethod = new SysDictMethod(UtilElementType::ClassInstanceMethod,this.id(),methodName); # # if (! dictMethod) # return false; # # if (! dictMethod.compiledOk()) # return false; # # return true; #} ENDSOURCE SOURCE #hasStaticMethod #boolean hasStaticMethod(identifiername methodName) #{ # SysDictMethod dictMethod = new SysDictMethod(UtilElementType::ClassStaticMethod,this.id(),methodName); # # if (! dictMethod) # return false; # # if (! dictMethod.compiledOk()) # return false; # # return true; #} ENDSOURCE SOURCE #implementedBy #//Returns set of classid's of those classes that are implementing the specified interface (_id). #public List implementedBy() #{ # Dictionary dictionary = new Dictionary(); # SysDictClass sysDictClass; # List implementList = new List(Types::Integer); # List classList = new List(Types::Integer); # Counter counter; # int classCount; # classId classId; # ; # # classCount = dictionary.classCnt(); # for (counter=1;counter<=classCount;counter++) # { # classId = dictionary.classCnt2Id(counter); # sysDictClass = new SysDictClass(classId); # # if (sysDictClass.isImplementing(this.id())) # implementList.addEnd(classId); # } # # return implementList; #} ENDSOURCE SOURCE #isExtending #//Extended version of the DictClass.extend(.) that checks if the object - or #//any of its superclasses are extending the specified class #boolean isExtending(classId _superClassId) #{ # boolean ret = false; # SysDictClass sysDictClass; # ; # # if (this.extend() == _superClassId) # { # ret = true; # } # # if (!ret && this.extend()) # { # sysDictClass = new SysDictClass(this.extend()); # ret = sysDictClass.isExtending(_superClassId); # } # # return ret; #} # ENDSOURCE SOURCE #isImplementing #//Extended version of the DictClass.implements(.) that checks if the object - or #//any of its superclasses are implementing the specified interface #boolean isImplementing(classId _interfaceId) #{ # int local; # boolean ret = false; # SysDictClass sysDictClass; # int implementCount # ; # if (this.id() == _interfaceId) # return true; # # implementCount = this.implementsCnt(); # for (local=1;local<=implementCount;local++) # { # if (this.implements(local) == _interfaceId) # { # ret = true; # break; # } # sysDictClass = new SysDictClass(this.implements(local)); # if(sysDictClass && sysDictClass.isImplementing(_interfaceId)) # { # ret = true; # break; # } # } # # if (!ret && this.extend()) # { # sysDictClass = new SysDictClass(this.extend()); # if (sysDictClass) # ret = sysDictClass.isImplementing(_interfaceId); # } # # return ret; #} ENDSOURCE SOURCE #isInheritedVariable #// #// Check if the variable is an inherited variable. #// Need to do this check because the classDeclartion #// method returns all the inherited variables, not just #// the local variables. #// #// # #public boolean isInheritedVariable( str _varName, Types _varType, int _varId ) #{ # #VisioUml # boolean isFound = false; # DictMethod objectMethod; # # int varIndex; # str varName; # Types varType; # int varId; # SysDictClass parent; # ; # # // # // Check this class # // # # objectMethod = new DictMethod( UtilElementType::ClassInstanceMethod, this.id(), #classDeclaration ); # for ( varIndex=1; varIndex <= objectMethod.varCnt(); varIndex++ ) # { # varName = objectMethod.varName( varIndex ); # varType = objectMethod.varType( varIndex ); # varId = objectMethod.varId( varIndex ); # # if ( strlen( varName ) == strlen( _varName ) && # varName == _varName && # varType == _varType && # varId == _varId ) # { # isFound = true; # break; # } # } # # // Check parent class # # if ( !isFound ) # { # parent = new SysDictClass( this.extend() ); # # if ( parent ) # { # isFound = parent.isInheritedVariable( _varName, _varType, _varId ); # } # } # # return isFound; #} # ENDSOURCE SOURCE #isMethodActual #boolean isMethodActual(identifiername _methodName) #{ # int i; # for (i=1; i<=this.objectMethodCnt(); i++) # { # if (this.objectMethod(i) == _methodName) # return true; # } # return false; #} ENDSOURCE SOURCE #isSystemClass #public boolean isSystemClass() #{ # classId id = this.id(); # # switch (id) # { # case classnum(VersionControl): # case classnum(Global): # case classnum(ClassFactory): # case classnum(Info): # case classnum(Site): # case classnum(Company): # case classnum(Application): # case classnum(Session): # return false; # } # # return isSysId(id); #} ENDSOURCE SOURCE #methods #public Set methods( # boolean _includeInstanceMethods = true, # boolean _includeStaticMethods = true, # boolean _includeInheritedMethods = true) #{ # return this.methodsRecursive(_includeInstanceMethods, _includeStaticMethods, _includeInheritedMethods, null); #} ENDSOURCE SOURCE #methodsActualClassId #classId methodsActualClassId(identifiername _methodName) #{ # if (this.isMethodActual(_methodName)) # return this.id(); # # return this.superMethodsClassId(_methodName); #} ENDSOURCE SOURCE #methodsRecursive #protected Set methodsRecursive( # boolean _includeInstanceMethods, # boolean _includeStaticMethods, # boolean _includeInheritedMethods, # Set _overriddenMethods) #{ # #SysBPCheck # int cnt; # int i; # classId classId = this.id(); # SysDictMethod dictMethod; # Set set = new Set(Types::Class); # Set setMethodName = new Set(Types::String); # # if (_overriddenMethods) # { # setMethodName = _overriddenMethods; # } # else # { # setMethodName = new Set(Types::String); # } # # // # // Include instance methods # // # if (_includeInstanceMethods) # { # cnt = this.objectMethodCnt(); # for (i=1; i<=cnt; i++) # { # if (this.objectMethod(i) != #MethodNameClassDeclaration) # { # // # // Skip if method is overridden # // # if (!_overriddenMethods || !_overriddenMethods.in(this.objectMethod(i))) # { # dictMethod = new SysDictMethod(UtilElementType::ClassInstanceMethod, classId, this.objectMethod(i)); # set.add(dictMethod); # setMethodName.add(dictMethod.name()); # } # } # } # } # # // # // Include static methods # // # if (_includeStaticMethods) # { # cnt = this.staticMethodCnt(); # for (i=1; i<=cnt; i++) # { # dictMethod = new SysDictMethod(UtilElementType::ClassStaticMethod, classId, this.staticMethod(i)); # set.add(dictMethod); # } # } # # // # // Include inherited methods # // # if (_includeInstanceMethods && _includeInheritedMethods) # { # if (this.extend()) # { # set = Set::union(set, new SysDictClass(this.extend()).methodsRecursive(true, false, true, setMethodName)); # } # else # { # // # // Include Object, even if the inheritance isn't explicitly specified # // # if (this.name() != classstr(Object)) # { # set = Set::union(set, new SysDictClass(classnum(Object)).methodsRecursive(true, false, true, setMethodName)); # } # } # } # # return set; #} ENDSOURCE SOURCE #objectMethods2ClassId #public Map objectMethods2ClassId(boolean _includeExtendedClasses = true) #{ # Map methodNames = new Map(Types::String,Types::Integer); # int i; # # if (_includeExtendedClasses && this.extend()) # { # methodNames = new SysDictClass(this.extend()).objectMethods2ClassId(true); # } # # for (i=1; i<=this.objectMethodCnt(); i++) # { # if (! methodNames.exists(this.objectMethod(i))) # { # methodNames.insert(this.objectMethod(i),this.id()); # } # } # # return methodNames; #} ENDSOURCE SOURCE #ObjectMethodSet #public Set objectMethodSet(boolean _includeInheritedMethods = true) #{ # Set methodNames = new Set(Types::String); # int i; # # for (i=1; i<=this.objectMethodCnt(); i++) # { # methodNames.add(this.objectMethod(i)); # } # # if (_includeInheritedMethods && this.extend()) # { # methodNames = Set::union(methodNames, new SysDictClass(this.extend()).objectMethodSet(true)); # } # return methodNames; #} ENDSOURCE SOURCE #path #xRefPath path() #{ # return xRefNames::calcPath(xRefKind::Class,this.name(),'',this.id()); #} ENDSOURCE SOURCE #pathForDeveloperDocumentation #public TreeNodePath pathForDeveloperDocumentation() #{ # #AOT # TreeNodePath treeNodePath; # # if (this.isSystemClass()) # { # treeNodePath = #SystemClassesPath+#AOTDelimiter+this.name(); # } # else # { # treeNodePath = #ApplicationDeveloperDocClassesPath+#AOTDelimiter+this.name(); # } # return treeNodePath; #} ENDSOURCE SOURCE #superMethodsClassId #classId superMethodsClassId(identifiername _methodName) #{ # SysDictClass dictClass = new SysDictClass(this.extend()); # # while (dictClass) # { # if (dictClass.isMethodActual(_methodName)) # { # return dictClass.id(); # } # # dictClass = new SysDictClass(dictClass.extend()); # } # # // no actual method found for this.name(),_methodName; # return 0; #} ENDSOURCE SOURCE #syntax #public str syntax() #{ # #SysBPCheck # SysDictMethod classDeclarationDictMethod = new SysDictMethod(UtilElementType::ClassInstanceMethod, this.id(), #MethodNameClassDeclaration); # # if (classDeclarationDictMethod) # return classDeclarationDictMethod.syntax(); # # return ''; #} ENDSOURCE SOURCE #toString #public str toString() #{ # return strfmt('%1 [%2]', this.name(), this.id()); #} ENDSOURCE SOURCE #treeNode #TreeNode treeNode() #{ # TreeNode treeNode = TreeNode::findNode(this.path()); # if (!treeNode) # { # throw error(strfmt("@SYS28152",this.path())); # } # return treeNode; #} ENDSOURCE SOURCE #xmlDocumentation #public XML xmlDocumentation() #{ # // # // Read from file if available # // # XML xml = this.xmlDocumentationFromFile(); # # if (!xml) # { # // # // If file is not available, extract from the source code # // # xml = this.xmlDocumentationFromMethods(); # } # return xml; #} ENDSOURCE SOURCE #xmlDocumentationFromFile #// #// This method can only be used on the client tier. #// #protected XML xmlDocumentationFromFile() #{ # int infologLine; # InfologData errorData; # SysInfologEnumerator enum; # str errorMessage; # SysTreeNode sysTreeNode = SysTreeNode::newTreeNodePath(this.path()); # XML xml; # SysVersionControlSystem versionControlSystem; # Filename filename; # str filePath; # str fileExtension; # XmlReader xmlReader; # #file # # if (this.objectOnServer()) # throw error(strfmt("@SYS19306", funcname())); # # if (versioncontrol && versioncontrol.parmSysVersionControlSystem()) # { # versionControlSystem = versioncontrol.parmSysVersionControlSystem(); # [filePath, filename, fileExtension] = fileNameSplit(versionControlSystem.fileName(sysTreeNode)); # # filename = filePath + filename + #xml; # if (WinAPI::fileExists(filename)) # { # // # // Read the contents of the tag # // # infologLine = infolog.line(); # try # { # //BP Deviation documented # xmlReader = XmlReader::newFile(filename); # while (xmlReader.read()) # { # if (xmlReader.nodeType() == XmlNodeType::Element && # xmlReader.name() == #XmlMembers) # { # xml = xmlReader.readInnerXml(); # } # } # } # catch (Exception::Error) # { # errorData = infolog.cut(infologLine+1); # enum = SysInfologEnumerator::newData(errorData); # while (enum.moveNext()) # { # errorMessage += (errorMessage?',':'')+strrem(enum.currentMessage(), '\n\t'); # } # xml = strfmt('', this.name(), errorMessage); # } # } # } # return xml; #} ENDSOURCE SOURCE #xmlDocumentationFromMethods #protected XML xmlDocumentationFromMethods() #{ # TextBuffer textBuffer = new TextBuffer(); # Set methods = this.methods(true, true, false); # SetEnumerator enum; # SysDictMethod dictMethod; # #SysBpCheck #; # // # // Include ClassDeclaration in the list of methods, as it contains the documentation for the class. # // # # methods.add(new SysDictMethod(UtilElementType::ClassInstanceMethod, this.id(), #MethodNameClassDeclaration)); # # enum = methods.getEnumerator(); # while (enum.moveNext()) # { # dictMethod = enum.current(); # textBuffer.appendText(dictMethod.xmlDocumentation(true)); # } # # return textBuffer.getText(); #} ENDSOURCE SOURCE #xmlQualifiedName #public XML xmlQualifiedName() #{ # return strfmt('T:%1', this.name()); #} ENDSOURCE SOURCE #xmlReflection #public void xmlReflection(XmlWriter _xmlWriter) #{ #; # _xmlWriter.writeStartElement(#XmlApi); # _xmlWriter.writeAttributeString(#XmlId, this.xmlQualifiedName()); # # this.xmlReflectionApiData(_xmlWriter); # this.xmlReflectionTypeData(_xmlWriter); # this.xmlReflectionFamily(_xmlWriter); # this.xmlReflectionImplements(_xmlWriter); # this.xmlReflectionSyntax(_xmlWriter); # this.xmlReflectionElements(_xmlWriter); # this.xmlReflectionContainers(_xmlWriter); # this.xmlReflectionFile(_xmlWriter); # # _xmlWriter.writeEndElement(); # # this.xmlReflectionMembers(_xmlWriter); #} ENDSOURCE SOURCE #xmlReflectionApiData #protected void xmlReflectionApiData(XmlWriter _xmlWriter) #{ #; # _xmlWriter.writeStartElement(#XmlApiData); # _xmlWriter.writeAttributeString(#XmlName, this.name()); # _xmlWriter.writeAttributeString(#XmlGroup, #XmlGroupType); # _xmlWriter.writeAttributeString(#XmlSubGroup, this.isInterface() ? #XmlSubGroupInterface : #XmlSubGroupClass); # _xmlWriter.writeEndElement(); #} ENDSOURCE SOURCE #xmlReflectionContainers #protected void xmlReflectionContainers(XmlWriter _xmlWriter) #{ #; # _xmlWriter.writeStartElement(#XmlContainers); # _xmlWriter.writeStartElement(#XmlType); # _xmlWriter.writeAttributeString(#XmlApi, #XmlRootProject); # _xmlWriter.writeEndElement(); # _xmlWriter.writeEndElement(); #} ENDSOURCE SOURCE #xmlReflectionElements #protected void xmlReflectionElements(XmlWriter _xmlWriter) #{ # #SysBPCheck # SysDictMethod dictMethod; # SetEnumerator enum = this.methods(true).getEnumerator(); # # _xmlWriter.writeStartElement(#XmlElements); # # while (enum.moveNext()) # { # dictMethod = enum.current(); # _xmlWriter.writeStartElement(#XmlElement); # _xmlWriter.writeAttributeString(#XmlApi, dictMethod.xmlQualifiedName()); # _xmlWriter.writeEndElement(); # } # # _xmlWriter.writeEndElement(); #} ENDSOURCE SOURCE #xmlReflectionFamily #protected void xmlReflectionFamily(XmlWriter _xmlWriter) #{ # SysDictClass sysDictClass; # List ancestors = new List(Types::String); # Set descendents = new Set(Types::String); # boolean objectFound; # #void writeList(Enumerator enum) #{ # while (enum.moveNext()) # { # _xmlWriter.writeStartElement(#XmlType); # _xmlWriter.writeAttributeString(#XmlApi, strfmt('T:%1', enum.current())); # _xmlWriter.writeEndElement(); # } #} #; # // # // Find ancestors # // # sysDictClass = new SysDictClass(this.extend()); # while (sysDictClass) # { # if (sysDictClass.id() == classnum(Object)) # objectFound = true; # # ancestors.addEnd(sysDictClass.name()); # sysDictClass = new SysDictClass(sysDictClass.extend()); # } # # if (!objectFound && this.id() != classnum(Object)) # { # ancestors.addEnd(classstr(Object)); # } # # // # // Find descendents # // # descendents = Set::create(xRefTypeHierarchy::descendents(Types::Class, this.id())); # # // # // Write xml # // # _xmlWriter.writeStartElement(#XmlFamily); # # _xmlWriter.writeStartElement(#XmlAncestors); # writeList(ancestors.getEnumerator()); # _xmlWriter.writeEndElement(); # # _xmlWriter.writeStartElement(#XmlDescendents); # writeList(descendents.getEnumerator()); # _xmlWriter.writeEndElement(); # # _xmlWriter.writeEndElement(); #} ENDSOURCE SOURCE #xmlReflectionFile #protected void xmlReflectionFile(XmlWriter _xmlWriter) #{ # TreeNodePath treeNodePath = this.pathForDeveloperDocumentation(); # DocNode docNode; # # if (treeNodePath) # { # docNode = TreeNode::findNode(treeNodePath); # # if (docNode && # docNode.hTMLHelpEnabled() && # docNode.hTMLHelpTopic()) # { # _xmlWriter.writeElementString(#XmlFile, docNode.hTMLHelpTopic()); # } # } #} ENDSOURCE SOURCE #xmlReflectionImplements #protected void xmlReflectionImplements(XmlWriter _xmlWriter) #{ # int i; # # if (this.implementsCnt()) # { # _xmlWriter.writeStartElement(#XmlImplements); # # for (i=1; i<=this.implementsCnt(); i++) # { # _xmlWriter.writeStartElement(#XmlType); # _xmlWriter.writeAttributeString(#XmlApi, strfmt('T:%1', extendedTypeId2DisplayName(Types::Class, this.implements(i)))); # _xmlWriter.writeEndElement(); # } # _xmlWriter.writeEndElement(); # } #} ENDSOURCE SOURCE #xmlReflectionMembers #protected void xmlReflectionMembers(XmlWriter _xmlWriter) #{ # SysDictXmlReflectionProvider xmlReflectionProvider; # SetEnumerator enum = this.methods(true, true, false).getEnumerator(); # # while (enum.moveNext()) # { # xmlReflectionProvider = SysDictClass::as(enum.current(), classnum(SysDictXmlReflectionProvider)); # if (xmlReflectionProvider) # { # xmlReflectionProvider.xmlReflection(_xmlWriter); # } # } #} ENDSOURCE SOURCE #xmlReflectionSyntax #protected void xmlReflectionSyntax(XmlWriter _xmlWriter) #{ # _xmlWriter.writeElementString(#XmlSyntax, this.syntax()); #} ENDSOURCE SOURCE #xmlReflectionTypeData #protected void xmlReflectionTypeData(XmlWriter _xmlWriter) #{ # _xmlWriter.writeStartElement(#XmlTypeData); # _xmlWriter.writeAttributeString(#XmlId, int2str(this.id())); # _xmlWriter.writeAttributeString(#XmlFinal, this.isFinal() ? 'true' : 'false'); # _xmlWriter.writeAttributeString(#XmlAbstract, this.isAbstract() ? 'true' : 'false'); # _xmlWriter.writeAttributeString(#XmlRunOn, strfmt('%1', this.RunMode())); # _xmlWriter.writeEndElement(); #} ENDSOURCE SOURCE #as #static public Object as(Object _class, classId _classId) #{ # if (SysDictClass::is(_class, _classId)) # return _class; # return null; #} ENDSOURCE SOURCE #getImplements #//Returns set of classid's of those classes that are implementing the specified interface (_id). #//If _onlyLeafClasses is specified as true no superclasses are included. #public static Set getImplements(classId _id, boolean _onlyLeafClasses = true) #{ # Dictionary dictionary = new Dictionary(); # SysDictClass sysDictClass; # boolean removed; # Set set = new Set(Types::Integer); # SetIterator setIterator = new SetIterator(set); # int i; # ; # # for (i=1;i<=dictionary.classCnt();i++) # { # sysDictClass = new SysDictClass(dictionary.classCnt2Id(i)); # if (sysDictClass.isImplementing(_id)) # { # set.add(sysDictClass.id()); # } # } # # if (_onlyLeafClasses) # { # //Only leaf classes are included in return set # setIterator.begin(); # while (setIterator.more()) # { # removed = false; # sysDictClass = new SysDictClass(setIterator.value()); # while (sysDictClass.extend()) # { # removed = removed | set.remove(sysDictClass.extend()); # sysDictClass = new SysDictClass(sysDictClass.extend()); # } # if (removed) # setIterator.begin(); //restart search # else # setIterator.next(); // # } # } # # return set; #} ENDSOURCE SOURCE #HELInvokeEventHandlerCallBackMethod #// KeSae : 2010.09.09 : For event handler we need to invoke a method with an object parameters and an HELEventArguments parameter #public static anytype HELInvokeEventHandlerCallBackMethod(Object _object # , IdentifierName _methodName # , Object _theEventSender # , HELEventArguments _theEventArguments) #{ # DictClass dictClass = new DictClass(classidget(_object)); # DictClass dictClassBase; # DictMethod dictMethod; # int i; #; # for (i=1; i<=dictClass.objectMethodCnt(); i++) # { # if (dictClass.objectMethod(i) == _methodName) # { # dictMethod = dictClass.objectMethodObject(i); # if (dictMethod.parameterCnt() == 2) # { # // BP deviation documented # return dictClass.callObject(_methodName, _object, _theEventSender, _theEventArguments); # } # throw error(strfmt("@SYS87800", _methodName)); # } # } # # throw error(strfmt("@SYS60360", _methodName)); #} ENDSOURCE SOURCE #invokeObjectMethod #public static anytype invokeObjectMethod(Object _object, identifiername _methodName, boolean _tryBaseClass = false) #{ # DictClass dictClass = new DictClass(classidget(_object)); # DictClass dictClassBase; # DictMethod dictMethod; # int i; #; # for (i=1; i<=dictClass.objectMethodCnt(); i++) # { # if (dictClass.objectMethod(i) == _methodName) # { # dictMethod = dictClass.objectMethodObject(i); # if (dictMethod.parameterCnt() == 0) # { # // invokeObjectMethod is listed as a dangerous API. Just suppress BP error; # // CAS is implemented by DictClass::callObject. # # // BP deviation documented # return dictClass.callObject(_methodName, _object); # } # throw error(strfmt("@SYS87800", _methodName)); # } # } # # if (_tryBaseClass && dictClass.extend()) # { # dictClassBase = new DictClass(dictClass.extend()); # # // BP deviation documented # return SysDictClass::invokeObjectMethod(dictClassBase.makeObject(), _methodName, _tryBaseClass); # } # # throw error(strfmt("@SYS60360", _methodName)); #} ENDSOURCE SOURCE #is #public static boolean is(Object _class, classId _classId) #{ # boolean ret = new SysDictClass(classidget(_class)).isImplementing(_classId); # # if (!ret) # { # ret = SysDictClass::isEqualOrSuperclass(classidget(_class), _classId); # } # # return ret; #} ENDSOURCE SOURCE #isEqualOrSuperclass #static boolean isEqualOrSuperclass( // not: isSuperclass # classId _id, # classId _potentialAncestorId # ) #{ # // is Equal? # # if (_id == _potentialAncestorId) # return true; # # // is ascendant? # return SysDictClass::isSuperclass(_id,_potentialAncestorId); #} ENDSOURCE SOURCE #isSuperclass #static boolean isSuperclass( // not: IsEqualOrSuperclass # classId _id, # classId _potentialAncestorId # ) #{ # DictClass dictClass = new DictClass(_id); # while (dictClass) # { # if (dictClass.extend() == _potentialAncestorId) # return true; # dictClass = new DictClass(dictClass.extend()); # } # return false; #} ENDSOURCE SOURCE #superClass #static classId superClass( # classId _id # ) #{ # DictClass dictClass = new DictClass(_id); # return dictClass.extend(); #} ENDSOURCE ENDMETHODS ENDCLASS ***Element: CLS ; Microsoft Dynamics AX Class: HELIEventHandler unloaded ; -------------------------------------------------------------------------------- CLSVERSION 1 INTERFACE #HELIEventHandler PROPERTIES Name #HELIEventHandler Extends # RunOn #Called from ENDPROPERTIES METHODS Version: 3 SOURCE #attachListener #public void attachListener(Object _theListener, SysMethodName _methodName) #{ #} ENDSOURCE SOURCE #classDeclaration #interface HELIEventHandler #{ #} ENDSOURCE SOURCE #fireEvent #public void fireEvent(Object _sender, HELEventArguments _arguments) #{ #} ENDSOURCE SOURCE #validateListener #private boolean validateListener(Object _theListener, SysMethodName _methodName) #{ #} ENDSOURCE ENDMETHODS ENDCLASS ***Element: CLS ; Microsoft Dynamics AX Class: HELEventArguments unloaded ; -------------------------------------------------------------------------------- CLSVERSION 1 CLASS #HELEventArguments PROPERTIES Name #HELEventArguments Extends # RunOn #Called from ENDPROPERTIES METHODS Version: 3 SOURCE #classDeclaration #class HELEventArguments #{ #} ENDSOURCE ENDMETHODS ENDCLASS ***Element: CLS ; Microsoft Dynamics AX Class: HELEventHandler unloaded ; -------------------------------------------------------------------------------- CLSVERSION 1 CLASS #HELEventHandler PROPERTIES Name #HELEventHandler Extends # RunOn #Called from ENDPROPERTIES METHODS Version: 3 SOURCE #attachListener #/// #/// Attaches an object to the handler together with the method name to be called back when the event handler fires the event #/// #/// #/// Object that will listen to this event #/// #/// #/// Method to be called back by the event handler when the event is fired #/// #/// #/// Only one method per object can be listening #/// #public void attachListener(Object _theListener, SysMethodName _methodName) #{ # ; # # // Validate the structure of the callback method # if(this.validateListener(_theListener, _methodName)) # { # // If the listener is already listening # if(mListeners.exists(_theListener)) # { # // Then remove the current registered method # mListeners.remove(_theListener); # } # # // Add the listener object along with the method to be called when the event is fired # mListeners.insert(_theListener, _methodName); # } # else # { # throw error("The listener could not be attached to the event"); # } #} ENDSOURCE SOURCE #classDeclaration #class HELEventHandler implements HELIEventHandler #{ # Map mListeners; // Map that contains objects along with their methods to call #} ENDSOURCE SOURCE #fireEvent #/// #/// Fires the event and notifies all the listeners by calling their specified callback methods #/// #/// #/// The object that actually sent the event #/// #/// #/// Event arguments that can be passed together with the event for extra information #/// #public void fireEvent(Object _sender, HELEventArguments _arguments) #{ # MapEnumerator enumerator = mListeners.getEnumerator(); # SysMethodName callBackMethodName; # Object listenerObject; # ; # # // Loop all the attached listeners # while(enumerator.moveNext()) # { # // Get the object listening # listenerObject = enumerator.currentKey(); # # // Get the callback method name to be called # callBackMethodName = enumerator.currentValue(); # # // Invoke the method on the listener # SysDictClass::HELInvokeEventHandlerCallBackMethod(listenerObject, callBackMethodName, _sender, _arguments); # } #} ENDSOURCE SOURCE #new #protected void new() #{ # ; # mListeners = new Map(Types::Class, Types::String); #} ENDSOURCE SOURCE #removeListener #/// #/// Removes an attached listener from the EventHandler #/// #/// #/// Object that will be removed from the listeners for this event #/// #public void removeListener(Object _theListener) #{ # ; # // If the listener is already listening # if(mListeners.exists(_theListener)) # { # // Then remove the current registered method # mListeners.remove(_theListener); # } #} ENDSOURCE SOURCE #validateListener #/// #/// Validates the structure of the call back method #/// #/// #/// The listener object that contains the call back method #/// #/// #/// The call back method to be validated #/// #/// #/// True if the structure is correct. Throws error if not correct. #/// #/// #/// Error thrown when the class id is invalid #/// #/// #/// Error thrown when the method is not existing on the listener object #/// #/// #/// Error thrown when the call back method is abstract #/// #/// #/// Error thrown when the call back method is static #/// #private boolean validateListener(Object _theListener, SysMethodName _methodName) #{ # DictClass dictClass = new DictClass(ClassIdGet(_theListener)); # DictMethod dictMethod; # int i = 1; # boolean ret = true; # ; # # // If no dictclass could be created, something is wrong with the ID # if(!dictClass) # { # error("Listener object has an invalid id"); # ret = false; # } # # // Loop all the methods of the class # for(i=1;i