Java Code Examples for org.springframework.util.CollectionUtils#containsInstance()

The following examples show how to use org.springframework.util.CollectionUtils#containsInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs the actual autodetection process, delegating to an
 * {@code AutodetectCallback} instance to vote on the inclusion of a
 * given bean.
 * @param callback the {@code AutodetectCallback} to use when deciding
 * whether to include a bean or not
 */
private void autodetect(AutodetectCallback callback) {
	Set<String> beanNames = new LinkedHashSet<String>(this.beanFactory.getBeanDefinitionCount());
	beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
	}
	for (String beanName : beanNames) {
		if (!isExcluded(beanName) && !isBeanDefinitionAbstract(this.beanFactory, beanName)) {
			try {
				Class<?> beanClass = this.beanFactory.getType(beanName);
				if (beanClass != null && callback.include(beanClass, beanName)) {
					boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
					Object beanInstance = (!lazyInit ? this.beanFactory.getBean(beanName) : null);
					if (!ScopedProxyUtils.isScopedTarget(beanName) && !this.beans.containsValue(beanName) &&
							(beanInstance == null ||
									!CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
						// Not already registered for JMX exposure.
						this.beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
						if (logger.isInfoEnabled()) {
							logger.info("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
						}
					}
					else {
						if (logger.isDebugEnabled()) {
							logger.debug("Bean with name '" + beanName + "' is already registered for JMX exposure");
						}
					}
				}
			}
			catch (CannotLoadBeanClassException ex) {
				if (this.allowEagerInit) {
					throw ex;
				}
				// otherwise ignore beans where the class is not resolvable
			}
		}
	}
}
 
Example 2
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Performs the actual autodetection process, delegating to an
 * {@code AutodetectCallback} instance to vote on the inclusion of a
 * given bean.
 * @param callback the {@code AutodetectCallback} to use when deciding
 * whether to include a bean or not
 */
private void autodetect(AutodetectCallback callback) {
	Set<String> beanNames = new LinkedHashSet<String>(this.beanFactory.getBeanDefinitionCount());
	beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
	}
	for (String beanName : beanNames) {
		if (!isExcluded(beanName) && !isBeanDefinitionAbstract(this.beanFactory, beanName)) {
			try {
				Class<?> beanClass = this.beanFactory.getType(beanName);
				if (beanClass != null && callback.include(beanClass, beanName)) {
					boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
					Object beanInstance = (!lazyInit ? this.beanFactory.getBean(beanName) : null);
					if (!ScopedProxyUtils.isScopedTarget(beanName) && !this.beans.containsValue(beanName) &&
							(beanInstance == null ||
									!CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
						// Not already registered for JMX exposure.
						this.beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
						if (logger.isInfoEnabled()) {
							logger.info("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
						}
					}
					else {
						if (logger.isDebugEnabled()) {
							logger.debug("Bean with name '" + beanName + "' is already registered for JMX exposure");
						}
					}
				}
			}
			catch (CannotLoadBeanClassException ex) {
				if (this.allowEagerInit) {
					throw ex;
				}
				// otherwise ignore beans where the class is not resolvable
			}
		}
	}
}
 
Example 3
Source File: MBeanExporter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Performs the actual autodetection process, delegating to an
 * {@code AutodetectCallback} instance to vote on the inclusion of a
 * given bean.
 * @param callback the {@code AutodetectCallback} to use when deciding
 * whether to include a bean or not
 */
private void autodetect(Map<String, Object> beans, AutodetectCallback callback) {
	Assert.state(this.beanFactory != null, "No BeanFactory set");
	Set<String> beanNames = new LinkedHashSet<>(this.beanFactory.getBeanDefinitionCount());
	Collections.addAll(beanNames, this.beanFactory.getBeanDefinitionNames());
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		Collections.addAll(beanNames, ((ConfigurableBeanFactory) this.beanFactory).getSingletonNames());
	}

	for (String beanName : beanNames) {
		if (!isExcluded(beanName) && !isBeanDefinitionAbstract(this.beanFactory, beanName)) {
			try {
				Class<?> beanClass = this.beanFactory.getType(beanName);
				if (beanClass != null && callback.include(beanClass, beanName)) {
					boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
					Object beanInstance = null;
					if (!lazyInit) {
						beanInstance = this.beanFactory.getBean(beanName);
						if (!beanClass.isInstance(beanInstance)) {
							continue;
						}
					}
					if (!ScopedProxyUtils.isScopedTarget(beanName) && !beans.containsValue(beanName) &&
							(beanInstance == null ||
									!CollectionUtils.containsInstance(beans.values(), beanInstance))) {
						// Not already registered for JMX exposure.
						beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
						if (logger.isDebugEnabled()) {
							logger.debug("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
						}
					}
					else {
						if (logger.isTraceEnabled()) {
							logger.trace("Bean with name '" + beanName + "' is already registered for JMX exposure");
						}
					}
				}
			}
			catch (CannotLoadBeanClassException ex) {
				if (this.allowEagerInit) {
					throw ex;
				}
				// otherwise ignore beans where the class is not resolvable
			}
		}
	}
}
 
Example 4
Source File: MBeanExporter.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Performs the actual autodetection process, delegating to an
 * {@code AutodetectCallback} instance to vote on the inclusion of a
 * given bean.
 * @param callback the {@code AutodetectCallback} to use when deciding
 * whether to include a bean or not
 */
private void autodetect(Map<String, Object> beans, AutodetectCallback callback) {
	Assert.state(this.beanFactory != null, "No BeanFactory set");
	Set<String> beanNames = new LinkedHashSet<>(this.beanFactory.getBeanDefinitionCount());
	Collections.addAll(beanNames, this.beanFactory.getBeanDefinitionNames());
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		Collections.addAll(beanNames, ((ConfigurableBeanFactory) this.beanFactory).getSingletonNames());
	}

	for (String beanName : beanNames) {
		if (!isExcluded(beanName) && !isBeanDefinitionAbstract(this.beanFactory, beanName)) {
			try {
				Class<?> beanClass = this.beanFactory.getType(beanName);
				if (beanClass != null && callback.include(beanClass, beanName)) {
					boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
					Object beanInstance = null;
					if (!lazyInit) {
						beanInstance = this.beanFactory.getBean(beanName);
						if (!beanClass.isInstance(beanInstance)) {
							continue;
						}
					}
					if (!ScopedProxyUtils.isScopedTarget(beanName) && !beans.containsValue(beanName) &&
							(beanInstance == null ||
									!CollectionUtils.containsInstance(beans.values(), beanInstance))) {
						// Not already registered for JMX exposure.
						beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
						if (logger.isDebugEnabled()) {
							logger.debug("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
						}
					}
					else {
						if (logger.isTraceEnabled()) {
							logger.trace("Bean with name '" + beanName + "' is already registered for JMX exposure");
						}
					}
				}
			}
			catch (CannotLoadBeanClassException ex) {
				if (this.allowEagerInit) {
					throw ex;
				}
				// otherwise ignore beans where the class is not resolvable
			}
		}
	}
}