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

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

Introduction

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

Prototype

public Problem(String message, Location location, @Nullable ParseState parseState,
        @Nullable Throwable rootCause) 

Source Link

Document

Create a new instance of the Problem class.

Usage

From source file:grails.spring.BeanBuilder.java

/**
 * Loads a set of given beans/*from  w w w . j  a va 2  s .com*/
 * @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) {
    @SuppressWarnings("rawtypes")
    Closure beans = new Closure(this) {
        private static final long serialVersionUID = -2778328821635253740L;

        @Override
        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) {
                super.setVariable(name, value);
            } else {
                setPropertyOnBeanConfig(name, value);
            }
        }
    };
    b.setVariable("beans", beans);

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

From source file:org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.java

/**
 * Load bean definitions from the specified Groovy script or XML file.
 * <p>Note that {@code ".xml"} files will be parsed as XML content; all other kinds
 * of resources will be parsed as Groovy scripts.
 * @param encodedResource the resource descriptor for the Groovy script or XML file,
 * allowing specification of an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 *//*www.java 2  s  .co  m*/
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
    // Check for XML files and redirect them to the "standard" XmlBeanDefinitionReader
    String filename = encodedResource.getResource().getFilename();
    if (StringUtils.endsWithIgnoreCase(filename, ".xml")) {
        return this.standardXmlBeanDefinitionReader.loadBeanDefinitions(encodedResource);
    }

    Closure beans = new Closure(this) {
        public Object call(Object[] args) {
            invokeBeanDefiningClosure((Closure) args[0]);
            return null;
        }
    };
    Binding binding = new Binding() {
        @Override
        public void setVariable(String name, Object value) {
            if (currentBeanDefinition != null) {
                applyPropertyToBeanDefinition(name, value);
            } else {
                super.setVariable(name, value);
            }
        }
    };
    binding.setVariable("beans", beans);

    int countBefore = getRegistry().getBeanDefinitionCount();
    try {
        GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
        shell.evaluate(encodedResource.getReader(), "beans");
    } catch (Throwable ex) {
        throw new BeanDefinitionParsingException(
                new Problem("Error evaluating Groovy script: " + ex.getMessage(),
                        new Location(encodedResource.getResource()), null, ex));
    }
    return getRegistry().getBeanDefinitionCount() - countBefore;
}

From source file:org.springframework.beans.factory.parsing.FailFastProblemReporterTests.java

@Test(expected = BeanDefinitionParsingException.class)
public void testError() throws Exception {
    FailFastProblemReporter reporter = new FailFastProblemReporter();
    reporter.error(new Problem("VGER", new Location(new DescriptiveResource("here")), null,
            new IllegalArgumentException()));
}

From source file:org.springframework.beans.factory.parsing.FailFastProblemReporterTests.java

@Test
public void testWarn() throws Exception {
    Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")), null,
            new IllegalArgumentException());

    Log log = mock(Log.class);

    FailFastProblemReporter reporter = new FailFastProblemReporter();
    reporter.setLogger(log);/*from   ww w  .  j  av  a  2s .  co m*/
    reporter.warning(problem);

    verify(log).warn(any(), isA(IllegalArgumentException.class));
}

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

/**
 * Loads a set of given beans//  www . java  2 s. 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));
        }
    }
}