プロジェクトのグローバル共有変数の設定


public class ContextUtil
  implements ApplicationContextAware
{
  private static ApplicationContext appContext = null;

  public void setApplicationContext(ApplicationContext newAppContext)
    throws BeansException
  {
    appContext = newAppContext;
  }

  public static String getMessage(String code, Object[] params, String defaultDesc, Locale local) {
    return appContext.getMessage(code, params, defaultDesc, local);
  }

  public static <T> T getBean(String beanId, Class<T> clazz) throws BeansException {
    return appContext.getBean(beanId, clazz);
  }

  public static <T> T getBean(Class<T> clazz) throws BeansException {
    return appContext.getBean(clazz);
  }

  public static Object getBean(String beanId) throws BeansException {
    return appContext.getBean(beanId);
  }

  public static Cap4jUserInfo getLoginUser() {
    Object userInfo = null;
    SecurityContext securityContext = SecurityContextHolder.getContext();
    if ((securityContext != null) && (securityContext.getAuthentication() != null)) {
      userInfo = securityContext.getAuthentication().getPrincipal();
      if (userInfo instanceof Cap4jUserInfo)
        return ((Cap4jUserInfo)userInfo);
    }

    return null;
  }

  public static ServletContext getServletContext() {
    return ((WebApplicationContext)appContext).getServletContext();
  }

  public static boolean isLoginCheck() {
    Cap4jInvocationSecurityMetadataSourceService medadataSource = (Cap4jInvocationSecurityMetadataSourceService)appContext.getBean("cap4jSecurityMetadataSource");
    return medadataSource.isLoginCheck();
  }

  public static boolean isUrlCheck() {
    Cap4jInvocationSecurityMetadataSourceService medadataSource = (Cap4jInvocationSecurityMetadataSourceService)appContext.getBean("cap4jSecurityMetadataSource");
    return medadataSource.isUrlCheck();
  }