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