configLocation = SHERPA_CONFIG_LOCATION;
}
SherpaSettings settings = new SherpaSettings(configLocation);
ApplicationContext applicationContext = null;
// check if sherpa for spring application context is available
// if not, then use non-spring app context
Class<?> springApplicationContextClass = null;
try {
springApplicationContextClass = Class.forName(SPRING_APP_CONTEXT_CLASS_NAME);
LOGGER.info("USING SHERPA SPRING APPLICATION CONTEXT");
} catch (ClassNotFoundException e1) {
springApplicationContextClass = null;
}
if(springApplicationContextClass != null) {
try {
applicationContext = (ApplicationContext) springApplicationContextClass.getDeclaredConstructor(ServletContext.class).newInstance(servletContextEvent.getServletContext());
} catch (InstantiationException e) {
e.printStackTrace();
throw new SherpaRuntimeException(e);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new SherpaRuntimeException(e);
} catch (IllegalArgumentException e) {
e.printStackTrace();
throw new SherpaRuntimeException(e);
} catch (SecurityException e) {
e.printStackTrace();
throw new SherpaRuntimeException(e);
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new SherpaRuntimeException(e);
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new SherpaRuntimeException(e);
}
} else {
applicationContext = new GenericApplicationContext();
}
ManagedBeanFactory managedBeanFactory = applicationContext.getManagedBeanFactory();
applicationContext.setAttribute(ApplicationContext.CONTEXT_PATH,
servletContextEvent.getServletContext().getContextPath());
applicationContext.setAttribute(ApplicationContext.SETTINGS_JSONP, settings.jsonpSupport());
applicationContext.setAttribute(ApplicationContext.SETTINGS_ADMIN_USER, settings.sherpaAdmin());
applicationContext.setAttribute(ApplicationContext.SETTINGS_ENDPOINT_AUTH, settings.endpointAuthenication());
applicationContext.setAttribute(StringParamParser.DEFAULT, settings.encoding());
applicationContext.setAttribute(DateParamParser.DEFAULT, settings.dateFormat());
applicationContext.setAttribute(CalendarParamParser.DEFAULT, settings.dateFormat());
// Settings
applicationContext.setAttribute(SherpaSettings.SETTINGS_SERVER_URL, settings.serverUrl());
applicationContext.setAttribute(SherpaSettings.SETTINGS_SERVER_TOKEN, settings.serverToken());
if(InitManageBeanFactory.class.isAssignableFrom(managedBeanFactory.getClass())) {
((InitManageBeanFactory)managedBeanFactory).init(settings, servletContextEvent.getServletContext());
((InitManageBeanFactory)managedBeanFactory).loadManagedBeans(settings.endpoint());
}