/**
   * Load definitions from the given input stream and close it.
   *
   * @param is InputStream containing XML
   */
  public void loadBeanDefinitions(InputStream is) throws BeansException {
    if (is == null)
      throw new BeanDefinitionStoreException(
          "InputStream cannot be null: expected an XML file", null);

    try {
      logger.info("Loading XmlBeanFactory from InputStream [" + is + "]");
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      logger.debug("Using JAXP implementation [" + factory + "]");
      factory.setValidating(true);
      DocumentBuilder db = factory.newDocumentBuilder();
      db.setErrorHandler(new BeansErrorHandler());
      db.setEntityResolver(
          this.entityResolver != null ? this.entityResolver : new BeansDtdResolver());
      Document doc = db.parse(is);
      loadBeanDefinitions(doc);
    } catch (ParserConfigurationException ex) {
      throw new BeanDefinitionStoreException("ParserConfiguration exception parsing XML", ex);
    } catch (SAXException ex) {
      throw new BeanDefinitionStoreException("XML document is invalid", ex);
    } catch (IOException ex) {
      throw new BeanDefinitionStoreException("IOException parsing XML document", ex);
    } finally {
      try {
        if (is != null) is.close();
      } catch (IOException ex) {
        throw new FatalBeanException("IOException closing stream for XML document", ex);
      }
    }
  }
 /**
  * Load definitions from the given file.
  *
  * @param filename name of the file containing the XML document
  */
 public void loadBeanDefinitions(String filename) throws BeansException {
   try {
     logger.info("Loading XmlBeanFactory from file '" + filename + "'");
     loadBeanDefinitions(new FileInputStream(filename));
   } catch (IOException ex) {
     throw new BeanDefinitionStoreException("Can't open file [" + filename + "]", ex);
   }
 }
 /**
  * Create a new XmlBeanFactory with the given input stream, which must be parsable using DOM.
  *
  * @param is InputStream containing XML
  * @param parentBeanFactory parent bean factory
  * @throws BeansException
  */
 public XmlBeanFactory(InputStream is, BeanFactory parentBeanFactory) throws BeansException {
   super(parentBeanFactory);
   loadBeanDefinitions(is);
 }
 /**
  * Create new XmlBeanFactory using java.io to read the XML document with the given filename.
  *
  * @param filename name of the file containing the XML document
  * @param parentBeanFactory parent bean factory
  */
 public XmlBeanFactory(String filename, BeanFactory parentBeanFactory) throws BeansException {
   super(parentBeanFactory);
   loadBeanDefinitions(filename);
 }