Project

General

Profile

1
package eu.dnetlib.validator.service.config;
2

    
3
import java.util.Properties;
4

    
5
import javax.servlet.ServletContext;
6

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

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

    
18

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

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

    
27
	@Override
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
		Boolean standaloneMode = Boolean.parseBoolean(props.getProperty("services.validator.mode.standalone"));
37
		
38
		logger.debug("User mode: " + userMode);
39
		logger.debug("Repo mode: " + repoMode);
40
		logger.debug("Dnet workflow enabled: " + repoMode);
41
		XmlWebApplicationContext ctx = new XmlWebApplicationContext();
42
//		AbstractApplicationContext ctxP = 
43
//			    new ClassPathXmlApplicationContext("classpath:WEB-INF/applicationContext.xml");
44
//		
45
//		ctx.setParent(ctxP);
46

    
47
//		<import	resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml" />
48

    
49
		ctx.setServletContext(servletContext);
50
		
51
		
52
		String[] springContextCore = new String[] {
53
				
54
				"classpath*:/eu/dnetlib/validator/service/config/springContext-validator-config.xml",
55
				"classpath:META-INF/cxf/cxf.xml",
56
				"classpath:META-INF/cxf/cxf-extension-soap.xml",
57
				"classpath:META-INF/cxf/cxf-extension-jaxws.xml",
58
				"classpath:META-INF/cxf/cxf-servlet.xml",
59
				"classpath*:/cxf.xml",
60
				"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml",
61
				"classpath*:/eu/dnetlib/validator/commons/dao/springContext-validator-dao-datasource.xml",
62
				"classpath*:/eu/dnetlib/validator/commons/dao/springContext-validator-dao.xml",
63
				"classpath*:/eu/dnetlib/validator/commons/email/springContext-validator-emailer.xml",
64
				"classpath*:/eu/dnetlib/validator/service/listeners/springContext-validator-listeners.xml",
65
				"classpath*:/eu/dnetlib/validator/service/providers/springContext-validator-providers.xml",
66
				"classpath*:/eu/dnetlib/validator/service/springContext-validator-library.xml",
67
				"classpath*:/eu/dnetlib/validator/service/springContext-validator-manager.xml",
68
				"classpath*:/eu/dnetlib/validator/service/springContext-validator-service-standalone.xml"
69
		};
70
		
71
		String[] springContextForIS = new String[] {
72
				"classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml",
73
				"classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml",
74
				"classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml",
75
				"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml",
76
				"classpath*:/gr/uoa/di/driver/util/springContext-locators.xml",
77
				"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml",
78
				"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml",
79
				"classpath*:/eu/dnetlib/validator/service/springContext-validator-blackboard.xml",
80
				"classpath*:/eu/dnetlib/validator/service/springContext-validator-service.xml"
81
		};
82
		
83
		if (standaloneMode) {
84
			logger.debug("Loading contexts for standalone mode");
85
			ctx.setConfigLocations(springContextCore);
86
		} else {
87
			logger.debug("Loading contexts for dnet");
88
			ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForIS));
89
		}
90
		
91
		ctx.refresh();
92
		
93
		logger.debug("done");
94
		
95
		return ctx;
96
	}	
97
	
98
	private Properties loadProperties() {
99
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {
100
				"classpath*:/eu/dnetlib/validator/service/config/springContext-validator-config.xml"
101
		});
102
		
103
		CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader1");
104
		Properties props = pLoader.getProperties();
105
		
106
		ctx.destroy();
107
		ctx.close();
108
		return props;
109
	}
110

    
111
}
(3-3/3)