All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.beangle.inject.spring.config.BeanDefinitionReader Maven / Gradle / Ivy

The newest version!
/*
 * Beangle, Agile Development Scaffold and Toolkits.
 *
 * Copyright © 2005, The Beangle Software.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */
package org.beangle.inject.spring.config;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.springframework.core.io.Resource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

/**
 * 

* BeanDefinitionReader class. *

* * @author chaostone * @version $Id: $ */ class BeanDefinitionReader { /** *

* load. *

* * @param resource a {@link org.springframework.core.io.Resource} object. * @return a {@link java.util.List} object. */ public List load(Resource resource) { List holders = new ArrayList(); try { InputStream inputStream = resource.getInputStream(); try { InputSource inputSource = new InputSource(inputStream); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = factory.newDocumentBuilder(); Document doc = docBuilder.parse(inputSource); Element root = doc.getDocumentElement(); NodeList nl = root.getChildNodes(); BeanDefinitionParser parser = new BeanDefinitionParser(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element) { Element ele = (Element) node; ReconfigBeanDefinitionHolder holder = parser.parseBeanDefinitionElement(ele); holders.add(holder); } } } finally { if (null != inputStream) { inputStream.close(); } } } catch (Exception ex) { throw new RuntimeException("IOException parsing XML document from " + resource.getDescription(), ex); } return holders; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy