code: public static void setHandler(XMLReader reader, Object handler) throws SAXNotSupportedException, SAXNotRecognizedException{
          if(handler instanceof ContentHandler)
              reader.setContentHandler((ContentHandler)handler);
          if(handler instanceof EntityResolver)
              reader.setEntityResolver((EntityResolver)handler);
          if(handler instanceof ErrorHandler)
              reader.setErrorHandler((ErrorHandler)handler);
          if(handler instanceof DTDHandler)
              reader.setDTDHandler((DTDHandler)handler);
          if(handler instanceof LexicalHandler){
              try{
                  reader.setProperty(SAXProperties.LEXICAL_HANDLER, handler);
              }catch(SAXException ex){
                  reader.setProperty(SAXProperties.LEXICAL_HANDLER_ALT, handler);
              }
          }
          if(handler instanceof DeclHandler){
              try{
                  reader.setProperty(SAXProperties.DECL_HANDLER, handler);
              }catch(SAXException ex){
                  reader.setProperty(SAXProperties.DECL_HANDLER_ALT, handler);
              }
          }
      }
docs: Registers all sax hander interfaces implemented by <code>handler</code> to the
  specified <code>reader</reader>