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