org.opennms.core.utils
Class BeanUtils

java.lang.Object
  extended by org.opennms.core.utils.BeanUtils

public class BeanUtils
extends Object

Helper methods for working with Spring beans.

Version:
$Id: $
Author:
DJ Gregor

Method Summary
static
<T> T
getBean(org.springframework.beans.factory.access.BeanFactoryReference beanFactory, String beanId, Class<T> clazz)
          Get a Spring bean by name.
static
<T> T
getBean(String contextId, String beanId, Class<T> clazz)
          Helper method that combines getBeanFactory and getBean.
static org.springframework.beans.factory.access.BeanFactoryReference getBeanFactory(String contextId)
          Get a Spring BeanFactory by context ID.
static
<T> T
getFactory(String contextId, Class<T> clazz)
          Helper method that calls getBeanFactory(contextId).getFactory() and casts the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBeanFactory

public static org.springframework.beans.factory.access.BeanFactoryReference getBeanFactory(String contextId)
Get a Spring BeanFactory by context ID.

Parameters:
contextId - the context ID of the BeanFactory to fetch
Returns:
the BeanFactory

getBean

public static <T> T getBean(org.springframework.beans.factory.access.BeanFactoryReference beanFactory,
                            String beanId,
                            Class<T> clazz)
Get a Spring bean by name. Uses Java 5 generics to cast the returned class to the appropriate type.

Type Parameters:
T - class for the returned bean
Parameters:
beanFactory - bean factory to use to fetch this bean
beanId - ID of the bean to fetch
clazz - class representing the type for the returned bean
Returns:
bean for given bean ID casted to the appropriate class

getBean

public static <T> T getBean(String contextId,
                            String beanId,
                            Class<T> clazz)
Helper method that combines getBeanFactory and getBean.

Type Parameters:
T - class for the returned bean
Parameters:
contextId - the context ID of the BeanFactory from which to fetch this bean
beanId - ID of the bean to fetch
clazz - class representing the type for the returned bean
Returns:
bean for given bean ID casted to the appropriate class

getFactory

public static <T> T getFactory(String contextId,
                               Class<T> clazz)
Helper method that calls getBeanFactory(contextId).getFactory() and casts the result.

Type Parameters:
T - class for the returned factory
Parameters:
contextId - the context ID of the BeanFactory to fetch
clazz - class representing the type for the returned factory
Returns:
the factory casted to


Copyright © 2011. All Rights Reserved.