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

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

Introduction

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

Prototype

@Nullable
    public Object extractSource(Object sourceCandidate) 

Source Link

Usage

From source file:fr.xebia.management.config.EhCacheManagementServiceDefinitionParser.java

/**
 * Instantiates a {@link net.sf.ehcache.management.ManagementService}
 *///from w  w w  .  ja v a  2s .  c o m
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .rootBeanDefinition(net.sf.ehcache.management.ManagementService.class);

    // Mark as infrastructure bean and attach source location.
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    builder.addConstructorArgReference(element.getAttribute(CACHE_MANAGER_ATTRIBUTE));
    builder.addConstructorArgReference(element.getAttribute(MBEAN_SERVER_ATTRIBUTE));
    builder.addConstructorArgValue(element.getAttribute(REGISTER_CACHE_MANAGER_ATTRIBUTE));
    builder.addConstructorArgValue(element.getAttribute(REGISTER_CACHES_ATTRIBUTE));
    builder.addConstructorArgValue(element.getAttribute(REGISTER_CACHE_CONFIGURATIONS_ATTRIBUTE));
    builder.addConstructorArgValue(element.getAttribute(REGISTER_CACHE_STATISTICS_ATTRIBUTE));

    builder.setInitMethodName("init");
    builder.setDestroyMethodName("dispose");

    return builder.getBeanDefinition();
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    final CompositeComponentDefinition compositeDef;
    final BeanDefinitionBuilder bdd;
    final AbstractBeanDefinition beanDefinition;
    String id;/*from   w  w w.jav a2 s. c om*/

    compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
    parserContext.pushContainingComponent(compositeDef);

    bdd = BeanDefinitionBuilder.rootBeanDefinition(RemoteServiceControllerConfig.class);
    bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    if (parserContext.isDefaultLazyInit()) {
        bdd.setLazyInit(true);
    }

    bdd.addConstructorArgReference(getSerializationPolicyProviderBeanRef(element, parserContext).getBeanName());
    bdd.addPropertyValue("serviceModuleConfigs", parseModules(element, parserContext));
    getBaseServiceConfigParser().update(element, parserContext, bdd,
            RemoteServiceControllerConfig.DEFAULT_RPC_VALIDATOR_SERVICE_NAME);

    id = element.getAttribute(XmlNames.ID_ATTR);
    if (!StringUtils.hasText(id)) {
        id = RemoteServiceControllerConfig.DEFAULT_BEAN_ID;
    }
    beanDefinition = bdd.getBeanDefinition();
    parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id));

    parserContext.popAndRegisterContainingComponent();
    return beanDefinition;
}

From source file:fr.xebia.management.config.ThreadPoolExecutorFactoryDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ThreadPoolExecutorFactory.class);

    // Mark as infrastructure bean and attach source location.
    builder.setRole(BeanDefinition.ROLE_APPLICATION);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    String poolSize = element.getAttribute(POOL_SIZE_ATTRIBUTE);
    if (StringUtils.hasText(poolSize)) {
        builder.addPropertyValue("poolSize", poolSize);
    }/*www .  java  2 s  .  c  o  m*/

    String queueCapacity = element.getAttribute(QUEUE_CAPACITY_ATTRIBUTE);
    if (StringUtils.hasText(queueCapacity)) {
        builder.addPropertyValue("queueCapacity", queueCapacity);
    }

    String keepAlive = element.getAttribute(KEEP_ALIVE_ATTRIBUTE);
    if (StringUtils.hasText(keepAlive)) {
        builder.addPropertyValue("keepAliveTimeInSeconds", keepAlive);
    }

    String rejectionPolicy = element.getAttribute(REJECTION_POLICY_ATTRIBUTE);

    Class<? extends RejectedExecutionHandler> rejectedExecutionHandlerClass;
    if ("ABORT".equals(rejectionPolicy)) {
        rejectedExecutionHandlerClass = AbortPolicy.class;
    } else if ("CALLER_RUNS".equals(rejectionPolicy)) {
        rejectedExecutionHandlerClass = CallerRunsPolicy.class;
    } else if ("DISCARD".equals(rejectionPolicy)) {
        rejectedExecutionHandlerClass = DiscardPolicy.class;
    } else if ("DISCARD_OLDEST".equals(rejectionPolicy)) {
        rejectedExecutionHandlerClass = DiscardOldestPolicy.class;
    } else {
        throw new IllegalArgumentException(
                "Unsupported '" + REJECTION_POLICY_ATTRIBUTE + "': '" + rejectionPolicy + "'");
    }
    builder.addPropertyValue("rejectedExecutionHandlerClass", rejectedExecutionHandlerClass);

    return builder.getBeanDefinition();
}

From source file:de.itsvs.cwtrpc.controller.config.CacheControlConfigBeanDefinitionParser.java

protected AbstractBeanDefinition createUriConfigBeanDefinition(Element element, ParserContext parserContext) {
    final BeanDefinitionBuilder bdd;

    bdd = BeanDefinitionBuilder.rootBeanDefinition(CacheControlUriConfig.class);
    if (parserContext.isDefaultLazyInit()) {
        bdd.setLazyInit(true);/* w w  w.j ava  2 s . com*/
    }
    bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    bdd.addConstructorArgValue(createUriPattern(element, parserContext));

    if (element.hasAttribute(XmlNames.SERVICE_INTERFACE_ATTR)) {
        bdd.addPropertyValue("serviceInterface", element.getAttribute(XmlNames.SERVICE_INTERFACE_ATTR));
    }

    update(element, bdd, XmlNames.METHOD_ATTR, "method");
    update(element, bdd, XmlNames.PUBLIC_ATTR, "publicContent");
    update(element, bdd, XmlNames.PRIVATE_ATTR, "privateContent");
    update(element, bdd, XmlNames.NO_CACHE_ATTR, "noCache");
    update(element, bdd, XmlNames.NO_STORE_ATTR, "noStore");
    update(element, bdd, XmlNames.NO_TRANSFORM_ATTR, "noTransform");
    update(element, bdd, XmlNames.MUST_REVALIDATE_ATTR, "mustRevalidate");
    update(element, bdd, XmlNames.PROXY_REVALIDATE_ATTR, "proxyRevalidate");
    update(element, bdd, XmlNames.MAX_AGE_ATTR, "maxAge");
    update(element, bdd, XmlNames.S_MAXAGE_ATTR, "sharedMaxage");
    update(element, bdd, XmlNames.EXPIRES_ATTR, "expires");
    update(element, bdd, XmlNames.PRAGMA_NO_CACHE_ATTR, "pragmaNoCache");

    return bdd.getBeanDefinition();
}

From source file:fr.xebia.management.config.ServletContextAwareMBeanServerDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .rootBeanDefinition(ServletContextAwareMBeanServerFactory.class);

    // Mark as infrastructure bean and attach source location.
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
    if (StringUtils.hasText(serverBeanName)) {
        builder.addPropertyReference("server", serverBeanName);
    } else {// w ww.  j  a  v  a2  s.c o m
        AbstractBeanDefinition specialServer = findServerForSpecialEnvironment();
        if (specialServer != null) {
            builder.addPropertyValue("server", specialServer);
        }
    }

    return builder.getBeanDefinition();
}

From source file:biz.c24.io.spring.config.C24MarshallerBeanDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    String modelRef = element.getAttribute("model-ref");
    modelRef = StringUtils.hasText(modelRef) ? modelRef : C24ModelBeanDefinitionParser.DEFAULT_BEAN_NAME;

    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(C24Marshaller.class);
    builder.addConstructorArgReference(modelRef);
    return getSourcedBeanDefinition(builder, parserContext.extractSource(element));
}

From source file:fr.xebia.management.config.ManagedBasicDataSourceBeanDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ManagedBasicDataSource.class);

    builder.setRole(BeanDefinition.ROLE_APPLICATION);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    fillBuilderWithAttributeIfExists(builder, element, "accessToUnderlyingConnectionAllowed",
            "access-to-underlying-connection-allowed", boolean.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "connectionInitSqls", "connection-init-sqls",
            java.util.Collection.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "connectionProperties", "connection-properties",
            String.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "defaultAutoCommit", "default-auto-commit",
            boolean.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "defaultCatalog", "default-catalog", String.class,
            parserContext);/*  www.  j av  a  2  s.  co m*/
    fillBuilderWithAttributeIfExists(builder, element, "defaultReadOnly", "default-read-only", boolean.class,
            parserContext);

    Element defaultTransactionIsolationElement = DomUtils.getChildElementByTagName(element,
            "default-transaction-isolation");
    if (defaultTransactionIsolationElement != null) {
        int defaultTransactionIsolation;
        String value = defaultTransactionIsolationElement.getAttribute("value");
        if ("NONE".equals(value)) {
            defaultTransactionIsolation = Connection.TRANSACTION_NONE;
        } else if ("READ_UNCOMMITTED".equals(value)) {
            defaultTransactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED;
        } else if ("READ_COMMITTED".equals(value)) {
            defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED;
        } else if ("REPEATABLE_READ".equals(value)) {
            defaultTransactionIsolation = Connection.TRANSACTION_REPEATABLE_READ;
        } else if ("SERIALIZABLE".equals(value)) {
            defaultTransactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
        } else {
            String msg = "Invalid value for '<default-transaction-isolation' value=\"" + value + "\" />'";
            parserContext.getReaderContext().fatal(msg, defaultTransactionIsolationElement);
            throw new IllegalStateException(msg);
        }
        builder.addPropertyValue("defaultTransactionIsolation", defaultTransactionIsolation);

    }

    fillBuilderWithAttributeIfExists(builder, element, "driverClassName", "driver-class-name", String.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "initialSize", "initial-size", int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "logAbandoned", "log-abandoned", boolean.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "maxActive", "max-active", int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "maxIdle", "max-idle", int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "maxOpenPreparedStatements",
            "max-open-prepared-statements", int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "maxWait", "max-wait", long.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "minEvictableIdleTimeMillis",
            "min-evictable-idle-time-millis", long.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "minIdle", "min-idle", int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "numTestsPerEvictionRun", "num-tests-per-eviction-run",
            int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "password", "password", String.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "poolPreparedStatements", "pool-prepared-statements",
            boolean.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "removeAbandoned", "remove-abandoned", boolean.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "removeAbandonedTimeout", "remove-abandoned-timeout",
            int.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "testOnBorrow", "test-on-borrow", boolean.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "testOnReturn", "test-on-return", boolean.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "testWhileIdle", "test-while-idle", boolean.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "timeBetweenEvictionRunsMillis",
            "time-between-eviction-runs-millis", long.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "url", "url", String.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "username", "username", String.class, parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "validationQuery", "validation-query", String.class,
            parserContext);
    fillBuilderWithAttributeIfExists(builder, element, "validationQueryTimeout", "validation-query-timeout",
            int.class, parserContext);

    builder.setDestroyMethodName("close");

    return builder.getBeanDefinition();
}

From source file:de.itsvs.cwtrpc.controller.config.CacheControlConfigBeanDefinitionParser.java

protected AbstractBeanDefinition createUriPattern(Element element, ParserContext parserContext) {
    final String value;
    final Object type;
    final RootBeanDefinition beanDefinition;

    value = element.getAttribute(XmlNames.VALUE_ATTR);
    if (!StringUtils.hasText(value)) {
        parserContext.getReaderContext().error("URI value must not be empty",
                parserContext.extractSource(element));
    }//from   www  .  jav a  2 s.co  m
    if (element.hasAttribute(XmlNames.TYPE_ATTR)) {
        type = element.getAttribute(XmlNames.TYPE_ATTR);
    } else {
        type = CacheControlUriConfig.DEFAULT_PATTERN_TYPE;
    }

    beanDefinition = new RootBeanDefinition(PatternFactory.class);
    beanDefinition.setSource(parserContext.extractSource(element));
    if (parserContext.isDefaultLazyInit()) {
        beanDefinition.setLazyInit(true);
    }
    beanDefinition.setFactoryMethodName("compile");

    beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, type);
    beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(1, MatcherType.URI);
    beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(2, value);

    return beanDefinition;
}

From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java

/**
 * Creates a {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} instance for the
 * bean class and passes it to the/*from  w  w w  .  ja  va  2  s .c o  m*/
 * {@link #doParse} strategy method.
 * @param element the element that is to be parsed into a single BeanDefinition
 * @param parserContext the object encapsulating the current state of the parsing process
 * @return the BeanDefinition resulting from the parsing of the supplied {@link org.w3c.dom.Element}
 * @throws IllegalStateException if the bean {@link Class} returned from
 * bean class is <code>null</code>
 * @see #doParse
 */
protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(beanClass);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    if (parserContext.isNested()) {
        // Inner bean definition must receive same scope as containing bean.
        builder.setScope(parserContext.getContainingBeanDefinition().getScope());
    }
    if (parserContext.isDefaultLazyInit()) {
        // Default-lazy-init applies to custom bean definitions as well.
        builder.setLazyInit(true);
    }
    builder.setAutowireMode(autowireMode);
    builder.setFactoryMethod(factoryMethod);
    doParse(element, parserContext, builder);
    return builder.getBeanDefinition();
}

From source file:biz.c24.io.spring.config.FormatBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {

    List<MediaType> mediaTypes = MediaType.parseMediaTypes(element.getAttribute("content-type"));
    String format = element.getAttribute("type");

    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DataFormat.class);
    builder.addConstructorArgValue(format.toUpperCase());
    builder.addConstructorArgValue(mediaTypes);

    return BeanDefinitionUtils.getSourcedBeanDefinition(builder, parserContext.extractSource(element));
}