View Javadoc

1   /*
2    * Copyright 2006-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.osgi.web.deployer.jetty;
18  
19  import org.mortbay.jetty.webapp.WebAppContext;
20  import org.osgi.framework.Bundle;
21  import org.springframework.osgi.web.deployer.OsgiWarDeploymentException;
22  import org.springframework.osgi.web.deployer.WarDeployment;
23  import org.springframework.osgi.web.deployer.WarDeploymentContext;
24  import org.springframework.osgi.web.deployer.internal.support.DefaultWarDeploymentContext;
25  
26  /**
27   * Jetty specific deployment class.
28   * 
29   * @author Costin Leau
30   * 
31   */
32  //do all logging in the deployer since that is a public class
33  class JettyWarDeployment implements WarDeployment {
34  
35  	/** active flag */
36  	private boolean active = true;
37  	/** Jetty webapp context associated with this object */
38  	private final WebAppContext webAppCtx;
39  	/** undeployer entity */
40  	private final JettyContextUndeployer undeployer;
41  	/** context object */
42  	private final WarDeploymentContext deploymentContext;
43  
44  
45  	public JettyWarDeployment(JettyContextUndeployer jettyWarUndeployer, Bundle bundle, WebAppContext wac) {
46  		this.undeployer = jettyWarUndeployer;
47  		this.webAppCtx = wac;
48  
49  		// create context
50  		this.deploymentContext = new DefaultWarDeploymentContext(bundle, wac.getContextPath(), wac.getServletContext());
51  	}
52  
53  	public WarDeploymentContext getDeploymentContext() {
54  		return deploymentContext;
55  	}
56  
57  	public boolean isActive() {
58  		return active;
59  	}
60  
61  	public void undeploy() throws OsgiWarDeploymentException {
62  		if (!active)
63  			return;
64  
65  		active = false;
66  		undeployer.undeploy(webAppCtx);
67  	}
68  
69  	// package protected method
70  	WebAppContext getWebAppContext() {
71  		return webAppCtx;
72  	}
73  }