Java 类org.springframework.beans.factory.xml.BeanDefinitionParserDelegate 实例源码
项目:JRediClients
文件:RedissonDefinitionParser.java
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();
}
}
项目:gemini.blueprint
文件:StandardAttributeCallback.java
public boolean process(Element parent, Attr attribute, BeanDefinitionBuilder builder) {
String name = attribute.getLocalName();
if (BeanDefinitionParserDelegate.ID_ATTRIBUTE.equals(name)) {
return false;
}
if (BeanDefinitionParserDelegate.DEPENDS_ON_ATTRIBUTE.equals(name)) {
builder.getBeanDefinition().setDependsOn(
(StringUtils.tokenizeToStringArray(attribute.getValue(),
BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS)));
return false;
}
if (BeanDefinitionParserDelegate.LAZY_INIT_ATTRIBUTE.equals(name)) {
builder.setLazyInit(Boolean.valueOf(attribute.getValue()));
return false;
}
return true;
}
项目:gemini.blueprint
文件:ServiceParsingUtils.java
public static boolean parseServiceProperties(Element parent, Element element, ParserContext parserContext,
BeanDefinitionBuilder builder) {
String name = element.getLocalName();
if (PROPS_ID.equals(name)) {
if (DomUtils.getChildElementsByTagName(element, BeanDefinitionParserDelegate.ENTRY_ELEMENT).size() > 0) {
Object props = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
builder.addPropertyValue(Conventions.attributeNameToPropertyName(PROPS_ID), props);
}
else {
parserContext.getReaderContext().error("Invalid service property type", element);
}
return true;
}
return false;
}
项目:gemini.blueprint
文件:BlueprintParser.java
private void parsePropertyElement(Element ele, BeanDefinition bd) {
String propertyName = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
if (!StringUtils.hasLength(propertyName)) {
error("Tag 'property' must have a 'name' attribute", ele);
return;
}
this.parseState.push(new PropertyEntry(propertyName));
try {
if (bd.getPropertyValues().contains(propertyName)) {
error("Multiple 'property' definitions for property '" + propertyName + "'", ele);
return;
}
Object val = parsePropertyValue(ele, bd, propertyName);
PropertyValue pv = new PropertyValue(propertyName, val);
pv.setSource(parserContext.extractSource(ele));
bd.getPropertyValues().addPropertyValue(pv);
} finally {
this.parseState.pop();
}
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Return a typed String value Object for the given value element.
*
* @param ele element
* @param defaultTypeName type class name
* @return typed String value Object
*/
private Object parseValueElement(Element ele, String defaultTypeName) {
// It's a literal value.
String value = DomUtils.getTextValue(ele);
String specifiedTypeName = ele.getAttribute(BeanDefinitionParserDelegate.TYPE_ATTRIBUTE);
String typeName = specifiedTypeName;
if (!StringUtils.hasText(typeName)) {
typeName = defaultTypeName;
}
try {
TypedStringValue typedValue = buildTypedStringValue(value, typeName);
typedValue.setSource(extractSource(ele));
typedValue.setSpecifiedTypeName(specifiedTypeName);
return typedValue;
} catch (ClassNotFoundException ex) {
error("Type class [" + typeName + "] not found for <value> element", ele, ex);
return value;
}
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parse a props element.
*/
public Properties parsePropsElement(Element propsEle) {
ManagedProperties props = new OrderedManagedProperties();
props.setSource(extractSource(propsEle));
props.setMergeEnabled(parseMergeAttribute(propsEle));
List propEles = DomUtils.getChildElementsByTagName(propsEle, BeanDefinitionParserDelegate.PROP_ELEMENT);
for (Iterator it = propEles.iterator(); it.hasNext();) {
Element propEle = (Element) it.next();
String key = propEle.getAttribute(BeanDefinitionParserDelegate.KEY_ATTRIBUTE);
// Trim the text value to avoid unwanted whitespace
// caused by typical XML formatting.
String value = DomUtils.getTextValue(propEle).trim();
TypedStringValue keyHolder = new TypedStringValue(key);
keyHolder.setSource(extractSource(propEle));
TypedStringValue valueHolder = new TypedStringValue(value);
valueHolder.setSource(extractSource(propEle));
props.put(keyHolder, valueHolder);
}
return props;
}
项目:lams
文件:GroovyBeanDefinitionReader.java
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
XmlReaderContext readerContext = this.xmlBeanDefinitionReader.createReaderContext(new DescriptiveResource("Groovy"));
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext, getEnvironment());
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;
}
}
};
}
项目:spring4-understanding
文件:GroovyBeanDefinitionReader.java
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;
}
}
};
}
项目:spring
文件:GroovyBeanDefinitionReader.java
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;
}
}
};
}
项目:txnmgr-springframework-ext
文件:TransactionManagerBeanDefinitionParser.java
private BeanDefinition parseParticipant(Element participantElement) {
AbstractBeanDefinition participantDef = createParticipantBeanDefinition(
participantElement, parserContext);
String id = participantElement.getAttribute(ID_ATTRIBUTE);
String participantBeanName = id;
if (StringUtils.hasText(participantBeanName)) {
parserContext.getRegistry().registerBeanDefinition(
participantBeanName, participantDef);
} else {
participantBeanName = parserContext.getReaderContext()
.registerWithGeneratedName(participantDef);
}
this.parseState.push(new ParticipantEntry(participantBeanName));
try {
BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
delegate.parsePropertyElements(participantElement, participantDef);
} finally {
this.parseState.pop();
}
return participantDef;
}
项目:zxl
文件:MulCommonBaseServiceParser.java
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;
}
项目:spring-osgi
文件:VirtualBundleBeanDefinitionParser.java
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
Element e = DomUtils.getChildElementByTagName(element, "exports");
if (e != null) {
beanDefinition.addPropertyValue("exports", extractPackageSet(e));
}
e = DomUtils.getChildElementByTagName(element, "imports");
if (e != null) {
beanDefinition.addPropertyValue("imports", extractPackageSet(e));
}
String dependsOn = element.getAttribute(DEPENDS_ON);
if (StringUtils.hasText(dependsOn)) {
beanDefinition.getBeanDefinition().setDependsOn(
StringUtils.tokenizeToStringArray(dependsOn, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS));
}
// e = DomUtils.getChildElementByTagName(element, "dynamic-imports");
// if (e != null) {
// // builder.addPropertyValue("dynamicImports", extractPackageSet(e));
// }
}
项目:spring-osgi
文件:StandardAttributeCallback.java
public boolean process(Element parent, Attr attribute, BeanDefinitionBuilder builder) {
String name = attribute.getLocalName();
if (BeanDefinitionParserDelegate.ID_ATTRIBUTE.equals(name)) {
return false;
}
if (BeanDefinitionParserDelegate.DEPENDS_ON_ATTRIBUTE.equals(name)) {
builder.getBeanDefinition().setDependsOn(
(StringUtils.tokenizeToStringArray(attribute.getValue(),
BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS)));
return false;
}
if (BeanDefinitionParserDelegate.LAZY_INIT_ATTRIBUTE.equals(name)) {
builder.setLazyInit(Boolean.getBoolean(attribute.getValue()));
return false;
}
return true;
}
项目:spring-osgi
文件:ServiceParsingUtils.java
public static boolean parseServiceProperties(Element parent, Element element, ParserContext parserContext,
BeanDefinitionBuilder builder) {
String name = element.getLocalName();
if (PROPS_ID.equals(name)) {
if (DomUtils.getChildElementsByTagName(element, BeanDefinitionParserDelegate.ENTRY_ELEMENT).size() > 0) {
Object props = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
builder.addPropertyValue(Conventions.attributeNameToPropertyName(PROPS_ID), props);
}
else {
parserContext.getReaderContext().error("Invalid service property type", element);
}
return true;
}
return false;
}
项目:gemini.blueprint
文件:BlueprintBeanDefinitionParser.java
public BeanDefinition parse(Element componentsRootElement, ParserContext parserContext) {
// re-initialize defaults
BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
delegate.initDefaults(componentsRootElement);
NodeList nl = componentsRootElement.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
String namespaceUri = ele.getNamespaceURI();
// check beans namespace
if (delegate.isDefaultNamespace(namespaceUri)) {
BeanDefinitionHolder holder = delegate.parseBeanDefinitionElement(ele);
ParsingUtils.decorateAndRegister(ele, holder, parserContext);
}
// handle own components
else if (BlueprintParser.NAMESPACE_URI.equals(namespaceUri)) {
parseTopLevelElement(ele, parserContext);
}
// leave the delegate to find a parser for it
else {
delegate.parseCustomElement(ele);
}
}
}
return null;
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parses property elements.
*
* @param ele
* @param beanDefinition
* @param parserContext
*/
private void parsePropertyElements(Element ele, AbstractBeanDefinition beanDefinition) {
NodeList nl = ele.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element && DomUtils.nodeNameEquals(node, BeanDefinitionParserDelegate.PROPERTY_ELEMENT)) {
parsePropertyElement((Element) node, beanDefinition);
}
}
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parse an array element.
*/
public Object parseArrayElement(Element arrayEle, BeanDefinition bd) {
String elementType = arrayEle.getAttribute(BeanDefinitionParserDelegate.VALUE_TYPE_ATTRIBUTE);
NodeList nl = arrayEle.getChildNodes();
ManagedArray target = new ManagedArray(elementType, nl.getLength());
target.setSource(extractSource(arrayEle));
target.setElementTypeName(elementType);
target.setMergeEnabled(parseMergeAttribute(arrayEle));
parseCollectionElements(nl, target, bd, elementType);
return target;
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parse a list element.
*/
public List<?> parseListElement(Element collectionEle, BeanDefinition bd) {
String defaultElementType = collectionEle.getAttribute(BeanDefinitionParserDelegate.VALUE_TYPE_ATTRIBUTE);
NodeList nl = collectionEle.getChildNodes();
ManagedList<Object> target = new ManagedList<Object>(nl.getLength());
target.setSource(extractSource(collectionEle));
target.setElementTypeName(defaultElementType);
target.setMergeEnabled(parseMergeAttribute(collectionEle));
parseCollectionElements(nl, target, bd, defaultElementType);
return target;
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parse a set element.
*/
public Set<?> parseSetElement(Element collectionEle, BeanDefinition bd) {
String defaultElementType = collectionEle.getAttribute(BeanDefinitionParserDelegate.VALUE_TYPE_ATTRIBUTE);
NodeList nl = collectionEle.getChildNodes();
ManagedSet<Object> target = new ManagedSet<Object>(nl.getLength());
target.setSource(extractSource(collectionEle));
target.setElementTypeName(defaultElementType);
target.setMergeEnabled(parseMergeAttribute(collectionEle));
parseCollectionElements(nl, target, bd, defaultElementType);
return target;
}
项目:gemini.blueprint
文件:BlueprintParser.java
protected void parseCollectionElements(NodeList elementNodes, Collection<Object> target, BeanDefinition bd,
String defaultElementType) {
for (int i = 0; i < elementNodes.getLength(); i++) {
Node node = elementNodes.item(i);
if (node instanceof Element
&& !DomUtils.nodeNameEquals(node, BeanDefinitionParserDelegate.DESCRIPTION_ELEMENT)) {
target.add(parsePropertySubElement((Element) node, bd, defaultElementType));
}
}
}
项目:gemini.blueprint
文件:TypeConverterBeanDefinitionParser.java
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder registrarDefinitionBuilder =
BeanDefinitionBuilder.genericBeanDefinition(BlueprintConverterConfigurer.class);
List<Element> components = DomUtils.getChildElementsByTagName(element, BlueprintParser.BEAN);
List<Element> componentRefs =
DomUtils.getChildElementsByTagName(element, BeanDefinitionParserDelegate.REF_ELEMENT);
ManagedList<Object> converterList = new ManagedList<Object>(componentRefs.size() + components.size());
// add components
for (Element component : components) {
converterList.add(BlueprintParser.parsePropertySubElement(parserContext, component,
registrarDefinitionBuilder.getBeanDefinition()));
}
// followed by bean references
for (Element componentRef : componentRefs) {
converterList.add(BlueprintParser.parsePropertySubElement(parserContext, componentRef,
registrarDefinitionBuilder.getBeanDefinition()));
}
// add the list to the registrar definition
registrarDefinitionBuilder.addConstructorArgValue(converterList);
registrarDefinitionBuilder.setRole(BeanDefinition.ROLE_SUPPORT);
registrarDefinitionBuilder.getRawBeanDefinition().setSynthetic(true);
// build the CustomEditorConfigurer
return registrarDefinitionBuilder.getBeanDefinition();
}
项目:alfresco-data-model
文件:NoAutoStartClassPathXmlApplicationContext.java
@Override
protected BeanDefinitionParserDelegate createHelper(
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
BeanDefinitionParserDelegate delegate = new NoAutoStartBeanDefinitionParserDelegate(readerContext);
delegate.initDefaults(root);
return delegate;
}
项目:alfresco-data-model
文件:LazyClassPathXmlApplicationContext.java
@Override
protected BeanDefinitionParserDelegate createHelper(
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
BeanDefinitionParserDelegate helper = super.createHelper(readerContext, root, parentDelegate);
helper.getDefaults().setLazyInit("true");
return helper;
}
项目:parabuild-ci
文件:DwrNamespaceHandler.java
public BeanDefinition parse(Element element, ParserContext parserContext)
{
BeanDefinitionBuilder dwrController = BeanDefinitionBuilder.rootBeanDefinition(DwrController.class);
List configurators = new ManagedList();
configurators.add(new RuntimeBeanReference(DEFAULT_SPRING_CONFIGURATOR_ID));
dwrController.addPropertyValue("configurators", configurators);
String debug = element.getAttribute("debug");
if (StringUtils.hasText(debug))
{
dwrController.addPropertyValue("debug", debug);
}
String beanName = element.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
String nameAttr = element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
String[] aliases = null;
if (!StringUtils.hasText(beanName))
{
beanName = element.getAttribute("name");
}
else
{
String aliasName = element.getAttribute("name");
if (StringUtils.hasText(aliasName))
{
aliases = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
}
}
parseControllerParameters(dwrController, element);
BeanDefinitionHolder holder = new BeanDefinitionHolder(dwrController.getBeanDefinition(), beanName, aliases);
BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
return dwrController.getBeanDefinition();
}
项目:beyondj
文件:ProfileBeanDefinitionParser.java
private BeanDefinition registerBean(Element element,
ParserContext parserContext) {
BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
BeanDefinitionHolder holder = delegate
.parseBeanDefinitionElement(element);
BeanDefinitionReaderUtils.registerBeanDefinition(holder,
parserContext.getRegistry());
return holder.getBeanDefinition();
}
项目:sdcct
文件:AbstractSdcctBeanDefinitionParser.java
protected AbstractBeanDefinition parseDefinition(ParserContext parserContext, BeanDefinitionRegistry beanDefRegistry, Element elem, String elemNsPrefix,
String elemNsUri, String elemLocalName, AbstractBeanDefinition beanDef) throws Exception {
if (beanDef.hasAttribute(BeanDefinitionParserDelegate.ABSTRACT_ATTRIBUTE) && SdcctOptionUtils
.getBooleanValue(BeanDefinitionParserDelegate.ABSTRACT_ATTRIBUTE, beanDef.getAttribute(BeanDefinitionParserDelegate.ABSTRACT_ATTRIBUTE))) {
beanDef.setAbstract(true);
}
if (elem.hasAttribute(BeanDefinitionParserDelegate.PARENT_ATTRIBUTE)) {
beanDef.setParentName(elem.getAttribute(BeanDefinitionParserDelegate.PARENT_ATTRIBUTE));
}
return beanDef;
}
项目:community-edition-old
文件:NoAutoStartClassPathXmlApplicationContext.java
@Override
protected BeanDefinitionParserDelegate createHelper(
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
BeanDefinitionParserDelegate delegate = new NoAutoStartBeanDefinitionParserDelegate(readerContext);
delegate.initDefaults(root);
return delegate;
}
项目:community-edition-old
文件:LazyClassPathXmlApplicationContext.java
@Override
protected BeanDefinitionParserDelegate createHelper(
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
BeanDefinitionParserDelegate helper = super.createHelper(readerContext, root, parentDelegate);
helper.getDefaults().setLazyInit("true");
return helper;
}
项目:zxl
文件:MulCommonBaseServiceParser.java
@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);
}
}
项目:zxl
文件:MulCommonBaseServiceParser.java
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;
}
项目:jdal
文件:CustomBeanDefinitionParser.java
/**
* 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);
}
}
项目:JRediClients
文件:RedissonRPCServerDefinitionParser.java
@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);
}
项目:gemini.blueprint
文件:ManagedServiceFactoryDefinitionParser.java
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
// do conversion for some of them (mainly enums)
ParserUtils.parseCustomAttributes(element, builder, new AttributeCallback[] { new ServiceAttributeCallback() });
// get nested elements
NodeList children = element.getChildNodes();
ManagedList listeners = new ManagedList(children.getLength());
BeanDefinition nestedDefinition = null;
for (int i = 0; i < children.getLength(); i++) {
Node nd = children.item(i);
if (nd instanceof Element) {
Element nestedElement = (Element) nd;
String name = nestedElement.getLocalName();
// osgi:interface
if (ServiceParsingUtils.parseInterfaces(element, nestedElement, parserContext, builder)) {
}
// osgi:service-properties
else if (ServiceParsingUtils.parseServiceProperties(element, nestedElement, parserContext, builder)) {
}
// osgi:registration-listener
else if (LISTENER.equals(name)) {
listeners.add(ServiceParsingUtils.parseListener(parserContext, nestedElement, builder));
}
// nested bean reference/declaration
else {
String ns = nestedElement.getNamespaceURI();
// it's a Spring Bean
if ((ns == null && name.equals(BeanDefinitionParserDelegate.BEAN_ELEMENT))
|| ns.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
nestedDefinition =
parserContext.getDelegate().parseBeanDefinitionElement(nestedElement)
.getBeanDefinition();
}
// it's non Spring
else {
nestedDefinition = parserContext.getDelegate().parseCustomElement(nestedElement);
}
}
}
// don't pass the properties as a bean definition since Spring tries to do conversion
// and even if we mark the pv as being converted, the flag gets ignored (SPR-5293)
builder.addPropertyValue(TEMPLATE_PROP, new BeanDefinition[] { nestedDefinition });
builder.addPropertyValue(LISTENERS_PROP, listeners);
}
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parses the supplied <code><bean></code> element. May return <code>null</code> if there were errors during
* parse. Errors are reported to the {@link org.springframework.beans.factory.parsing.ProblemReporter}.
*/
private BeanDefinitionHolder parseComponentDefinitionElement(Element ele, BeanDefinition containingBean) {
// extract bean name
String id = ele.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
String nameAttr = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
List<String> aliases = new ArrayList<String>(4);
if (StringUtils.hasLength(nameAttr)) {
String[] nameArr =
StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
aliases.addAll(Arrays.asList(nameArr));
}
String beanName = id;
if (!StringUtils.hasText(beanName) && !aliases.isEmpty()) {
beanName = (String) aliases.remove(0);
if (log.isDebugEnabled()) {
log.debug("No XML 'id' specified - using '" + beanName + "' as bean name and " + aliases
+ " as aliases");
}
}
if (containingBean == null) {
if (checkNameUniqueness(beanName, aliases, usedNames)) {
error("Bean name '" + beanName + "' is already used in this file", ele);
}
if (ParsingUtils.isReservedName(beanName, ele, parserContext)) {
error("Blueprint reserved name '" + beanName + "' cannot be used", ele);
}
}
AbstractBeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName, containingBean);
if (beanDefinition != null) {
if (!StringUtils.hasText(beanName)) {
try {
if (containingBean != null) {
beanName =
ParsingUtils.generateBlueprintBeanName(beanDefinition, parserContext.getRegistry(),
true);
} else {
beanName =
ParsingUtils.generateBlueprintBeanName(beanDefinition, parserContext.getRegistry(),
false);
// TODO: should we support 2.0 behaviour (see below):
//
// Register an alias for the plain bean class name, if still possible,
// if the generator returned the class name plus a suffix.
// This is expected for Spring 1.2/2.0 backwards compatibility.
}
if (log.isDebugEnabled()) {
log.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name [" + beanName
+ "]");
}
} catch (Exception ex) {
error(ex.getMessage(), ele, ex);
return null;
}
}
return new BeanDefinitionHolder(beanDefinition, beanName);
}
return null;
}
项目:gemini.blueprint
文件:BlueprintParser.java
private void parseConstructorArgElement(Element ele, AbstractBeanDefinition beanDefinition) {
String indexAttr = ele.getAttribute(BeanDefinitionParserDelegate.INDEX_ATTRIBUTE);
String typeAttr = ele.getAttribute(BeanDefinitionParserDelegate.TYPE_ATTRIBUTE);
boolean hasIndex = false;
int index = -1;
if (StringUtils.hasLength(indexAttr)) {
hasIndex = true;
try {
index = Integer.parseInt(indexAttr);
} catch (NumberFormatException ex) {
error("Attribute 'index' of tag 'constructor-arg' must be an integer", ele);
}
if (index < 0) {
error("'index' cannot be lower than 0", ele);
}
}
try {
this.parseState.push(hasIndex ? new ConstructorArgumentEntry(index) : new ConstructorArgumentEntry());
ConstructorArgumentValues values = beanDefinition.getConstructorArgumentValues();
// Blueprint failure (index duplication)
Integer indexInt = Integer.valueOf(index);
if (values.getIndexedArgumentValues().containsKey(indexInt)) {
error("duplicate 'index' with value=[" + index + "] specified", ele);
}
Object value = parsePropertyValue(ele, beanDefinition, null);
ConstructorArgumentValues.ValueHolder valueHolder = new ConstructorArgumentValues.ValueHolder(value);
if (StringUtils.hasLength(typeAttr)) {
valueHolder.setType(typeAttr);
}
valueHolder.setSource(extractSource(ele));
if (hasIndex) {
values.addIndexedArgumentValue(index, valueHolder);
} else {
values.addGenericArgumentValue(valueHolder);
}
// Blueprint failure (mixed index/non-indexed arguments)
if (!values.getGenericArgumentValues().isEmpty() && !values.getIndexedArgumentValues().isEmpty()) {
error("indexed and non-indexed constructor arguments are not supported by Blueprint; "
+ "consider using the Spring namespace instead", ele);
}
} finally {
this.parseState.pop();
}
}
项目:gemini.blueprint
文件:BlueprintParser.java
/**
* Parse a value, ref or collection sub-element of a property or constructor-arg element. This method is called from
* several places to handle reusable elements such as idref, ref, null, value and so on.
*
* In fact, this method is the main reason why the BeanDefinitionParserDelegate is not used in full since the
* element namespace becomes important as mixed rfc124/bean content can coexist.
*
* @param ele subelement of property element; we don't know which yet
* @param defaultValueType the default type (class name) for any <code><value></code> tag that might be
* created
*/
private Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
// skip other namespace
String namespaceUri = ele.getNamespaceURI();
// check Spring own namespace
if (parserContext.getDelegate().isDefaultNamespace(namespaceUri)) {
return parserContext.getDelegate().parsePropertySubElement(ele, bd);
}
// let the delegate handle other ns
else if (!NAMESPACE_URI.equals(namespaceUri)) {
return parserContext.getDelegate().parseCustomElement(ele);
}
//
else {
if (DomUtils.nodeNameEquals(ele, BEAN)) {
BeanDefinitionHolder bdHolder = parseComponentDefinitionElement(ele, bd);
if (bdHolder != null) {
bdHolder = ParsingUtils.decorateBeanDefinitionIfRequired(ele, bdHolder, parserContext);
}
return bdHolder;
}
if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.REF_ELEMENT)) {
return parseRefElement(ele);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.IDREF_ELEMENT)) {
return parseIdRefElement(ele);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.VALUE_ELEMENT)) {
return parseValueElement(ele, defaultValueType);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.NULL_ELEMENT)) {
// It's a distinguished null value. Let's wrap it in a TypedStringValue
// object in order to preserve the source location.
TypedStringValue nullHolder = new TypedStringValue(null);
nullHolder.setSource(parserContext.extractSource(ele));
return nullHolder;
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.ARRAY_ELEMENT)) {
return parseArrayElement(ele, bd);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.LIST_ELEMENT)) {
return parseListElement(ele, bd);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.SET_ELEMENT)) {
return parseSetElement(ele, bd);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.MAP_ELEMENT)) {
return parseMapElement(ele, bd);
} else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.PROPS_ELEMENT)) {
return parsePropsElement(ele);
}
// maybe it's a nested service/reference/ref-list/ref-set
return parserContext.getDelegate().parseCustomElement(ele, bd);
}
}
项目:sdcct
文件:AbstractXmlTransformBeanDefinitionParser.java
protected AbstractBeanDefinition parseStaticOptions(ParserContext parserContext, BeanDefinitionRegistry beanDefRegistry, Element elem, String elemNsPrefix,
String elemNsUri, String elemLocalName, AbstractBeanDefinition beanDef) throws Exception {
super.parseDefinition(parserContext, beanDefRegistry, elem, elemNsPrefix, elemNsUri, elemLocalName, beanDef);
MutablePropertyValues staticOptsPropValues = beanDef.getPropertyValues();
List<Element> staticFuncElems = SdcctDomUtils.findChildElements(elem, elemNsUri, STATIC_FUNC_ELEM_LOCAL_NAME);
if (!staticFuncElems.isEmpty()) {
ManagedList<Object> staticFuncs = new ManagedList<>(staticFuncElems.size());
staticFuncs.setMergeEnabled(true);
staticFuncs.setElementTypeName(ExtensionFunctionDefinition.class.getName());
staticFuncElems
.forEach(staticFuncElem -> staticFuncs.add(new RuntimeBeanReference(staticFuncElem.getAttribute(BeanDefinitionParserDelegate.REF_ATTRIBUTE))));
staticOptsPropValues.addPropertyValue(FUNCS_PROP_NAME, staticFuncs);
}
List<Element> staticNsElems = SdcctDomUtils.findChildElements(elem, elemNsUri, STATIC_NS_ELEM_LOCAL_NAME);
if (!staticNsElems.isEmpty()) {
ManagedMap<String, String> staticNamespaces = new ManagedMap<>(staticNsElems.size());
staticNamespaces.setMergeEnabled(true);
for (Element staticNsElem : staticNsElems) {
staticNamespaces.put(staticNsElem.getAttribute(PREFIX_ATTR_NAME), DomUtils.getTextValue(staticNsElem).trim());
}
staticOptsPropValues.addPropertyValue(NAMESPACES_PROP_NAME, staticNamespaces);
}
List<Element> staticVarElems = SdcctDomUtils.findChildElements(elem, elemNsUri, STATIC_VAR_ELEM_LOCAL_NAME);
if (!staticVarElems.isEmpty()) {
ManagedMap<QName, Object> staticVars = new ManagedMap<>(staticVarElems.size());
staticVars.setMergeEnabled(true);
staticVars.setValueTypeName(XdmValue.class.getName());
for (Element staticVarElem : staticVarElems) {
staticVars.put(new QName(staticVarElem.getAttribute(NAME_ATTRIBUTE)), DomUtils.getTextValue(staticVarElem).trim());
}
staticOptsPropValues.addPropertyValue(VARS_PROP_NAME, staticVars);
}
List<Element> staticPooledDocElems = SdcctDomUtils.findChildElements(elem, elemNsUri, STATIC_POOLED_DOC_ELEM_LOCAL_NAME);
if (!staticPooledDocElems.isEmpty()) {
XdmDocumentBeanDefinitionParser docBeanDefParser =
((XdmDocumentBeanDefinitionParser) this.nsHandler.getBeanDefinitionParsers().get(XdmDocumentBeanDefinitionParser.DOC_ELEM_LOCAL_NAME));
ManagedList<Object> staticPooledDocs = new ManagedList<>(staticPooledDocElems.size());
staticPooledDocs.setMergeEnabled(true);
staticPooledDocs.setElementTypeName(XdmDocument.class.getName());
for (Element staticPooledDocElem : staticPooledDocElems) {
staticPooledDocs.add(
docBeanDefParser.parse(staticPooledDocElem, new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), beanDef)));
}
staticOptsPropValues.addPropertyValue(POOLED_DOCS_PROP_NAME, staticPooledDocs);
}
return beanDef;
}
项目:spring-osgi
文件:ManagedServiceFactoryDefinitionParser.java
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
// do conversion for some of them (mainly enums)
ParserUtils.parseCustomAttributes(element, builder, new AttributeCallback[] { new ServiceAttributeCallback(),
new UpdateStrategyAttributeCallback() });
// get nested elements
NodeList children = element.getChildNodes();
ManagedList listeners = new ManagedList(children.getLength());
BeanDefinition nestedDefinition = null;
for (int i = 0; i < children.getLength(); i++) {
Node nd = children.item(i);
if (nd instanceof Element) {
Element nestedElement = (Element) nd;
String name = nestedElement.getLocalName();
// osgi:interface
if (ServiceParsingUtils.parseInterfaces(element, nestedElement, parserContext, builder))
;
// osgi:registration-listener
else if (LISTENER.equals(name)) {
listeners.add(ServiceParsingUtils.parseListener(parserContext, nestedElement, builder));
}
// nested bean reference/declaration
else {
String ns = nestedElement.getNamespaceURI();
// it's a Spring Bean
if ((ns == null && name.equals(BeanDefinitionParserDelegate.BEAN_ELEMENT))
|| ns.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
nestedDefinition = parserContext.getDelegate().parseBeanDefinitionElement(nestedElement).getBeanDefinition();
}
// it's non Spring
else {
nestedDefinition = parserContext.getDelegate().parseCustomElement(nestedElement);
}
}
}
// don't pass the properties as a bean definition since Spring tries to do conversion
// and even if we mark the pv as being converted, the flag gets ignored (SPR-5293)
builder.addPropertyValue(TEMPLATE_PROP, new BeanDefinition[] { nestedDefinition });
builder.addPropertyValue(LISTENERS_PROP, listeners);
}
}
项目:kuali_rice
文件:CustomSchemaParser.java
/**
* Parses the xml bean into a standard bean definition format and fills the information in the passed in definition
* builder
*
* @param element - The xml bean being parsed.
* @param parserContext - Provided information and functionality regarding current bean set.
* @param bean - A definition builder used to build a new spring bean from the information it is filled with.
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {
// Retrieve custom schema information build from the annotations
Map<String, Map<String, BeanTagAttributeInfo>> attributeProperties =
CustomTagAnnotations.getAttributeProperties();
Map<String, BeanTagAttributeInfo> entries = attributeProperties.get(element.getLocalName());
// Log error if there are no attributes found for the bean tag
if (entries == null) {
LOG.error("Bean Tag not found " + element.getLocalName());
}
// Retrieve the information for the new bean tag and fill in the default parent if needed
BeanTagInfo tagInfo = CustomTagAnnotations.getBeanTags().get(element.getLocalName());
if (tagInfo.getParent().compareTo("none") != 0) {
bean.setParentName(tagInfo.getParent());
}
// Create the map for the attributes found in the tag and process them in to the definition builder.
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
processSingleValue(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue(), entries, bean);
}
ArrayList<Element> children = (ArrayList<Element>) DomUtils.getChildElements(element);
// Process the children found in the xml tag
for (int i = 0; i < children.size(); i++) {
String tag = children.get(i).getLocalName();
BeanTagAttributeInfo info = entries.get(tag);
String propertyName;
BeanTagAttribute.AttributeType type;
if(children.get(i).getTagName().equals("spring:property")){
BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
delegate.parsePropertyElement(children.get(i), bean.getBeanDefinition());
continue;
}
// Sets the property name to be used when adding the property value
if (info == null) {
// If the tag is not in the schema map let spring handle the value by forwarding the tag as the
// propertyName
propertyName = tag;
type = findBeanType(children.get(i));
} else {
// If the tag is found in the schema map use the connected name stored in the attribute information
propertyName = info.getName();
type = info.getType();
}
// Process the information stored in the child bean
ArrayList<Element> grandChildren = (ArrayList<Element>) DomUtils.getChildElements(children.get(i));
if (type == BeanTagAttribute.AttributeType.SINGLEBEAN) {
bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext));
} else if (type == BeanTagAttribute.AttributeType.LISTBEAN) {
bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext));
} else if (type == BeanTagAttribute.AttributeType.LISTVALUE) {
bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext));
} else if (type == BeanTagAttribute.AttributeType.MAPVALUE) {
bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext));
} else if (type == BeanTagAttribute.AttributeType.MAPBEAN) {
bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext));
} else if (type == BeanTagAttribute.AttributeType.SETVALUE) {
bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext));
} else if (type == BeanTagAttribute.AttributeType.SETBEAN) {
bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext));
}
}
return;
}