Project

General

Profile

« Previous | Next » 

Revision 27888

Added by Nikon Gasparis almost 10 years ago

updated for spring4

View differences:

ValidatorContextLoaderListener.java
1 1
package gr.uoa.di.validator.api.config;
2 2

  
3
import org.springframework.web.context.ContextLoader;
3
import java.util.Properties;
4

  
5
import javax.servlet.ServletContext;
6

  
7
import org.apache.log4j.Logger;
8
import org.springframework.beans.BeansException;
9
import org.springframework.context.support.AbstractApplicationContext;
10
import org.springframework.context.support.ClassPathXmlApplicationContext;
4 11
import org.springframework.web.context.ContextLoaderListener;
12
import org.springframework.web.context.WebApplicationContext;
13
import org.springframework.web.context.support.XmlWebApplicationContext;
5 14

  
6 15
public class ValidatorContextLoaderListener extends ContextLoaderListener {
16
	private static Logger logger = Logger.getLogger(ValidatorContextLoaderListener.class);
7 17

  
18

  
19
	public ValidatorContextLoaderListener() {
20
		super();
21
	}
22

  
23
	public ValidatorContextLoaderListener(WebApplicationContext context) {
24
		super(context);
25
	}
26

  
8 27
	@Override
9
	protected ContextLoader createContextLoader() {
10
		return new ValidatorContextLoader();
28
	protected WebApplicationContext createWebApplicationContext(
29
			ServletContext servletContext)
30
			throws BeansException {
31
		logger.debug("Creating web application context");
32
		Properties props = this.loadProperties();
33
		String repoMode = props.getProperty("services.validator.mode.repo");
34
		String userMode = props.getProperty("services.validator.mode.user");
35
		String dbMode = props.getProperty("services.validator.mode.db");
36
		
37
		logger.debug("User mode: " + userMode);
38
		logger.debug("Repo mode: " + repoMode);
39
		logger.debug("Dnet workflow enabled: " + repoMode);
40
		XmlWebApplicationContext ctx = new XmlWebApplicationContext();
41
//		AbstractApplicationContext ctxP = 
42
//			    new ClassPathXmlApplicationContext("classpath:WEB-INF/applicationContext.xml");
43
//		
44
//		ctx.setParent(ctxP);
45
		ctx.setServletContext(servletContext);
46
		ctx.setConfigLocations(new String[] {
47
				"classpath:META-INF/cxf/cxf.xml",
48
				"classpath:META-INF/cxf/cxf-extension-soap.xml",
49
				"classpath:META-INF/cxf/cxf-extension-jaxws.xml",
50
				"classpath:META-INF/cxf/cxf-servlet.xml",
51
				"classpath*:/cxf.xml",
52
				"classpath*:/gr/uoa/di/driver/util/springContext-locators.xml",
53
				"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml",
54
				"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml",
55
				"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml",
56
				"classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml",
57
				"classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml",
58
				"classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml",
59
				"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml",
60
				"classpath*:/gr/**/springContext-validator-dao.xml",
61
				"classpath*:/gr/**/springContext-validator-library.xml",
62
				"classpath*:/gr/**/springContext-validator-dao-datasource.xml",
63
				"classpath*:/gr/uoa/di/validatorweb/actions/springContext-validator-struts.xml",
64
				"classpath*:/gr/uoa/di/validator/api/springContext-validator.xml",
65
				"classpath*:/gr/uoa/di/validator/api/springContext-validator-config.xml",
66
				"classpath*:/gr/uoa/di/validator/api/springContext-validator-user-" + userMode + ".xml",
67
				"classpath*:/gr/uoa/di/validator/api/springContext-validator-repo-" + repoMode + ".xml",
68
				"classpath*:/gr/uoa/di/validator/api/springContext-validator-openaire.xml",
69
//				"classpath*:/gr/uoa/di/validator/ehcacher/springContext-validator-ehcacher.xml",
70
				"classpath*:/gr/uoa/di/validator/database/springContext-validator-openaire-datasource-" + dbMode + ".xml",
71
				"classpath*:/gr/uoa/di/validator/api/listeners/springContext-validator-openAIRE_Listeners.xml",
72
				"classpath*:/gr/uoa/di/validator/impls/listeners/springContext-validator-listeners.xml",
73
				"classpath*:/gr/uoa/di/validator/impls/listeners/springContext-validator-datasources.xml",
74
				"classpath*:/gr/uoa/di/validatorweb/email/springContext-validator-emailer.xml",
75
				"classpath*:/eu/dnetlib/enabling/datasources/applicationContext-dnet-openaireplus-datasource-manager-service.xml"
76

  
77
		});
78
		
79
		ctx.refresh();
80
		
81
		logger.debug("done");
82
		
83
		return ctx;
84
	}	
85
	
86
	private Properties loadProperties() {
87
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {
88
				"classpath*:/gr/uoa/di/validator/api/springContext-validator-config.xml"
89
		});
90
		
91
		CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader");
92
		Properties props = pLoader.getProperties();
93
		
94
		ctx.destroy();
95
		
96
		return props;
11 97
	}
12 98

  
13 99
}

Also available in: Unified diff