Example usage for org.springframework.beans.factory.parsing Location Location

List of usage examples for org.springframework.beans.factory.parsing Location Location

Introduction

In this page you can find the example usage for org.springframework.beans.factory.parsing Location Location.

Prototype

public Location(Resource resource) 

Source Link

Document

Create a new instance of the Location class.

Usage

From source file:org.springframework.context.groovy.GroovyBeanDefinitionReader.java

/**
 * Loads a set of given beans/* ww  w. ja v  a 2s.  c  o  m*/
 * @param resources The resources to load
 * @throws IOException Thrown if there is an error reading one of the passes resources
 */
public void loadBeans(Resource[] resources) throws IOException {
    Closure beans = new Closure(this) {
        public Object call(Object[] args) {
            invokeBeanDefiningClosure((Closure) args[0]);
            return null;
        }
    };
    Binding b = new Binding() {
        @Override
        public void setVariable(String name, Object value) {
            if (currentBeanConfig != null) {
                setPropertyOnBeanConfig(name, value);
            } else {
                super.setVariable(name, value);
            }
        }
    };
    b.setVariable("beans", beans);

    for (Resource resource : resources) {
        try {
            GroovyShell shell = classLoader != null ? new GroovyShell(classLoader, b) : new GroovyShell(b);
            shell.evaluate(resource.getInputStream());
        } catch (Throwable e) {
            throw new BeanDefinitionParsingException(
                    new Problem("Error evaluating bean definition script: " + e.getMessage(),
                            new Location(resource), null, e));
        }
    }
}