1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.extend.server.deployment.danube;
14
15 import org.abstracthorizon.danube.connection.ConnectionHandler;
16 import org.abstracthorizon.danube.http.Selector;
17 import org.abstracthorizon.danube.http.matcher.Prefix;
18 import org.abstracthorizon.extend.server.deployment.Module;
19 import org.abstracthorizon.extend.server.deployment.ModuleId;
20 import org.abstracthorizon.extend.support.spring.service.ServiceApplicationContextModule;
21 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
22 import org.springframework.context.ApplicationContext;
23
24
25
26
27
28
29 public class DanubeWebApplicationContext extends ServiceApplicationContextModule {
30
31
32 protected Prefix matcher;
33
34
35 protected String contextPath;
36
37
38 protected ApplicationContext webServerContext;
39
40
41
42
43 public DanubeWebApplicationContext(ModuleId moduleId) {
44 super(moduleId);
45 }
46
47
48
49
50
51
52
53 protected void initBeanDefinitionReader(XmlBeanDefinitionReader xmlbeandefinitionreader) {
54 xmlbeandefinitionreader.setDocumentReaderClass(DanubeWarModuleXmlParser.class);
55 xmlbeandefinitionreader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
56 xmlbeandefinitionreader.setBeanClassLoader(internalClassLoader);
57 }
58
59
60
61
62 protected void createInternal() {
63 super.createInternal();
64 Module module = (Module)webServerContext;
65 getDependsOn().add(module);
66 module.getDependOnThis().add(this);
67 }
68
69
70
71
72
73
74
75 @Override
76 protected void startInternal() {
77 super.startInternal();
78 Selector selector = (Selector)webServerContext.getBean("httpServerSelector");
79 ConnectionHandler handler = (ConnectionHandler)getBean("web-application");
80 matcher = new Prefix();
81
82 ThreadContextHandler threadContextHandler = new ThreadContextHandler(handler, this);
83
84 String contextPath = getContextPath();
85 if (contextPath == null) {
86 contextPath = "/" + getModuleId().getArtifactId();
87 setContextPath(contextPath);
88 }
89 if (!contextPath.startsWith("/")) {
90 contextPath = "/" + contextPath;
91 setContextPath(contextPath);
92 }
93
94 matcher.setPrefix(contextPath);
95 matcher.setConnectionHandler(threadContextHandler);
96 selector.getComponents().add(matcher);
97 }
98
99
100
101
102 @Override
103 protected void stopInternal() {
104 super.stopInternal();
105 Selector selector = (Selector)webServerContext.getBean("httpServerSelector");
106 selector.getComponents().remove(matcher);
107 }
108
109
110
111
112 @Override
113 protected void destroyInternal() {
114 super.destroyInternal();
115 }
116
117
118
119
120
121 protected String getContextFileName() {
122 return "web-application.xml";
123 }
124
125
126
127
128
129 public ApplicationContext getWebServerContext() {
130 return webServerContext;
131 }
132
133
134
135
136
137 public void setWebServerContext(ApplicationContext webServerContext) {
138 this.webServerContext = webServerContext;
139 }
140
141
142
143
144
145 public String getContextPath() {
146 return contextPath;
147 }
148
149
150
151
152
153 public void setContextPath(String contextPath) {
154 this.contextPath = contextPath;
155 }
156
157 }