Java 类org.springframework.beans.factory.parsing.Problem 实例源码

项目:lams    文件:GroovyBeanDefinitionReader.java   
/**
 * Define a Spring namespace definition to use.
 * @param definition the namespace definition
 */
public void xmlns(Map<String, String> definition) {
    if (!definition.isEmpty()) {
        for (Map.Entry<String,String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = entry.getValue();
            if (uri == null) {
                throw new IllegalArgumentException("Namespace definition must supply a non-null URI");
            }
            NamespaceHandler namespaceHandler = this.xmlBeanDefinitionReader.getNamespaceHandlerResolver().resolve(uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri,
                        new Location(new DescriptiveResource(("Groovy")))));
            }
            this.namespaces.put(namespace, uri);
        }
    }
}
项目:spring4-understanding    文件:GroovyBeanDefinitionReader.java   
/**
 * Define a Spring XML namespace definition to use.
 * @param definition the namespace definition
 */
public void xmlns(Map<String, String> definition) {
    if (!definition.isEmpty()) {
        for (Map.Entry<String,String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = entry.getValue();
            if (uri == null) {
                throw new IllegalArgumentException("Namespace definition must supply a non-null URI");
            }
            NamespaceHandler namespaceHandler = this.groovyDslXmlBeanDefinitionReader.getNamespaceHandlerResolver().resolve(
                uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri,
                        new Location(new DescriptiveResource(("Groovy")))));
            }
            this.namespaces.put(namespace, uri);
        }
    }
}
项目:spring    文件:GroovyBeanDefinitionReader.java   
/**
 * Define a Spring XML namespace definition to use.
 * @param definition the namespace definition
 */
public void xmlns(Map<String, String> definition) {
    if (!definition.isEmpty()) {
        for (Map.Entry<String,String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = entry.getValue();
            if (uri == null) {
                throw new IllegalArgumentException("Namespace definition must supply a non-null URI");
            }
            NamespaceHandler namespaceHandler =
                    this.groovyDslXmlBeanDefinitionReader.getNamespaceHandlerResolver().resolve(uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri,
                        new Location(new DescriptiveResource(("Groovy")))));
            }
            this.namespaces.put(namespace, uri);
        }
    }
}
项目:further-open-core    文件:PFixtureManagerBeanDefinitionParser.java   
/**
 * @param element
 * @param parserContext
 * @return
 * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element,
 *      org.springframework.beans.factory.xml.ParserContext)
 */
@Override
protected AbstractBeanDefinition parseInternal(final Element element,
        final ParserContext parserContext)
{
    final BeanDefinitionBuilder factory = parsePFixture(element);

    final List<Element> childElements = DomUtils.getChildElementsByTagName(element,
            CoreSchemaConstants.ELEMENT_LOCATION);
    // Must have at least one element
    if (childElements == null || childElements.isEmpty())
    {
        throw new BeanDefinitionParsingException(
                new Problem(
                        "Portable test fixture manager must be wired with at least one context location",
                        new Location(parserContext.getReaderContext().getResource())));
    }
    parseChildLocations(childElements, factory);

    return factory.getBeanDefinition();
}
项目:lams    文件:GroovyBeanDefinitionReader.java   
/**
 * Load bean definitions from the specified Groovy script.
 * @param encodedResource the resource descriptor for the Groovy script,
 * allowing to specify an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 */
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
    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(getResourceLoader().getClassLoader(), binding);
        shell.evaluate(encodedResource.getReader(), encodedResource.getResource().getFilename());
    }
    catch (Throwable ex) {
        throw new BeanDefinitionParsingException(new Problem("Error evaluating Groovy script: " + ex.getMessage(),
                new Location(encodedResource.getResource()), null, ex));
    }
    return getRegistry().getBeanDefinitionCount() - countBefore;
}
项目:spring4-understanding    文件: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
 */
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(getResourceLoader().getClassLoader(), 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;
}
项目:spring    文件: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
 */
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(getResourceLoader().getClassLoader(), 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;
}