Search in sources :

Example 31 with ReflectionException

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

the class RequiredModelMBean method resolveMethod.

private Method resolveMethod(Class<?> targetClass, String opMethodName, final String[] sig) throws ReflectionException {
    final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
    if (tracing) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "resolveMethod", "resolving " + targetClass.getName() + "." + opMethodName);
    }
    final Class<?>[] argClasses;
    if (sig == null)
        argClasses = null;
    else {
        final AccessControlContext stack = AccessController.getContext();
        final ReflectionException[] caughtException = new ReflectionException[1];
        final ClassLoader targetClassLoader = targetClass.getClassLoader();
        argClasses = new Class<?>[sig.length];
        javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {

            @Override
            public Void run() {
                for (int i = 0; i < sig.length; i++) {
                    if (tracing) {
                        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "resolveMethod", "resolve type " + sig[i]);
                    }
                    argClasses[i] = (Class<?>) primitiveClassMap.get(sig[i]);
                    if (argClasses[i] == null) {
                        try {
                            ReflectUtil.checkPackageAccess(sig[i]);
                            argClasses[i] = Class.forName(sig[i], false, targetClassLoader);
                        } catch (ClassNotFoundException e) {
                            if (tracing) {
                                MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "resolveMethod", "class not found");
                            }
                            final String msg = "Parameter class not found";
                            caughtException[0] = new ReflectionException(e, msg);
                        }
                    }
                }
                return null;
            }
        }, stack, acc);
        if (caughtException[0] != null) {
            throw caughtException[0];
        }
    }
    try {
        return targetClass.getMethod(opMethodName, argClasses);
    } catch (NoSuchMethodException e) {
        final String msg = "Target method not found: " + targetClass.getName() + "." + opMethodName;
        throw new ReflectionException(e, msg);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AccessControlContext(java.security.AccessControlContext)

Example 32 with ReflectionException

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

the class RelationSupport method setRoleInt.

// Sets the role with given value
//
// This method is called in setRole() above.
// It is also called by the Relation Service setRole() method.
// It is also called in setRolesInt() method below (used in setRoles()
// above and in RelationService setRoles() method).
//
// Will check the role according to its corresponding role definition
// provided in relation's relation type
// Will send a notification (RelationNotification with type
// RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
// relation is a MBean or not) if not initialization of role.
//
// -param aRole  role to be set (name and new value)
// -param relationServCallFlg  true if call from the Relation Service; this
//  will happen if the current RelationSupport object has been created by
//  the Relation Service (via createRelation()) method, so direct access is
//  possible.
// -param relationServ  reference to Relation Service object, if internal
//  relation
// -param multiRoleFlg  true if getting the role in the scope of a
//  multiple retrieval.
//
// -return (except other "critical" exceptions):
//  - for single role retrieval (multiRoleFlg false):
//    - null if the role has been set
//    - raise an InvalidRoleValueException
// else
//  - for multi-role retrieval (multiRoleFlg true):
//    - the Role object for given role name if role has been set
//    - a RoleUnresolved object with problem else.
//
// -exception IllegalArgumentException if null parameter
// -exception RoleNotFoundException  if multiRoleFlg is false and:
//  - internal relation and the role does not exist
//  or
//  - existing role (i.e. not initializing it) and the role is not
//    writable.
// -exception InvalidRoleValueException  ifmultiRoleFlg is false and
//  value provided for:
//   - the number of referenced MBeans in given value is less than
//     expected minimum degree
//   or
//   - the number of referenced MBeans in provided value exceeds expected
//     maximum degree
//   or
//   - one referenced MBean in the value is not an Object of the MBean
//     class expected for that role
//   or
//   - a MBean provided for that role does not exist
// -exception RelationServiceNotRegisteredException  if the Relation
//  Service is not registered in the MBean Server
// -exception RelationTypeNotFoundException  if relation type unknown
// -exception RelationNotFoundException  if a relation MBean has not been
//  added in the Relation Service
Object setRoleInt(Role aRole, boolean relationServCallFlg, RelationService relationServ, boolean multiRoleFlg) throws IllegalArgumentException, RoleNotFoundException, InvalidRoleValueException, RelationServiceNotRegisteredException, RelationTypeNotFoundException, RelationNotFoundException {
    if (aRole == null || (relationServCallFlg && relationServ == null)) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationSupport.class.getName(), "setRoleInt", new Object[] { aRole, relationServCallFlg, relationServ, multiRoleFlg });
    String roleName = aRole.getRoleName();
    int pbType = 0;
    // Checks if role exists in the relation
    // No error if the role does not exist in the relation, to be able to
    // handle initialization of role when creating the relation
    // (roles provided in the RoleList parameter are directly set but
    // roles automatically initialized are set using setRole())
    Role role;
    synchronized (myRoleName2ValueMap) {
        role = (myRoleName2ValueMap.get(roleName));
    }
    List<ObjectName> oldRoleValue;
    Boolean initFlg;
    if (role == null) {
        initFlg = true;
        oldRoleValue = new ArrayList<ObjectName>();
    } else {
        initFlg = false;
        oldRoleValue = role.getRoleValue();
    }
    // initialization) and correct value
    try {
        Integer status;
        if (relationServCallFlg) {
            // Call from the Relation Service, so direct access to it,
            // avoiding MBean Server
            //
            // Shall not raise a RelationTypeNotFoundException
            status = relationServ.checkRoleWriting(aRole, myRelTypeName, initFlg);
        } else {
            // Call from setRole() method above
            // So we have a MBean. We must access the Relation Service
            // via the MBean Server.
            Object[] params = new Object[3];
            params[0] = aRole;
            params[1] = myRelTypeName;
            params[2] = initFlg;
            String[] signature = new String[3];
            signature[0] = "javax.management.relation.Role";
            signature[1] = "java.lang.String";
            signature[2] = "java.lang.Boolean";
            // Can throw InstanceNotFoundException if the Relation Service
            // is not registered (to be transformed into
            // RelationServiceNotRegisteredException in any case).
            //
            // Can throw a MBeanException wrapping a
            // RelationTypeNotFoundException:
            // throw wrapped exception.
            //
            // Shall not throw a ReflectionException
            status = (Integer) (myRelServiceMBeanServer.invoke(myRelServiceName, "checkRoleWriting", params, signature));
        }
        pbType = status.intValue();
    } catch (MBeanException exc2) {
        // Retrieves underlying exception
        Exception wrappedExc = exc2.getTargetException();
        if (wrappedExc instanceof RelationTypeNotFoundException) {
            throw ((RelationTypeNotFoundException) wrappedExc);
        } else {
            throw new RuntimeException(wrappedExc.getMessage());
        }
    } catch (ReflectionException exc3) {
        throw new RuntimeException(exc3.getMessage());
    } catch (RelationTypeNotFoundException exc4) {
        throw new RuntimeException(exc4.getMessage());
    } catch (InstanceNotFoundException exc5) {
        throw new RelationServiceNotRegisteredException(exc5.getMessage());
    }
    Object result = null;
    if (pbType == 0) {
        // Role can be set
        if (!(initFlg.booleanValue())) {
            // Not initializing the role
            // If role being initialized:
            // - do not send an update notification
            // - do not try to update internal map of Relation Service
            //   listing referenced MBeans, as role is initialized to an
            //   empty list
            // Sends a notification (RelationNotification)
            // Can throw a RelationNotFoundException
            sendRoleUpdateNotification(aRole, oldRoleValue, relationServCallFlg, relationServ);
            // Updates the role map of the Relation Service
            // Can throw RelationNotFoundException
            updateRelationServiceMap(aRole, oldRoleValue, relationServCallFlg, relationServ);
        }
        // Sets the role
        synchronized (myRoleName2ValueMap) {
            myRoleName2ValueMap.put(roleName, (Role) (aRole.clone()));
        }
        if (multiRoleFlg) {
            // Multi-roles retrieval: returns the role
            result = aRole;
        }
    } else {
        if (!(multiRoleFlg)) {
            // Problem when setting a simple role: either role not
            // found, not writable, or incorrect value:
            // raises appropriate exception, RoleNotFoundException or
            // InvalidRoleValueException
            RelationService.throwRoleProblemException(pbType, roleName);
            // To keep compiler happy :)
            return null;
        } else {
            // Problem when retrieving a role in a multi-role retrieval:
            // returns a RoleUnresolved object
            result = new RoleUnresolved(roleName, aRole.getRoleValue(), pbType);
        }
    }
    RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRoleInt");
    return result;
}
Also used : ReflectionException(javax.management.ReflectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 33 with ReflectionException

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

the class RelationService method initializeMissingRoles.

// Initializes roles associated to given role infos to default value (empty
// ArrayList of ObjectNames) in given relation.
// It will succeed for every role except if the role info has a minimum
// cardinality greater than 0. In that case, an InvalidRoleValueException
// will be raised.
//
// -param relationBaseFlag  flag true if the relation is a RelationSupport
//  object, false if it is an MBean
// -param relationObj  RelationSupport object (if relation is internal)
// -param relationObjName  ObjectName of the MBean to be added as a relation
//  (only for the relation MBean)
// -param relationId  relation id
// -param relationTypeName  name of the relation type (has to be created
//  in the Relation Service)
// -param roleInfoList  list of role infos for roles to be defaulted
//
// -exception IllegalArgumentException  if null paramater
// -exception RelationServiceNotRegisteredException  if the Relation
//  Service is not registered in the MBean Server
// -exception InvalidRoleValueException  if role must have a non-empty
//  value
// Revisit [cebro] Handle CIM qualifiers as REQUIRED to detect roles which
//    should have been initialized by the user
private void initializeMissingRoles(boolean relationBaseFlag, RelationSupport relationObj, ObjectName relationObjName, String relationId, String relationTypeName, List<RoleInfo> roleInfoList) throws IllegalArgumentException, RelationServiceNotRegisteredException, InvalidRoleValueException {
    if ((relationBaseFlag && (relationObj == null || relationObjName != null)) || (!relationBaseFlag && (relationObjName == null || relationObj != null)) || relationId == null || relationTypeName == null || roleInfoList == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "initializeMissingRoles", new Object[] { relationBaseFlag, relationObj, relationObjName, relationId, relationTypeName, roleInfoList });
    // Can throw RelationServiceNotRegisteredException
    isActive();
    // empty value, according to its minimum cardinality
    for (RoleInfo currRoleInfo : roleInfoList) {
        String roleName = currRoleInfo.getName();
        // Creates an empty value
        List<ObjectName> emptyValue = new ArrayList<ObjectName>();
        // Creates a role
        Role role = new Role(roleName, emptyValue);
        if (relationBaseFlag) {
            // RelationTypeNotFoundException
            try {
                relationObj.setRoleInt(role, true, this, false);
            } catch (RoleNotFoundException exc1) {
                throw new RuntimeException(exc1.getMessage());
            } catch (RelationNotFoundException exc2) {
                throw new RuntimeException(exc2.getMessage());
            } catch (RelationTypeNotFoundException exc3) {
                throw new RuntimeException(exc3.getMessage());
            }
        } else {
            // Relation is an MBean
            // Use standard setRole()
            Object[] params = new Object[1];
            params[0] = role;
            String[] signature = new String[1];
            signature[0] = "javax.management.relation.Role";
            // the relation MBeans are registered in the same MBean Server.
            try {
                myMBeanServer.setAttribute(relationObjName, new Attribute("Role", role));
            } catch (InstanceNotFoundException exc1) {
                throw new RuntimeException(exc1.getMessage());
            } catch (ReflectionException exc3) {
                throw new RuntimeException(exc3.getMessage());
            } catch (MBeanException exc2) {
                Exception wrappedExc = exc2.getTargetException();
                if (wrappedExc instanceof InvalidRoleValueException) {
                    throw ((InvalidRoleValueException) wrappedExc);
                } else {
                    throw new RuntimeException(wrappedExc.getMessage());
                }
            } catch (AttributeNotFoundException exc4) {
                throw new RuntimeException(exc4.getMessage());
            } catch (InvalidAttributeValueException exc5) {
                throw new RuntimeException(exc5.getMessage());
            }
        }
    }
    RELATION_LOGGER.exiting(RelationService.class.getName(), "initializeMissingRoles");
    return;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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)

Example 34 with ReflectionException

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

the class RelationService method setRole.

/**
     * Sets the given role in given relation.
     * <P>Will check the role according to its corresponding role definition
     * provided in relation's relation type
     * <P>The Relation Service will keep track of the change to keep the
     * consistency of relations by handling referenced MBean deregistrations.
     *
     * @param relationId  relation id
     * @param role  role to be set (name and new value)
     *
     * @exception RelationServiceNotRegisteredException  if the Relation
     * Service is not registered in the MBean Server
     * @exception IllegalArgumentException  if null parameter
     * @exception RelationNotFoundException  if no relation with given id
     * @exception RoleNotFoundException  if the role does not exist or is not
     * writable
     * @exception InvalidRoleValueException  if value provided for role is not
     * valid:
     * <P>- the number of referenced MBeans in given value is less than
     * expected minimum degree
     * <P>or
     * <P>- the number of referenced MBeans in provided value exceeds expected
     * maximum degree
     * <P>or
     * <P>- one referenced MBean in the value is not an Object of the MBean
     * class expected for that role
     * <P>or
     * <P>- an MBean provided for that role does not exist
     *
     * @see #getRole
     */
public void setRole(String relationId, Role role) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException, InvalidRoleValueException {
    if (relationId == null || role == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "setRole", new Object[] { relationId, role });
    // Can throw RelationServiceNotRegisteredException
    isActive();
    // Can throw a RelationNotFoundException
    Object relObj = getRelation(relationId);
    if (relObj instanceof RelationSupport) {
        // (as relation exists in the RS, its relation type is known)
        try {
            ((RelationSupport) relObj).setRoleInt(role, true, this, false);
        } catch (RelationTypeNotFoundException exc) {
            throw new RuntimeException(exc.getMessage());
        }
    } else {
        // Relation MBean
        Object[] params = new Object[1];
        params[0] = role;
        String[] signature = new String[1];
        signature[0] = "javax.management.relation.Role";
        // InstanceNotFoundException
        try {
            myMBeanServer.setAttribute(((ObjectName) relObj), new Attribute("Role", role));
        } catch (InstanceNotFoundException exc1) {
            throw new RuntimeException(exc1.getMessage());
        } catch (ReflectionException exc3) {
            throw new RuntimeException(exc3.getMessage());
        } catch (MBeanException exc2) {
            Exception wrappedExc = exc2.getTargetException();
            if (wrappedExc instanceof RoleNotFoundException) {
                throw ((RoleNotFoundException) wrappedExc);
            } else if (wrappedExc instanceof InvalidRoleValueException) {
                throw ((InvalidRoleValueException) wrappedExc);
            } else {
                throw new RuntimeException(wrappedExc.getMessage());
            }
        } catch (AttributeNotFoundException exc4) {
            throw new RuntimeException(exc4.getMessage());
        } catch (InvalidAttributeValueException exc5) {
            throw new RuntimeException(exc5.getMessage());
        }
    }
    RELATION_LOGGER.exiting(RelationService.class.getName(), "setRole");
    return;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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)

Example 35 with ReflectionException

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

the class XSheet method displayMBeanAttributesNode.

// Call on EDT
private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.ATTRIBUTES)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    final XMBean xmb = mbean;
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {

        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
            MBeanInfo mbi = xmb.getMBeanInfo();
            return mbi;
        }

        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null && mbi.getAttributes() != null && mbi.getAttributes().length > 0) {
                    mbeanAttributes.loadAttributes(xmb, mbi);
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    invalidate();
                    mainPanel.removeAll();
                    JPanel borderPanel = new JPanel(new BorderLayout());
                    borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.ATTRIBUTE_VALUES));
                    borderPanel.add(new JScrollPane(mbeanAttributes));
                    mainPanel.add(borderPanel, BorderLayout.CENTER);
                    // add the refresh button to the south panel
                    southPanel.removeAll();
                    southPanel.add(refreshButton, BorderLayout.SOUTH);
                    southPanel.setVisible(true);
                    refreshButton.setEnabled(true);
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem displaying MBean " + "attributes for MBean [" + mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MBeanInfo(javax.management.MBeanInfo) BorderLayout(java.awt.BorderLayout) SwingWorker(javax.swing.SwingWorker) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException)

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