FileDocCategorySizeDatePackage
RelationSupport.javaAPI DocJava SE 5 API62843Fri Aug 26 14:57:36 BST 2005javax.management.relation

RelationSupport

public class RelationSupport extends Object implements RelationSupportMBean, MBeanRegistration
A RelationSupport object is used internally by the Relation Service to represent simple relations (only roles, no properties or methods), with an unlimited number of roles, of any relation type. As internal representation, it is not exposed to the user.

RelationSupport class conforms to the design patterns of standard MBean. So the user can decide to instantiate a RelationSupport object himself as a MBean (as it follows the MBean design patterns), to register it in the MBean Server, and then to add it in the Relation Service.

The user can also, when creating his own MBean relation class, have it extending RelationSupport, to retrieve the implementations of required interfaces (see below).

It is also possible to have in a user relation MBean class a member being a RelationSupport object, and to implement the required interfaces by delegating all to this member.

RelationSupport implements the Relation interface (to be handled by the Relation Service).

It implements also the MBeanRegistration interface to be able to retrieve the MBean Server where it is registered (if registered as a MBean) to access to its Relation Service.

since
1.5

Fields Summary
private String
myRelId
private ObjectName
myRelServiceName
private MBeanServer
myRelServiceMBeanServer
private String
myRelTypeName
private HashMap
myRoleName2ValueMap
private Boolean
myInRelServFlg
private static String
localClassName
Constructors Summary
public RelationSupport(String theRelId, ObjectName theRelServiceName, String theRelTypeName, RoleList theRoleList)
Creates object.

This constructor has to be used when the RelationSupport object will be registered as a MBean by the user, or when creating a user relation MBean those class extends RelationSupport.

Nothing is done at the Relation Service level, i.e. the RelationSupport object is not added, and no check if the provided values are correct. The object is always created, EXCEPT if:

- one mandatory parameter is not provided

- the same name is used for two roles.

To be handled as a relation, the object has then to be added in the Relation Service using Relation Service method addRelation().

param
theRelId relation identifier, to identify the relation in the Relation Service.

Expected to be unique in the given Relation Service.

param
theRelServiceName ObjectName of the Relation Service where the relation will be registered.

It is required as this is the Relation Service that is aware of the definition of the relation type of given relation, so that will be able to check update operations (set).

param
theRelTypeName Name of relation type.

Expected to have been created in given Relation Service.

param
theRoleList list of roles (Role objects) to initialised the relation. Can be null.

Expected to conform to relation info in associated relation type.

exception
InvalidRoleValueException if the same name is used for two roles.
exception
IllegalArgumentException if a required value (Relation Service Object Name, etc.) is not provided as parameter.


    //
    // Constructors
    //

                                                                                                                                                                                                                                                        
      
			 
			 
			 
	 
                

	super();

	if (isTraceOn())
            trace("Constructor: entering", null);

	// Can throw InvalidRoleValueException and IllegalArgumentException
	initMembers(theRelId,
		    theRelServiceName,
		    null,
		    theRelTypeName,
		    theRoleList);

	if (isTraceOn())
	    trace("Constructor: exiting", null);
    
public RelationSupport(String theRelId, ObjectName theRelServiceName, MBeanServer theRelServiceMBeanServer, String theRelTypeName, RoleList theRoleList)
Creates object.

This constructor has to be used when the user relation MBean implements the interfaces expected to be supported by a relation by delegating to a RelationSupport object.

This object needs to know the Relation Service expected to handle the relation. So it has to know the MBean Server where the Relation Service is registered.

According to a limitation, a relation MBean must be registered in the same MBean Server as the Relation Service expected to handle it. So the user relation MBean has to be created and registered, and then the wrapped RelationSupport object can be created with identified MBean Server.

Nothing is done at the Relation Service level, i.e. the RelationSupport object is not added, and no check if the provided values are correct. The object is always created, EXCEPT if:

- one required parameter is not provided

- the same name is used for two roles.

To be handled as a relation, the object has then to be added in the Relation Service using the Relation Service method addRelation().

param
theRelId relation identifier, to identify the relation in the Relation Service.

Expected to be unique in the given Relation Service.

param
theRelServiceName ObjectName of the Relation Service where the relation will be registered.

It is required as this is the Relation Service that is aware of the definition of the relation type of given relation, so that will be able to check update operations (set).

param
theRelServiceMBeanServer MBean Server where the wrapping MBean is or will be registered.

Expected to be the MBean Server where the Relation Service is or will be registered.

param
theRelTypeName Name of relation type.

Expected to have been created in given Relation Service.

param
theRoleList list of roles (Role objects) to initialised the relation. Can be null.

Expected to conform to relation info in associated relation type.

exception
InvalidRoleValueException if the same name is used for two roles.
exception
IllegalArgumentException if a required value (Relation Service Object Name, etc.) is not provided as parameter.


	super();

	if (theRelServiceMBeanServer == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("Constructor: entering", null);

	// Can throw InvalidRoleValueException and
	// IllegalArgumentException
	initMembers(theRelId,
		    theRelServiceName,
		    theRelServiceMBeanServer,
		    theRelTypeName,
		    theRoleList);

	if (isTraceOn())
	    trace("Constructor: exiting", null);
    
Methods Summary
private voiddebug(java.lang.String methodName, java.lang.String info)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, localClassName, methodName, info);
	Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, "", "", "\n");
    
public javax.management.relation.RoleResultgetAllRoles()
Returns all roles present in the relation.

return
a RoleResult object, including a RoleList (for roles successfully retrieved) and a RoleUnresolvedList (for roles not readable).
exception
RelationServiceNotRegisteredException if the Relation Service is not registered in the MBean Server


	if (isTraceOn())
            trace("getAllRoles: entering", null);

	RoleResult result = null;
	try {
	    result = getAllRolesInt(false, null);
	} catch (IllegalArgumentException exc) {
	    // OK : Invalid parameters, ignore...
	}

	if (isTraceOn())
            trace("getAllRoles: exiting", null);
	return result;
    
javax.management.relation.RoleResultgetAllRolesInt(boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ)


	if (theRelServCallFlg && theRelServ == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn())
	    debug("getAllRolesInt: entering", null);

	ArrayList roleNameList = null;
	synchronized(myRoleName2ValueMap) {
	    roleNameList =
		new ArrayList(myRoleName2ValueMap.keySet());
	}
	String[] roleNames = new String[roleNameList.size()];
	int i = 0;
	for (Iterator roleNameIter = roleNameList.iterator();
	     roleNameIter.hasNext();) {
	    String currRoleName = (String)(roleNameIter.next());
	    roleNames[i] = currRoleName;
	    i++;
	}

	RoleResult result = getRolesInt(roleNames,
					theRelServCallFlg,
					theRelServ);

	if (isDebugOn())
	    debug("getAllRolesInt: exiting", null);
	return result;
    
public java.util.MapgetReferencedMBeans()
Retrieves MBeans referenced in the various roles of the relation.

return
a HashMap mapping:

ObjectName -> ArrayList of String (role names)


	if (isTraceOn())
            trace("getReferencedMBeans: entering", null);

	HashMap refMBeanMap = new HashMap();

	synchronized(myRoleName2ValueMap) {

	    for (Iterator roleIter = (myRoleName2ValueMap.values()).iterator();
		 roleIter.hasNext();) {

		Role currRole = (Role)(roleIter.next());

		String currRoleName = currRole.getRoleName();
		// Retrieves ObjectNames of MBeans referenced in current role
		ArrayList currRefMBeanList = (ArrayList)
		    (currRole.getRoleValue());

		for (Iterator mbeanIter = currRefMBeanList.iterator();
		     mbeanIter.hasNext();) {

		    ObjectName currRoleObjName =
			(ObjectName)(mbeanIter.next());

		    // Sees if current MBean has been already referenced in
		    // roles already seen
		    ArrayList mbeanRoleNameList =
			(ArrayList)(refMBeanMap.get(currRoleObjName));

		    boolean newRefFlg = false;
		    if (mbeanRoleNameList == null) {
			newRefFlg = true;
			mbeanRoleNameList = new ArrayList();
		    }
		    mbeanRoleNameList.add(currRoleName);
		    if (newRefFlg) {
			refMBeanMap.put(currRoleObjName, mbeanRoleNameList);
		    }
		}
	    }
	}

	if (isTraceOn())
            trace("getReferencedMBeans: exiting", null);
	return refMBeanMap;		    
    
public java.lang.StringgetRelationId()
Returns relation identifier (used to uniquely identify the relation inside the Relation Service).

return
the relation id.

	return myRelId;
    
public javax.management.ObjectNamegetRelationServiceName()
Returns ObjectName of the Relation Service handling the relation.

return
the ObjectName of the Relation Service.

	return myRelServiceName;
    
public java.lang.StringgetRelationTypeName()
Returns name of associated relation type.

	return myRelTypeName;
    
public java.util.ListgetRole(java.lang.String theRoleName)
Retrieves role value for given role name.

Checks if the role exists and is readable according to the relation type.

param
theRoleName name of role
return
the ArrayList of ObjectName objects being the role value
exception
IllegalArgumentException if null role name
exception
RoleNotFoundException if:

- there is no role with given name

- the role is not readable.

exception
RelationServiceNotRegisteredException if the Relation Service is not registered in the MBean Server
see
#setRole


	if (theRoleName == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
	    trace("getRole: entering", theRoleName);

	// Can throw RoleNotFoundException and
	// RelationServiceNotRegisteredException
	ArrayList result = (ArrayList)
	    (getRoleInt(theRoleName, false, null, false));

	if (isTraceOn())
	    trace("getRole: exiting", null);
	return result;
    
public java.lang.IntegergetRoleCardinality(java.lang.String theRoleName)
Returns the number of MBeans currently referenced in the given role.

param
theRoleName name of role
return
the number of currently referenced MBeans in that role
exception
IllegalArgumentException if null role name
exception
RoleNotFoundException if there is no role with given name


	if (theRoleName == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("getRoleCardinality: entering", theRoleName);

	// Try to retrieve the role
	Role role = null;
	synchronized(myRoleName2ValueMap) {
	    // No null Role is allowed, so direct use of get()
	    role = (Role)(myRoleName2ValueMap.get(theRoleName));
	}
	if (role == null) {
	    int pbType = RoleStatus.NO_ROLE_WITH_NAME;
	    // Will throw a RoleNotFoundException
	    //
	    // Will not throw InvalidRoleValueException, so catch it for the
	    // compiler
	    try {
		RelationService.throwRoleProblemException(pbType,
							  theRoleName);
	    } catch (InvalidRoleValueException exc) {
		// OK : Do not throw InvalidRoleValueException as
		//      a RoleNotFoundException will be thrown.
	    }
	}

	ArrayList roleValue = (ArrayList)(role.getRoleValue());

	if (isTraceOn())
            trace("getRoleCardinality: exiting", null);
	return new Integer(roleValue.size());
    
java.lang.ObjectgetRoleInt(java.lang.String theRoleName, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ, boolean theMultiRoleFlg)


	if (theRoleName == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    String str = "theRoleName " + theRoleName;
	    debug("getRoleInt: entering", str);
	}

	int pbType = 0;

	Role role = null;
	synchronized(myRoleName2ValueMap) {
	    // No null Role is allowed, so direct use of get()
	    role = (Role)(myRoleName2ValueMap.get(theRoleName));
	}

	if (role == null) {
		pbType = RoleStatus.NO_ROLE_WITH_NAME;

	} else {
	    // Checks if the role is readable
	    Integer status = null;

	    if (theRelServCallFlg) {

		// Call from the Relation Service, so direct access to it,
		// avoiding MBean Server
		// Shall not throw a RelationTypeNotFoundException
		try {
		    status = theRelServ.checkRoleReading(theRoleName,
							 myRelTypeName);
		} catch (RelationTypeNotFoundException exc) {
		    throw new RuntimeException(exc.getMessage());
		}

	    } else {

		// Call from getRole() method above
		// So we have a MBean. We must access the Relation Service
		// via the MBean Server.		
		Object[] params = new Object[2];
		params[0] = theRoleName;
		params[1] = myRelTypeName;
		String[] signature = new String[2];
		signature[0] = "java.lang.String";
		signature[1] = "java.lang.String";
		// Can throw InstanceNotFoundException if the Relation
		// Service is not registered (to be catched in any case and
		// transformed into RelationServiceNotRegisteredException).
		//
		// Shall not throw a MBeanException, or a ReflectionException
		// or an InstanceNotFoundException
		try {
		    status = (Integer)
			(myRelServiceMBeanServer.invoke(myRelServiceName,
							"checkRoleReading",
							params,
							signature));
		} catch (MBeanException exc1) {
		    throw new RuntimeException("incorrect relation type");
		} catch (ReflectionException exc2) {
		    throw new RuntimeException(exc2.getMessage());
		} catch (InstanceNotFoundException exc3) {
		    throw new RelationServiceNotRegisteredException(
							    exc3.getMessage());
		}
	    }

	    pbType = status.intValue();
	}

	Object result = null;

	if (pbType == 0) {
	    // Role can be retrieved

	    if (!(theMultiRoleFlg)) {
		// Single role retrieved: returns its value
		// Note: no need to test if role value (list) not null before
		//       cloning, null value not allowed, empty list if
		//       nothing.
		result = (ArrayList)
		    (((ArrayList)(role.getRoleValue())).clone());

	    } else {
		// Role retrieved during multi-role retrieval: returns the
		// role
		result = (Role)(role.clone());
	    }

	} else {
	    // Role not retrieved

	    if (!(theMultiRoleFlg)) {
		// Problem when retrieving a simple role: either role not
		// found or not readable, so raises a RoleNotFoundException.
		try {
		    RelationService.throwRoleProblemException(pbType,
							      theRoleName);
		    // To keep compiler happy :)
		    return null;
		} catch (InvalidRoleValueException exc) {
		    throw new RuntimeException(exc.getMessage());
		}

	    } else {
		// Problem when retrieving a role in a multi-role retrieval:
		// returns a RoleUnresolved object
		result = new RoleUnresolved(theRoleName, null, pbType);
	    }
	}

	if (isDebugOn())
	    debug("getRoleInt: exiting", null);	
	return result;
    
public javax.management.relation.RoleResultgetRoles(java.lang.String[] theRoleNameArray)
Retrieves values of roles with given names.

Checks for each role if it exists and is readable according to the relation type.

param
theRoleNameArray array of names of roles to be retrieved
return
a RoleResult object, including a RoleList (for roles successfully retrieved) and a RoleUnresolvedList (for roles not retrieved).
exception
IllegalArgumentException if null role name
exception
RelationServiceNotRegisteredException if the Relation Service is not registered in the MBean Server
see
#setRoles


	if (theRoleNameArray == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("getRoles: entering", null);

	// Can throw RelationServiceNotRegisteredException
	RoleResult result = getRolesInt(theRoleNameArray, false, null);

	if (isTraceOn())
            trace("getRoles: exiting", null);
	return result;
    
javax.management.relation.RoleResultgetRolesInt(java.lang.String[] theRoleNameArray, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ)


	if (theRoleNameArray == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn())
	    debug("getRolesInt: entering", null);

	RoleList roleList = new RoleList();
	RoleUnresolvedList roleUnresList = new RoleUnresolvedList();

	for (int i = 0; i < theRoleNameArray.length; i++) {
	    String currRoleName = theRoleNameArray[i];

	    Object currResult = null;

	    // Can throw RelationServiceNotRegisteredException
	    //
	    // RoleNotFoundException: not possible but catch it for compiler :)
	    try {
		currResult = getRoleInt(currRoleName,
					theRelServCallFlg,
					theRelServ,
					true);

	    } catch (RoleNotFoundException exc) {
		return null; // :)
	    }

	    if (currResult instanceof Role) {
		// Can throw IllegalArgumentException if role is null
		// (normally should not happen :(
		try {
		    roleList.add((Role)currResult);
		} catch (IllegalArgumentException exc) {
		    throw new RuntimeException(exc.getMessage());
		}

	    } else if (currResult instanceof RoleUnresolved) {
		// Can throw IllegalArgumentException if role is null
		// (normally should not happen :(
		try {
		    roleUnresList.add((RoleUnresolved)currResult);
		} catch (IllegalArgumentException exc) {
		    throw new RuntimeException(exc.getMessage());
		}
	    }
	}

	RoleResult result = new RoleResult(roleList, roleUnresList);
	if (isDebugOn())
	    debug("getRolesInt: exiting", null);
	return result;
    
public voidhandleMBeanUnregistration(javax.management.ObjectName theObjName, java.lang.String theRoleName)
Callback used by the Relation Service when a MBean referenced in a role is unregistered.

The Relation Service will call this method to let the relation take action to reflect the impact of such unregistration.

BEWARE. the user is not expected to call this method.

Current implementation is to set the role with its current value (list of ObjectNames of referenced MBeans) without the unregistered one.

param
theObjName ObjectName of unregistered MBean
param
theRoleName name of role where the MBean is referenced
exception
IllegalArgumentException if null parameter
exception
RoleNotFoundException if role does not exist in the relation or is not writable
exception
InvalidRoleValueException if role value does not conform to the associated role info (this will never happen when called from the Relation Service)
exception
RelationServiceNotRegisteredException if the Relation Service is not registered in the MBean Server
exception
RelationTypeNotFoundException if the relation type has not been declared in the Relation Service.
exception
RelationNotFoundException if this method is called for a relation MBean not added in the Relation Service.


	if (theObjName == null || theRoleName == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("handleMBeanUnregistration: entering",
		  "theObjName " + theObjName + ", theRoleName " + theRoleName);

	// Can throw RoleNotFoundException, InvalidRoleValueException,
	// or RelationTypeNotFoundException
	handleMBeanUnregistrationInt(theObjName,
				     theRoleName,
				     false,
				     null);

	if (isTraceOn())
            trace("handleMBeanUnregistration: exiting", null);
	return;
    
voidhandleMBeanUnregistrationInt(javax.management.ObjectName theObjName, java.lang.String theRoleName, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ)


	if (theObjName == null ||
	    theRoleName == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    String str =
		"theObjName " + theObjName
		+ ", theRoleName " + theRoleName
		+ ", theRelServCallFlg " + theRelServCallFlg;
	    debug("handleMBeanUnregistrationInt: entering", str);
	}

	// Retrieves current role value
	Role role = null;
	synchronized(myRoleName2ValueMap) {
	    role = (Role)(myRoleName2ValueMap.get(theRoleName));
	}

	if (role == null) {
	    StringBuffer excMsgStrB = new StringBuffer();
	    // Revisit [cebro] Localize message
	    String excMsg = "No role with name ";
	    excMsgStrB.append(excMsg);
	    excMsgStrB.append(theRoleName);
	    throw new RoleNotFoundException(excMsgStrB.toString());
	}
	ArrayList currRoleValue = (ArrayList)(role.getRoleValue());

	// Note: no need to test if list not null before cloning, null value
	//       not allowed for role value.
	ArrayList newRoleValue = (ArrayList)(currRoleValue.clone());
	newRoleValue.remove(theObjName);
	Role newRole = new Role(theRoleName, newRoleValue);

	// Can throw InvalidRoleValueException,
	// RelationTypeNotFoundException
	// (RoleNotFoundException already detected)
	Object result =
	    setRoleInt(newRole, theRelServCallFlg, theRelServ, false);

	if (isDebugOn())
	    debug("handleMBeanUnregistrationInt: exiting", null);
	return;
    
private voidinitMembers(java.lang.String theRelId, javax.management.ObjectName theRelServiceName, javax.management.MBeanServer theRelServiceMBeanServer, java.lang.String theRelTypeName, javax.management.relation.RoleList theRoleList)


	if (theRelId == null ||
	    theRelServiceName == null ||
	    theRelTypeName == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    StringBuffer strB =
		new StringBuffer("theRelId " + theRelId
				 + ", theRelServiceName "
				 + theRelServiceName.toString()
				 + ", theRelTypeName " + theRelTypeName);
	    if (theRoleList != null) {
		strB.append(", theRoleList " + theRoleList.toString());
	    }
	    debug("initMembers: entering", strB.toString());
	}

	myRelId = theRelId;
	myRelServiceName = theRelServiceName;
	myRelServiceMBeanServer = theRelServiceMBeanServer;
	myRelTypeName = theRelTypeName;
	// Can throw InvalidRoleValueException
	initRoleMap(theRoleList);
	myInRelServFlg = new Boolean(false);

	if (isDebugOn())
	    debug("initMembers: exiting", null);
	return;
    
private voidinitRoleMap(javax.management.relation.RoleList theRoleList)


	if (theRoleList == null) {
	    return;
	}

	if (isDebugOn())
	    debug("initRoleMap: entering", theRoleList.toString());

	synchronized(myRoleName2ValueMap) {

	    for (Iterator roleIter = theRoleList.iterator();
		 roleIter.hasNext();) {

		// No need to check if role is null, it is not allowed to store
		// a null role in a RoleList :)
		Role currRole = (Role)(roleIter.next());
		String currRoleName = currRole.getRoleName();

		if (myRoleName2ValueMap.containsKey(currRoleName)) {
		    // Role already provided in current list
		    // Revisit [cebro] Localize message
		    StringBuffer excMsgStrB = new StringBuffer("Role name ");
		    excMsgStrB.append(currRoleName);
		    excMsgStrB.append(" used for two roles.");
		    throw new InvalidRoleValueException(excMsgStrB.toString());
		}

		myRoleName2ValueMap.put(currRoleName,
					(Role)(currRole.clone()));
	    }
	}

	if (isDebugOn())
	    debug("initRoleMap: exiting", null);
	return;
    
private booleanisDebugOn()

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_RELATION);
    
public java.lang.BooleanisInRelationService()
Returns an internal flag specifying if the object is still handled by the Relation Service.

	Boolean result = null;
	synchronized(myInRelServFlg) {
	    result = new Boolean(myInRelServFlg.booleanValue());
	}
	return result;
    
private booleanisTraceOn()


    // trace level
       
        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_RELATION);
    
public voidpostDeregister()

	return;
    
public voidpostRegister(java.lang.Boolean registrationDone)

	return;
    
public voidpreDeregister()

	return;
    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)


	myRelServiceMBeanServer = server;
	return name;
    
public javax.management.relation.RoleListretrieveAllRoles()
Returns all roles in the relation without checking read mode.

return
a RoleList


	if (isTraceOn())
            trace("retrieveAllRoles: entering", null);

	RoleList result = null;
	synchronized(myRoleName2ValueMap) {
	    result =
		new RoleList(new ArrayList(myRoleName2ValueMap.values()));
	}

	if (isTraceOn())
            trace("retrieveAllRoles: exiting", null);
	return result;
    
private voidsendRoleUpdateNotification(javax.management.relation.Role theNewRole, java.util.List theOldRoleValue, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ)


	if (theNewRole == null ||
	    theOldRoleValue == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    String str =
		"theNewRole " + theNewRole
		+ ", theOldRoleValue " + theOldRoleValue
		+ ", theRelServCallFlg " + theRelServCallFlg;
	    debug("sendRoleUpdateNotification: entering", str);
	}

	if (theRelServCallFlg) {
	    // Direct call to the Relation Service
	    // Shall not throw a RelationNotFoundException for an internal
	    // relation
	    try {
		theRelServ.sendRoleUpdateNotification(myRelId,
						      theNewRole,
						      theOldRoleValue);
	    } catch (RelationNotFoundException exc) {
		throw new RuntimeException(exc.getMessage());
	    }

	} else {

	    Object[] params = new Object[3];
	    params[0] = myRelId;
	    params[1] = theNewRole;
	    params[2] = ((ArrayList)theOldRoleValue);
	    String[] signature = new String[3];
	    signature[0] = "java.lang.String";
	    signature[1] = "javax.management.relation.Role";
	    signature[2] = "java.util.List";

	    // Can throw InstanceNotFoundException if the Relation Service
	    // is not registered (to be transformed).
	    //
	    // Can throw a MBeanException wrapping a
	    // RelationNotFoundException (to be raised in any case): wrapped
	    // exception to be thrown
	    //
	    // Shall not throw a ReflectionException
	    try {
		myRelServiceMBeanServer.invoke(myRelServiceName,
					       "sendRoleUpdateNotification",
					       params,
					       signature);
	    } catch (ReflectionException exc1) {
		throw new RuntimeException(exc1.getMessage());
	    } catch (InstanceNotFoundException exc2) {
		throw new RelationServiceNotRegisteredException(
							    exc2.getMessage());
	    } catch (MBeanException exc3) {
		Exception wrappedExc = exc3.getTargetException();
		if (wrappedExc instanceof RelationNotFoundException) {
		    throw ((RelationNotFoundException)wrappedExc);
		} else {
		    throw new RuntimeException(wrappedExc.getMessage());
		}
	    }
	}

	if (isDebugOn())
	    debug("sendRoleUpdateNotification: exiting", null);
	return;
    
public voidsetRelationServiceManagementFlag(java.lang.Boolean theFlg)


	if (theFlg == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}
	synchronized(myInRelServFlg) {
	    myInRelServFlg = new Boolean(theFlg.booleanValue());
	}
	return;
    
public voidsetRole(javax.management.relation.Role theRole)
Sets the given role.

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).

param
theRole role to be set (name and new value)
exception
IllegalArgumentException if null role
exception
RoleNotFoundException if the role is not writable (no test on the write access mode performed when initialising the role)
exception
InvalidRoleValueException if value provided for role is not valid, i.e.:

- the number of referenced MBeans in given value is less than expected minimum degree

- the number of referenced MBeans in provided value exceeds expected maximum degree

- one referenced MBean in the value is not an Object of the MBean class expected for that role

- 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 the relation type has not been declared in the Relation Service
exception
RelationNotFoundException if the relation has not been added in the Relation Service.
see
#getRole


	if (theRole == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("setRole: entering", theRole.toString());

	// Will return null :)
	Object result = setRoleInt(theRole, false, null, false);

	if (isTraceOn())
            trace("setRole: exiting", null);
	return;
    
java.lang.ObjectsetRoleInt(javax.management.relation.Role theRole, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ, boolean theMultiRoleFlg)


	if (theRole == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    String str =
		"theRole " + theRole
		+ ", theRelServCallFlg " + theRelServCallFlg
		+ ", theMultiRoleFlg " + theMultiRoleFlg;
	    debug("setRoleInt: entering" , str);
	}

	String roleName = theRole.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 initialisation of role when creating the relation
	// (roles provided in the RoleList parameter are directly set but
	// roles automatically initialised are set using setRole())
	Role role = null;
	synchronized(myRoleName2ValueMap) {
	    role = (Role)(myRoleName2ValueMap.get(roleName));
	}

	ArrayList oldRoleValue = null;
	Boolean initFlg = null;

	if (role == null) {
	    initFlg = new Boolean(true);
	    oldRoleValue = new ArrayList();

	} else {
	    initFlg = new Boolean(false);
	    oldRoleValue = (ArrayList)(role.getRoleValue());
	}

	// Checks if the role can be set: is writable (except if
	// initialisation) and correct value
	try {
	    Integer status = null;

	    if (theRelServCallFlg) {

		// Call from the Relation Service, so direct access to it,
		// avoiding MBean Server
		//
		// Shall not raise a RelationTypeNotFoundException
		status = theRelServ.checkRoleWriting(theRole,
						     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] = theRole;
		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 initialising the role
		// If role being initialised:
		// - do not send an update notification
		// - do not try to update internal map of Relation Service
		//   listing referenced MBeans, as role is initialised to an
		//   empty list

		// Sends a notification (RelationNotification)
		// Can throw a RelationNotFoundException
		sendRoleUpdateNotification(theRole,
					   oldRoleValue,
					   theRelServCallFlg,
					   theRelServ);

		// Updates the role map of the Relation Service
		// Can throw RelationNotFoundException
		updateRelationServiceMap(theRole,
					 oldRoleValue,
					 theRelServCallFlg,
					 theRelServ);

	    }

	    // Sets the role
	    synchronized(myRoleName2ValueMap) {
		myRoleName2ValueMap.put(roleName,
					(Role)(theRole.clone()));
	    }

	    // Single role set: returns null: nothing to set in result

	    if (theMultiRoleFlg) {
		// Multi-roles retrieval: returns the role
		result = theRole;
	    }

	} else {

	    // Role not set

	    if (!(theMultiRoleFlg)) {
		// 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,
					    theRole.getRoleValue(),
					    pbType);
	    }
	}

	if (isDebugOn())
	    debug("setRoleInt: exiting", null);
	return result;
    
public javax.management.relation.RoleResultsetRoles(javax.management.relation.RoleList theRoleList)
Sets the given roles.

Will check the role according to its corresponding role definition provided in relation's relation type

Will send one notification (RelationNotification with type RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the relation is a MBean or not) per updated role.

param
theRoleList list of roles to be set
return
a RoleResult object, including a RoleList (for roles successfully set) and a RoleUnresolvedList (for roles not set).
exception
IllegalArgumentException if null role name
exception
RelationServiceNotRegisteredException if the Relation Service is not registered in the MBean Server
exception
RelationTypeNotFoundException if the relation type has not been declared in the Relation Service.
exception
RelationNotFoundException if the relation MBean has not been added in the Relation Service.
see
#getRoles


	if (theRoleList == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("setRoles: entering", theRoleList.toString());

	RoleResult result = setRolesInt(theRoleList, false, null);

	if (isTraceOn())
            trace("setRoles: exiting", null);
	return result;
    
javax.management.relation.RoleResultsetRolesInt(javax.management.relation.RoleList theRoleList, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ)


	if (theRoleList == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    String str =
		"theRoleList " + theRoleList
		+ ", theRelServCallFlg " + theRelServCallFlg;
	    debug("setRolesInt: entering", str);
	}

	RoleList roleList = new RoleList();
	RoleUnresolvedList roleUnresList = new RoleUnresolvedList();

	for (Iterator roleIter = theRoleList.iterator();
	     roleIter.hasNext();) {

	    Role currRole = (Role)(roleIter.next());

	    Object currResult = null;
	    // Can throw:
	    // RelationServiceNotRegisteredException,
	    // RelationTypeNotFoundException
	    //
	    // Will not throw, due to parameters, RoleNotFoundException or
	    // InvalidRoleValueException, but catch them to keep compiler
	    // happy
	    try {
		currResult = setRoleInt(currRole,
					theRelServCallFlg,
					theRelServ,
					true);
	    } catch (RoleNotFoundException exc1) {
		// OK : Do not throw a RoleNotFoundException.
	    } catch (InvalidRoleValueException exc2) {
		// OK : Do not throw an InvalidRoleValueException.
	    }

	    if (currResult instanceof Role) {
		// Can throw IllegalArgumentException if role is null
		// (normally should not happen :(
		try {
		    roleList.add((Role)currResult);
		} catch (IllegalArgumentException exc) {
		    throw new RuntimeException(exc.getMessage());
		}

	    } else if (currResult instanceof RoleUnresolved) {
		// Can throw IllegalArgumentException if role is null
		// (normally should not happen :(
		try {
		    roleUnresList.add((RoleUnresolved)currResult);
		} catch (IllegalArgumentException exc) {
		    throw new RuntimeException(exc.getMessage());
		}
	    }
	}

	RoleResult result = new RoleResult(roleList, roleUnresList);

	if (isDebugOn())
	    debug("setRolesInt: exiting", null);
	return result;
    
private voidtrace(java.lang.String methodName, java.lang.String info)

        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, localClassName, methodName, info);
	Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, "", "", "\n");
    
private voidupdateRelationServiceMap(javax.management.relation.Role theNewRole, java.util.List theOldRoleValue, boolean theRelServCallFlg, javax.management.relation.RelationService theRelServ)


	if (theNewRole == null ||
	    theOldRoleValue == null ||
	    (theRelServCallFlg && theRelServ == null)) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn()) {
	    String str =
		"theNewRole " + theNewRole
		+ ", theOldRoleValue " + theOldRoleValue
		+ ", theRelServCallFlg " + theRelServCallFlg;
	    debug("updateRelationServiceMap: entering", str);
	}

	if (theRelServCallFlg) {
	    // Direct call to the Relation Service
	    // Shall not throw a RelationNotFoundException
	    try {
		theRelServ.updateRoleMap(myRelId,
					 theNewRole,
					 theOldRoleValue);
	    } catch (RelationNotFoundException exc) {
		throw new RuntimeException(exc.getMessage());
	    }

	} else {
	    Object[] params = new Object[3];
	    params[0] = myRelId;
	    params[1] = theNewRole;
	    params[2] = theOldRoleValue;
	    String[] signature = new String[3];
	    signature[0] = "java.lang.String";
	    signature[1] = "javax.management.relation.Role";
	    signature[2] = "java.util.List";
	    // Can throw InstanceNotFoundException if the Relation Service
	    // is not registered (to be transformed).
	    // Can throw a MBeanException wrapping a RelationNotFoundException:
	    // wrapped exception to be thrown
	    //
	    // Shall not throw a ReflectionException
	    try {
		myRelServiceMBeanServer.invoke(myRelServiceName,
					       "updateRoleMap",
					       params,
					       signature);
	    } catch (ReflectionException exc1) {
		throw new RuntimeException(exc1.getMessage());
	    } catch (InstanceNotFoundException exc2) {
		throw new
		     RelationServiceNotRegisteredException(exc2.getMessage());
	    } catch (MBeanException exc3) {
		Exception wrappedExc = exc3.getTargetException();
		if (wrappedExc instanceof RelationNotFoundException) {
		    throw ((RelationNotFoundException)wrappedExc);
		} else {
		    throw new RuntimeException(wrappedExc.getMessage());
		}
	    }
	}

	if (isDebugOn())
	    debug("updateRelationServiceMap: exiting", null);
	return;