Example usage for org.springframework.beans.factory.xml ParserContext getReaderContext

List of usage examples for org.springframework.beans.factory.xml ParserContext getReaderContext

Introduction

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

Prototype

public final XmlReaderContext getReaderContext() 

Source Link

Usage

From source file:com.griddynamics.banshun.config.xml.ParserUtils.java

public static Class<?> findClassByName(String className, String beanName, ParserContext parserContext) {
    String description = parserContext.getReaderContext().getResource().getDescription();
    try {//w  w  w. j  a  va  2  s. com
        return Class.forName(className);
    } catch (ClassNotFoundException ex) {
        throw new CannotLoadBeanClassException(description, beanName, className, ex);
    }
}

From source file:com.mtgi.analytics.aop.config.v11.BtXmlPersisterBeanDefinitionParser.java

public static void configureLogRotation(ParserContext parserContext, ConfigurableListableBeanFactory factory,
        String schedule) {//ww w.  j  a  va 2s  .c om
    BeanDefinition trigger = factory.getBeanDefinition(CONFIG_ROTATE_TRIGGER);
    configureTriggerDefinition(trigger, schedule,
            parserContext.getReaderContext().generateBeanName(trigger) + "_rotate");
    registerPostProcessor(parserContext, factory, CONFIG_SCHEDULER, CONFIG_ROTATE_TRIGGER);
}

From source file:com.mtgi.analytics.aop.config.v11.SchedulerActivationPostProcessor.java

/**
 * Convenience method to register a {@link SchedulerActivationPostProcessor} in the given BeanFactory
 * parse context with the given properties.
 * @param parseContext the target bean factory in this context will have a {@link SchedulerActivationPostProcessor} registered
 * @param sourceFactory the source for both the named scheduler and trigger instances
 * @param schedulerName the name of the Quartz {@link Scheduler} in <code>sourceFactory</code> to use
 * @param triggerName the name of the Quarty {@link Trigger} in <code>sourceFactory</code> that must be scheduled
 *//* w w  w  .  j  a  v a2  s. c om*/
public static void registerPostProcessor(ParserContext parseContext, BeanFactory sourceFactory,
        String schedulerName, String triggerName) {
    BeanDefinitionBuilder scheduleBootstrap = BeanDefinitionBuilder
            .rootBeanDefinition(SchedulerActivationPostProcessor.class);
    scheduleBootstrap.addPropertyValue("sourceFactory", sourceFactory);
    scheduleBootstrap.addPropertyValue("schedulerName", schedulerName);
    scheduleBootstrap.addPropertyValue("triggerName", triggerName);
    scheduleBootstrap.setLazyInit(false);
    parseContext.getReaderContext().registerWithGeneratedName(scheduleBootstrap.getBeanDefinition());
}

From source file:com.seovic.validation.config.ValidationBeanDefinitionParser.java

private static BeanDefinition parseErrorMessageAction(Element message, ParserContext parserContext) {
    String messageId = message.getAttribute("id");
    String[] providers = message.getAttribute("providers").split(",");
    String typeName = ErrorMessageAction.class.getName();

    ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues();
    ctorArgs.addGenericArgumentValue(messageId);
    ctorArgs.addGenericArgumentValue(providers);

    String when = message.getAttribute("when");
    MutablePropertyValues properties = new MutablePropertyValues();
    if (StringUtils.hasText(when)) {
        properties.addPropertyValue("when", when);
    }/*from  ww w .  j  a va  2 s.c  o m*/
    AbstractBeanDefinition action;
    try {
        action = BeanDefinitionReaderUtils.createBeanDefinition(null, typeName,
                parserContext.getReaderContext().getBeanClassLoader());
    } catch (ClassNotFoundException e) {
        throw new BeanCreationException("Error occured during creation of bean definition", e);
    }
    action.setConstructorArgumentValues(ctorArgs);
    action.setPropertyValues(properties);
    return action;
}

From source file:com.bstek.dorado.web.servlet.DefaultDoradoAppContextImporter.java

protected void importBeanDefinitionResource(String location, Element element, ParserContext parserContext)
        throws Exception {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    try {// ww w.j a v  a 2  s.  co m
        ResourceLoader resourceLoader = readerContext.getResourceLoader();
        Resource relativeResource = resourceLoader.getResource(location);

        int importCount = readerContext.getReader().loadBeanDefinitions(relativeResource);
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Imported " + importCount + " bean definitions from dorado-context [" + location + "]");
        }
    } catch (Exception ex) {
        readerContext.error("Invalid dorado-context [" + location + "] to import bean definitions from",
                element, null, ex);
    }

    readerContext.fireImportProcessed(location, readerContext.extractSource(element));
}

From source file:com.griddynamics.banshun.config.xml.ImportBeanDefinitionParser.java

@Override
protected void doParse(Element el, ParserContext parserContext, BeanDefinitionBuilder builder) {

    Resource resource = parserContext.getReaderContext().getResource();

    String rootName = defaultIfBlank(el.getAttribute(ROOT_ATTR), DEFAULT_ROOT_FACTORY_NAME);
    String serviceIfaceName = el.getAttribute(INTERFACE_ATTR);
    String serviceName = el.getAttribute(ID_ATTR);

    Class<?> serviceIface = ParserUtils.findClassByName(serviceIfaceName, el.getAttribute(ID_ATTR),
            parserContext);/*from w  ww.  ja  v a 2s  . c  o m*/

    AbstractBeanDefinition beanDef = builder.getRawBeanDefinition();
    beanDef.setFactoryBeanName(rootName);
    beanDef.setFactoryMethodName(Registry.LOOKUP_METHOD_NAME);
    beanDef.setConstructorArgumentValues(defineLookupMethodArgs(serviceName, serviceIface));
    beanDef.setLazyInit(true);
    beanDef.setScope(SCOPE_SINGLETON);
    beanDef.setResource(resource);

    beanDef.setAttribute(IMPORT_BEAN_DEF_ATTR_NAME,
            new BeanReferenceInfo(serviceName, serviceIface, extractResourcePath(resource)));
}

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 .ja v a 2 s. c  om

    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.jboss.snowdrop.context.support.JBossActivationSpecBeanDefinitionParser.java

private String detectJBossActivationSpecClass(ParserContext parserContext) {
    ClassLoader classLoader = parserContext.getReaderContext().getBeanClassLoader();
    if (classLoader == null) {
        classLoader = ClassUtils.getDefaultClassLoader();
    }//  ww  w  .  java2 s  .  co m
    for (String activationSpecClassNameCandidate : ACTIVATION_SPEC_CLASSNAME_CANDIDATES) {
        try {
            classLoader.loadClass(activationSpecClassNameCandidate);
            return activationSpecClassNameCandidate;
        } catch (ClassNotFoundException e) {
            // ignore
        }
    }

    throw new BeanCreationException("Cannot find a suitable ActivationSpec class on the classpath");
}

From source file:org.springjutsu.validation.namespace.ValidationMVCAnnotationsDefinitionParser.java

private String registerInfrastructureBean(Element element, ParserContext context,
        BeanDefinitionBuilder componentBuilder) {

    BeanDefinition definition = componentBuilder.getBeanDefinition();
    String entityName = context.getReaderContext().registerWithGeneratedName(definition);
    context.registerComponent(new BeanComponentDefinition(definition, entityName));
    return entityName;
}

From source file:org.carewebframework.shell.BaseXmlParser.java

/**
 * Return the path of the resource being parsed.
 * /*w  w  w .ja  v a  2  s  .  c o m*/
 * @param parserContext The current parser context.
 * @return The resource being parsed, or null if cannot be determined.
 */
protected String getResourcePath(ParserContext parserContext) {
    if (parserContext != null) {
        try {
            Resource resource = parserContext.getReaderContext().getResource();
            return resource == null ? null : resource.getURL().getPath();
        } catch (IOException e) {
        }
    }

    return null;
}