User: oleg    
  Date: 00/10/05 03:36:04

  Modified:    src/main/org/jboss/configuration ConfigurationService.java
  Log:
  Now the message "Detected JMX Bug..." is classified as "Debug"
  
  Revision  Changes    Path
  1.7       +144 -144  jboss/src/main/org/jboss/configuration/ConfigurationService.java
  
  Index: ConfigurationService.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/configuration/ConfigurationService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConfigurationService.java 2000/10/05 01:36:33     1.6
  +++ ConfigurationService.java 2000/10/05 10:36:03     1.7
  @@ -29,183 +29,183 @@
    *
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.6 $
  + *   @version $Revision: 1.7 $
    */
   public class ConfigurationService
      extends ServiceMBeanSupport
      implements ConfigurationServiceMBean
   {
      // Constants -----------------------------------------------------
  -     static Hashtable primitives = new Hashtable();
  +    static Hashtable primitives = new Hashtable();
   
  -     static
  -     {
  -             primitives.put("int",Integer.TYPE);
  -             primitives.put("boolean",Boolean.TYPE);
  -             primitives.put("double",Double.TYPE);
  -             primitives.put("float",Float.TYPE);
  +    static
  +    {
  +        primitives.put("int",Integer.TYPE);
  +        primitives.put("boolean",Boolean.TYPE);
  +        primitives.put("double",Double.TYPE);
  +        primitives.put("float",Float.TYPE);
           primitives.put("long",Long.TYPE);
  -     }
  +    }
   
      // Attributes ----------------------------------------------------
  -     Log log = new Log(getName());
  +    Log log = new Log(getName());
   
  -     String configurationUrl = "jboss.jcml";
  +    String configurationUrl = "jboss.jcml";
   
  -     MBeanServer server;
  +    MBeanServer server;
   
      // Static --------------------------------------------------------
   
      // Constructors --------------------------------------------------
   
      // Public --------------------------------------------------------
  -     public ObjectName getObjectName(MBeanServer server, ObjectName name)
  -        throws javax.management.MalformedObjectNameException
  -     {
  -             this.server = server;
  -        return new ObjectName(OBJECT_NAME);
  -     }
  -
  -     public String getName()
  -     {
  -        return "Configuration";
  -     }
  -
  -     public void load(String configuration)
  -             throws Exception
  -     {
  -             try
  -             {
  -                     // Parse XML
  -                     Document doc;
  -                     XmlDocumentBuilder xdb = new XmlDocumentBuilder();
  -                     Parser parser = new com.sun.xml.parser.Parser();
  -                     xdb.setParser(parser);
  -
  -                     try
  -                     {
  -                             parser.parse(new InputSource(new 
StringReader(configuration)));
  -                             doc = xdb.getDocument();
  -                     }
  -                     catch (SAXException se)
  -                     {
  -                          throw new IOException(se.getMessage());
  -                     }
  -
  -                     // Set configuration to MBeans from XML
  -                     NodeList nl = doc.getElementsByTagName("mbean");
  -                     for (int i = 0; i < nl.getLength(); i++)
  -                     {
  -                             Element mbeanElement = (Element)nl.item(i);
  -
  -                             String name = mbeanElement.getAttribute("name");
  -                             ObjectName objectName = new ObjectName(name);
  -
  -                             MBeanInfo info;
  -                             try {
  -                                     info = server.getMBeanInfo(objectName);
  -                             } catch (InstanceNotFoundException e) {
  -                                     // the service is no longer available (removed 
from jboss.conf?)
  -                                     // it's ok, skip to next one
  -                                     continue;
  -                             }
  -
  -                             NodeList attrs = 
mbeanElement.getElementsByTagName("attribute");
  -                             for (int j = 0; j < attrs.getLength(); j++)
  -                             {
  -                                     Element attributeElement = 
(Element)attrs.item(j);
  -                                     String attributeName = 
attributeElement.getAttribute("name");
  -                                     if (attributeElement.hasChildNodes())
  -                                     {
  -                                             String attributeValue = 
((Text)attributeElement.getFirstChild()).getData();
  -
  -                                             MBeanAttributeInfo[] attributes = 
info.getAttributes();
  -                                             for (int k = 0; k < attributes.length; 
k++)
  -                                             {
  -                                                     if 
(attributeName.equals(attributes[k].getName()))
  -                                                     {
  -                                                             String typeName = 
attributes[k].getType();
  -                                                             Class typeClass;
  -                                                             if 
(primitives.containsKey(typeName))
  -                                                             {
  -                                                                     typeClass = 
(Class)primitives.get(typeName);
  -                                                             } else
  -                                                             {
  -                                                                     typeClass = 
Class.forName(typeName);
  -                                                             }
  -                                                             PropertyEditor editor 
= PropertyEditorManager.findEditor(typeClass);
  -                                                             
editor.setAsText(attributeValue);
  -                                                             Object value = 
editor.getValue();
  -
  -                                                             
log.debug(attributeName +" set to "+attributeValue+" in "+name);
  -                                                             
server.setAttribute(objectName, new Attribute(attributeName, value));
  -
  -                                                             break;
  -                                                     }
  -                                             }
  -                                     }
  -
  -                             }
  -                     }
  -             } catch (Throwable e)
  -             {
  -                     Log.getLog().exception(e);
  -                     throw (Exception)e;
  -             }
  -     }
  +    public ObjectName getObjectName(MBeanServer server, ObjectName name)
  +       throws javax.management.MalformedObjectNameException
  +    {
  +        this.server = server;
  +       return new ObjectName(OBJECT_NAME);
  +    }
  +
  +    public String getName()
  +    {
  +       return "Configuration";
  +    }
  +
  +    public void load(String configuration)
  +        throws Exception
  +    {
  +        try
  +        {
  +            // Parse XML
  +            Document doc;
  +            XmlDocumentBuilder xdb = new XmlDocumentBuilder();
  +            Parser parser = new com.sun.xml.parser.Parser();
  +            xdb.setParser(parser);
  +
  +            try
  +            {
  +                parser.parse(new InputSource(new StringReader(configuration)));
  +                doc = xdb.getDocument();
  +            }
  +            catch (SAXException se)
  +            {
  +                 throw new IOException(se.getMessage());
  +            }
  +
  +            // Set configuration to MBeans from XML
  +            NodeList nl = doc.getElementsByTagName("mbean");
  +            for (int i = 0; i < nl.getLength(); i++)
  +            {
  +                Element mbeanElement = (Element)nl.item(i);
  +
  +                String name = mbeanElement.getAttribute("name");
  +                ObjectName objectName = new ObjectName(name);
  +
  +                MBeanInfo info;
  +                try {
  +                    info = server.getMBeanInfo(objectName);
  +                } catch (InstanceNotFoundException e) {
  +                    // the service is no longer available (removed from jboss.conf?)
  +                    // it's ok, skip to next one
  +                    continue;
  +                }
  +
  +                NodeList attrs = mbeanElement.getElementsByTagName("attribute");
  +                for (int j = 0; j < attrs.getLength(); j++)
  +                {
  +                    Element attributeElement = (Element)attrs.item(j);
  +                    String attributeName = attributeElement.getAttribute("name");
  +                    if (attributeElement.hasChildNodes())
  +                    {
  +                        String attributeValue = 
((Text)attributeElement.getFirstChild()).getData();
  +
  +                        MBeanAttributeInfo[] attributes = info.getAttributes();
  +                        for (int k = 0; k < attributes.length; k++)
  +                        {
  +                            if (attributeName.equals(attributes[k].getName()))
  +                            {
  +                                String typeName = attributes[k].getType();
  +                                Class typeClass;
  +                                if (primitives.containsKey(typeName))
  +                                {
  +                                    typeClass = (Class)primitives.get(typeName);
  +                                } else
  +                                {
  +                                    typeClass = Class.forName(typeName);
  +                                }
  +                                PropertyEditor editor = 
PropertyEditorManager.findEditor(typeClass);
  +                                editor.setAsText(attributeValue);
  +                                Object value = editor.getValue();
  +
  +                                log.debug(attributeName +" set to 
"+attributeValue+" in "+name);
  +                                server.setAttribute(objectName, new 
Attribute(attributeName, value));
  +
  +                                break;
  +                            }
  +                        }
  +                    }
  +
  +                }
  +            }
  +        } catch (Throwable e)
  +        {
  +            Log.getLog().exception(e);
  +            throw (Exception)e;
  +        }
  +    }
   
      public String save()
  -             throws Exception
  +        throws Exception
      {
  -             Writer out = new StringWriter();
  +        Writer out = new StringWriter();
   
  -             // Create new ProjectX XML doc
  -             XmlDocument doc = new XmlDocument();
  +        // Create new ProjectX XML doc
  +        XmlDocument doc = new XmlDocument();
   
  -             Element serverElement = doc.createElement("server");
  +        Element serverElement = doc.createElement("server");
   
  -             Iterator mbeans = server.queryNames(null, null).iterator();
  -             while (mbeans.hasNext())
  -             {
  -                     ObjectName name = (ObjectName)mbeans.next();
  -                     Element mbeanElement = doc.createElement("mbean");
  -                     mbeanElement.setAttribute("name",name.toString());
  -
  -                     MBeanInfo info = server.getMBeanInfo(name);
  -                     MBeanAttributeInfo[] attributes = info.getAttributes();
  -                     boolean hasAttributes = false;
  -                     for (int i = 0; i < attributes.length; i++)
  -                     {
  -                             if (attributes[i].isReadable() && 
isAttributeWriteable(server.getObjectInstance(name).getClassName(), 
attributes[i].getName(), attributes[i].getType()))
  -                             {
  +        Iterator mbeans = server.queryNames(null, null).iterator();
  +        while (mbeans.hasNext())
  +        {
  +            ObjectName name = (ObjectName)mbeans.next();
  +            Element mbeanElement = doc.createElement("mbean");
  +            mbeanElement.setAttribute("name",name.toString());
  +
  +            MBeanInfo info = server.getMBeanInfo(name);
  +            MBeanAttributeInfo[] attributes = info.getAttributes();
  +            boolean hasAttributes = false;
  +            for (int i = 0; i < attributes.length; i++)
  +            {
  +                if (attributes[i].isReadable() && 
isAttributeWriteable(server.getObjectInstance(name).getClassName(), 
attributes[i].getName(), attributes[i].getType()))
  +                {
                       if(!attributes[i].isWritable())
  -                        log.error("Detected JMX Bug: Server reports attribute 
'"+attributes[i].getName()+"' is not writeable for MBean 
'"+name.getCanonicalName()+"'");
  -                                     Element attributeElement = 
doc.createElement("attribute");
  -                                     Object value = server.getAttribute(name, 
attributes[i].getName());
  +                        log.debug("Detected JMX Bug: Server reports attribute 
'"+attributes[i].getName()+"' is not writeable for MBean 
'"+name.getCanonicalName()+"'");
  +                    Element attributeElement = doc.createElement("attribute");
  +                    Object value = server.getAttribute(name, 
attributes[i].getName());
   
  -                                     attributeElement.setAttribute("name", 
attributes[i].getName());
  +                    attributeElement.setAttribute("name", attributes[i].getName());
   
  -                                     if (value != null)
  -                                             
attributeElement.appendChild(doc.createTextNode(value.toString()));
  +                    if (value != null)
  +                        
attributeElement.appendChild(doc.createTextNode(value.toString()));
   
  -                                     mbeanElement.appendChild(attributeElement);
  +                    mbeanElement.appendChild(attributeElement);
   
  -                                     hasAttributes = true;
  -                             }
  -                     }
  +                    hasAttributes = true;
  +                }
  +            }
   
  -                     if (hasAttributes)
  -                             serverElement.appendChild(mbeanElement);
  -             }
  +            if (hasAttributes)
  +                serverElement.appendChild(mbeanElement);
  +        }
   
  -             doc.appendChild(serverElement);
  +        doc.appendChild(serverElement);
   
  -             // Write configuration
  -             doc.writeXml(new XmlWriteContext(out,3));
  -             out.close();
  +        // Write configuration
  +        doc.writeXml(new XmlWriteContext(out,3));
  +        out.close();
   
  -             // Return configuration
  -             return out.toString();
  +        // Return configuration
  +        return out.toString();
      }
   
       // Protected -----------------------------------------------------
  
  
  

Reply via email to