Java Code Examples for org.springframework.beans.factory.xml.BeanDefinitionParserDelegate

The following examples show how to use org.springframework.beans.factory.xml.BeanDefinitionParserDelegate. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: GroovyBeanDefinitionReader.java    License: MIT License 6 votes vote down vote up
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example 2
Source Project: java-technology-stack   Source File: GroovyBeanDefinitionReader.java    License: MIT License 6 votes vote down vote up
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example 3
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example 4
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example 5
Source Project: zxl   Source File: MulCommonBaseServiceParser.java    License: Apache License 2.0 6 votes vote down vote up
private BeanDefinition buildSessionFactoryBeanDefinition(Element element, String name, BeanDefinitionParserDelegate beanDefinitionParserDelegate, BeanDefinitionRegistry beanDefinitionRegistry) {
	AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setAttribute(ID_ATTRIBUTE, name + SESSION_FACTORY_SUFFIX);
	beanDefinition.setBeanClass(LocalSessionFactoryBean.class);
	beanDefinition.setParentName(SESSION_FACTORY_PARENT_BEAN_NAME);
	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("dataSource", new RuntimeBeanReference(name + DATA_SOURCE_SUFFIX));
	if (element.hasAttribute(TABLE_PREFIX_NAME) && !StringUtil.isEmpty(element.getAttribute(TABLE_PREFIX_NAME))) {
		AbstractBeanDefinition namingStrategyBeanDefinition = new GenericBeanDefinition();
		String randomBeanName = UUID.randomUUID().toString();
		namingStrategyBeanDefinition.setAttribute(ID_ATTRIBUTE, randomBeanName);
		namingStrategyBeanDefinition.setBeanClass(HibernateNamingStrategy.class);
		MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
		mutablePropertyValues.add("prefix", element.getAttribute(TABLE_PREFIX_NAME));
		namingStrategyBeanDefinition.setPropertyValues(mutablePropertyValues);
		beanDefinitionRegistry.registerBeanDefinition(randomBeanName, namingStrategyBeanDefinition);
		propertyValues.addPropertyValue("namingStrategy", new RuntimeBeanReference(randomBeanName));
	}
	beanDefinition.setPropertyValues(propertyValues);
	beanDefinitionParserDelegate.parsePropertyElements(element, beanDefinition);
	return beanDefinition;
}
 
Example 6
Source Project: redisson   Source File: RedissonDefinitionParser.java    License: Apache License 2.0 6 votes vote down vote up
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    if (element.hasChildNodes()) {
        CompositeComponentDefinition compositeDef
                = new CompositeComponentDefinition(parentId,
                        parserContext.extractSource(element));
        parserContext.pushContainingComponent(compositeDef);
        List<Element> childElts = DomUtils.getChildElements(element);
        for (Element elt : childElts) {
            if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
                continue; //parsed elsewhere
            }
            String localName = parserContext.getDelegate().getLocalName(elt);
            localName = Conventions.attributeNameToPropertyName(localName);
            if (ConfigType.contains(localName)) {
                parseConfigTypes(elt, localName, redissonDef, parserContext);
            } else if (AddressType.contains(localName)) {
                parseAddressTypes(elt, localName, redissonDef, parserContext);
            } else if (helper.isRedissonNS(elt)) {
                elt.setAttribute(REDISSON_REF, redissonRef);
                parserContext.getDelegate().parseCustomElement(elt);
            }
        }
        parserContext.popContainingComponent();
    }
}
 
Example 7
@Override
protected BeanDefinitionParserDelegate createDelegate(
        XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate)
{
    BeanDefinitionParserDelegate delegate = new NoAutoStartBeanDefinitionParserDelegate(readerContext);
    delegate.initDefaults(root);
    return delegate;
}
 
Example 8
@Override
protected BeanDefinitionParserDelegate createDelegate(
        XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate)
{
    BeanDefinitionParserDelegate delegate = super.createDelegate(readerContext, root, parentDelegate);
    delegate.getDefaults().setLazyInit("true");
    return delegate;
}
 
Example 9
Source Project: zxl   Source File: MulCommonBaseServiceParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	if (StringUtil.isEmpty(element.getAttribute(NAME_ATTRIBUTE))) {
		parserContext.getReaderContext().error("CommonBaseService must have name attribute", element);
	}
	AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
	BeanDefinitionRegistry beanDefinitionRegistry = parserContext.getRegistry();
	BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
	String name = element.getAttribute(NAME_ATTRIBUTE);
	beanDefinition.setAttribute(ID_ATTRIBUTE, name + COMMON_BASE_SERVICE_SUFFIX);
	beanDefinition.setBeanClassName(CLASS_NAME);
	beanDefinitionRegistry.registerBeanDefinition(name + DATA_SOURCE_SUFFIX, buildDataSourceBeanDefinition(element, name));
	beanDefinitionRegistry.registerBeanDefinition(name + SQL_SESSION_FACTORY_SUFFIX, buildSqlSessionFactoryBeanDefinition(element, name));
	beanDefinitionRegistry.registerBeanDefinition(name + SESSION_FACTORY_SUFFIX, buildSessionFactoryBeanDefinition(element, name, parserContext.getDelegate(), beanDefinitionRegistry));
	beanDefinitionRegistry.registerBeanDefinition(name + SQL_SESSION_TEMPLATE_SUFFIX, buildSqlSessionTemplateBeanDefinition(element, name));
	beanDefinitionRegistry.registerBeanDefinition(name + COMMON_BASE_DAO_SUFFIX, buildCommonBaseDaoBeanDefinition(element, name));
	builder.addPropertyReference(COMMON_BASE_DAO_FIELD_NAME, name + COMMON_BASE_DAO_SUFFIX);
	element.setAttribute(ID_ATTRIBUTE, name + COMMON_BASE_SERVICE_SUFFIX);

	List<String> expressionList = buildExpressionList(element, delegate);
	if (expressionList.size() > 0) {
		beanDefinitionRegistry.registerBeanDefinition(name + HIBERNATE_TRANSACTION_MANAGER_SUFFIX, buildHibernateTransactionManagerBeanDefinition(element, name));
		beanDefinitionRegistry.registerBeanDefinition(name + TRANSACTION_ATTRIBUTE_SOURCE_SUFFIX, buildTransactionAttributeSourceBeanDefinition());
		beanDefinitionRegistry.registerBeanDefinition(name + HIBERNATE_ADVICE_SUFFIX, buildHibernateAdviceBeanDefinition(element, name));
		buildPointcutAndAdvisorBeanDefinition(name, expressionList, parserContext, beanDefinitionRegistry);
	}
}
 
Example 10
Source Project: zxl   Source File: MulCommonBaseServiceParser.java    License: Apache License 2.0 5 votes vote down vote up
private List<String> buildExpressionList(Element element, BeanDefinitionParserDelegate delegate) {
	NodeList childNodes = element.getChildNodes();
	List<String> expressionList = new ArrayList<String>();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node node = childNodes.item(i);
		if (node instanceof Element && delegate.nodeNameEquals(node, "mul-transaction-expression")) {
			Element mulTransactionExpressionElement = (Element) node;
			expressionList.add(mulTransactionExpressionElement.getAttribute("expression"));
		}
	}
	return expressionList;
}
 
Example 11
Source Project: cxf   Source File: AbstractBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
protected void setFirstChildAsProperty(Element element, ParserContext ctx,
                                     BeanDefinitionBuilder bean, String propertyName) {

    Element first = getFirstChild(element);

    if (first == null) {
        throw new IllegalStateException(propertyName + " property must have child elements!");
    }

    String id;
    BeanDefinition child;
    if (first.getNamespaceURI().equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
        String name = first.getLocalName();
        if ("ref".equals(name)) {
            id = first.getAttribute("bean");
            if (id == null) {
                throw new IllegalStateException("<ref> elements must have a \"bean\" attribute!");
            }
            bean.addPropertyReference(propertyName, id);
            return;
        } else if ("bean".equals(name)) {
            BeanDefinitionHolder bdh = ctx.getDelegate().parseBeanDefinitionElement(first);
            child = bdh.getBeanDefinition();
            bean.addPropertyValue(propertyName, child);
            return;
        } else {
            throw new UnsupportedOperationException("Elements with the name " + name
                                                    + " are not currently "
                                                    + "supported as sub elements of "
                                                    + element.getLocalName());
        }
    }
    child = ctx.getDelegate().parseCustomElement(first, bean.getBeanDefinition());
    bean.addPropertyValue(propertyName, child);
}
 
Example 12
Source Project: cxf   Source File: AbstractBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
protected String getIdOrName(Element elem) {
    String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);

    if (null == id || "".equals(id)) {
        String names = elem.getAttribute("name");
        if (null != names) {
            StringTokenizer st =
                new StringTokenizer(names, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
            if (st.countTokens() > 0) {
                id = st.nextToken();
            }
        }
    }
    return id;
}
 
Example 13
Source Project: jdal   Source File: CustomBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parse bean like a real bean definition.
 * @param ele element
 * @param parserContext parserContext
 * @param builder builder
 */
protected void parseBeanDefinition(Element ele, ParserContext parserContext, BeanDefinitionBuilder builder) {	
	BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
	AbstractBeanDefinition bd = builder.getRawBeanDefinition();
	XmlReaderContext reader =  parserContext.getReaderContext();
	
	try {
		delegate.parseBeanDefinitionAttributes(ele, beanName, null , bd);
		bd.setDescription(DomUtils.getChildElementValueByTagName(ele, "description"));

		delegate.parseMetaElements(ele, bd);
		delegate.parseLookupOverrideSubElements(ele, bd.getMethodOverrides());
		delegate.parseReplacedMethodSubElements(ele, bd.getMethodOverrides());

		delegate.parseConstructorArgElements(ele, bd);
		delegate.parsePropertyElements(ele, bd);
		delegate.parseQualifierElements(ele, bd);

	}
	catch (NoClassDefFoundError err) {
		reader.error("Class that bean class [" + this.beanClass + "] depends on not found", ele, err);
	}
	catch (Throwable ex) {
		reader.error("Unexpected failure during bean definition parsing", ele, ex);
	}
	
}
 
Example 14
private static AbstractBeanDefinition parseEncryptTableRuleConfiguration(final Element element) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(EncryptTableRuleConfiguration.class);
    factory.addConstructorArgValue(element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE));
    factory.addConstructorArgValue(parseEncryptColumnRuleConfigurations(element));
    return factory.getBeanDefinition();
}
 
Example 15
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    Class<?> apiClass;
    try {
        apiClass = Class.forName(helper.getAttribute(element,
                RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE));
    } catch (ClassNotFoundException ex) {
        throw new IllegalArgumentException(
                "The class [" + helper.getAttribute(element,
                        RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE)
                + "] specified in \""
                + RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE
                + "\" attribute has not "
                + "found. Please check the class path.", ex);
    }
    builder.addPropertyValue("targetObject", new RuntimeBeanReference(
            helper.getAttribute(element,
                    RedissonNamespaceParserSupport.REMOTE_SERVICE_REF_ATTRIBUTE)));
    builder.addPropertyValue("targetMethod", "register");
    ManagedList args = new ManagedList(); 
    args.add(apiClass);
    args.add(new RuntimeBeanReference(
                    helper.getAttribute(element,
                            BeanDefinitionParserDelegate.BEAN_REF_ATTRIBUTE)));
    String workers = null;
    if (helper.hasAttribute(element,
            RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE)) {
        workers = helper.getAttribute(element,
                RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE);
    }
    if (StringUtils.hasText(workers)) {
        args.add(Integer.parseInt(workers));
    }
    if (helper.hasAttribute(element,
            RedissonNamespaceParserSupport.EXECUTOR_REF_ATTRIBUTE)) {
        Assert.state(helper.hasAttribute(element,
                RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE),
                "The \""
                + RedissonNamespaceParserSupport.CONCURRENT_WORKERS_ATTRIBUTE
                + "\" attribute in \""
                + RedissonNamespaceParserSupport.RPC_SERVER_ELEMENT
                + "\" element is required when \""
                + RedissonNamespaceParserSupport.EXECUTOR_REF_ATTRIBUTE
                + "\" attribute is specified.");
        args.add(new RuntimeBeanReference(
                helper.getAttribute(element,
                        RedissonNamespaceParserSupport.EXECUTOR_REF_ATTRIBUTE)));
    }
    builder.addPropertyValue("arguments", args);
}