Search in sources :

Example 1 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project felix by apache.

the class DynamicMBeanImpl method setAttribute.

/**
 * Changes specified attribute value.
 *
 * @param attribute the attribute with new value to be changed
 * @throws AttributeNotFoundException if the required attribute was not found
 * @throws InvalidAttributeValueException if the value is inccorrect type
 * @throws MBeanException if something bad occures
 * @throws ReflectionException if something bad occures
 */
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    // Check attribute is not null to avoid NullPointerException later on
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of " + m_className + " with null attribute");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of " + m_className + " with null attribute name");
    }
    // Check for a recognized attribute name and call the corresponding
    // setter
    // 
    PropertyField propertyField = (PropertyField) m_configMap.getPropertyFromName(name);
    if (propertyField == null) {
        // unrecognized attribute name:
        throw new AttributeNotFoundException("Attribute " + name + " not found in " + m_className);
    }
    if (!propertyField.isWritable()) {
        throw new InvalidAttributeValueException("Attribute " + name + " can not be set");
    }
    if (value == null) {
        try {
            m_instanceManager.onSet(null, propertyField.getField(), null);
        } catch (Exception e) {
            throw new InvalidAttributeValueException("Cannot set attribute " + name + " to null");
        }
    } else {
        // if non null value, make sure it is assignable to the
        // attribute
        // if (true /* TODO type.class.isAssignableFrom(value.getClass()) */) {
        // propertyField.setValue(value);
        // setValue(attributeField.getField(),null);
        m_instanceManager.onSet(null, propertyField.getField(), value);
    // } else {
    // throw new InvalidAttributeValueException(
    // "Cannot set attribute " + name + " to a "
    // + value.getClass().getName()
    // + " object, String expected");
    // }
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project felix by apache.

the class AbstractDynamicMBean method invoke.

/**
 * Returns the value of the manageable operation as specified by the DynamicMBean interface
 * @see #createMBeanOperationInfo
 */
public Object invoke(String method, Object[] arguments, String[] params) throws MBeanException, ReflectionException {
    if (method == null)
        throw new IllegalArgumentException("Method name cannot be null");
    if (arguments == null)
        arguments = new Object[0];
    if (params == null)
        params = new String[0];
    Object resource = null;
    MBeanInfo info = null;
    synchronized (this) {
        resource = getResourceOrThis();
        info = getMBeanInfo();
    }
    MBeanOperationInfo[] opers = info.getOperations();
    if (opers == null || opers.length == 0)
        throw new ReflectionException(new NoSuchMethodException("No operations defined for this MBean"));
    for (int i = 0; i < opers.length; ++i) {
        MBeanOperationInfo oper = opers[i];
        if (oper == null)
            continue;
        if (method.equals(oper.getName())) {
            MBeanParameterInfo[] parameters = oper.getSignature();
            if (params.length != parameters.length)
                continue;
            String[] signature = new String[parameters.length];
            for (int j = 0; j < signature.length; ++j) {
                MBeanParameterInfo param = parameters[j];
                if (param == null)
                    signature[j] = null;
                else
                    signature[j] = param.getType();
            }
            if (Utils.arrayEquals(params, signature)) {
                // Found the right operation
                try {
                    Class[] classes = Utils.loadClasses(resource.getClass().getClassLoader(), signature);
                    return invoke(resource, method, classes, arguments);
                } catch (ClassNotFoundException x) {
                    throw new ReflectionException(x);
                } catch (InvalidAttributeValueException x) {
                    throw new ReflectionException(x);
                }
            }
        }
    }
    throw new ReflectionException(new NoSuchMethodException("Operation " + method + " with signature " + Arrays.asList(params) + " is not defined for this MBean"));
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 3 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project felix by apache.

the class ReflectedMBeanInvoker method setAttribute.

public void setAttribute(MBeanMetaData metadata, Attribute attribute) throws MBeanException, AttributeNotFoundException, InvalidAttributeValueException, ReflectionException {
    String name = attribute.getName();
    MBeanAttributeInfo attr = getStandardAttributeInfo(metadata, name, true);
    if (attr != null) {
        String attributeName = getAttributeName(attr, false);
        try {
            invokeImpl(metadata, attributeName, new String[] { attr.getType() }, new Object[] { attribute.getValue() });
        } catch (IllegalArgumentException x) {
            throw new InvalidAttributeValueException("Invalid value for attribute " + name + ": " + attribute.getValue());
        }
    } else {
        throw new AttributeNotFoundException(name);
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 4 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException 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 5 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException 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)

Aggregations

InvalidAttributeValueException (javax.management.InvalidAttributeValueException)39 AttributeNotFoundException (javax.management.AttributeNotFoundException)26 ReflectionException (javax.management.ReflectionException)24 MBeanException (javax.management.MBeanException)23 Attribute (javax.management.Attribute)19 InstanceNotFoundException (javax.management.InstanceNotFoundException)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 RuntimeOperationsException (javax.management.RuntimeOperationsException)8 AttributeList (javax.management.AttributeList)6 IntrospectionException (javax.management.IntrospectionException)6 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)6 Test (org.testng.annotations.Test)6 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 Method (java.lang.reflect.Method)5 URI (java.net.URI)5 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 RuntimeErrorException (javax.management.RuntimeErrorException)5 Consumes (javax.ws.rs.Consumes)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5