View Javadoc

1   // ========================================================================
2   // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
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  }