List of usage examples for org.springframework.beans.factory.config BeanDefinition getBeanClassName
@Nullable String getBeanClassName();
From source file:com.searchbox.framework.web.ApplicationConversionService.java
@Override public void afterPropertiesSet() throws Exception { LOGGER.info("Scanning for SearchComponents"); Map<Class<?>, String> conditionUrl = new HashMap<Class<?>, String>(); ClassPathScanningCandidateComponentProvider scanner; // Getting all the SearchElements scanner = new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(SearchCondition.class)); for (BeanDefinition bean : scanner.findCandidateComponents("com.searchbox")) { try {// w w w. ja va2 s .co m Class<?> clazz = Class.forName(bean.getBeanClassName()); String urlParam = clazz.getAnnotation(SearchCondition.class).urlParam(); conditionUrl.put(clazz, urlParam); } catch (Exception e) { LOGGER.error("Could not introspect SearchElement: " + bean, e); } } // Getting all converters for SearchConditions scanner = new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(SearchConverter.class)); for (BeanDefinition bean : scanner.findCandidateComponents("com.searchbox")) { try { Class<?> clazz = Class.forName(bean.getBeanClassName()); for (Type i : clazz.getGenericInterfaces()) { ParameterizedType pi = (ParameterizedType) i; for (Type piarg : pi.getActualTypeArguments()) { if (AbstractSearchCondition.class.isAssignableFrom(((Class<?>) piarg))) { Class<?> conditionClass = ((Class<?>) piarg); searchConditions.put(conditionUrl.get(conditionClass), ((Class<?>) piarg)); this.addConverter((Converter<?, ?>) clazz.newInstance()); LOGGER.info("Registered Converter " + clazz.getSimpleName() + " for " + ((Class<?>) piarg).getSimpleName() + " with prefix: " + conditionUrl.get(conditionClass)); } } } } catch (Exception e) { LOGGER.error("Could not create Converter for: " + bean.getBeanClassName(), e); } } this.addConverter(new Converter<String, SearchboxEntity>() { @Override public SearchboxEntity convert(String slug) { return searchboxRepository.findBySlug(slug); } }); this.addConverter(new Converter<SearchboxEntity, String>() { @Override public String convert(SearchboxEntity searchbox) { return searchbox.getSlug(); } }); this.addConverter(new Converter<Long, SearchboxEntity>() { @Override public SearchboxEntity convert(java.lang.Long id) { return searchboxRepository.findOne(id); } }); this.addConverter(new Converter<SearchboxEntity, Long>() { @Override public Long convert(SearchboxEntity searchbox) { return searchbox.getId(); } }); this.addConverter(new Converter<String, PresetEntity>() { @Override public PresetEntity convert(String slug) { return presetRepository.findPresetDefinitionBySlug(slug); } }); this.addConverter(new Converter<Long, PresetEntity>() { @Override public PresetEntity convert(java.lang.Long id) { return presetRepository.findOne(id); } }); this.addConverter(new Converter<PresetEntity, String>() { @Override public String convert(PresetEntity presetDefinition) { return new StringBuilder().append(presetDefinition.getSlug()).toString(); } }); this.addConverter(new Converter<Class<?>, String>() { @Override public String convert(Class<?> source) { return source.getName(); } }); this.addConverter(new Converter<String, Class<?>>() { @Override public Class<?> convert(String source) { try { // TODO Such a bad hack... if (source.contains("class")) { source = source.replace("class", "").trim(); } return context.getClassLoader().loadClass(source); // Class.forName(source); } catch (ClassNotFoundException e) { LOGGER.error("Could not convert \"" + source + "\" to class.", e); } return null; } }); }
From source file:org.os890.ds.addon.spring.impl.SpringBridgeExtension.java
public void initContainerBridge(@Observes AfterBeanDiscovery abd, BeanManager beanManager) { this.springContext = new EditableConfigurableApplicationContextProxy( resolveSpringContext(abd, beanManager)); if (this.springContext == null) { abd.addDefinitionError(new IllegalStateException("no spring-context found/created")); return;/*from www .j a v a 2 s. com*/ } for (String beanName : this.springContext.getBeanDefinitionNames()) { BeanDefinition beanDefinition = this.springContext.getBeanFactory().getBeanDefinition(beanName); String name = beanDefinition.getBeanClassName(); if (name == null) //can be null in case of config-files as spring bean { continue; } Class<?> beanClass = ClassUtils.tryToLoadClassForName(name); if (CdiSpringScope.class.getName().equals(beanDefinition.getScope()) || isFilteredSpringBean(beanClass)) { continue; //don't add cdi-beans registered in spring back to cdi } abd.addBean( createBeanAdapter(beanClass, beanName, beanDefinition, this.springContext, beanManager, abd)); } this.beanFilterList.clear(); this.cdiBeansForSpring.clear(); }
From source file:com.arondor.common.reflection.parser.spring.XMLBeanDefinitionParser.java
private ObjectConfiguration parseBeanDefinition(BeanDefinition beanDefinition) { LOGGER.debug("Resource description : " + beanDefinition.getResourceDescription()); ObjectConfiguration objectConfiguration = objectConfigurationFactory.createObjectConfiguration(); objectConfiguration.setClassName(hashHelper.hashClassName(beanDefinition.getBeanClassName())); objectConfiguration.setSingleton(beanDefinition.isSingleton()); Map<String, ElementConfiguration> fields = new LinkedHashMap<String, ElementConfiguration>(); objectConfiguration.setFields(fields); for (PropertyValue ppt : beanDefinition.getPropertyValues().getPropertyValueList()) { try {//from ww w .ja v a 2 s . c o m ElementConfiguration fieldConfiguration = beanPropertyParser.parseProperty(ppt.getValue()); fields.put(hashHelper.hashFieldName(beanDefinition.getBeanClassName(), ppt.getName()), fieldConfiguration); } catch (Exception e) { LOGGER.error("The value " + ppt.getValue() + " of property " + ppt + " cannot be parsed", e); } } List<ElementConfiguration> constructorArguments = new ArrayList<ElementConfiguration>(); objectConfiguration.setConstructorArguments(constructorArguments); for (ValueHolder va : beanDefinition.getConstructorArgumentValues().getGenericArgumentValues()) { ElementConfiguration constructorAgrument = beanPropertyParser.parseProperty(va.getValue()); constructorArguments.add(constructorAgrument); } return objectConfiguration; }
From source file:com.mmnaseri.dragonfly.runtime.session.ApplicationSessionPreparator.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory context) throws BeansException { showDeprecationWarning();/*from ww w. j av a 2 s. c o m*/ long time = System.nanoTime(); log.warn( "Preparing the session at runtime can be harmful to your performance. You should consider switching to " + "the Maven plugin."); log.debug("Looking up the necessary components ..."); tableMetadataRegistry = context.getBean(TableMetadataRegistry.class); statementRegistry = context.getBean(StatementRegistry.class); final ModifiableEntityContext entityContext = context.getBean(ModifiableEntityContext.class); final ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); log.info("Finding entity classes ..."); log.debug("Looking for classes with @Entity"); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Entity.class)); if (parentClassLoader == null) { log.debug("Falling back to the application context class loader"); parentClassLoader = context.getBeanClassLoader(); } for (String basePackage : basePackages) { final Set<BeanDefinition> beanDefinitions = componentProvider.findCandidateComponents(basePackage); for (BeanDefinition beanDefinition : beanDefinitions) { try { log.debug("Registering entity " + beanDefinition.getBeanClassName()); //noinspection unchecked definitionContext.addDefinition(new ImmutableEntityDefinition<Object>( ClassUtils.forName(beanDefinition.getBeanClassName(), parentClassLoader), Collections.<Class<?>, Class<?>>emptyMap())); } catch (ClassNotFoundException e) { throw new FatalBeanException("Failed to retrieve class: " + beanDefinition.getBeanClassName(), e); } } } componentProvider.resetFilters(false); log.info("Finding extensions to the data access ..."); log.debug("Looking for classes with @Extension"); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Extension.class)); final AnnotationExtensionMetadataResolver extensionMetadataResolver = new AnnotationExtensionMetadataResolver( metadataResolver); for (String basePackage : basePackages) { final Set<BeanDefinition> beanDefinitions = componentProvider.findCandidateComponents(basePackage); for (BeanDefinition beanDefinition : beanDefinitions) { try { log.debug("Registering extension " + beanDefinition.getBeanClassName()); extensionManager.addExtension(extensionMetadataResolver .resolve(ClassUtils.forName(beanDefinition.getBeanClassName(), parentClassLoader))); } catch (ClassNotFoundException e) { throw new FatalBeanException("Failed to retrieve class: " + beanDefinition.getBeanClassName(), e); } } } log.info("Preparing entity statements for later use"); final StatementRegistryPreparator preparator = new StatementRegistryPreparator(databaseDialect, resolverContext, tableMetadataRegistry); for (Class<?> entity : definitionContext.getEntities()) { preparator.addEntity(entity); } preparator.prepare(statementRegistry); log.info("Registering interfaces with the context"); entityContext.setInterfaces( with(definitionContext.getEntities()).map(new Transformer<Class<?>, Map<Class<?>, Class<?>>>() { @Override public Map<Class<?>, Class<?>> map(Class<?> input) { //noinspection unchecked final EntityDefinition<Object> definition = extensionManager .intercept(new ImmutableEntityDefinition<Object>((Class<Object>) input, Collections.<Class<?>, Class<?>>emptyMap())); return definition.getInterfaces(); } })); if (initializeSession) { final DataAccessSession session = context.getBean(DataAccessSession.class); session.initialize(); session.markInitialized(); } log.info("Setting the class loader for the entity context"); entityContext.setDefaultClassLoader(context.getBeanClassLoader()); time = System.nanoTime() - time; log.info("Session preparation took " + Math.round((double) time / 1000000d) / 1000d + " second(s)"); }
From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeansGenerator.java
protected void findModels() throws Exception { Set<BeanDefinition> entityBeanDefs = EntityUtil.findAnnotatedClasses(basePackage); for (BeanDefinition beanDef : entityBeanDefs) { Class<?> entity = ClassUtils.getClass(beanDef.getBeanClassName()); entityModelContextsMap.put(entity, ModelContext.from(entity)); }//from w w w.jav a 2 s. co m }
From source file:de.javadesign.cdi.extension.spring.SpringBeanIntegrationExtension.java
/** * Try to create a bean if class is found. * //from ww w .j av a 2 s. co m * @param beanName * the bean name to find and create * @param beanDefinition * the spring bean definition * @param beanManager * the injection bean manager * @param beanFactory * a ConfigurableListableBeanFactory * @return the created bean or null if class was not found */ private Bean<?> createBean(final String beanName, final BeanDefinition beanDefinition, final ConfigurableListableBeanFactory beanFactory, final BeanManager beanManager) { Class<?> beanClass = null; try { if (null == beanDefinition.getBeanClassName()) { // TODO: Support beans which are created via factory bean. LOGGER.warn("Ignored bean with name {} - there is no definition via bean's class name available", beanName); return CLASS_NOT_FOUND; } beanClass = Class.forName(beanDefinition.getBeanClassName()); // FactoryBean? Bean class is returned by getObjectType method for (Class<?> beanClassInterface : beanClass.getInterfaces()) { if (!beanClassInterface.equals(FactoryBean.class)) { continue; } try { Method getObjectTypeMethod = beanClass.getDeclaredMethod(METHOD_NAME_GET_OBJECT_TYPE); String s = ((ParameterizedType) getObjectTypeMethod.getGenericReturnType()) .getActualTypeArguments()[0].toString(); beanClass = Class.forName(s.substring(s.lastIndexOf(" ") + 1)); } catch (NoSuchMethodException ignored) { LOGGER.warn("Ignored bean {} with Class {} that is assumed to be a FactoryBean, " + "but has no getObjectType method.", beanName, beanClass); return CLASS_NOT_FOUND; } break; } } catch (final ClassNotFoundException e) { LOGGER.warn("Class {} not found.", beanName); return CLASS_NOT_FOUND; } final AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(beanClass); final Set<Type> beanTypes = annotatedType.getTypeClosure(); final Set<Annotation> qualifiers = new HashSet<Annotation>(); qualifiers.add(new AnnotationLiteral<Any>() { private static final long serialVersionUID = 1L; // any implementation }); qualifiers.add(new AnnotationLiteral<Default>() { private static final long serialVersionUID = 1L; // default implementation }); final Set<Class<? extends Annotation>> stereotypes = new HashSet<Class<? extends Annotation>>(); for (final Annotation annotation : annotatedType.getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { qualifiers.add(annotation); } if (beanManager.isStereotype(annotation.annotationType())) { stereotypes.add(annotation.annotationType()); } } return new SpringBean(beanName, beanClass, beanTypes, qualifiers, stereotypes, beanFactory); }
From source file:jeeves.server.overrides.AddPropertyUpdater.java
@SuppressWarnings("unchecked") @Override// w ww . j av a 2 s . c om protected void doUpdate(ConfigurableListableBeanFactory beanFactory, BeanDefinition bean, Object value) { Log.debug(Log.JEEVES, "Adding new value " + value + " to property: " + propertyName + " on " + beanName); PropertyValue propertyValue = bean.getPropertyValues().getPropertyValue(propertyName); if (propertyValue == null) { final String beanClassName = bean.getBeanClassName(); try { final Class<?> aClass = Class.forName(beanClassName); final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(aClass); for (PropertyDescriptor descriptor : propertyDescriptors) { if (propertyName.equals(descriptor.getName())) { final Class<?> collectionType = descriptor.getWriteMethod().getParameterTypes()[0]; if (List.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedList<Object>()); } else if (Set.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedSet<Object>()); } else if (Map.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedMap<Object, Object>()); } else if (Properties.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedProperties()); } else if (Array.class.isAssignableFrom(collectionType)) { throw new IllegalArgumentException("Array collections not currently supported"); } else if (Collection.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedList<Object>()); } else { throw new IllegalArgumentException( collectionType + " is not a supported type for adding new values"); } break; } } if (propertyValue == null) { throw new IllegalArgumentException("Unable to find the collection type for property: " + propertyName + " on bean " + beanName); } bean.getPropertyValues().addPropertyValue(propertyValue); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } Object originalValue = propertyValue.getValue(); if (originalValue instanceof Collection) { Collection<Object> coll = (Collection<Object>) originalValue; coll.add(value); } else { throw new IllegalArgumentException(originalValue + " is not a collection as expected"); } }
From source file:org.devefx.httpmapper.spring.mapper.ClassPathMapperScanner.java
@Override protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException { if (super.checkCandidate(beanName, beanDefinition)) { return true; } else {/*w ww. j a v a 2 s .c o m*/ logger.warn("Skipping MapperFactoryBean with name '" + beanName + "' and '" + beanDefinition.getBeanClassName() + "' mapperInterface" + ". Bean already defined with the same name!"); return false; } }
From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeanGeneratingRegistryPostProcessor.java
/** * Checks if the given BeanDefinition extends/impleents the given target * type/*w w w. j av a 2 s. c om*/ * * @param beanDef * @param targetType * @return */ protected boolean isOfType(BeanDefinition beanDef, Class<?> targetType) { if (beanDef.getBeanClassName() != null) { Class<?> beanClass = ClassUtils.getClass(beanDef.getBeanClassName()); return targetType.isAssignableFrom(beanClass); } return false; }
From source file:lodsve.core.condition.BeanTypeRegistry.java
private Class<?> getDirectFactoryBeanGeneric(ConfigurableListableBeanFactory beanFactory, BeanDefinition definition, String name) throws ClassNotFoundException, LinkageError { Class<?> factoryBeanClass = ClassUtils.forName(definition.getBeanClassName(), beanFactory.getBeanClassLoader()); Class<?> generic = ResolvableType.forClass(factoryBeanClass).as(FactoryBean.class).resolveGeneric(); if ((generic == null || generic.equals(Object.class)) && definition.hasAttribute(FACTORY_BEAN_OBJECT_TYPE)) { generic = getTypeFromAttribute(definition.getAttribute(FACTORY_BEAN_OBJECT_TYPE)); }//from ww w . j a v a 2 s .co m return generic; }