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 public String[] getBindingTargets()
36 {
37 return new String[]
38 { "undeploying" };
39 }
40
41 public void processBinding(Node node, App app) throws Exception
42 {
43 ContextHandler handler = app.getContextHandler();
44 ContextHandlerCollection chcoll = app.getDeploymentManager().getContexts();
45
46 recursiveRemoveContext(chcoll,handler);
47 }
48
49 private void recursiveRemoveContext(HandlerCollection coll, ContextHandler context)
50 {
51 Handler children[] = coll.getHandlers();
52 int originalCount = children.length;
53
54 for (int i = 0, n = children.length; i < n; i++)
55 {
56 Handler child = children[i];
57 LOG.debug("Child handler {}",child);
58 if (child.equals(context))
59 {
60 LOG.debug("Removing handler {}",child);
61 coll.removeHandler(child);
62 child.destroy();
63 if (LOG.isDebugEnabled())
64 LOG.debug("After removal: {} (originally {})",coll.getHandlers().length,originalCount);
65 }
66 else if (child instanceof HandlerCollection)
67 {
68 recursiveRemoveContext((HandlerCollection)child,context);
69 }
70 }
71 }
72 }