View Javadoc

    1   //========================================================================
    2   //Copyright 2004-2008 Mort Bay Consulting Pty. Ltd.
    3   //------------------------------------------------------------------------
    4   //Licensed under the Apache License, Version 2.0 (the "License");
    5   //you may not use this file except in compliance with the License.
    6   //You may obtain a copy of the License at
    7   //http://www.apache.org/licenses/LICENSE-2.0
    8   //Unless required by applicable law or agreed to in writing, software
    9   //distributed under the License is distributed on an "AS IS" BASIS,
    10  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  //See the License for the specific language governing permissions and
    12  //limitations under the License.
    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  }