JMX no longer depends on JavaBeans. There is code injection interface to handle their communication with reasonable default fallback. eliminateswing
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 22 Jun 2009 12:49:51 +0200
brancheliminateswing
changeset 1251adeb4a4c4aa6
parent 1250 7d9cedc2c758
child 1252 61423df84120
JMX no longer depends on JavaBeans. There is code injection interface to handle their communication with reasonable default fallback.
build.xml
src/share/classes/META-INF/services/com.sun.jmx.mbeanserver.IntrospectorProxy
src/share/classes/com/sun/beans/IntrospectorProxyImpl.java
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
src/share/classes/com/sun/jmx/mbeanserver/IntrospectorProxy.java
src/share/classes/javax/management/JMX.java
     1.1 --- a/build.xml	Mon Jun 22 10:15:54 2009 +0200
     1.2 +++ b/build.xml	Mon Jun 22 12:49:51 2009 +0200
     1.3 @@ -180,12 +180,20 @@
     1.4                  <filename name="sun/awt/X11/**"/>
     1.5  
     1.6                  <filename name="java/beans/javax_swing*"/>
     1.7 -                <filename name="java/beans/MetaData*"/>
     1.8 -                <filename name="java/beans/PropertyEdit*"/>
     1.9 -                <filename name="java/beans/beancontext/*"/>
    1.10 +                <filename name="java/beans/**"/>
    1.11 +                <filename name="com/sun/beans/**"/>
    1.12 +                <!-- bridge between jmx and beans -->
    1.13 +                <filename name="META-INF/services/com.sun.jmx.mbeanserver.IntrospectorProxy"/>
    1.14              </or>
    1.15              <none>
    1.16                  <filename name="java/awt/AWTPermission*"/>
    1.17 +
    1.18 +                <filename name="java/beans/ConstructorProperties*"/>
    1.19 +                <filename name="java/beans/PropertyChangeListener*"/>
    1.20 +                <filename name="java/beans/PropertyChangeEvent*"/>
    1.21 +                <filename name="java/beans/IndexedPropertyChangeEvent*"/>
    1.22 +                <filename name="java/beans/PropertyChangeSupport*"/>
    1.23 +                <filename name="java/beans/ChangeListenerMap*"/>
    1.24              </none>
    1.25          </and>
    1.26      </selector>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/classes/META-INF/services/com.sun.jmx.mbeanserver.IntrospectorProxy	Mon Jun 22 12:49:51 2009 +0200
     2.3 @@ -0,0 +1,1 @@
     2.4 +sun.beans.IntrospectorProxyImpl
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/share/classes/com/sun/beans/IntrospectorProxyImpl.java	Mon Jun 22 12:49:51 2009 +0200
     3.3 @@ -0,0 +1,66 @@
     3.4 +/*
     3.5 + * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.  Sun designates this
    3.11 + * particular file as subject to the "Classpath" exception as provided
    3.12 + * by Sun in the LICENSE file that accompanied this code.
    3.13 + *
    3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 + * version 2 for more details (a copy is included in the LICENSE file that
    3.18 + * accompanied this code).
    3.19 + *
    3.20 + * You should have received a copy of the GNU General Public License version
    3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 + *
    3.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.26 + * have any questions.
    3.27 + */
    3.28 +
    3.29 +package sun.beans;
    3.30 +
    3.31 +import java.beans.BeanInfo;
    3.32 +import java.beans.PropertyDescriptor;
    3.33 +import java.lang.reflect.InvocationTargetException;
    3.34 +import java.lang.reflect.Method;
    3.35 +import java.util.Map;
    3.36 +import java.util.TreeMap;
    3.37 +
    3.38 +import com.sun.jmx.mbeanserver.IntrospectorProxy;
    3.39 +
    3.40 +public abstract class IntrospectorProxyImpl extends IntrospectorProxy {
    3.41 +    public Map<String, Object> inspectClass(Class<?> type, Object values) {
    3.42 +        Map<String, Object> map = new TreeMap<String, Object>();
    3.43 +        try {
    3.44 +            BeanInfo bi = java.beans.Introspector.getBeanInfo(type);
    3.45 +            PropertyDescriptor[] pds = bi.getPropertyDescriptors();
    3.46 +            for (PropertyDescriptor pd : pds) {
    3.47 +                String name = pd.getName();
    3.48 +                if (name.equals("class")) {
    3.49 +                    continue;
    3.50 +                }
    3.51 +                Method get = pd.getReadMethod();
    3.52 +                if (get != null) {
    3.53 +                    if (values == null) {
    3.54 +                        map.put(name, get);
    3.55 +                    } else {
    3.56 +                        map.put(name, get.invoke(values));
    3.57 +                    }
    3.58 +                }
    3.59 +            }
    3.60 +        } catch (Exception e) {
    3.61 +            Throwable t = e;
    3.62 +            if (t instanceof InvocationTargetException) {
    3.63 +                t = t.getCause();
    3.64 +            }
    3.65 +            map.put("Exception", t);
    3.66 +        }
    3.67 +        return map;
    3.68 +    }
    3.69 +}
    3.70 \ No newline at end of file
     4.1 --- a/src/share/classes/com/sun/jmx/mbeanserver/Introspector.java	Mon Jun 22 10:15:54 2009 +0200
     4.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/Introspector.java	Mon Jun 22 12:49:51 2009 +0200
     4.3 @@ -25,14 +25,9 @@
     4.4  
     4.5  package com.sun.jmx.mbeanserver;
     4.6  
     4.7 -import com.sun.jmx.remote.util.EnvHelp;
     4.8 -import java.beans.BeanInfo;
     4.9 -import java.beans.PropertyDescriptor;
    4.10  import java.lang.annotation.Annotation;
    4.11  import java.lang.reflect.AnnotatedElement;
    4.12 -import java.lang.reflect.Array;
    4.13  import java.lang.reflect.Constructor;
    4.14 -import java.lang.reflect.InvocationTargetException;
    4.15  import java.lang.reflect.Method;
    4.16  import java.lang.reflect.Modifier;
    4.17  import java.lang.reflect.Proxy;
    4.18 @@ -41,7 +36,6 @@
    4.19  import java.util.HashMap;
    4.20  import java.util.Map;
    4.21  import java.util.logging.Level;
    4.22 -import javax.management.AttributeNotFoundException;
    4.23  import javax.management.Description;
    4.24  
    4.25  import javax.management.Descriptor;
    4.26 @@ -53,14 +47,11 @@
    4.27  import javax.management.MBeanInfo;
    4.28  import javax.management.MXBean;
    4.29  import javax.management.NotCompliantMBeanException;
    4.30 -import javax.management.openmbean.CompositeData;
    4.31  import javax.management.openmbean.MXBeanMappingFactory;
    4.32  
    4.33  import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
    4.34  import com.sun.jmx.mbeanserver.Util;
    4.35  import com.sun.jmx.remote.util.EnvHelp;
    4.36 -import java.beans.BeanInfo;
    4.37 -import java.beans.PropertyDescriptor;
    4.38  import java.lang.reflect.Array;
    4.39  import java.lang.reflect.InvocationTargetException;
    4.40  import java.util.LinkedHashSet;
    4.41 @@ -732,11 +723,11 @@
    4.42              } else {
    4.43                  // Java Beans introspection
    4.44                  //
    4.45 -                BeanInfo bi = java.beans.Introspector.getBeanInfo(complex.getClass());
    4.46 -                PropertyDescriptor[] pds = bi.getPropertyDescriptors();
    4.47 -                for (PropertyDescriptor pd : pds)
    4.48 -                    if (pd.getName().equals(element))
    4.49 -                        return pd.getReadMethod().invoke(complex);
    4.50 +                Map<String,Object> methods = IntrospectorProxy.getDefault().inspectClass(complex.getClass(), null);
    4.51 +                Object method = methods.get(element);
    4.52 +                if (method instanceof Method) {
    4.53 +                    return ((Method)method).invoke(complex);
    4.54 +                }
    4.55                  throw new AttributeNotFoundException(
    4.56                      "Could not find the getter method for the property " +
    4.57                      element + " using the Java Beans introspector");
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/share/classes/com/sun/jmx/mbeanserver/IntrospectorProxy.java	Mon Jun 22 12:49:51 2009 +0200
     5.3 @@ -0,0 +1,85 @@
     5.4 +/*
     5.5 + * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.  Sun designates this
    5.11 + * particular file as subject to the "Classpath" exception as provided
    5.12 + * by Sun in the LICENSE file that accompanied this code.
    5.13 + *
    5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 + * version 2 for more details (a copy is included in the LICENSE file that
    5.18 + * accompanied this code).
    5.19 + *
    5.20 + * You should have received a copy of the GNU General Public License version
    5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 + *
    5.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    5.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    5.26 + * have any questions.
    5.27 + */
    5.28 +
    5.29 +package com.sun.jmx.mbeanserver;
    5.30 +
    5.31 +import java.lang.reflect.InvocationTargetException;
    5.32 +import java.lang.reflect.Method;
    5.33 +import java.util.Iterator;
    5.34 +import java.util.Map;
    5.35 +import java.util.ServiceLoader;
    5.36 +import java.util.TreeMap;
    5.37 +
    5.38 +public abstract class IntrospectorProxy {
    5.39 +    public static IntrospectorProxy getDefault() {
    5.40 +        Iterator<IntrospectorProxy> it = ServiceLoader.load(IntrospectorProxy.class).iterator();
    5.41 +        return it.hasNext() ? it.next() : new SimpleIntrospector();
    5.42 +    }
    5.43 +
    5.44 +    /** Either fills the map with inspected Method objects (if values == null)
    5.45 +     * or with real values of those methods called on the values target
    5.46 +     */
    5.47 +    public abstract Map<String, Object> inspectClass(Class<?> type, Object values);
    5.48 +
    5.49 +    private static final class SimpleIntrospector extends IntrospectorProxy {
    5.50 +        @Override
    5.51 +        public Map<String,Object> inspectClass(Class<?> type, Object values) {
    5.52 +            Map<String, Object> map = new TreeMap<String, Object>();
    5.53 +            try {
    5.54 +                for (Method get : type.getMethods()) {
    5.55 +                    if (get.getName().equals("getClass")) {
    5.56 +                        continue;
    5.57 +                    }
    5.58 +                    if (get.getParameterTypes().length != 0) {
    5.59 +                        continue;
    5.60 +                    }
    5.61 +                    String name;
    5.62 +                    if (get.getName().startsWith("get")) {
    5.63 +                        name = get.getName().substring(3);
    5.64 +                    } else {
    5.65 +                        if (get.getName().startsWith("is")) {
    5.66 +                            name = get.getName().substring(2);
    5.67 +                        } else {
    5.68 +                            continue;
    5.69 +                        }
    5.70 +                    }
    5.71 +                    if (values == null) {
    5.72 +                        map.put(name, get);
    5.73 +                    } else {
    5.74 +                        map.put(name, get.invoke(values));
    5.75 +                    }
    5.76 +                }
    5.77 +            } catch (Exception e) {
    5.78 +                Throwable t = e;
    5.79 +                if (t instanceof InvocationTargetException) {
    5.80 +                    t = t.getCause();
    5.81 +                }
    5.82 +                map.put("Exception", t);
    5.83 +            }
    5.84 +            return map;
    5.85 +        }
    5.86 +
    5.87 +    }
    5.88 +}
    5.89 \ No newline at end of file
     6.1 --- a/src/share/classes/javax/management/JMX.java	Mon Jun 22 10:15:54 2009 +0200
     6.2 +++ b/src/share/classes/javax/management/JMX.java	Mon Jun 22 12:49:51 2009 +0200
     6.3 @@ -26,10 +26,8 @@
     6.4  package javax.management;
     6.5  
     6.6  import com.sun.jmx.mbeanserver.Introspector;
     6.7 +import com.sun.jmx.mbeanserver.IntrospectorProxy;
     6.8  import com.sun.jmx.mbeanserver.MBeanInjector;
     6.9 -import com.sun.jmx.remote.util.ClassLogger;
    6.10 -import java.beans.BeanInfo;
    6.11 -import java.beans.PropertyDescriptor;
    6.12  import java.io.IOException;
    6.13  import java.io.Serializable;
    6.14  import java.lang.reflect.InvocationHandler;
    6.15 @@ -298,25 +296,7 @@
    6.16          }
    6.17  
    6.18          private Map<String, Object> toMap() {
    6.19 -            Map<String, Object> map = new TreeMap<String, Object>();
    6.20 -            try {
    6.21 -                BeanInfo bi = java.beans.Introspector.getBeanInfo(getClass());
    6.22 -                PropertyDescriptor[] pds = bi.getPropertyDescriptors();
    6.23 -                for (PropertyDescriptor pd : pds) {
    6.24 -                    String name = pd.getName();
    6.25 -                    if (name.equals("class"))
    6.26 -                        continue;
    6.27 -                    Method get = pd.getReadMethod();
    6.28 -                    if (get != null)
    6.29 -                        map.put(name, get.invoke(this));
    6.30 -                }
    6.31 -            } catch (Exception e) {
    6.32 -                Throwable t = e;
    6.33 -                if (t instanceof InvocationTargetException)
    6.34 -                    t = t.getCause();
    6.35 -                map.put("Exception", t);
    6.36 -            }
    6.37 -            return map;
    6.38 +            return IntrospectorProxy.getDefault().inspectClass(getClass(), this);
    6.39          }
    6.40  
    6.41          @Override