@ Override public void loadValidators ( final Props props , final Logger log ) { this . validators = new LinkedHashMap <> ( ) ; if ( ! props . containsKey ( ValidatorConfigs . XML_FILE_PARAM ) ) { logger . warn ( "Azkaban properties file does not contain the key " + ValidatorConfigs . XML_FILE_PARAM ) ; return ; } final String xmlPath = props . get ( ValidatorConfigs . XML_FILE_PARAM ) ; final File file = new File ( xmlPath ) ; if ( ! file . exists ( ) ) { logger . error ( "Azkaban validator configuration file " + xmlPath + " does not exist." ) ; return ; } // Creating the document builder to parse xml. final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder builder = null ; try { builder = docBuilderFactory . newDocumentBuilder ( ) ; } catch ( final ParserConfigurationException e ) { throw new ValidatorManagerException ( "Exception while parsing validator xml. Document builder not created." , e ) ; } Document doc = null ; try { doc = builder . parse ( file ) ; } catch ( final SAXException e ) { throw new ValidatorManagerException ( "Exception while parsing " + xmlPath + ". Invalid XML." , e ) ; } catch ( final IOException e ) { throw new ValidatorManagerException ( "Exception while parsing " + xmlPath + ". Error reading file." , e ) ; } final NodeList tagList = doc . getChildNodes ( ) ; final Node azkabanValidators = tagList . item ( 0 ) ; final NodeList azkabanValidatorsList = azkabanValidators . getChildNodes ( ) ; for ( int i = 0 ; i < azkabanValidatorsList . getLength ( ) ; ++ i ) { final Node node = azkabanValidatorsList . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { if ( node . getNodeName ( ) . equals ( VALIDATOR_TAG ) ) { parseValidatorTag ( node , props , log ) ; } } } }
Instances of the validators are created here rather than in the constructors . This is because some validators might need to maintain project - specific states . By instantiating the validators here it ensures that the validator objects are project - specific rather than global .