public void load ( RulesDefinition . NewRepository repo , Reader reader ) { XMLInputFactory xmlFactory = XMLInputFactory . newInstance ( ) ; xmlFactory . setProperty ( XMLInputFactory . IS_COALESCING , Boolean . TRUE ) ; xmlFactory . setProperty ( XMLInputFactory . IS_NAMESPACE_AWARE , Boolean . FALSE ) ; // just so it won't try to load DTD in if there's DOCTYPE xmlFactory . setProperty ( XMLInputFactory . SUPPORT_DTD , Boolean . FALSE ) ; xmlFactory . setProperty ( XMLInputFactory . IS_VALIDATING , Boolean . FALSE ) ; SMInputFactory inputFactory = new SMInputFactory ( xmlFactory ) ; try { SMHierarchicCursor rootC = inputFactory . rootElementCursor ( reader ) ; rootC . advance ( ) ; // <rules> SMInputCursor rulesC = rootC . childElementCursor ( "rule" ) ; while ( rulesC . getNext ( ) != null ) { // <rule> processRule ( repo , rulesC ) ; } } catch ( XMLStreamException e ) { throw new IllegalStateException ( "XML is not valid" , e ) ; } }
Loads rules by reading the XML input stream . The reader is not closed by the method so it should be handled by the caller .