use of org.springframework.beans.factory.config.BeanDefinition in project iaf by ibissource.
the class MapPropertyDescriptorsTest method testPropertyDescriptorsBeingRegistered.
@Test
public void testPropertyDescriptorsBeingRegistered() throws ClassNotFoundException, IntrospectionException {
BeanDefinitionRegistry beanDefinitionRegistry = new SimpleBeanDefinitionRegistry();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
scanner.setIncludeAnnotationConfig(false);
scanner.addIncludeFilter(new AssignableTypeFilter(IConfigurable.class));
BeanNameGenerator beanNameGenerator = new AnnotationBeanNameGenerator() {
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
String beanClassName = definition.getBeanClassName();
Assert.state(beanClassName != null, "No bean class name set");
return beanClassName;
}
};
scanner.setBeanNameGenerator(beanNameGenerator);
int numberOfBeans = scanner.scan("nl.nn.adapterframework", "nl.nn.ibistesttool");
log.debug("Found " + numberOfBeans + " beans registered!");
String[] names = scanner.getRegistry().getBeanDefinitionNames();
for (String beanName : names) {
BeanInfo beanInfo = Introspector.getBeanInfo(Class.forName(beanName));
// get methods
MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
for (MethodDescriptor methodDescriptor : methodDescriptors) {
String methodName = methodDescriptor.getName();
if (methodName.startsWith("set")) {
String propertyName = methodName.substring(3);
String getterName = "get" + propertyName;
String getterStartsWithIs = "is" + propertyName;
propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1);
boolean getterMatches = Arrays.stream(methodDescriptors).anyMatch(name -> name.getName().equals(getterName) || name.getName().equals(getterStartsWithIs));
if (getterMatches) {
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
PropertyDescriptor pd = Arrays.stream(pds).filter(name -> name.getWriteMethod() != null && methodName.equals(name.getWriteMethod().getName())).findAny().orElse(null);
assertNotNull("Make sure that the attribute [" + propertyName + "] has proper getter and setters in class [" + beanName + "].", pd);
}
}
}
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project iaf by ibissource.
the class TestAnnotationUtils method findInterfacesWithAnnotations.
@Test
public void findInterfacesWithAnnotations() throws Exception {
// assumeTrue(TestAssertions.isTestRunningOnCI());
BeanDefinitionRegistry beanDefinitionRegistry = new SimpleBeanDefinitionRegistry();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
scanner.setIncludeAnnotationConfig(false);
scanner.addIncludeFilter(new TypeFilter() {
// Find everything that has an interface
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
ClassMetadata metadata = metadataReader.getClassMetadata();
return metadata.getInterfaceNames().length > 0;
}
});
BeanNameGenerator beanNameGenerator = new AnnotationBeanNameGenerator() {
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
String beanClassName = definition.getBeanClassName();
Assert.state(beanClassName != null, "No bean class name set");
return beanClassName;
}
};
scanner.setBeanNameGenerator(beanNameGenerator);
String frankFrameworkPackage = "nl.nn.adapterframework";
int numberOfBeans = scanner.scan(frankFrameworkPackage);
assertTrue(numberOfBeans > 0);
Set<Class<?>> interfazes = new HashSet<>();
String[] names = scanner.getRegistry().getBeanDefinitionNames();
for (String beanName : names) {
// Ignore this class
if (beanName.contains(this.getClass().getCanonicalName()))
continue;
List<Class<?>> interfaces = ClassUtils.getAllInterfaces(Class.forName(beanName));
interfazes.addAll(interfaces);
}
for (Class<?> interfaze : interfazes) {
if (interfaze.getCanonicalName().startsWith(frankFrameworkPackage)) {
for (Method method : interfaze.getDeclaredMethods()) {
for (Annotation annotation : method.getAnnotations()) {
if (AnnotationFilter.PLAIN.matches(annotation) || AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
fail("Found java annotation [" + annotation + "] on interface [" + interfaze.getTypeName() + "], is not seen by digester because it uses Spring AnnotationUtils");
}
}
}
}
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project records-management by Alfresco.
the class DictionaryBootstrapPostProcessor method postProcessBeanFactory.
/**
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
// if the site service bootstrap bean and the RM dictionary bean are present in the bean factory
if (beanFactory.containsBean(BEAN_SITESERVICE_BOOTSTRAP) && beanFactory.containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP)) {
// get the RM dictionary bootstrap bean definition
BeanDefinition beanDef = beanFactory.getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
// set the dependency
beanDef.setDependsOn(new String[] { BEAN_SITESERVICE_BOOTSTRAP });
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project webanno by webanno.
the class ProjectSettingsPanelRegistryServiceImpl method scan.
private void scan() {
panels = new ArrayList<>();
// Scan project settings using annotation
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(ProjectSettingsPanel.class));
for (BeanDefinition bd : scanner.findCandidateComponents("de.tudarmstadt.ukp")) {
try {
@SuppressWarnings("unchecked") Class<? extends Panel> panelClass = (Class<? extends Panel>) Class.forName(bd.getBeanClassName());
ProjectSettingsPanel mia = panelClass.getAnnotation(ProjectSettingsPanel.class);
ProjectSettingsPanelDecl panel = new ProjectSettingsPanelDecl();
panel.label = mia.label();
panel.prio = mia.prio();
panel.panel = panelClass;
panels.add(panel);
log.debug("Found settings panel: {} ({})", panel.label, panel.prio);
List<Method> methods = MethodUtils.getMethodsListWithAnnotation(panelClass, ProjectSettingsPanelCondition.class);
if (!methods.isEmpty()) {
panel.condition = (aProject) -> {
try {
// Need to look the method up again here because methods are not
// serializable
Method m = MethodUtils.getMethodsListWithAnnotation(panelClass, ProjectSettingsPanelCondition.class).get(0);
return (boolean) m.invoke(null, aProject);
} catch (Exception e) {
LoggerFactory.getLogger(ProjectSettingsPanelRegistryServiceImpl.class).error("Unable to invoke settings panel condition method", e);
return false;
}
};
} else {
panel.condition = (aProject) -> aProject != null;
}
} catch (ClassNotFoundException e) {
log.error("Settings panel class [{}] not found", bd.getBeanClassName(), e);
}
}
panels.sort(Comparator.comparingInt(a -> a.prio));
}
use of org.springframework.beans.factory.config.BeanDefinition in project wildfly-camel by wildfly-extras.
the class SpringCamelContextBootstrap method getJndiNames.
/**
* Gets JNDI names for all configured instances of {@link JndiObjectFactoryBean}
*
* Note: If this method is invoked before ApplicationContext.refresh() then any bean property
* values containing property placeholders will not be resolved.
*
* @return the unmodifiable list of JNDI binding names
*/
public List<String> getJndiNames() {
List<String> bindings = new ArrayList<>();
for (String beanName : applicationContext.getBeanDefinitionNames()) {
BeanDefinition definition = applicationContext.getBeanDefinition(beanName);
String beanClassName = definition.getBeanClassName();
if (beanClassName != null && beanClassName.equals(JndiObjectFactoryBean.class.getName())) {
MutablePropertyValues propertyValues = definition.getPropertyValues();
Object jndiPropertyValue = propertyValues.get("jndiName");
if (jndiPropertyValue == null) {
LOGGER.debug("Skipping JNDI binding dependency for bean: {}", beanName);
continue;
}
String jndiName = null;
if (jndiPropertyValue instanceof String) {
jndiName = (String) jndiPropertyValue;
} else if (jndiPropertyValue instanceof TypedStringValue) {
jndiName = ((TypedStringValue) jndiPropertyValue).getValue();
} else {
LOGGER.debug("Ignoring unknown JndiObjectFactoryBean property value type {}", jndiPropertyValue.getClass().getSimpleName());
}
if (jndiName != null) {
bindings.add(jndiName);
}
}
}
return Collections.unmodifiableList(bindings);
}
Aggregations