class RefreshConfigurationCommand implements CommandHasRequest<RefreshConfigurationRequest, RefreshConfigurationResponse> {

	@Override
	public void execute(RefreshConfigurationRequest request, RefreshConfigurationResponse response) throws Exception {
		if (context instanceof ReconfigurableApplicationContext) {
			ReconfigurableApplicationContext rollback = (ReconfigurableApplicationContext) context;
			if (request.getConfigLocations() != null) {
				ArrayList<String> configLocations = new ArrayList<String>();
				configLocations.add("org/geomajas/spring/geomajasContext.xml");

				configLocations.addAll(Arrays.asList(request.getConfigLocations()));
				try {
					rollback.refresh(configLocations.toArray(new String[configLocations.size()]));
				} catch (GeomajasException e) {
					log.error("Could not refresh context", e);
					rollback.rollback();
					response.setApplicationNames(context.getBeanNamesForType(ClientApplicationInfo.class));
					throw e;
				}
				response.setApplicationNames(context.getBeanNamesForType(ClientApplicationInfo.class));
			}
		} else {
			response.setApplicationNames(context.getBeanNamesForType(ClientApplicationInfo.class));
			throw new GeomajasException(ExceptionCode.REFRESH_CONFIGURATION_FAILED);
		}
	}

}