com.sun.jmx.mbeanserver.MXBeanMappingFactory Java Examples

The following examples show how to use com.sun.jmx.mbeanserver.MXBeanMappingFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenMethod.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public OpenMethod(Method m) {
  try {
    final MXBeanMappingFactory mapping = MXBeanMappingFactory.DEFAULT;
    final Type[] params = m.getGenericParameterTypes();
    final MXBeanMapping[] paramConverters = new MXBeanMapping[params.length];
    boolean skipParamsConversion = true;
    // using reflection since isIdentity method is package protected
    final Method identityCheck = DefaultMXBeanMappingFactory.class
        .getDeclaredMethod("isIdentity", MXBeanMapping.class);
    identityCheck.setAccessible(true);
    for (int i = 0; i < params.length; i++) {
      paramConverters[i] = mapping.mappingForType(params[i], mapping);
      if (skipParamsConversion) {
        skipParamsConversion = (Boolean)identityCheck.invoke(null,
            paramConverters[i]);
      }
    }
    // null converters denotes no conversion required for the case when
    // all parameter conversions are identity converters
    this.paramConverters = skipParamsConversion ? null : paramConverters;
    this.returnValConverter = mapping.mappingForType(
        m.getGenericReturnType(), mapping);
  } catch (OpenDataException ode) {
    throw new IllegalArgumentException("Failed getting converter of " +
        "parameter or return value to open type for given method: " + m, ode);
  } catch (Exception e) {
    throw new IllegalStateException("Exception getting converter of " +
        "parameter or return value to open type of given method: " + m, e);
  }
}
 
Example #2
Source File: OpenMethod.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public OpenMethod(Method m) {
  try {
    final MXBeanMappingFactory mapping = MXBeanMappingFactory.DEFAULT;
    final Type[] params = m.getGenericParameterTypes();
    final MXBeanMapping[] paramConverters = new MXBeanMapping[params.length];
    boolean skipParamsConversion = true;
    // using reflection since isIdentity method is package protected
    final Method identityCheck = DefaultMXBeanMappingFactory.class
        .getDeclaredMethod("isIdentity", MXBeanMapping.class);
    identityCheck.setAccessible(true);
    for (int i = 0; i < params.length; i++) {
      paramConverters[i] = mapping.mappingForType(params[i], mapping);
      if (skipParamsConversion) {
        skipParamsConversion = (Boolean)identityCheck.invoke(null,
            paramConverters[i]);
      }
    }
    // null converters denotes no conversion required for the case when
    // all parameter conversions are identity converters
    this.paramConverters = skipParamsConversion ? null : paramConverters;
    this.returnValConverter = mapping.mappingForType(
        m.getGenericReturnType(), mapping);
  } catch (OpenDataException ode) {
    throw new IllegalArgumentException("Failed getting converter of " +
        "parameter or return value to open type for given method: " + m, ode);
  } catch (Exception e) {
    throw new IllegalStateException("Exception getting converter of " +
        "parameter or return value to open type of given method: " + m, e);
  }
}
 
Example #3
Source File: CompositeDataInvocationHandler.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #4
Source File: CompositeDataInvocationHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #5
Source File: CompositeDataInvocationHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #6
Source File: CompositeDataInvocationHandler.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #7
Source File: CompositeDataInvocationHandler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #8
Source File: CompositeDataInvocationHandler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #9
Source File: CompositeDataInvocationHandler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #10
Source File: CompositeDataInvocationHandler.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #11
Source File: CompositeDataInvocationHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #12
Source File: CompositeDataInvocationHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #13
Source File: CompositeDataInvocationHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #14
Source File: CompositeDataInvocationHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #15
Source File: CompositeDataInvocationHandler.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #16
Source File: CompositeDataInvocationHandler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #17
Source File: CompositeDataInvocationHandler.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
 
Example #18
Source File: CompositeDataInvocationHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    final String methodName = method.getName();

    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1
            && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            /* Either someone is calling invoke by hand, or
               it is a non-final method from Object overriden
               by the generated Proxy.  At the time of writing,
               the only non-final methods in Object that are not
               handled above are finalize and clone, and these
               are not overridden in generated proxies.  */
            // this plain Method.invoke is called only if the declaring class
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }

    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " +
                                           method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg =
                "No CompositeData item " + propertyName +
                (decap.equals(propertyName) ? "" : " or " + decap) +
                " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping =
        MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
                               MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}