Example usage for org.springframework.beans.factory.xml XmlReaderContext error

List of usage examples for org.springframework.beans.factory.xml XmlReaderContext error

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlReaderContext error.

Prototype

public void error(String message, @Nullable Object source) 

Source Link

Document

Raise a regular error.

Usage

From source file:com.trigonic.utils.spring.beans.ImportBeanDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    String primaryLocation = element.getAttribute(RESOURCE_ATTRIBUTE);
    if (!StringUtils.hasText(primaryLocation)) {
        readerContext.error("Resource location must not be empty", element);
        return null;
    }/*from w  w w.j  a va  2  s  .com*/

    String alternateLocation = element.getAttribute(ALTERNATE_ATTRIBUTE);
    boolean optional = Boolean.parseBoolean(element.getAttribute(OPTIONAL_ATTRIBUTE));

    String currentLocation = primaryLocation;
    try {
        Set<Resource> actualResources = ImportHelper.importResource(readerContext.getReader(),
                readerContext.getResource(), currentLocation);

        if (actualResources.isEmpty() && StringUtils.hasLength(alternateLocation)) {
            currentLocation = alternateLocation;
            actualResources = ImportHelper.importResource(readerContext.getReader(),
                    readerContext.getResource(), currentLocation);
        }

        if (actualResources.isEmpty() && !optional) {
            readerContext.error("Primary location [" + primaryLocation + "]"
                    + (alternateLocation == null ? "" : " and alternate location [" + alternateLocation + "]")
                    + " are not optional", element);
            return null;
        }

        Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]);
        readerContext.fireImportProcessed(primaryLocation, actResArray, readerContext.extractSource(element));
    } catch (BeanDefinitionStoreException ex) {
        readerContext.error("Failed to import bean definitions from location [" + currentLocation + "]",
                element, ex);
    }

    return null;
}

From source file:org.qi4j.library.spring.bootstrap.internal.application.Qi4jBootstrapBeanDefinitionParser.java

private Qi4jApplicationBootstrap createQi4jApplicationBootstrap(Element anElement,
        ParserContext aParserContext) {/*from   w  ww  . j a  va 2s  .  c  o m*/
    String bootstrapClassString = anElement.getAttribute(CLASS);
    hasText(bootstrapClassString);
    XmlReaderContext readerContext = aParserContext.getReaderContext();

    Class<?> bootstrapClass;
    try {
        bootstrapClass = forName(bootstrapClassString);
    } catch (ClassNotFoundException e) {
        readerContext.error("Qi4j bootstrap class [" + bootstrapClassString + "] is not found.", anElement);
        return null;
    }

    if (!Qi4jApplicationBootstrap.class.isAssignableFrom(bootstrapClass)) {
        readerContext.error(CLASS + "attribute is not an instance of ["
                + Qi4jApplicationBootstrap.class.getName() + "] class", anElement);
        return null;
    }

    Qi4jApplicationBootstrap bootstrap = null;
    try {
        bootstrap = (Qi4jApplicationBootstrap) instantiateClass(bootstrapClass);
    } catch (BeanInstantiationException e) {
        readerContext.error("Fail to instantiate qi4j bootstrap class [" + bootstrapClassString + "]",
                anElement, e);
    }
    return bootstrap;
}

From source file:org.romaz.spring.scripting.ext.ExtScriptBeanDefinitionParser.java

/**
 * Resolves the script source from either the '<code>script-source</code>' attribute or
 * the '<code>inline-script</code>' element. Logs and {@link XmlReaderContext#error} and
 * returns <code>null</code> if neither or both of these values are specified.
 *//* w  w  w  . j  a v a2  s.com*/
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
    boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
    List elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
    if (hasScriptSource && !elements.isEmpty()) {
        readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
        return null;
    } else if (hasScriptSource) {
        return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
    } else if (!elements.isEmpty()) {
        Element inlineElement = (Element) elements.get(0);
        return "inline:" + DomUtils.getTextValue(inlineElement);
    } else {
        readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
        return null;
    }
}