Package com.hybris.cockpitng.util
Class BackofficeSpringUtil
- java.lang.Object
-
- com.hybris.cockpitng.util.BackofficeSpringUtil
-
public final class BackofficeSpringUtil extends java.lang.ObjectUtility methods for access the cockpit module application context.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsBean(java.lang.String name)Checks if bean for the given name exists.static <T> TcreateClassInstance(java.lang.String className, java.lang.Class<T> clazz)Loads a class by class name using cockpit module class loader and returns a new instance of the class.static <T> java.util.Map<java.lang.String,T>getAllBeans(java.lang.Class<T> clazz)Gets all beans for given class.static <T> java.util.Map<java.lang.String,T>getAllBeans(java.lang.Class<T> clazz, boolean respectAutowireFlag)Gets all beans for given class can respect the autowire-candidate flag for bean.static CockpitApplicationContextgetApplicationContext()Gets the cockpit module application context, if existing, otherwise null.static <C> CgetBean(java.lang.String name)Gets the bean for the given name.static <C> CgetBean(java.lang.String name, java.lang.Class<? extends C> clz)Gets the bean for the given name and class.static <C> CgetBean(java.lang.String name, java.lang.Object... args)Allows to get a bean and provide constructor args in runtime.static <T> TgetBeanForField(java.lang.String beanName, T fieldValue)A method designed to be used in situations when a bean is stored in a class field and should be searched only once:
someField = BackofficeSpringUtil.getBeanForField("someBean", someField);
return someField;protected static booleanisAutowireCandidate(org.springframework.context.ApplicationContext applicationContext, java.lang.String beanName)static <T> TloadClass(java.lang.String className)Loads a class by class name using cockpit module class loader and returns it.
-
-
-
Method Detail
-
containsBean
public static boolean containsBean(java.lang.String name)
Checks if bean for the given name exists. First it checks, if the bean is in the cockpit module application context. If not, it falls back toSpringUtil.getBean(String).
-
getBean
public static <C> C getBean(java.lang.String name)
Gets the bean for the given name. First it checks, if the bean is in the cockpit module application context. If not, it falls back toSpringUtil.getBean(String).
-
getBean
public static <C> C getBean(java.lang.String name, java.lang.Object... args)Allows to get a bean and provide constructor args in runtime. Common use case is when bean with prototype scope is needed with some specific runtime data passed into constructor.- Parameters:
name- bean nameargs- constructor args which can be passed to bean
-
getBean
public static <C> C getBean(java.lang.String name, java.lang.Class<? extends C> clz)Gets the bean for the given name and class. First it checks, if the bean is in the cockpit module application context. If not, it falls back toSpringUtil.getBean(String, Class).
-
getAllBeans
public static <T> java.util.Map<java.lang.String,T> getAllBeans(java.lang.Class<T> clazz)
Gets all beans for given class. Starts in cockpit module application context and goes all the way up to global context.
-
getAllBeans
public static <T> java.util.Map<java.lang.String,T> getAllBeans(java.lang.Class<T> clazz, boolean respectAutowireFlag)Gets all beans for given class can respect the autowire-candidate flag for bean. Starts in cockpit module application context and goes all the way up to global context.- Parameters:
clazz- - given classrespectAutowireFlag- - whether autowire-candidate attribute should be respected
-
isAutowireCandidate
protected static boolean isAutowireCandidate(org.springframework.context.ApplicationContext applicationContext, java.lang.String beanName)
-
getApplicationContext
public static CockpitApplicationContext getApplicationContext()
Gets the cockpit module application context, if existing, otherwise null.
-
createClassInstance
public static <T> T createClassInstance(java.lang.String className, java.lang.Class<T> clazz)Loads a class by class name using cockpit module class loader and returns a new instance of the class.- Type Parameters:
T- type of returned instance- Parameters:
className- class name to create.clazz- class used for generalization- Returns:
- new instance off clazz
-
loadClass
public static <T> T loadClass(java.lang.String className)
Loads a class by class name using cockpit module class loader and returns it.- Parameters:
className- class name to create.- Returns:
- class loaded by class name using cockpit module class loader
-
getBeanForField
public static <T> T getBeanForField(java.lang.String beanName, T fieldValue)A method designed to be used in situations when a bean is stored in a class field and should be searched only once:
someField = BackofficeSpringUtil.getBeanForField("someBean", someField);
return someField;- Type Parameters:
T- expected type of bean- Parameters:
beanName- name of a bean to be foundfieldValue- current value of a field- Returns:
- a bean instance
-
-