use of org.springframework.beans.factory.config.BeanDefinition in project dubbo by alibaba.
the class DubboBeanDefinitionParser method parseNested.
private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
NodeList nodeList = element.getChildNodes();
if (nodeList != null && nodeList.getLength() > 0) {
boolean first = true;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if (tag.equals(node.getNodeName()) || tag.equals(node.getLocalName())) {
if (first) {
first = false;
String isDefault = element.getAttribute("default");
if (isDefault == null || isDefault.length() == 0) {
beanDefinition.getPropertyValues().addPropertyValue("default", "false");
}
}
BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
if (subDefinition != null && ref != null && ref.length() > 0) {
subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
}
}
}
}
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterParser method getInititalEntityClasses.
private static Set<String> getInititalEntityClasses(Element element) {
String basePackage = element.getAttribute(BASE_PACKAGE);
if (!StringUtils.hasText(basePackage)) {
return null;
}
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
Set<String> classes = new ManagedSet<String>();
for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
classes.add(candidate.getBeanClassName());
}
return classes;
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-security-oauth by spring-projects.
the class ConfigUtils method createSecurityMetadataSource.
public static BeanDefinition createSecurityMetadataSource(Element element, ParserContext pc) {
List<Element> filterPatterns = DomUtils.getChildElementsByTagName(element, "url");
if (filterPatterns.isEmpty()) {
return null;
}
String patternType = element.getAttribute("path-type");
if (!StringUtils.hasText(patternType)) {
patternType = "ant";
}
MatcherType matcherType = MatcherType.valueOf(patternType);
ManagedMap<BeanDefinition, BeanDefinition> invocationDefinitionMap = new ManagedMap<BeanDefinition, BeanDefinition>();
for (Element filterPattern : filterPatterns) {
String path = filterPattern.getAttribute("pattern");
if (!StringUtils.hasText(path)) {
pc.getReaderContext().error("pattern attribute cannot be empty or null", filterPattern);
}
String method = filterPattern.getAttribute("httpMethod");
if (!StringUtils.hasText(method)) {
method = null;
}
String access = filterPattern.getAttribute("resources");
if (StringUtils.hasText(access)) {
BeanDefinition matcher;
if (createMatcherMethod4x != null) {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod4x, matcherType, pc, path, method);
} else {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod3x, matcherType, path, method);
}
if (access.equals("none")) {
invocationDefinitionMap.put(matcher, BeanDefinitionBuilder.rootBeanDefinition(Collections.class).setFactoryMethod("emptyList").getBeanDefinition());
} else {
BeanDefinitionBuilder attributeBuilder = BeanDefinitionBuilder.rootBeanDefinition(SecurityConfig.class);
attributeBuilder.addConstructorArgValue(access);
attributeBuilder.setFactoryMethod("createListFromCommaDelimitedString");
if (invocationDefinitionMap.containsKey(matcher)) {
pc.getReaderContext().warning("Duplicate URL defined: " + path + ". The original attribute values will be overwritten", pc.extractSource(filterPattern));
}
invocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
}
}
}
BeanDefinitionBuilder fidsBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultFilterInvocationSecurityMetadataSource.class);
fidsBuilder.addConstructorArgValue(invocationDefinitionMap);
fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(element));
return fidsBuilder.getBeanDefinition();
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-security-oauth by spring-projects.
the class ConfigUtils method findDefaultFilterChainBeanId.
@SuppressWarnings({ "unchecked" })
protected static String findDefaultFilterChainBeanId(ParserContext parserContext) {
BeanDefinition filterChainList = parserContext.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS);
// Get the list of SecurityFilterChain beans
List<BeanReference> filterChains = (List<BeanReference>) filterChainList.getPropertyValues().getPropertyValue("sourceList").getValue();
return filterChains.get(filterChains.size() - 1).getBeanName();
}
use of org.springframework.beans.factory.config.BeanDefinition in project easy-tests by malinink.
the class EachMapperHaveOwnTestTest method checkEachMapperHaveOwnTest.
@Test
public void checkEachMapperHaveOwnTest() throws Exception {
final Set<BeanDefinition> mappers = getMappers();
final Set<BeanDefinition> mappersTests = getMappersTests();
final Set<Class> mappersClasses = new HashSet<>();
final Set<Class> mappersWithTestsClasses = new HashSet<>();
for (BeanDefinition mapper : mappers) {
mappersClasses.add(Class.forName(mapper.getBeanClassName()));
}
for (BeanDefinition mapperTest : mappersTests) {
final Class mapperTestClass = Class.forName(mapperTest.getBeanClassName());
final Field mapperField = MapperTestHelper.findMapperFieldInTest(mapperTestClass);
Assert.assertNotNull(String.format("Mapper '%1$s' use unknown mapper, or mapper have no @Mapper annotation", mapperTestClass.getName()), mapperField);
mappersWithTestsClasses.add(mapperField.getType());
}
for (Class mapperClass : mappersClasses) {
Assert.assertTrue(String.format("Mapper '%1$s' have no test", mapperClass.getName()), mappersWithTestsClasses.contains(mapperClass));
}
}
Aggregations