1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.osgi.web.deployer.support;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.osgi.framework.Bundle;
22 import org.osgi.framework.BundleContext;
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.osgi.context.BundleContextAware;
25 import org.springframework.osgi.util.OsgiStringUtils;
26 import org.springframework.osgi.web.deployer.OsgiWarDeploymentException;
27 import org.springframework.osgi.web.deployer.WarDeployer;
28 import org.springframework.osgi.web.deployer.WarDeployment;
29 import org.springframework.util.Assert;
30
31
32
33
34
35
36
37 public abstract class AbstractWarDeployer implements WarDeployer, InitializingBean, BundleContextAware {
38
39
40 protected final Log log = LogFactory.getLog(getClass());
41
42 private BundleContext bundleContext;
43
44
45 public void afterPropertiesSet() throws Exception {
46 Assert.notNull(bundleContext, "bundleContext is not set");
47 }
48
49 public void setBundleContext(BundleContext bundleContext) {
50 this.bundleContext = bundleContext;
51 }
52
53
54
55
56
57
58 protected BundleContext getBundleContext() {
59 return bundleContext;
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public WarDeployment deploy(Bundle bundle, String contextPath) throws OsgiWarDeploymentException {
76 String commonMessage = "bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] at [" + contextPath
77 + "] on server " + getServerInfo();
78 if (log.isDebugEnabled())
79 log.debug("Creating deployment for " + commonMessage);
80 WarDeployment deployment;
81
82 try {
83 deployment = createDeployment(bundle, contextPath);
84 }
85 catch (Exception ex) {
86 throw new OsgiWarDeploymentException("Cannot create war deployment for " + commonMessage, ex);
87 }
88
89 if (log.isDebugEnabled())
90 log.debug("About to deploy " + commonMessage);
91
92 try {
93 startDeployment(deployment);
94 log.info("Successfully deployed " + commonMessage);
95 }
96 catch (Exception ex) {
97 throw new OsgiWarDeploymentException("Cannot create war deployment for " + commonMessage, ex);
98 }
99
100 return deployment;
101 }
102
103
104
105
106
107
108
109
110
111
112
113 protected abstract WarDeployment createDeployment(Bundle bundle, String contextPath) throws Exception;
114
115
116
117
118
119
120
121
122 protected abstract void startDeployment(WarDeployment deployment) throws Exception;
123
124
125
126
127
128
129
130 protected abstract String getServerInfo();
131 }