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