本文整理汇总了Java中org.springframework.beans.factory.support.BeanDefinitionBuilder类的典型用法代码示例。如果您正苦于以下问题:Java BeanDefinitionBuilder类的具体用法?Java BeanDefinitionBuilder怎么用?Java BeanDefinitionBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanDefinitionBuilder类属于org.springframework.beans.factory.support包,在下文中一共展示了BeanDefinitionBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doParse
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
protected void doParse(Element element, BeanDefinitionBuilder bean) {
boolean fallbackToSystemLocale = false;
String[] basenames = null;
if (element.hasAttribute(FALLBACK_TO_SYSTEM_LOCALE)) {
fallbackToSystemLocale = Boolean.valueOf(element.getAttribute(FALLBACK_TO_SYSTEM_LOCALE));
}
if (element.hasAttribute(BASENAMES)) {
basenames = StringUtils.tokenizeToStringArray(element.getAttribute(BASENAMES), ",");
}
bean.addPropertyValue("fallbackToSystemLocale", fallbackToSystemLocale);
bean.addPropertyValue("basenames", basenames);
}
示例2: parse
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
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();
}
示例3: parseInterfaces
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
public static boolean parseInterfaces(Element parent, Element element, ParserContext parserContext,
BeanDefinitionBuilder builder) {
String name = element.getLocalName();
// osgi:interfaces
if (INTERFACES_ID.equals(name)) {
// check shortcut on the parent
if (parent.hasAttribute(INTERFACE)) {
parserContext.getReaderContext().error(
"either 'interface' attribute or <intefaces> sub-element has be specified", parent);
}
Set interfaces = parserContext.getDelegate().parseSetElement(element, builder.getBeanDefinition());
builder.addPropertyValue(INTERFACES_PROP, interfaces);
return true;
}
return false;
}
示例4: doParse
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
builder.addPropertyValue(PojoConst.FIELD_MICROSERVICE_NAME,
element.getAttribute(PojoConst.MICROSERVICE_NAME));
String schemaId = element.getAttribute(PojoConst.SCHEMA_ID);
String intf = element.getAttribute(PojoConst.INTERFACE);
if (StringUtils.isEmpty(intf) && !StringUtils.isEmpty(schemaId)) {
// 尝试将schemaId当作接口名使用
Class<?> consumerIntf = ClassUtils.getClassByName(null, schemaId);
if (consumerIntf != null) {
intf = schemaId;
}
}
builder.addPropertyValue(PojoConst.FIELD_SCHEMA_ID, schemaId);
builder.addPropertyValue(PojoConst.FIELD_INTERFACE, intf);
if (StringUtils.isEmpty(schemaId) && StringUtils.isEmpty(intf)) {
throw new Error("schema-id and interface can not both be empty.");
}
}
示例5: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
ComposedTaskProperties properties = composedTaskProperties();
TaskParser taskParser = new TaskParser("bean-registration",
properties.getGraph(), false, true);
Map<String, Integer> taskSuffixMap = getTaskApps(taskParser);
for (String taskName : taskSuffixMap.keySet()) {
//handles the possibility that multiple instances of
// task definition exist in a composed task
for (int taskSuffix = 0; taskSuffixMap.get(taskName) >= taskSuffix; taskSuffix++) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.rootBeanDefinition(ComposedTaskRunnerStepFactory.class);
builder.addConstructorArgValue(properties);
builder.addConstructorArgValue(String.format("%s_%s",
taskName, taskSuffix));
builder.addPropertyValue("taskSpecificProps",
getPropertiesForTask(taskName, properties));
builder.addPropertyValue("arguments", properties.getComposedTaskArguments());
registry.registerBeanDefinition(String.format("%s_%s",
taskName, taskSuffix), builder.getBeanDefinition());
}
}
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:26,代码来源:StepBeanDefinitionRegistrar.java
示例6: doParse
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String path = element.getAttribute("path");
if (!StringUtils.hasText(path)) {
parserContext.getReaderContext().error("Attribute 'path' must not be empty", element);
return;
}
int dotIndex = path.indexOf(".");
if (dotIndex == -1) {
parserContext.getReaderContext().error(
"Attribute 'path' must follow pattern 'beanName.propertyName'", element);
return;
}
String beanName = path.substring(0, dotIndex);
String propertyPath = path.substring(dotIndex + 1);
builder.addPropertyValue("targetBeanName", beanName);
builder.addPropertyValue("propertyPath", propertyPath);
}
示例7: setDefault
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
private void setDefault(Element element, BeanDefinitionBuilder builder)
{
String name = element.getAttribute("name");
if (StringUtils.hasText(name)) {
builder.addPropertyValue("name", name);
element.setAttribute("name", name);
} else {
throw new IllegalArgumentException("tc-template:name is not allow empty!");
}
String id = element.getAttribute("id");
if (StringUtils.hasText(id)) {
builder.addPropertyValue("id", id);
element.setAttribute("id", Template.TC_SUFFIX + id);
} else {
throw new IllegalArgumentException("tc-template:id is not allow empty!");
}
}
示例8: parseNested
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
Class<?> apiClass;
try {
apiClass = Class.forName(helper.getAttribute(element,
RedissonNamespaceParserSupport.CLASS_ATTRIBUTE));
} catch (ClassNotFoundException ex) {
throw new IllegalArgumentException(
"The class [" + helper.getAttribute(element,
RedissonNamespaceParserSupport.CLASS_ATTRIBUTE)
+ "] specified in \"api-class\" attribute has not "
+ "found. Please check the class path.", ex);
}
builder.addPropertyValue("targetObject", new RuntimeBeanReference(
helper.getAttribute(element,
RedissonNamespaceParserSupport.LIVE_OBJECT_SERVICE_REF_ATTRIBUTE)));
builder.addPropertyValue("targetMethod", "registerClass");
builder.addPropertyValue("arguments", new Object[] {apiClass});
}
示例9: parseNested
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
private void parseNested(Element element, String eltType, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
NodeList list = element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, eltType);
if (list.getLength() == 1) {
Element elt = (Element) list.item(0);
if (StringUtils.hasText(referenceAttribute)) {
helper.setAttribute(elt, referenceAttribute,
helper.getAttribute(element,
RedissonNamespaceParserSupport.ID_ATTRIBUTE));
helper.setAttribute(elt, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE,
helper.getAttribute(element,
RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
}
parserContext.getDelegate()
.parseCustomElement(elt, builder.getRawBeanDefinition());
}
}
示例10: doParse
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
protected void doParse(Element element, BeanDefinitionBuilder bean) {
String application = element.getAttribute("application");
String registry = element.getAttribute("registry");
String rpcPort = element.getAttribute("rpcPort");
String httpPort = element.getAttribute("httpPort");
if (StringUtils.hasText(application)) {
bean.addPropertyValue("application", application);
}
if (StringUtils.hasText(registry)) {
bean.addPropertyValue("registryAddress", registry);
}
if (StringUtils.hasText(rpcPort)) {
bean.addPropertyValue("realityRpcPort", Integer.valueOf(rpcPort));
}
if (StringUtils.hasText(httpPort)) {
bean.addPropertyValue("httpPort", Integer.valueOf(httpPort));
}
}
示例11: doParse
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
Assert.state(helper.isRedissonNS(element),
"Illegal state. "
+ this.getClass().getName()
+ " can only parse "
+ RedissonNamespaceParserSupport.REDISSON_NAMESPACE
+ " namespace elements");
Assert.state(element.hasAttribute(parentRefAttribute),
"Illegal state. property \"" + parentRefAttribute
+ "\" is required in the \""
+ helper.getName(element)
+ "\" element.");
helper.populateIdAttribute(element, builder, parserContext);
AbstractBeanDefinition bd = builder.getRawBeanDefinition();
parseNested(element, parserContext, builder, bd);
decorator.decorate(element, parserContext, builder, helper);
parserContext.getDelegate().parseQualifierElements(element, bd);
if (parserContext.isNested()) {
helper.registerBeanDefinition(builder, element, parserContext);
}
}
示例12: convertClassesToStrings
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
/**
* Utility method used for maintaining backwards compatibility by converting Class objects to String (using their
* class names). Used by importer and exporter parsing to set the 'interfaces' property.
*
* @param parsedClasses collection of parsed classes
* @return a collection of converted (if necessary) metadata
*/
public static Set<?> convertClassesToStrings(Set<?> parsedClasses) {
Set<Object> interfaces = new ManagedSet<Object>(parsedClasses.size());
for (Object clazz : parsedClasses) {
if (clazz instanceof TypedStringValue || clazz instanceof String) {
interfaces.add(clazz);
} else {
// add adapter definition for bean references (which can be classes)
interfaces.add(BeanDefinitionBuilder.genericBeanDefinition(ToStringClassAdapter.class)
.addConstructorArgValue(clazz).getBeanDefinition());
}
}
return interfaces;
}
示例13: setDefault
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
private void setDefault(Element element, BeanDefinitionBuilder builder)
{
String name = element.getAttribute("name");
if (StringUtils.hasText(name)) {
builder.addPropertyValue("name", name);
element.setAttribute("name", name);
} else {
throw new IllegalArgumentException("fc-template:name is not allow empty!");
}
String id = element.getAttribute("id");
if (StringUtils.hasText(id)) {
builder.addPropertyValue("id", id);
element.setAttribute("id", Template.FC_SUFFIX + id);
} else {
throw new IllegalArgumentException("fc-template:id is not allow empty!");
}
}
示例14: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableBeanContext.class.getName());
if (attributes == null) {
return;
}
boolean lookupByType = (boolean) attributes.get("lookupByType");
// check environment
if (environment.containsProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME)) {
lookupByType = environment.getProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME, Boolean.class);
}
// register post processor
if (!registry.containsBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME)) {
BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder
.genericBeanDefinition(BeanFactoryScopePostProcessor.class).setDestroyMethodName("unregister")
.addPropertyValue("lookupByType", lookupByType).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME,
postProcessorBuilder.getBeanDefinition());
}
}
示例15: parseDeclareParents
import org.springframework.beans.factory.support.BeanDefinitionBuilder; //导入依赖的package包/类
/**
* Parse a '{@code declare-parents}' element and register the appropriate
* DeclareParentsAdvisor with the BeanDefinitionRegistry encapsulated in the
* supplied ParserContext.
*/
private AbstractBeanDefinition parseDeclareParents(Element declareParentsElement, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DeclareParentsAdvisor.class);
builder.addConstructorArgValue(declareParentsElement.getAttribute(IMPLEMENT_INTERFACE));
builder.addConstructorArgValue(declareParentsElement.getAttribute(TYPE_PATTERN));
String defaultImpl = declareParentsElement.getAttribute(DEFAULT_IMPL);
String delegateRef = declareParentsElement.getAttribute(DELEGATE_REF);
if (StringUtils.hasText(defaultImpl) && !StringUtils.hasText(delegateRef)) {
builder.addConstructorArgValue(defaultImpl);
}
else if (StringUtils.hasText(delegateRef) && !StringUtils.hasText(defaultImpl)) {
builder.addConstructorArgReference(delegateRef);
}
else {
parserContext.getReaderContext().error(
"Exactly one of the " + DEFAULT_IMPL + " or " + DELEGATE_REF + " attributes must be specified",
declareParentsElement, this.parseState.snapshot());
}
AbstractBeanDefinition definition = builder.getBeanDefinition();
definition.setSource(parserContext.extractSource(declareParentsElement));
parserContext.getReaderContext().registerWithGeneratedName(definition);
return definition;
}