public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { for (DataSourceRegister dataSourceRegister : applicationContext.getBeansOfType(DataSourceRegister.class).values()) { if(dataSourceRegister.getName().equals(dataSourceName)){ this.setDataSource(dataSourceRegister.getDataSource()); if(dataSourceRegister.isAsDefault()){ this.asDefault=true; } } } List<String> packageNames=new ArrayList<String>(); for(AnnotationPackages packages:applicationContext.getBeansOfType(AnnotationPackages.class).values()){ packageNames.addAll(packages.getScanPackages()); } if(scanPackages!=null){ packageNames.addAll(scanPackages); } if(packageNames.size()>0){ String[] tmp=new String[packageNames.size()]; packageNames.toArray(tmp); super.setPackagesToScan(tmp); } }
/** * Load/use a bean factory, as specified by a factory key which is a JNDI * address, of the form {@code java:comp/env/ejb/BeanFactoryPath}. The * contents of this JNDI location must be a string containing one or more * classpath resource names (separated by any of the delimiters '{@code ,; \t\n}' * if there is more than one. The resulting BeanFactory (or ApplicationContext) * will be created from the combined resources. * @see #createBeanFactory */ @Override public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException { try { String beanFactoryPath = lookup(factoryKey, String.class); if (logger.isTraceEnabled()) { logger.trace("Bean factory path from JNDI environment variable [" + factoryKey + "] is: " + beanFactoryPath); } String[] paths = StringUtils.tokenizeToStringArray(beanFactoryPath, BEAN_FACTORY_PATH_DELIMITERS); return createBeanFactory(paths); } catch (NamingException ex) { throw new BootstrapException("Define an environment variable [" + factoryKey + "] containing " + "the class path locations of XML bean definition files", ex); } }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { //Map<String, Object> serviceMap = applicationContext.getBeansWithAnnotation(XxlWebHandlerMapping.class); String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames(); if (beanDefinitionNames!=null && beanDefinitionNames.length>0) { for (String beanDefinitionName : beanDefinitionNames) { boolean isApiHandler = applicationContext.isTypeMatch(beanDefinitionName, XxlWebHandler.class); if (isApiHandler) { // if (beanDefinition instanceof XxlWebHandler) { Object beanDefinition = applicationContext.getBean(beanDefinitionName); // valid annotation XxlWebHandlerMapping annotation = beanDefinition.getClass().getAnnotation(XxlWebHandlerMapping.class); if (annotation!=null && annotation.value()!=null && annotation.value().trim().length()>0 ) { handlerRepository.put(annotation.value(), (XxlWebHandler) beanDefinition); logger.warn(">>>>>>>>>>> xxl-hex, bind hex handler success : {}", annotation.value()); } } } } }
@Override public PropertyValues postProcessPropertyValues( PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { if (!this.validatedBeanNames.contains(beanName)) { if (!shouldSkip(this.beanFactory, beanName)) { List<String> invalidProperties = new ArrayList<String>(); for (PropertyDescriptor pd : pds) { if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) { invalidProperties.add(pd.getName()); } } if (!invalidProperties.isEmpty()) { throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName)); } } this.validatedBeanNames.add(beanName); } return pvs; }
@Bean public BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext applicationContext) { return new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (beanFactory instanceof BeanDefinitionRegistry) { try { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry); scanner.setResourceLoader(applicationContext); scanner.scan("com.quancheng.saluki.boot.web"); } catch (Throwable e) { log.error(e.getMessage(), e); } } } }; }
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) throws BeansException, OsgiException { Bundle bundle = bundleContext.getBundle(); try { // Try and load the annotation code using the bundle classloader Class<?> annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS); // instantiate the class final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass); // everything went okay so configure the BPP and add it to the BF ((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory); ((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader()); ((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext); beanFactory.addBeanPostProcessor(annotationBeanPostProcessor); } catch (ClassNotFoundException exception) { log.info("Spring-DM annotation package could not be loaded from bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled..."); if (log.isDebugEnabled()) log.debug("Cannot load annotation injection processor", exception); } }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { Iterator<String> iterator = configurableListableBeanFactory.getBeanNamesIterator(); while (iterator.hasNext()) { Object obj = configurableListableBeanFactory.getBean(iterator.next()); Field[] fields = obj.getClass().getDeclaredFields(); for (Field field : fields) { if (field.getType().isAnnotationPresent(ConfigBean.class)) { field.setAccessible(true); try { Object value = config.configBeanParser(field.getType()).getConfigBean(); field.set(obj, value); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } }
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; Map<String, HibernateSessionFactoryRepository> map = applicationContext .getBeansOfType(HibernateSessionFactoryRepository.class); if (map.size() > 0) { this.sessionFactoryRepository = map.values().iterator().next(); } else if (applicationContext.getParent() != null) { map = applicationContext.getParent().getBeansOfType(HibernateSessionFactoryRepository.class); if (map.size() > 0) { this.sessionFactoryRepository = map.values().iterator().next(); } } }
private X parseResultSet(Object rs) { try { IPojoFactory<X> pojoFactory = getPojoFactory(); if (pojoFactory.isPrimitive()) { return pojoFactory.parsePrimitive(rs); } Object[] row; if (rs instanceof Object[]) { row = (Object[]) rs; } else { row = new Object[] { rs }; } if (row.length < aliases.size()) { throw new ParseSqlException( "En número de alias de la select no coindicen con el numero de columnas devueltas por la query. Alias definidos: " + aliases); } X result = pojoFactory.newInstance(); IBeanWrapper bean = new BeanWrapper(result); prepareBeanWrapper(bean); int index = 0; for (String propertyName : aliases.getBeanAliases()) { Object value = row[index++]; bean.setPropertyValue(propertyName, value); } return result; } catch (BeansException e) { log.error("Error haciendo set " + targetClass, e); } return null; }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; for (String name : beanFactory.getBeanDefinitionNames()) { BeanDefinition definition = beanFactory.getBeanDefinition(name); String method = definition.getFactoryMethodName(); String bean = definition.getFactoryBeanName(); if (method != null && bean != null) { this.beans.put(name, new MetaData(bean, method)); } } }
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext=applicationContext; Collection<DataSourceRepository> dataSourceRepositoryCollection=applicationContext.getBeansOfType(DataSourceRepository.class).values(); if(dataSourceRepositoryCollection.size()>0){ this.dataSourceRepository=dataSourceRepositoryCollection.iterator().next(); }else if(applicationContext.getParent()!=null){ dataSourceRepositoryCollection=applicationContext.getParent().getBeansOfType(DataSourceRepository.class).values(); if(dataSourceRepositoryCollection.size()>0){ this.dataSourceRepository=dataSourceRepositoryCollection.iterator().next(); } } this.dialects=applicationContext.getBeansOfType(IDialect.class).values(); }
@Override public ChromeDriver getObject() throws BeansException { if (properties.getChrome().isEnabled()) { try { return new ChromeDriver(chromeDriverService); } catch (IllegalStateException e) { e.printStackTrace(); // swallow the exception } } return null; }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { final BeanDefinitionFinder beanDefinitionFinder = new BeanDefinitionFinder(beanFactory); doubleRegistry .mockSearch() .forEach(mockDefinition -> postProcessBeanFactoryForMock(beanDefinitionFinder, mockDefinition)); doubleRegistry .spySearch() .forEach(spyDefinition -> postProcessBeanFactoryForSpy(beanDefinitionFinder, spyDefinition)); beanDefinitionFinder.execute(); }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (!(beanFactory instanceof ConfigurableListableBeanFactory)) { throw new IllegalArgumentException( "AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory"); } this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; }
private void createContext() { xmlContext = new OsgiBundleXmlApplicationContext(new String[] {}) { public void refresh() throws BeansException { // no-op } }; xmlContext.setBundleContext(context); }
@Override public Object getBean(String name, Object... args) throws BeansException { if (args != null) { throw new UnsupportedOperationException( "StaticListableBeanFactory does not support explicit bean creation arguments)"); } return getBean(name); }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { OAuth2ExpressionHandlerInjectionPostProcessor processor = new OAuth2ExpressionHandlerInjectionPostProcessor( this.applicationContext); beanFactory.addBeanPostProcessor(processor); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof DefaultMethodSecurityExpressionHandler && !(bean instanceof OAuth2MethodSecurityExpressionHandler)) { return getExpressionHandler( (DefaultMethodSecurityExpressionHandler) bean); } return bean; }
@Override public PropertyValues postProcessPropertyValues( PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { InjectionMetadata metadata = findAutowiringMetadata(beanName, bean.getClass()); try { metadata.inject(bean, beanName, pvs); } catch (Throwable ex) { throw new BeanCreationException(beanName, "Injection of autowired dependencies failed", ex); } return pvs; }
protected void setUp() throws Exception { context = new AbstractOsgiBundleApplicationContext() { protected void loadBeanDefinitions(DefaultListableBeanFactory arg0) throws IOException, BeansException { } }; mocksControl = createStrictControl(); bundleCtx = mocksControl.createMock(BundleContext.class); bundle = createNiceMock(Bundle.class); expect(bundleCtx.getBundle()).andReturn(bundle); }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if(beanName.equals(name)) { System.err.println("BeanPostProcessor postProcessBeforeInitialization: " + beanName + ", " + bean); } return bean; }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if(applicationContext instanceof WebApplicationContext){ WebApplicationContext context=(WebApplicationContext)applicationContext; baseWebPath=context.getServletContext().getRealPath("/"); } this.applicationContext=applicationContext; }
/** * Create a new ClassPathXmlApplicationContext with the given parent, * loading the definitions from the given XML files and automatically * refreshing the context. * @param paths array of relative (or absolute) paths within the class path * @param clazz the class to load resources with (basis for the given paths) * @param parent the parent context * @throws BeansException if context creation failed * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class) * @see org.springframework.context.support.GenericApplicationContext * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader */ public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, ApplicationContext parent) throws BeansException { super(parent); Assert.notNull(paths, "Path array must not be null"); Assert.notNull(clazz, "Class argument must not be null"); this.configResources = new Resource[paths.length]; for (int i = 0; i < paths.length; i++) { this.configResources[i] = new ClassPathResource(paths[i], clazz); } refresh(); }
@Override public void setApplicationContext(ApplicationContext ctx) throws BeansException { // TODO Auto-generated method stub System.out.println("context set"); this.context=ctx; }
@Override public Object getValue(ELContext elContext, Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext) { WebApplicationContext wac = (WebApplicationContext) base; String beanName = property.toString(); if (logger.isTraceEnabled()) { logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext"); } if (wac.containsBean(beanName)) { if (logger.isDebugEnabled()) { logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext"); } elContext.setPropertyResolved(true); try { return wac.getBean(beanName); } catch (BeansException ex) { throw new ELException(ex); } } else { // Mimic standard JSF/JSP behavior when base is a Map by returning null. return null; } } } else { if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) { elContext.setPropertyResolved(true); return getWebApplicationContext(elContext); } } return null; }
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException { if(null != serviceMap){ Iterator<String> iterator = serviceMap.keySet().iterator(); while(iterator.hasNext()){ String beanId = iterator.next(); String className = serviceMap.get(beanId); GenericBeanDefinition definition = new GenericBeanDefinition(); definition.getPropertyValues().add("serviceInterface", className); definition.setBeanClass(LionServiceFactoryBean.class); beanDefinitionRegistry.registerBeanDefinition(beanId, definition); } } }
@Override public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException { // Use non-singleton bean definition, to avoid registering bean as dependent bean. RootBeanDefinition bd = new RootBeanDefinition(beanClass, autowireMode, dependencyCheck); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); return createBean(beanClass.getName(), bd, null); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof Tracer) { return new TracerWrapper((Tracer)bean); } return bean; }
/** * Return a merged RootBeanDefinition, traversing the parent bean definition * if the specified bean corresponds to a child bean definition. * @param beanName the name of the bean to retrieve the merged definition for * @return a (potentially merged) RootBeanDefinition for the given bean * @throws NoSuchBeanDefinitionException if there is no bean with the given name * @throws BeanDefinitionStoreException in case of an invalid bean definition */ protected RootBeanDefinition getMergedLocalBeanDefinition(String beanName) throws BeansException { // Quick check on the concurrent map first, with minimal locking. RootBeanDefinition mbd = this.mergedBeanDefinitions.get(beanName); if (mbd != null) { return mbd; } return getMergedBeanDefinition(beanName, getBeanDefinition(beanName)); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof WebTracingConfiguration) { WebTracingConfiguration config = (WebTracingConfiguration)bean; StringBuilder skip = new StringBuilder((config).getSkipPattern().pattern()) .append('|') .append(metricsPath); return config.toBuilder() .withSkipPattern(Pattern.compile(skip.toString())) .build(); } return bean; }
@Override public synchronized Object getTarget() throws BeansException { if (this.target == null) { this.target = getBeanFactory().getBean(getTargetBeanName()); postProcessTargetObject(this.target); } return this.target; }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Collection<ProcessProvider> coll=applicationContext.getBeansOfType(ProcessProvider.class).values(); providers=new ArrayList<ProcessProvider>(); for(ProcessProvider p:coll){ if(p.isDisabled()){ continue; } providers.add(p); } }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Collection<Function> coll=applicationContext.getBeansOfType(Function.class).values(); for(Function fun:coll){ functions.put(fun.name(), fun); } }
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { registerBeanDefinitions(registry); registerConfigItemPostProcessors(); initRefreshScopeBeanNames(registry); refresh(false); }
@Override @SuppressWarnings("unchecked") public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (this.customQualifierTypes != null) { if (!(beanFactory instanceof DefaultListableBeanFactory)) { throw new IllegalStateException( "CustomAutowireConfigurer needs to operate on a DefaultListableBeanFactory"); } DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory; if (!(dlbf.getAutowireCandidateResolver() instanceof QualifierAnnotationAutowireCandidateResolver)) { dlbf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); } QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver) dlbf.getAutowireCandidateResolver(); for (Object value : this.customQualifierTypes) { Class<? extends Annotation> customType = null; if (value instanceof Class) { customType = (Class<? extends Annotation>) value; } else if (value instanceof String) { String className = (String) value; customType = (Class<? extends Annotation>) ClassUtils.resolveClassName(className, this.beanClassLoader); } else { throw new IllegalArgumentException( "Invalid value [" + value + "] for custom qualifier type: needs to be Class or String."); } if (!Annotation.class.isAssignableFrom(customType)) { throw new IllegalArgumentException( "Qualifier type [" + customType.getName() + "] needs to be annotation type"); } resolver.addQualifierType(customType); } } }
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; // just return bean }
public void setApplicationContext(ApplicationContext context) throws BeansException { actionParsers=context.getBeansOfType(ActionParser.class).values(); }
/** * Cancel this context's refresh attempt, resetting the {@code active} flag * after an exception got thrown. * @param ex the exception that led to the cancellation */ protected void cancelRefresh(BeansException ex) { synchronized (this.activeMonitor) { this.active = false; } }
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { providers=applicationContext.getBeansOfType(IToolbarContentProvider.class).values(); }
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; }