1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.eclipse.jetty.deploy.bindings;
17
18 import org.eclipse.jetty.deploy.App;
19 import org.eclipse.jetty.deploy.AppLifeCycle;
20 import org.eclipse.jetty.deploy.graph.Node;
21 import org.eclipse.jetty.server.Handler;
22 import org.eclipse.jetty.server.handler.ContextHandler;
23 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
24 import org.eclipse.jetty.server.handler.HandlerCollection;
25 import org.eclipse.jetty.util.log.Log;
26 import org.eclipse.jetty.util.log.Logger;
27
28 public class StandardUndeployer implements AppLifeCycle.Binding
29 {
30 private static final Logger LOG = Log.getLogger(StandardUndeployer.class);
31
32 public String[] getBindingTargets()
33 {
34 return new String[]
35 { "undeploying" };
36 }
37
38 public void processBinding(Node node, App app) throws Exception
39 {
40 ContextHandler handler = app.getContextHandler();
41 ContextHandlerCollection chcoll = app.getDeploymentManager().getContexts();
42
43 recursiveRemoveContext(chcoll,handler);
44 }
45
46 private void recursiveRemoveContext(HandlerCollection coll, ContextHandler context)
47 {
48 Handler children[] = coll.getHandlers();
49 int originalCount = children.length;
50
51 for (int i = 0, n = children.length; i < n; i++)
52 {
53 Handler child = children[i];
54 LOG.debug("Child handler {}",child);
55 if (child.equals(context))
56 {
57 LOG.debug("Removing handler {}",child);
58 coll.removeHandler(child);
59 child.destroy();
60 if (LOG.isDebugEnabled())
61 LOG.debug("After removal: {} (originally {})",coll.getHandlers().length,originalCount);
62 }
63 else if (child instanceof HandlerCollection)
64 {
65 recursiveRemoveContext((HandlerCollection)child,context);
66 }
67 }
68 }
69 }