mx4j/src/core/javax/management/modelmbean DescriptorSupport.java,1.25,1.26

Simone Bordet <[email protected]> Tue, 07 Sep 2004 15:00:16 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/core/javax/management/modelmbean
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11771/src/core/javax/management/modelmbean

Modified Files:
	DescriptorSupport.java 
Log Message:
Fix and test for bug #938635: DescriptorSupport does not preserve case

Index: DescriptorSupport.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/modelmbean/DescriptorSupport.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** DescriptorSupport.java	4 Sep 2004 15:44:04 -0000	1.25
--- DescriptorSupport.java	7 Sep 2004 15:00:13 -0000	1.26
***************
*** 10,13 ****
--- 10,15 ----
  
  import java.io.ByteArrayInputStream;
+ import java.io.IOException;
+ import java.io.ObjectInputStream;
  import java.util.ArrayList;
  import java.util.HashMap;
***************
*** 35,43 ****
     private static final long serialVersionUID = -6292969195866300415L;
  
!    private HashMap descriptor;
  
     public DescriptorSupport()
     {
-       descriptor = new HashMap(20);
     }
  
--- 37,45 ----
     private static final long serialVersionUID = -6292969195866300415L;
  
!    private HashMap descriptor = new HashMap(20);
!    private transient HashMap fields = new HashMap(20);
  
     public DescriptorSupport()
     {
     }
  
***************
*** 49,57 ****
        }
        descriptor = new HashMap(initNumFields);
     }
  
     public DescriptorSupport(DescriptorSupport inDescr)
     {
-       this();
        if (inDescr != null)
        {
--- 51,59 ----
        }
        descriptor = new HashMap(initNumFields);
+       fields = new HashMap(initNumFields);
     }
  
     public DescriptorSupport(DescriptorSupport inDescr)
     {
        if (inDescr != null)
        {
***************
*** 60,68 ****
     }
  
!    public DescriptorSupport(String xml)
!            throws MBeanException, RuntimeOperationsException, XMLParseException
     {
-       this();
- 
        if (xml == null)
        {
--- 62,67 ----
     }
  
!    public DescriptorSupport(String xml) throws MBeanException, RuntimeOperationsException, XMLParseException
     {
        if (xml == null)
        {
***************
*** 79,83 ****
     public DescriptorSupport(String[] pairs)
     {
-       this();
        if (pairs != null && pairs.length != 0)
        {
--- 78,81 ----
***************
*** 110,114 ****
     public DescriptorSupport(String[] names, Object[] values)
     {
-       this();
        setFields(names, values);
     }
--- 108,111 ----
***************
*** 132,137 ****
           throw new RuntimeOperationsException(new IllegalArgumentException("Invalid field name"));
        }
!       Object value = descriptor.get(name.toLowerCase());
!       return value;
     }
  
--- 129,135 ----
           throw new RuntimeOperationsException(new IllegalArgumentException("Invalid field name"));
        }
!       // Field names are case insensitive, retrieve the value from the case-insensitive map
!       ValueHolder holder = (ValueHolder)fields.get(name.toLowerCase());
!       return holder == null ? null : holder.fieldValue;
     }
  
***************
*** 139,143 ****
     {
        checkField(name, value);
!       descriptor.put(name.toLowerCase(), value);
     }
  
--- 137,142 ----
     {
        checkField(name, value);
!       descriptor.put(name, value);
!       fields.put(name.toLowerCase(), new ValueHolder(name, value));
     }
  
***************
*** 146,150 ****
        if (name != null)
        {
!          descriptor.remove(name.toLowerCase());
        }
     }
--- 145,150 ----
        if (name != null)
        {
!          ValueHolder holder = (ValueHolder)fields.remove(name.toLowerCase());
!          if (holder != null) descriptor.remove(holder.fieldName);
        }
     }
***************
*** 152,155 ****
--- 152,156 ----
     public String[] getFieldNames()
     {
+       // Preserve the case of field names
        String[] names = (String[])descriptor.keySet().toArray(new String[0]);
        return names;
***************
*** 186,189 ****
--- 187,191 ----
        ArrayList list = new ArrayList();
        StringBuffer buffer = new StringBuffer();
+       // Preserve the case of field names
        for (Iterator i = descriptor.entrySet().iterator(); i.hasNext();)
        {
***************
*** 434,439 ****
     }
  
!    private Class getObjectValueClass(String value)
!            throws XMLParseException
     {
        int eoc = value.indexOf("/");
--- 436,440 ----
     }
  
!    private Class getObjectValueClass(String value) throws XMLParseException
     {
        int eoc = value.indexOf("/");
***************
*** 455,460 ****
     }
  
!    private String getObjectValueString(String value)
!            throws XMLParseException
     {
        int bov = value.indexOf("/");
--- 456,460 ----
     }
  
!    private String getObjectValueString(String value) throws XMLParseException
     {
        int bov = value.indexOf("/");
***************
*** 506,511 ****
     }
  
!    private Object parseValueString(String value)
!            throws XMLParseException
     {
        Object result = null;
--- 506,510 ----
     }
  
!    private Object parseValueString(String value) throws XMLParseException
     {
        Object result = null;
***************
*** 525,530 ****
     }
  
!    private Object parseObjectValueString(String value)
!            throws XMLParseException
     {
        if (value.charAt(value.length() - 1) != ')')
--- 524,528 ----
     }
  
!    private Object parseObjectValueString(String value) throws XMLParseException
     {
        if (value.charAt(value.length() - 1) != ')')
***************
*** 586,588 ****
--- 584,610 ----
        return result.toString();
     }
+ 
+    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
+    {
+       stream.defaultReadObject();
+       this.fields = new HashMap(descriptor.size());
+       for (Iterator i = descriptor.entrySet().iterator(); i.hasNext();)
+       {
+          Map.Entry entry = (Map.Entry)i.next();
+          String name = (String)entry.getKey();
+          fields.put(name.toLowerCase(), new ValueHolder(name, entry.getValue()));
+       }
+    }
+ 
+    private static class ValueHolder
+    {
+       private final String fieldName;
+       private final Object fieldValue;
+ 
+       private ValueHolder(String fieldName, Object value)
+       {
+          this.fieldName = fieldName;
+          this.fieldValue = value;
+       }
+    }
  }



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click