Java Code Examples for org.springframework.beans.factory.config.ConfigurableListableBeanFactory#containsBeanDefinition()

The following examples show how to use org.springframework.beans.factory.config.ConfigurableListableBeanFactory#containsBeanDefinition() . 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 File: BusWiringBeanFactoryPostProcessor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Object getBusForName(String name,
                             ConfigurableListableBeanFactory factory,
                             boolean create,
                             String cn) {
    if (!factory.containsBeanDefinition(name) && (create || Bus.DEFAULT_BUS_ID.equals(name))) {
        DefaultListableBeanFactory df = (DefaultListableBeanFactory)factory;
        RootBeanDefinition rbd = new RootBeanDefinition(SpringBus.class);
        if (cn != null) {
            rbd.setAttribute("busConfig", new RuntimeBeanReference(cn));
        }
        df.registerBeanDefinition(name, rbd);
    } else if (cn != null) {
        BeanDefinition bd = factory.getBeanDefinition(name);
        bd.getPropertyValues().addPropertyValue("busConfig", new RuntimeBeanReference(cn));
    }
    return new RuntimeBeanReference(name);
}
 
Example 2
Source File: AutoProxyUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Determine the original target class for the specified bean, if possible,
 * otherwise falling back to a regular {@code getType} lookup.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return the original target class as stored in the bean definition, if any
 * @since 4.2.3
 * @see org.springframework.beans.factory.BeanFactory#getType(String)
 */
@Nullable
public static Class<?> determineTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {

	if (beanName == null) {
		return null;
	}
	if (beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
		Class<?> targetClass = (Class<?>) bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE);
		if (targetClass != null) {
			return targetClass;
		}
	}
	return beanFactory.getType(beanName);
}
 
Example 3
Source File: UifBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Retrieves the expression graph map set on the bean with given name. If the bean has not been processed
 * by the bean factory post processor, that is done before retrieving the map
 *
 * @param parentBeanName name of the parent bean to retrieve map for (if empty a new map will be returned)
 * @param beanFactory bean factory to retrieve bean definition from
 * @param processedBeanNames set of bean names that have been processed so far
 * @return expression graph map from parent or new instance
 */
protected Map<String, String> getExpressionGraphFromParent(String parentBeanName,
        ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) {
    Map<String, String> expressionGraph = new HashMap<String, String>();
    if (StringUtils.isBlank(parentBeanName) || !beanFactory.containsBeanDefinition(parentBeanName)) {
        return expressionGraph;
    }

    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(parentBeanName);
    if (!processedBeanNames.contains(parentBeanName)) {
        processBeanDefinition(parentBeanName, beanDefinition, beanFactory, processedBeanNames);
    }

    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    PropertyValue propertyExpressionsPV = pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH);
    if (propertyExpressionsPV != null) {
        Object value = propertyExpressionsPV.getValue();
        if ((value != null) && (value instanceof ManagedMap)) {
            expressionGraph.putAll((ManagedMap) value);
        }
    }

    return expressionGraph;
}
 
Example 4
Source File: GenericTypeAwareAutowireCandidateResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 5
Source File: AutoProxyUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the original target class for the specified bean, if possible,
 * otherwise falling back to a regular {@code getType} lookup.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return the original target class as stored in the bean definition, if any
 * @since 4.2.3
 * @see org.springframework.beans.factory.BeanFactory#getType(String)
 */
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanName == null) {
		return null;
	}
	if (beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
		Class<?> targetClass = (Class<?>) bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE);
		if (targetClass != null) {
			return targetClass;
		}
	}
	return beanFactory.getType(beanName);
}
 
Example 6
Source File: GenericTypeAwareAutowireCandidateResolver.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 7
Source File: RequiredAnnotationBeanPostProcessor.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given bean definition is not subject to the annotation-based
 * required property check as performed by this post-processor.
 * <p>The default implementations check for the presence of the
 * {@link #SKIP_REQUIRED_CHECK_ATTRIBUTE} attribute in the bean definition, if any.
 * It also suggests skipping in case of a bean definition with a "factory-bean"
 * reference set, assuming that instance-based factories pre-populate the bean.
 * @param beanFactory the BeanFactory to check against
 * @param beanName the name of the bean to check against
 * @return {@code true} to skip the bean; {@code false} to process it
 */
protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
		return false;
	}
	BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
	if (beanDefinition.getFactoryBeanName() != null) {
		return true;
	}
	Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
	return (value != null && (Boolean.TRUE.equals(value) || Boolean.valueOf(value.toString())));
}
 
Example 8
Source File: HttpScenarioGenerator.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    try {
        Assert.notNull(swaggerResource,
                "Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation");

        Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource));

        for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) {
            for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) {

                if (beanFactory instanceof BeanDefinitionRegistry) {
                    log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId());
                    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class)
                            .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey())
                            .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name()))
                            .addConstructorArgValue(operation.getValue())
                            .addConstructorArgValue(swagger.getDefinitions());

                    if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) {
                        beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary");
                    }

                    if (beanFactory.containsBeanDefinition("outboundJsonDataDictionary")) {
                        beanDefinitionBuilder.addPropertyReference("outboundDataDictionary", "outboundJsonDataDictionary");
                    }

                    ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition());
                } else {
                    log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId());
                    beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions()));
                }
            }
        }
    } catch (IOException e) {
        throw new SimulatorException("Failed to read swagger api resource", e);
    }
}
 
Example 9
Source File: RequiredAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check whether the given bean definition is not subject to the annotation-based
 * required property check as performed by this post-processor.
 * <p>The default implementations check for the presence of the
 * {@link #SKIP_REQUIRED_CHECK_ATTRIBUTE} attribute in the bean definition, if any.
 * It also suggests skipping in case of a bean definition with a "factory-bean"
 * reference set, assuming that instance-based factories pre-populate the bean.
 * @param beanFactory the BeanFactory to check against
 * @param beanName the name of the bean to check against
 * @return {@code true} to skip the bean; {@code false} to process it
 */
protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
		return false;
	}
	BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
	if (beanDefinition.getFactoryBeanName() != null) {
		return true;
	}
	Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
	return (value != null && (Boolean.TRUE.equals(value) || Boolean.valueOf(value.toString())));
}
 
Example 10
Source File: RequiredAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given bean definition is not subject to the annotation-based
 * required property check as performed by this post-processor.
 * <p>The default implementations check for the presence of the
 * {@link #SKIP_REQUIRED_CHECK_ATTRIBUTE} attribute in the bean definition, if any.
 * It also suggests skipping in case of a bean definition with a "factory-bean"
 * reference set, assuming that instance-based factories pre-populate the bean.
 * @param beanFactory the BeanFactory to check against
 * @param beanName the name of the bean to check against
 * @return {@code true} to skip the bean; {@code false} to process it
 */
protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
		return false;
	}
	BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
	if (beanDefinition.getFactoryBeanName() != null) {
		return true;
	}
	Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
	return (value != null && (Boolean.TRUE.equals(value) || Boolean.valueOf(value.toString())));
}
 
Example 11
Source File: RequiredAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Check whether the given bean definition is not subject to the annotation-based
 * required property check as performed by this post-processor.
 * <p>The default implementations check for the presence of the
 * {@link #SKIP_REQUIRED_CHECK_ATTRIBUTE} attribute in the bean definition, if any.
 * It also suggests skipping in case of a bean definition with a "factory-bean"
 * reference set, assuming that instance-based factories pre-populate the bean.
 * @param beanFactory the BeanFactory to check against
 * @param beanName the name of the bean to check against
 * @return {@code true} to skip the bean; {@code false} to process it
 */
protected boolean shouldSkip(@Nullable ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
		return false;
	}
	BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
	if (beanDefinition.getFactoryBeanName() != null) {
		return true;
	}
	Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
	return (value != null && (Boolean.TRUE.equals(value) || Boolean.valueOf(value.toString())));
}
 
Example 12
Source File: AutoProxyUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Expose the given target class for the specified bean, if possible.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @param targetClass the corresponding target class
 * @since 4.2.3
 */
static void exposeTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName, Class<?> targetClass) {

	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
	}
}
 
Example 13
Source File: AutoProxyUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine whether the given bean should be proxied with its target
 * class rather than its interfaces. Checks the
 * {@link #PRESERVE_TARGET_CLASS_ATTRIBUTE "preserveTargetClass" attribute}
 * of the corresponding bean definition.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return whether the given bean should be proxied with its target class
 */
public static boolean shouldProxyTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {

	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
		return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
	}
	return false;
}
 
Example 14
Source File: GenericTypeAwareAutowireCandidateResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 15
Source File: AutoProxyUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Expose the given target class for the specified bean, if possible.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @param targetClass the corresponding target class
 * @since 4.2.3
 */
static void exposeTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName, Class<?> targetClass) {

	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
	}
}
 
Example 16
Source File: AutoProxyUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine whether the given bean should be proxied with its target
 * class rather than its interfaces. Checks the
 * {@link #PRESERVE_TARGET_CLASS_ATTRIBUTE "preserveTargetClass" attribute}
 * of the corresponding bean definition.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return whether the given bean should be proxied with its target class
 */
public static boolean shouldProxyTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {

	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
		return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
	}
	return false;
}
 
Example 17
Source File: BusWiringBeanFactoryPostProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) {
    Object inject = bus;
    if (inject == null) {
        inject = getBusForName(Bus.DEFAULT_BUS_ID, factory, true, null);
    } else {
        if (!factory.containsBeanDefinition(Bus.DEFAULT_BUS_ID)
            && !factory.containsSingleton(Bus.DEFAULT_BUS_ID)) {
            factory.registerSingleton(Bus.DEFAULT_BUS_ID, bus);
        }
    }
    for (String beanName : factory.getBeanDefinitionNames()) {
        BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
        BusWiringType type
            = (BusWiringType)beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
        if (type == null) {
            continue;
        }
        String busname = (String)beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
        String create = (String)beanDefinition
            .getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
        Object inj = inject;
        if (busname != null) {
            if (bus != null) {
                continue;
            }
            inj = getBusForName(busname, factory, create != null, create);
        }
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
        if (create == null) {
            if (BusWiringType.PROPERTY == type) {
                beanDefinition.getPropertyValues()
                    .addPropertyValue("bus", inj);
            } else if (BusWiringType.CONSTRUCTOR == type) {
                ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
                insertConstructorArg(constructorArgs, inj);
            }
        }
    }
}
 
Example 18
Source File: AutoProxyUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Determine whether the given bean should be proxied with its target
 * class rather than its interfaces. Checks the
 * {@link #PRESERVE_TARGET_CLASS_ATTRIBUTE "preserveTargetClass" attribute}
 * of the corresponding bean definition.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return whether the given bean should be proxied with its target class
 */
public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
		return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
	}
	return false;
}
 
Example 19
Source File: AutoProxyUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Expose the given target class for the specified bean, if possible.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @param targetClass the corresponding target class
 * @since 4.2.3
 */
static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName, Class<?> targetClass) {
	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
	}
}
 
Example 20
Source File: AutoProxyUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Expose the given target class for the specified bean, if possible.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @param targetClass the corresponding target class
 * @since 4.2.3
 */
static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName, Class<?> targetClass) {
	if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
		beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
	}
}