use of org.springframework.beans.factory.config.BeanDefinition in project invesdwin-context-persistence by subes.
the class JpaRepositoryScanContextLocation method scanForJpaRepositories.
private Map<Class<?>, Set<Class<?>>> scanForJpaRepositories(final String basePackage) {
final Map<Class<?>, Set<Class<?>>> jpaRepositories = new HashMap<Class<?>, Set<Class<?>>>();
final ClassPathScanner scanner = new ClassPathScanner().withInterfacesOnly();
scanner.addIncludeFilter(new AssignableTypeFilter(JpaRepository.class));
final Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
for (final BeanDefinition bd : candidateComponents) {
final String beanClassName = bd.getBeanClassName();
final Class<?> repositoryClass = Reflections.classForName(beanClassName);
if (!IDao.class.isAssignableFrom(repositoryClass)) {
final Class<?>[] typeArguments = Reflections.resolveTypeArguments(repositoryClass, JpaRepository.class);
Assertions.assertThat(typeArguments.length).isEqualTo(2);
final Class<?> entity = typeArguments[0];
Set<Class<?>> set = jpaRepositories.get(entity);
if (set == null) {
set = new HashSet<Class<?>>();
jpaRepositories.put(entity, set);
}
Assertions.assertThat(set.add(repositoryClass)).isTrue();
}
}
return jpaRepositories;
}
use of org.springframework.beans.factory.config.BeanDefinition in project POL-POM-5 by PhoenicisOrg.
the class DTOContractTest method findAllDTOs.
private static List<DTOContainer<?>> findAllDTOs() throws ClassNotFoundException {
final List<DTOContainer<?>> fondJsonCreatorClasses = new ArrayList<>();
final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
scanner.addIncludeFilter((metadataReader, metadataReaderFactory) -> true);
final Stream<String> classNamesStream = scanner.findCandidateComponents("org.phoenicis").stream().map(BeanDefinition::getBeanClassName);
final Iterable<String> classNames = classNamesStream::iterator;
for (String className : classNames) {
final Class<?> clazz = Class.forName(className);
if (isJsonClass(clazz)) {
fondJsonCreatorClasses.add(new DTOContainer<>(clazz));
}
}
return fondJsonCreatorClasses;
}
use of org.springframework.beans.factory.config.BeanDefinition in project POL-POM-5 by PhoenicisOrg.
the class TranslatableContractTest method findAllTranslatables.
private static List<TranslatableContainer<?>> findAllTranslatables() throws ClassNotFoundException {
final List<TranslatableContainer<?>> foundClasses = new ArrayList<>();
final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
scanner.addIncludeFilter((metadataReader, metadataReaderFactory) -> true);
final Stream<String> classNamesStream = scanner.findCandidateComponents("org.phoenicis").stream().map(BeanDefinition::getBeanClassName);
final Iterable<String> classNames = classNamesStream::iterator;
for (String className : classNames) {
final Class<?> clazz = Class.forName(className);
if (isTranslatable(clazz)) {
foundClasses.add(new TranslatableContainer<>(clazz));
}
}
return foundClasses;
}
use of org.springframework.beans.factory.config.BeanDefinition in project apollo by ctripcorp.
the class SpringValueDefinitionProcessor method processPropertyValues.
private void processPropertyValues(BeanDefinitionRegistry beanRegistry) {
if (!PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES.add(beanRegistry)) {
// already initialized
return;
}
if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) {
beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.<String, SpringValueDefinition>create());
}
Multimap<String, SpringValueDefinition> springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry);
String[] beanNames = beanRegistry.getBeanDefinitionNames();
for (String beanName : beanNames) {
BeanDefinition beanDefinition = beanRegistry.getBeanDefinition(beanName);
MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
List<PropertyValue> propertyValues = mutablePropertyValues.getPropertyValueList();
for (PropertyValue propertyValue : propertyValues) {
Object value = propertyValue.getValue();
if (!(value instanceof TypedStringValue)) {
continue;
}
String placeholder = ((TypedStringValue) value).getValue();
Set<String> keys = placeholderHelper.extractPlaceholderKeys(placeholder);
if (keys.isEmpty()) {
continue;
}
for (String key : keys) {
springValueDefinitions.put(beanName, new SpringValueDefinition(key, placeholder, propertyValue.getName()));
}
}
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project apollo by ctripcorp.
the class PlaceholderHelper method resolvePropertyValue.
/**
* Resolve placeholder property values, e.g.
* <br />
* <br />
* "${somePropertyValue}" -> "the actual property value"
*/
public Object resolvePropertyValue(ConfigurableBeanFactory beanFactory, String beanName, String placeholder) {
// resolve string value
String strVal = beanFactory.resolveEmbeddedValue(placeholder);
BeanDefinition bd = (beanFactory.containsBean(beanName) ? beanFactory.getMergedBeanDefinition(beanName) : null);
// resolve expressions like "#{systemProperties.myProp}"
return evaluateBeanDefinitionString(beanFactory, strVal, bd);
}
Aggregations