User: starksm 
  Date: 01/12/04 10:38:53

  Modified:    src/main/org/jboss/configuration Tag: Branch_2_4
                        ConfigurationService.java
  Log:
  Change the support of arbitrary mbean configuration to be based on
  attribute child nodes as is done in main for consistency.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.30.2.5  +41 -33    jboss/src/main/org/jboss/configuration/ConfigurationService.java
  
  Index: ConfigurationService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/configuration/ConfigurationService.java,v
  retrieving revision 1.30.2.4
  retrieving revision 1.30.2.5
  diff -u -r1.30.2.4 -r1.30.2.5
  --- ConfigurationService.java 2001/11/20 09:42:47     1.30.2.4
  +++ ConfigurationService.java 2001/12/04 18:38:52     1.30.2.5
  @@ -39,6 +39,7 @@
   
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  +import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   import org.w3c.dom.Text;
   import org.xml.sax.InputSource;
  @@ -67,7 +68,7 @@
    * @author  Rickard Öberg ([EMAIL PROTECTED])
    * @author  [EMAIL PROTECTED]
    * @author  Jason Dillon <a 
href="mailto:[EMAIL PROTECTED]";>&lt;[EMAIL PROTECTED]&gt;</a>
  - * @version $Revision: 1.30.2.4 $
  + * @version $Revision: 1.30.2.5 $
    */
   public class ConfigurationService
      extends ServiceMBeanSupport
  @@ -220,13 +221,16 @@
                  String attributeName = attributeElement.getAttribute("name");
                  if (attributeElement.hasChildNodes())
                  {
  -                  String attributeValue = 
((Text)attributeElement.getFirstChild()).getData();
  -                  
  -                  if (autoTrim)
  +                  Node n = attributeElement.getFirstChild();
  +                  // Check for a text value
  +                  String attributeText = null;
  +                  if( n instanceof Text )
                     {
  -                     attributeValue = attributeValue.trim();
  +                     attributeText = ((Text)n).getData();
  +                     if( autoTrim )
  +                        attributeText = attributeText.trim();
                     }
  -                  
  +
                     MBeanAttributeInfo[] attributes = info.getAttributes();
                     for (int k = 0; k < attributes.length; k++)
                     {
  @@ -241,13 +245,32 @@
                           else
                           {
                              typeClass = Class.forName(typeName);
  +                        }
  +                        Object value = attributeText;
  +                        // Check for Element type attribute
  +                        if( Element.class.isAssignableFrom(typeClass) )
  +                        {
  +                           // The attribute is an Element
  +                           NodeList nodes = attributeElement.getChildNodes();
  +                           for(int l=0; l < nodes.getLength(); l++)
  +                           {
  +                              n = nodes.item(l);
  +                              if (n.getNodeType() == Node.ELEMENT_NODE)
  +                              {
  +                                 value = (Element) n;
  +                                 break;
  +                              }
  +                           }
                           }
  -                        PropertyEditor editor = 
PropertyEditorManager.findEditor(typeClass);
  -                        Object value = attributeValue;
  -                        if( editor != null )
  +                        else
                           {
  -                           editor.setAsText(attributeValue);
  -                           value = editor.getValue();
  +                           // Get the property value from the string presentation
  +                           PropertyEditor editor = 
PropertyEditorManager.findEditor(typeClass);
  +                           if( editor != null )
  +                           {
  +                              editor.setAsText(attributeText);
  +                              value = editor.getValue();
  +                           }
                           }
                           log.debug(attributeName + " set to " + value + " in " + 
objectName);
                           server.setAttribute(objectName, new 
Attribute(attributeName, value));
  @@ -257,35 +280,20 @@
                     }
                  }
               }
  -            /* Look for a config element and if it exists invoke the 
importXml(Element)
  -             operation to allow the MBean to support its own arbitrary 
configuration.
  -            */
  -            NodeList configs = mbeanElement.getElementsByTagName("config");
  -            if( configs.getLength() > 0 )
  -            {
  -               Element configElement = (Element) configs.item(0);
  -               Object[] args = { configElement };
  -               String[] signature = { "org.w3c.dom.Element" };
  -               try
  -               {
  -                  server.invoke(objectName, "importXml", args, signature);
  -               }
  -               catch(Exception e)
  -               {
  -                  logException(e);
  -               }
  -            }
   
               // Register the mbean with the JBoss ServiceControl mbean
               registerService(objectName, info, mbeanElement);
            }
  +      }
  +      catch(Error e)
  +      {
  +         logException(e);
  +         throw new RuntimeException("Unexpected Error: "+ e.getMessage());
         }
  -      catch (Throwable e)
  +      catch(Exception e)
         {
            logException(e);
  -         
  -         // yikes this is not too safe
  -         throw (Exception)e;
  +         throw e;
         }
      }
      
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to