Search in sources :

Example 56 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class MBeanInstantiator method findSignatureClasses.

/**
     * Return an array of Class corresponding to the given signature, using
     * the specified class loader.
     */
public Class<?>[] findSignatureClasses(String[] signature, ClassLoader loader) throws ReflectionException {
    if (signature == null)
        return null;
    final ClassLoader aLoader = loader;
    final int length = signature.length;
    final Class<?>[] tab = new Class<?>[length];
    if (length == 0)
        return tab;
    try {
        for (int i = 0; i < length; i++) {
            // Start handling primitive types (int. boolean and so
            // forth)
            //
            final Class<?> primCla = primitiveClasses.get(signature[i]);
            if (primCla != null) {
                tab[i] = primCla;
                continue;
            }
            ReflectUtil.checkPackageAccess(signature[i]);
            //
            if (aLoader != null) {
                // We need to load the class through the class
                // loader of the target object.
                //
                tab[i] = Class.forName(signature[i], false, aLoader);
            } else {
                // Load through the default class loader
                //
                tab[i] = findClass(signature[i], this.getClass().getClassLoader());
            }
        }
    } catch (ClassNotFoundException e) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
            MBEANSERVER_LOGGER.logp(Level.FINEST, MBeanInstantiator.class.getName(), "findSignatureClasses", "The parameter class could not be found", e);
        }
        throw new ReflectionException(e, "The parameter class could not be found");
    } catch (RuntimeException e) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
            MBEANSERVER_LOGGER.logp(Level.FINEST, MBeanInstantiator.class.getName(), "findSignatureClasses", "Unexpected exception", e);
        }
        throw e;
    }
    return tab;
}
Also used : ReflectionException(javax.management.ReflectionException)

Example 57 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class JmxMBeanServer method deserialize.

/**
     * De-serializes a byte array in the context of a given MBean class loader.
     * The class loader is the one that loaded the class with name "className".
     *
     * @param className The name of the class whose class loader should be
     *      used for the de-serialization.
     * @param data The byte array to be de-sererialized.
     *
     * @return  The de-serialized object stream.
     *
     * @exception OperationsException Any of the usual Input/Output
     *      related exceptions.
     * @exception ReflectionException The specified class could not be
     *      loaded by the default loader repository
     *
     */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException, ReflectionException {
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null className passed in parameter");
    }
    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();
    Class<?> theClass;
    try {
        if (clr == null)
            throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e, "The given class could not be " + "loaded by the default loader " + "repository");
    }
    return instantiator.deserialize(theClass.getClassLoader(), data);
}
Also used : ClassLoaderRepository(javax.management.loading.ClassLoaderRepository) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 58 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class MBeanInstantiator method deserialize.

/**
     * De-serializes a byte array in the context of a given MBean class loader.
     * <P>The class loader is the one that loaded the class with name
     * "className".
     * <P>The name of the class loader to be used for loading the specified
     * class is specified. If null, a default one has to be provided (for a
     * MBean Server, its own class loader will be used).
     *
     * @param className The name of the class whose class loader should
     *  be used for the de-serialization.
     * @param data The byte array to be de-sererialized.
     * @param loaderName The name of the class loader to be used for loading
     * the specified class. If null, a default one has to be provided (for a
     * MBean Server, its own class loader will be used).
     *
     * @return  The de-serialized object stream.
     *
     * @exception InstanceNotFoundException The specified class loader MBean is
     * not found.
     * @exception OperationsException Any of the usual Input/Output related
     * exceptions.
     * @exception ReflectionException The specified class could not be loaded
     * by the specified class loader.
     */
public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data, ClassLoader loader) throws InstanceNotFoundException, OperationsException, ReflectionException {
    // Check parameter validity
    if (data == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null data passed in parameter");
    }
    if (data.length == 0) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Empty data passed in parameter");
    }
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null className passed in parameter");
    }
    ReflectUtil.checkPackageAccess(className);
    Class<?> theClass;
    if (loaderName == null) {
        // Load the class using the agent class loader
        theClass = findClass(className, loader);
    } else {
        // Get the class loader MBean
        try {
            ClassLoader instance = null;
            instance = getClassLoader(loaderName);
            if (instance == null)
                throw new ClassNotFoundException(className);
            theClass = Class.forName(className, false, instance);
        } catch (ClassNotFoundException e) {
            throw new ReflectionException(e, "The MBean class could not be loaded by the " + loaderName.toString() + " class loader");
        }
    }
    // Object deserialization
    ByteArrayInputStream bIn;
    ObjectInputStream objIn;
    bIn = new ByteArrayInputStream(data);
    try {
        objIn = new ObjectInputStreamWithLoader(bIn, theClass.getClassLoader());
    } catch (IOException e) {
        throw new OperationsException("An IOException occurred trying to de-serialize the data");
    }
    return objIn;
}
Also used : ReflectionException(javax.management.ReflectionException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ObjectInputStream(java.io.ObjectInputStream) OperationsException(javax.management.OperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 59 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class MBeanInstantiator method loadSignatureClasses.

/**
     * Load the classes specified in the signature with the given loader,
     * or with this object class loader.
     **/
static Class<?>[] loadSignatureClasses(String[] signature, ClassLoader loader) throws ReflectionException {
    if (signature == null)
        return null;
    final ClassLoader aLoader = (loader == null ? MBeanInstantiator.class.getClassLoader() : loader);
    final int length = signature.length;
    final Class<?>[] tab = new Class<?>[length];
    if (length == 0)
        return tab;
    try {
        for (int i = 0; i < length; i++) {
            // Start handling primitive types (int. boolean and so
            // forth)
            //
            final Class<?> primCla = primitiveClasses.get(signature[i]);
            if (primCla != null) {
                tab[i] = primCla;
                continue;
            }
            // Ok we do not have a primitive type ! We need to build
            // the signature of the method
            //
            // We need to load the class through the class
            // loader of the target object.
            //
            ReflectUtil.checkPackageAccess(signature[i]);
            tab[i] = Class.forName(signature[i], false, aLoader);
        }
    } catch (ClassNotFoundException e) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
            MBEANSERVER_LOGGER.logp(Level.FINEST, MBeanInstantiator.class.getName(), "findSignatureClasses", "The parameter class could not be found", e);
        }
        throw new ReflectionException(e, "The parameter class could not be found");
    } catch (RuntimeException e) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
            MBEANSERVER_LOGGER.logp(Level.FINEST, MBeanInstantiator.class.getName(), "findSignatureClasses", "Unexpected exception", e);
        }
        throw e;
    }
    return tab;
}
Also used : ReflectionException(javax.management.ReflectionException)

Example 60 with ReflectionException

use of javax.management.ReflectionException in project jdk8u_jdk by JetBrains.

the class RelationService method addRelation.

/**
     * Adds an MBean created by the user (and registered by him in the MBean
     * Server) as a relation in the Relation Service.
     * <P>To be added as a relation, the MBean must conform to the
     * following:
     * <P>- implement the Relation interface
     * <P>- have for RelationService ObjectName the ObjectName of current
     * Relation Service
     * <P>- have a relation id unique and unused in current Relation Service
     * <P>- have for relation type a relation type created in the Relation
     * Service
     * <P>- have roles conforming to the role info provided in the relation
     * type.
     *
     * @param relationObjectName  ObjectName of the relation MBean to be added.
     *
     * @exception IllegalArgumentException  if null parameter
     * @exception RelationServiceNotRegisteredException  if the Relation
     * Service is not registered in the MBean Server
     * @exception NoSuchMethodException  If the MBean does not implement the
     * Relation interface
     * @exception InvalidRelationIdException  if:
     * <P>- no relation identifier in MBean
     * <P>- the relation identifier is already used in the Relation Service
     * @exception InstanceNotFoundException  if the MBean for given ObjectName
     * has not been registered
     * @exception InvalidRelationServiceException  if:
     * <P>- no Relation Service name in MBean
     * <P>- the Relation Service name in the MBean is not the one of the
     * current Relation Service
     * @exception RelationTypeNotFoundException  if:
     * <P>- no relation type name in MBean
     * <P>- the relation type name in MBean does not correspond to a relation
     * type created in the Relation Service
     * @exception InvalidRoleValueException  if:
     * <P>- the number of referenced MBeans in a role is less than
     * expected minimum degree
     * <P>- the number of referenced MBeans in a role exceeds expected
     * maximum degree
     * <P>- one referenced MBean in the value is not an Object of the MBean
     * class expected for that role
     * <P>- an MBean provided for a role does not exist
     * @exception RoleNotFoundException  if a value is provided for a role
     * that does not exist in the relation type
     */
public void addRelation(ObjectName relationObjectName) throws IllegalArgumentException, RelationServiceNotRegisteredException, NoSuchMethodException, InvalidRelationIdException, InstanceNotFoundException, InvalidRelationServiceException, RelationTypeNotFoundException, RoleNotFoundException, InvalidRoleValueException {
    if (relationObjectName == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "addRelation", relationObjectName);
    // Can throw RelationServiceNotRegisteredException
    isActive();
    // registered MBean (else will throw an InstanceNotFoundException)
    if ((!(myMBeanServer.isInstanceOf(relationObjectName, "javax.management.relation.Relation")))) {
        String excMsg = "This MBean does not implement the Relation interface.";
        throw new NoSuchMethodException(excMsg);
    }
    // Checks there is a relation id in the relation MBean (its uniqueness
    // is checked in addRelationInt())
    // Can throw InstanceNotFoundException (but detected above)
    // No MBeanException as no exception raised by this method, and no
    // ReflectionException
    String relId;
    try {
        relId = (String) (myMBeanServer.getAttribute(relationObjectName, "RelationId"));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    } catch (AttributeNotFoundException exc3) {
        throw new RuntimeException(exc3.getMessage());
    }
    if (relId == null) {
        String excMsg = "This MBean does not provide a relation id.";
        throw new InvalidRelationIdException(excMsg);
    }
    // Checks that the Relation Service where the relation MBean is
    // expected to be added is the current one
    // Can throw InstanceNotFoundException (but detected above)
    // No MBeanException as no exception raised by this method, no
    // ReflectionException
    ObjectName relServObjName;
    try {
        relServObjName = (ObjectName) (myMBeanServer.getAttribute(relationObjectName, "RelationServiceName"));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    } catch (AttributeNotFoundException exc3) {
        throw new RuntimeException(exc3.getMessage());
    }
    boolean badRelServFlag = false;
    if (relServObjName == null) {
        badRelServFlag = true;
    } else if (!(relServObjName.equals(myObjName))) {
        badRelServFlag = true;
    }
    if (badRelServFlag) {
        String excMsg = "The Relation Service referenced in the MBean is not the current one.";
        throw new InvalidRelationServiceException(excMsg);
    }
    // Checks that a relation type has been specified for the relation
    // Can throw InstanceNotFoundException (but detected above)
    // No MBeanException as no exception raised by this method, no
    // ReflectionException
    String relTypeName;
    try {
        relTypeName = (String) (myMBeanServer.getAttribute(relationObjectName, "RelationTypeName"));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    } catch (AttributeNotFoundException exc3) {
        throw new RuntimeException(exc3.getMessage());
    }
    if (relTypeName == null) {
        String excMsg = "No relation type provided.";
        throw new RelationTypeNotFoundException(excMsg);
    }
    // Retrieves all roles without considering read mode
    // Can throw InstanceNotFoundException (but detected above)
    // No MBeanException as no exception raised by this method, no
    // ReflectionException
    RoleList roleList;
    try {
        roleList = (RoleList) (myMBeanServer.invoke(relationObjectName, "retrieveAllRoles", null, null));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    }
    // Can throw RoleNotFoundException, InvalidRelationIdException,
    // RelationTypeNotFoundException, InvalidRoleValueException
    addRelationInt(false, null, relationObjectName, relId, relTypeName, roleList);
    // Adds relation MBean ObjectName in map
    synchronized (myRelMBeanObjName2RelIdMap) {
        myRelMBeanObjName2RelIdMap.put(relationObjectName, relId);
    }
    // of the Relation interface, so may be not supported.
    try {
        myMBeanServer.setAttribute(relationObjectName, new Attribute("RelationServiceManagementFlag", Boolean.TRUE));
    } catch (Exception exc) {
    // OK : The flag is not supported.
    }
    // Updates listener information to received notification for
    // unregistration of this MBean
    List<ObjectName> newRefList = new ArrayList<ObjectName>();
    newRefList.add(relationObjectName);
    updateUnregistrationListener(newRefList, null);
    RELATION_LOGGER.exiting(RelationService.class.getName(), "addRelation");
    return;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) ArrayList(java.util.ArrayList) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Aggregations

ReflectionException (javax.management.ReflectionException)72 InstanceNotFoundException (javax.management.InstanceNotFoundException)50 MBeanException (javax.management.MBeanException)46 AttributeNotFoundException (javax.management.AttributeNotFoundException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)23 ObjectName (javax.management.ObjectName)22 Attribute (javax.management.Attribute)19 RuntimeOperationsException (javax.management.RuntimeOperationsException)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 IntrospectionException (javax.management.IntrospectionException)13 Method (java.lang.reflect.Method)12 AttributeList (javax.management.AttributeList)12 ServiceNotFoundException (javax.management.ServiceNotFoundException)12 IOException (java.io.IOException)11 MBeanInfo (javax.management.MBeanInfo)11 RuntimeErrorException (javax.management.RuntimeErrorException)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)9 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 MBeanRegistrationException (javax.management.MBeanRegistrationException)9