org.kuali.common.util.spring
Class SpringUtils

java.lang.Object
  extended by org.kuali.common.util.spring.SpringUtils

public class SpringUtils
extends Object


Constructor Summary
SpringUtils()
           
 
Method Summary
static List<org.springframework.core.env.PropertySource<?>> asList(org.springframework.core.env.PropertySource<?>... sources)
          Null safe method for converting an untyped array of property sources into a list.
static void closeQuietly(org.springframework.context.ConfigurableApplicationContext context)
          Null safe close for a context
static Properties convert(org.springframework.core.env.EnumerablePropertySource<?> source)
          Convert an EnumerablePropertySource into a Properties object.
static PropertySourceConversionResult convertEnumerablePropertySources(List<org.springframework.core.env.PropertySource<?>> sources)
          Convert any PropertySources that extend EnumerablePropertySource into Properties object's
static void debug(org.springframework.context.ApplicationContext ctx)
           
static boolean exists(org.springframework.core.env.Environment env, String key)
          Return true if the environment value for key is not null.
static List<org.springframework.core.env.PropertySource<?>> extractPropertySourcesAndClose(org.springframework.context.ConfigurableApplicationContext context)
           
static
<T> Map<String,T>
getAllBeans(org.springframework.context.ConfigurableApplicationContext ctx, Class<T> type)
           
static
<T> Map<String,T>
getAllBeans(List<String> locations, Class<T> type)
           
static
<T> Map<String,T>
getAllBeans(String location, Class<T> type)
           
static Properties getAllEnumerableProperties(org.springframework.core.env.ConfigurableEnvironment env)
          Examine ConfigurableEnvironment for PropertySource's that extend EnumerablePropertySource and aggregate them into a single Properties object
static boolean getBoolean(org.springframework.core.env.Environment env, String key)
           
static boolean getBoolean(org.springframework.core.env.Environment env, String key, boolean defaultValue)
           
static long getBytes(org.springframework.core.env.Environment env, String key)
          Parse bytes from a size string that ends with a unit of measure.
static long getBytes(org.springframework.core.env.Environment env, String key, String defaultValue)
          Parse bytes from a size string that ends with a unit of measure.
static org.springframework.context.ConfigurableApplicationContext getConfigurableApplicationContext()
           
static org.springframework.context.ConfigurableApplicationContext getContextWithPreRegisteredBean(String beanName, Object bean)
           
static org.springframework.context.ConfigurableApplicationContext getContextWithPreRegisteredBeans(List<String> beanNames, List<Object> beans)
           
static org.springframework.context.ConfigurableApplicationContext getContextWithPreRegisteredBeans(String id, String displayName, List<String> beanNames, List<Object> beans)
           
static String getDefaultPropertyContextLocation(String gav)
          Converts a GAV into Spring's classpath style notation for the default project properties context.
static double getDouble(org.springframework.core.env.Environment env, String key)
           
static double getDouble(org.springframework.core.env.Environment env, String key, double defaultValue)
           
static List<String> getExcludes(org.springframework.core.env.Environment env, String key)
           
static List<String> getExcludes(org.springframework.core.env.Environment env, String key, String defaultValue)
           
static File getFile(org.springframework.core.env.Environment env, String key)
           
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(List<String> locations, String encoding)
          Return a SpringContext that resolves all placeholders from the PropertySource passed in
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext project, List<ProjectContext> others)
          project needs to be a top level project eg rice-sampleapp, olefs-webapp.
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext project, List<ProjectContext> others, Properties properties)
          project needs to be a top level project eg rice-sampleapp, olefs-webapp.
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext project, ProjectContext other)
          project needs to be a top level project eg rice-sampleapp, olefs-webapp.
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext context, String... locations)
           
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectProperties project)
          project needs to be a top level project eg rice-sampleapp, olefs-webapp.
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectProperties project, List<ProjectProperties> others)
          project needs to be a top level project eg rice-sampleapp, olefs-webapp.
static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(String name, List<ProjectProperties> pps)
           
static List<String> getIncludes(org.springframework.core.env.Environment env, String key)
           
static List<String> getIncludes(org.springframework.core.env.Environment env, String key, String defaultValue)
           
static
<T> T
getInstance(org.springframework.core.env.Environment env, String key)
          Given a property holding the name of a class, return an instance of that class
static
<T> T
getInstance(org.springframework.core.env.Environment env, String key, Class<T> defaultValue)
          Given a property holding the name of a class, return an instance of that class
static int getInteger(org.springframework.core.env.Environment env, String key)
           
static int getInteger(org.springframework.core.env.Environment env, String key, int defaultValue)
           
static List<String> getListFromCSV(org.springframework.core.env.Environment env, String key, String defaultValue)
           
static long getLong(org.springframework.core.env.Environment env, String key)
           
static long getLong(org.springframework.core.env.Environment env, String key, long defaultValue)
           
static long getMillis(org.springframework.core.env.Environment env, String key, String defaultValue)
          Parse milliseconds from a time string that ends with a unit of measure.
static String getProperty(org.springframework.core.env.Environment env, String key)
          Get a fully resolved property value from the environment.
static String getProperty(org.springframework.core.env.Environment env, String key, String defaultValue)
          Always return a fully resolved value.
static org.springframework.core.env.PropertySource<?> getPropertySource(String name, List<ProjectProperties> pps)
           
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(Class<?> annotatedClass)
           
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(Class<?> annotatedClass, String propertiesBeanName, Properties properties)
           
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(org.springframework.context.ConfigurableApplicationContext context)
          This method returns a list of any PropertySource objects registered in the indicated context.
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(org.springframework.context.ConfigurableApplicationContext context, Comparator<org.springframework.core.env.PropertySource<?>> comparator)
          This method returns a list of any PropertySource objects registered in the indicated context.
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(org.springframework.core.env.ConfigurableEnvironment env)
          Get all PropertySource objects from the environment as a List.
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(SpringService service, Class<?> annotatedClass, String propertiesBeanName, Properties properties)
          Deprecated. 
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(SpringService service, String location, String mavenPropertiesBeanName, Properties mavenProperties)
          Deprecated. 
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(String location)
          Scan the XML Spring context for any beans that implement PropertySource
static List<org.springframework.core.env.PropertySource<?>> getPropertySources(String location, String mavenPropertiesBeanName, Properties mavenProperties)
           
static List<org.springframework.core.env.PropertySource<?>> getPropertySourcesFromAnnotatedClass(String annotatedClassName)
           
static org.springframework.core.env.PropertySource<?> getSinglePropertySource(Class<?> annotatedClass)
          Scan the annotated class to find the single bean registered in the context that implements PropertySource.
static org.springframework.core.env.PropertySource<?> getSinglePropertySource(Class<?> annotatedClass, String propertiesBeanName, Properties properties)
          Scan the annotated class to find the single bean registered in the context that implements PropertySource.
static SpringContext getSinglePropertySourceContext(List<String> locations, String encoding)
          Return a SpringContext that resolves all placeholders from the list of property locations passed in + System/Environment properties
static SpringContext getSinglePropertySourceContext(ProjectContext context, String location)
          Return a SpringContext that resolves all placeholders from the list of property locations passed in + System/Environment properties
static SpringContext getSinglePropertySourceContext(org.springframework.core.env.PropertySource<?> source)
          Return a SpringContext that resolves all placeholders from the PropertySource passed in
static SpringContext getSpringContext(Class<?> annotatedClass, ProjectContext project, List<ProjectContext> others)
           
static SpringContext getSpringContext(List<Class<?>> annotatedClasses, ProjectContext project, List<ProjectContext> others)
           
static Executable getSpringExecutable(org.springframework.core.env.Environment env, boolean skip, org.springframework.core.env.PropertySource<?> ps, List<Class<?>> annotatedClasses)
           
static SpringExecutable getSpringExecutable(ProjectContext project, String location, Class<?> annotatedClass)
          Return a SpringExecutable for the project, properties location, and config passed in.
static SpringExecutable getSpringExecutable(ProjectContext project, String location, List<Class<?>> annotatedClasses)
          Return a SpringExecutable for the project, properties location, and config passed in.
static boolean isTrue(org.springframework.core.env.Environment env, String property)
          Return true if, and only if, property is set in the environment and evaluates to true.
static void reconfigurePropertySources(org.springframework.core.env.ConfigurableEnvironment env, String name, Properties properties)
          Remove any existing property sources and add one property source backed by the properties passed in
static void refreshQuietly(org.springframework.context.ConfigurableApplicationContext context)
          Null safe refresh for a context
static void removeAllPropertySources(org.springframework.core.env.ConfigurableEnvironment env)
          Remove any existing property sources
static void showPropertySources(org.springframework.core.env.ConfigurableEnvironment env)
           
static void showPropertySources(List<org.springframework.core.env.PropertySource<?>> propertySources)
           
static void validateExists(List<String> locations)
          Make sure all of the locations actually exist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringUtils

public SpringUtils()
Method Detail

getSpringContext

public static SpringContext getSpringContext(List<Class<?>> annotatedClasses,
                                             ProjectContext project,
                                             List<ProjectContext> others)

getSpringContext

public static SpringContext getSpringContext(Class<?> annotatedClass,
                                             ProjectContext project,
                                             List<ProjectContext> others)

getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext project,
                                                                                     ProjectContext other)
project needs to be a top level project eg rice-sampleapp, olefs-webapp. others is projects for submodules organized into a list where the last one in wins.


getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext project,
                                                                                     List<ProjectContext> others)
project needs to be a top level project eg rice-sampleapp, olefs-webapp. others is projects for submodules organized into a list where the last one in wins.


getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext project,
                                                                                     List<ProjectContext> others,
                                                                                     Properties properties)
project needs to be a top level project eg rice-sampleapp, olefs-webapp. others is projects for submodules organized into a list where the last one in wins.


getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectProperties project)
project needs to be a top level project eg rice-sampleapp, olefs-webapp. others is projects for submodules organized into a list where the last one in wins.


getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectProperties project,
                                                                                     List<ProjectProperties> others)
project needs to be a top level project eg rice-sampleapp, olefs-webapp. others is projects for submodules organized into a list where the last one in wins.


getIncludes

public static List<String> getIncludes(org.springframework.core.env.Environment env,
                                       String key,
                                       String defaultValue)

getIncludes

public static List<String> getIncludes(org.springframework.core.env.Environment env,
                                       String key)

getExcludes

public static List<String> getExcludes(org.springframework.core.env.Environment env,
                                       String key,
                                       String defaultValue)

getExcludes

public static List<String> getExcludes(org.springframework.core.env.Environment env,
                                       String key)

getInstance

public static <T> T getInstance(org.springframework.core.env.Environment env,
                                String key,
                                Class<T> defaultValue)
Given a property holding the name of a class, return an instance of that class


getInstance

public static <T> T getInstance(org.springframework.core.env.Environment env,
                                String key)
Given a property holding the name of a class, return an instance of that class


getListFromCSV

public static List<String> getListFromCSV(org.springframework.core.env.Environment env,
                                          String key,
                                          String defaultValue)

getPropertySources

@Deprecated
public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(SpringService service,
                                                                                                 Class<?> annotatedClass,
                                                                                                 String propertiesBeanName,
                                                                                                 Properties properties)
Deprecated. 


getSinglePropertySource

public static org.springframework.core.env.PropertySource<?> getSinglePropertySource(Class<?> annotatedClass)
Scan the annotated class to find the single bean registered in the context that implements PropertySource. If more than one bean is located, throw IllegalStateException.


getSinglePropertySource

public static org.springframework.core.env.PropertySource<?> getSinglePropertySource(Class<?> annotatedClass,
                                                                                     String propertiesBeanName,
                                                                                     Properties properties)
Scan the annotated class to find the single bean registered in the context that implements PropertySource. If more than one bean is located, throw IllegalStateException.


getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(Class<?> annotatedClass,
                                                                                      String propertiesBeanName,
                                                                                      Properties properties)

getPropertySources

@Deprecated
public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(SpringService service,
                                                                                                 String location,
                                                                                                 String mavenPropertiesBeanName,
                                                                                                 Properties mavenProperties)
Deprecated. 


getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(String location,
                                                                                      String mavenPropertiesBeanName,
                                                                                      Properties mavenProperties)

getSpringExecutable

public static Executable getSpringExecutable(org.springframework.core.env.Environment env,
                                             boolean skip,
                                             org.springframework.core.env.PropertySource<?> ps,
                                             List<Class<?>> annotatedClasses)

getInteger

public static int getInteger(org.springframework.core.env.Environment env,
                             String key)

getInteger

public static int getInteger(org.springframework.core.env.Environment env,
                             String key,
                             int defaultValue)

getLong

public static long getLong(org.springframework.core.env.Environment env,
                           String key)

getLong

public static long getLong(org.springframework.core.env.Environment env,
                           String key,
                           long defaultValue)

getDouble

public static double getDouble(org.springframework.core.env.Environment env,
                               String key)

getDouble

public static double getDouble(org.springframework.core.env.Environment env,
                               String key,
                               double defaultValue)

getMillis

public static long getMillis(org.springframework.core.env.Environment env,
                             String key,
                             String defaultValue)
Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive.

See Also:
FormatUtils.getMillis(String time)

getBytes

public static long getBytes(org.springframework.core.env.Environment env,
                            String key,
                            String defaultValue)
Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive.

See Also:
FormatUtils.getBytes(String size)

getBytes

public static long getBytes(org.springframework.core.env.Environment env,
                            String key)
Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive.

See Also:
FormatUtils.getBytes(String size)

getFile

public static File getFile(org.springframework.core.env.Environment env,
                           String key)

getBoolean

public static boolean getBoolean(org.springframework.core.env.Environment env,
                                 String key,
                                 boolean defaultValue)

getBoolean

public static boolean getBoolean(org.springframework.core.env.Environment env,
                                 String key)

getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(String name,
                                                                                     List<ProjectProperties> pps)

getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(List<String> locations,
                                                                                     String encoding)
Return a SpringContext that resolves all placeholders from the PropertySource passed in


getSinglePropertySourceContext

public static SpringContext getSinglePropertySourceContext(ProjectContext context,
                                                           String location)
Return a SpringContext that resolves all placeholders from the list of property locations passed in + System/Environment properties


getSpringExecutable

public static SpringExecutable getSpringExecutable(ProjectContext project,
                                                   String location,
                                                   List<Class<?>> annotatedClasses)
Return a SpringExecutable for the project, properties location, and config passed in.


getSpringExecutable

public static SpringExecutable getSpringExecutable(ProjectContext project,
                                                   String location,
                                                   Class<?> annotatedClass)
Return a SpringExecutable for the project, properties location, and config passed in.


getSinglePropertySourceContext

public static SpringContext getSinglePropertySourceContext(List<String> locations,
                                                           String encoding)
Return a SpringContext that resolves all placeholders from the list of property locations passed in + System/Environment properties


getSinglePropertySourceContext

public static SpringContext getSinglePropertySourceContext(org.springframework.core.env.PropertySource<?> source)
Return a SpringContext that resolves all placeholders from the PropertySource passed in


getGlobalPropertySource

public static org.springframework.core.env.PropertySource<?> getGlobalPropertySource(ProjectContext context,
                                                                                     String... locations)

getPropertySource

public static org.springframework.core.env.PropertySource<?> getPropertySource(String name,
                                                                               List<ProjectProperties> pps)

getDefaultPropertyContextLocation

public static String getDefaultPropertyContextLocation(String gav)
Converts a GAV into Spring's classpath style notation for the default project properties context.
  org.kuali.common:kuali-jdbc -> classpath:org/kuali/common/kuali-jdbc-properties-context.xml
 


validateExists

public static void validateExists(List<String> locations)
Make sure all of the locations actually exist


getContextWithPreRegisteredBeans

public static org.springframework.context.ConfigurableApplicationContext getContextWithPreRegisteredBeans(String id,
                                                                                                          String displayName,
                                                                                                          List<String> beanNames,
                                                                                                          List<Object> beans)

getConfigurableApplicationContext

public static org.springframework.context.ConfigurableApplicationContext getConfigurableApplicationContext()

getContextWithPreRegisteredBeans

public static org.springframework.context.ConfigurableApplicationContext getContextWithPreRegisteredBeans(List<String> beanNames,
                                                                                                          List<Object> beans)

refreshQuietly

public static void refreshQuietly(org.springframework.context.ConfigurableApplicationContext context)
Null safe refresh for a context


closeQuietly

public static void closeQuietly(org.springframework.context.ConfigurableApplicationContext context)
Null safe close for a context


getContextWithPreRegisteredBean

public static org.springframework.context.ConfigurableApplicationContext getContextWithPreRegisteredBean(String beanName,
                                                                                                         Object bean)

getPropertySourcesFromAnnotatedClass

public static List<org.springframework.core.env.PropertySource<?>> getPropertySourcesFromAnnotatedClass(String annotatedClassName)

getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(Class<?> annotatedClass)

extractPropertySourcesAndClose

public static List<org.springframework.core.env.PropertySource<?>> extractPropertySourcesAndClose(org.springframework.context.ConfigurableApplicationContext context)

getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(String location)
Scan the XML Spring context for any beans that implement PropertySource


getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(org.springframework.context.ConfigurableApplicationContext context)
This method returns a list of any PropertySource objects registered in the indicated context. They are sorted by property source name.


getAllBeans

public static <T> Map<String,T> getAllBeans(List<String> locations,
                                            Class<T> type)

getAllBeans

public static <T> Map<String,T> getAllBeans(String location,
                                            Class<T> type)

getAllBeans

public static <T> Map<String,T> getAllBeans(org.springframework.context.ConfigurableApplicationContext ctx,
                                            Class<T> type)

getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(org.springframework.context.ConfigurableApplicationContext context,
                                                                                      Comparator<org.springframework.core.env.PropertySource<?>> comparator)
This method returns a list of any PropertySource objects registered in the indicated context. The comparator is responsible for putting them in correct order.


asList

public static List<org.springframework.core.env.PropertySource<?>> asList(org.springframework.core.env.PropertySource<?>... sources)
Null safe method for converting an untyped array of property sources into a list. Never returns null.


debug

public static void debug(org.springframework.context.ApplicationContext ctx)

showPropertySources

public static void showPropertySources(List<org.springframework.core.env.PropertySource<?>> propertySources)

showPropertySources

public static void showPropertySources(org.springframework.core.env.ConfigurableEnvironment env)

getProperty

public static String getProperty(org.springframework.core.env.Environment env,
                                 String key)
Get a fully resolved property value from the environment. If the property is not found or contains unresolvable placeholders an exception is thrown.


exists

public static boolean exists(org.springframework.core.env.Environment env,
                             String key)
Return true if the environment value for key is not null.


getProperty

public static String getProperty(org.springframework.core.env.Environment env,
                                 String key,
                                 String defaultValue)
Always return a fully resolved value. Use defaultValue if a value cannot be located in the environment. Throw an exception if the return value contains unresolvable placeholders.


getAllEnumerableProperties

public static Properties getAllEnumerableProperties(org.springframework.core.env.ConfigurableEnvironment env)
Examine ConfigurableEnvironment for PropertySource's that extend EnumerablePropertySource and aggregate them into a single Properties object


reconfigurePropertySources

public static void reconfigurePropertySources(org.springframework.core.env.ConfigurableEnvironment env,
                                              String name,
                                              Properties properties)
Remove any existing property sources and add one property source backed by the properties passed in


removeAllPropertySources

public static void removeAllPropertySources(org.springframework.core.env.ConfigurableEnvironment env)
Remove any existing property sources


getPropertySources

public static List<org.springframework.core.env.PropertySource<?>> getPropertySources(org.springframework.core.env.ConfigurableEnvironment env)
Get all PropertySource objects from the environment as a List.


convertEnumerablePropertySources

public static PropertySourceConversionResult convertEnumerablePropertySources(List<org.springframework.core.env.PropertySource<?>> sources)
Convert any PropertySources that extend EnumerablePropertySource into Properties object's


convert

public static Properties convert(org.springframework.core.env.EnumerablePropertySource<?> source)
Convert an EnumerablePropertySource into a Properties object.


isTrue

public static boolean isTrue(org.springframework.core.env.Environment env,
                             String property)
Return true if, and only if, property is set in the environment and evaluates to true.



Copyright © 2010-2013 The Kuali Foundation. All Rights Reserved.