1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.server.handler.jmx;
15
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.eclipse.jetty.jmx.ObjectMBean;
21 import org.eclipse.jetty.server.handler.ContextHandler;
22 import org.eclipse.jetty.util.Attributes;
23
24 public class ContextHandlerMBean extends ObjectMBean
25 {
26 public ContextHandlerMBean(Object managedObject)
27 {
28 super(managedObject);
29 }
30
31
32 public String getObjectNameBasis()
33 {
34 if (_managed!=null && _managed instanceof ContextHandler)
35 {
36 ContextHandler context = (ContextHandler)_managed;
37 String name = context.getDisplayName();
38 if (name!=null)
39 return name;
40
41 if (context.getBaseResource()!=null && context.getBaseResource().getName().length()>1)
42 return context.getBaseResource().getName();
43 }
44 return super.getObjectNameBasis();
45 }
46
47 public Map getContextAttributes()
48 {
49 Map map = new HashMap();
50 Attributes attrs = ((ContextHandler)_managed).getAttributes();
51 Enumeration en = attrs.getAttributeNames();
52 while (en.hasMoreElements())
53 {
54 String name = (String)en.nextElement();
55 Object value = attrs.getAttribute(name);
56 map.put(name,value);
57 }
58 return map;
59 }
60
61 public void setContextAttribute(String name, Object value)
62 {
63 Attributes attrs = ((ContextHandler)_managed).getAttributes();
64 attrs.setAttribute(name,value);
65 }
66
67 public void setContextAttribute(String name, String value)
68 {
69 Attributes attrs = ((ContextHandler)_managed).getAttributes();
70 attrs.setAttribute(name,value);
71 }
72
73 public void removeContextAttribute(String name)
74 {
75 Attributes attrs = ((ContextHandler)_managed).getAttributes();
76 attrs.removeAttribute(name);
77 }
78 }