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
27 public class StandardUndeployer implements AppLifeCycle.Binding
28 {
29 public String[] getBindingTargets()
30 {
31 return new String[]
32 { "undeploying" };
33 }
34
35 public void processBinding(Node node, App app) throws Exception
36 {
37 ContextHandler handler = app.getContextHandler();
38 ContextHandlerCollection chcoll = app.getDeploymentManager().getContexts();
39
40 recursiveRemoveContext(chcoll,handler);
41 }
42
43 private void recursiveRemoveContext(HandlerCollection coll, ContextHandler context)
44 {
45 Handler children[] = coll.getHandlers();
46 int originalCount = children.length;
47
48 for (int i = 0, n = children.length; i < n; i++)
49 {
50 Handler child = children[i];
51 Log.debug("Child handler: " + child);
52 if (child.equals(context))
53 {
54 Log.debug("Removing handler: " + child);
55 coll.removeHandler(child);
56 ((ContextHandler)child).destroy();
57 Log.debug(String.format("After removal: %d (originally %d)",coll.getHandlers().length,originalCount));
58 }
59 else if (child instanceof HandlerCollection)
60 {
61 recursiveRemoveContext((HandlerCollection)child,context);
62 }
63 }
64 }
65 }