public void execute ( ) { Iterator < ? > elementIter = XMLUtil . selectNodes ( document , "/BugCollection/BugInstance" ) . iterator ( ) ; Iterator < BugInstance > bugInstanceIter = bugCollection . iterator ( ) ; Set < String > bugTypeSet = new HashSet <> ( ) ; Set < String > bugCategorySet = new HashSet <> ( ) ; Set < String > bugCodeSet = new HashSet <> ( ) ; // Add short and long descriptions to BugInstance elements. // We rely on the Document and the BugCollection storing // the bug instances in the same order. while ( elementIter . hasNext ( ) && bugInstanceIter . hasNext ( ) ) { Element element = ( Element ) elementIter . next ( ) ; BugInstance bugInstance = bugInstanceIter . next ( ) ; String bugType = bugInstance . getType ( ) ; bugTypeSet . add ( bugType ) ; BugPattern bugPattern = bugInstance . getBugPattern ( ) ; bugCategorySet . add ( bugPattern . getCategory ( ) ) ; bugCodeSet . add ( bugPattern . getAbbrev ( ) ) ; element . addElement ( "ShortMessage" ) . addText ( bugPattern . getShortDescription ( ) ) ; element . addElement ( "LongMessage" ) . addText ( bugInstance . getMessage ( ) ) ; // Add pre-formatted display strings in "Message" // elements for all bug annotations. Iterator < ? > annElementIter = element . elements ( ) . iterator ( ) ; Iterator < BugAnnotation > annIter = bugInstance . annotationIterator ( ) ; while ( annElementIter . hasNext ( ) && annIter . hasNext ( ) ) { Element annElement = ( Element ) annElementIter . next ( ) ; BugAnnotation ann = annIter . next ( ) ; annElement . addElement ( "Message" ) . addText ( ann . toString ( ) ) ; } } // Add BugPattern elements for each referenced bug types. addBugCategories ( bugCategorySet ) ; addBugPatterns ( bugTypeSet ) ; addBugCodes ( bugCodeSet ) ; }
Add messages to the dom4j tree .