FileDocCategorySizeDatePackage
RelationTypeSupport.javaAPI DocJava SE 6 API16223Tue Jun 10 00:26:18 BST 2008javax.management.relation

RelationTypeSupport

public class RelationTypeSupport extends Object implements RelationType
A RelationTypeSupport object implements the RelationType interface.

It represents a relation type, providing role information for each role expected to be supported in every relation of that type.

A relation type includes a relation type name and a list of role infos (represented by RoleInfo objects).

A relation type has to be declared in the Relation Service:

- either using the createRelationType() method, where a RelationTypeSupport object will be created and kept in the Relation Service

- either using the addRelationType() method where the user has to create an object implementing the RelationType interface, and this object will be used as representing a relation type in the Relation Service.

The serialVersionUID of this class is 4611072955724144607L.

since
1.5

Fields Summary
private static final long
oldSerialVersionUID
private static final long
newSerialVersionUID
private static final ObjectStreamField[]
oldSerialPersistentFields
private static final ObjectStreamField[]
newSerialPersistentFields
private static final long
serialVersionUID
private static final ObjectStreamField[]
serialPersistentFields
private static boolean
compat
private String
typeName
private Map
roleName2InfoMap
private boolean
isInRelationService
private static String
localClassName
Constructors Summary
public RelationTypeSupport(String relationTypeName, RoleInfo[] roleInfoArray)
Constructor where all role definitions are dynamically created and passed as parameter.

param
relationTypeName Name of relation type
param
roleInfoArray List of role definitions (RoleInfo objects)
exception
IllegalArgumentException if null parameter
exception
InvalidRelationTypeException if:

- the same name has been used for two different roles

- no role info provided

- one null role info provided


    //
    // Constructors
    //

                                                                     
      
			     
	 
	        

	if (relationTypeName == null || roleInfoArray == null) {
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

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

	// Can throw InvalidRelationTypeException, ClassNotFoundException
	// and NotCompliantMBeanException
	initMembers(relationTypeName, roleInfoArray);

	if (isTraceOn())
	    trace("Constructor: exiting", null);
	return;
    
protected RelationTypeSupport(String relationTypeName)
Constructor to be used for subclasses.

param
relationTypeName Name of relation type.
exception
IllegalArgumentException if null parameter.

	if (relationTypeName == null) {
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
	    trace("Protected constructor: entering", relationTypeName);

	typeName = relationTypeName;

	if (isTraceOn())
	    trace("Protected constructor: exiting", null);
	return;
    
Methods Summary
protected voidaddRoleInfo(javax.management.relation.RoleInfo roleInfo)
Add a role info. This method of course should not be used after the creation of the relation type, because updating it would invalidate that the relations created associated to that type still conform to it. Can throw a RuntimeException if trying to update a relation type declared in the Relation Service.

param
roleInfo role info to be added.
exception
IllegalArgumentException if null parameter.
exception
InvalidRelationTypeException if there is already a role info in current relation type with the same name.


	if (roleInfo == null) {
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn())
	    debug("addRoleInfo: entering", roleInfo.toString());

	if (isInRelationService) {
	    // Trying to update a declared relation type
	    String excMsg = "Relation type cannot be updated as it is declared in the Relation Service.";
	    throw new RuntimeException(excMsg);
	}

	String roleName = roleInfo.getName();

	// Checks if the role info has already been described
	if (roleName2InfoMap.containsKey(roleName)) {
	    StringBuilder excMsgStrB = new StringBuilder();
	    String excMsg = "Two role infos provided for role ";
	    excMsgStrB.append(excMsg);
	    excMsgStrB.append(roleName);
	    throw new InvalidRelationTypeException(excMsgStrB.toString());
	}

	roleName2InfoMap.put(roleName, new RoleInfo(roleInfo));

	if (isDebugOn())
	    debug("addRoleInfo: exiting", null);
	return;
    
static voidcheckRoleInfos(javax.management.relation.RoleInfo[] roleInfoArray)


	if (roleInfoArray == null) {
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (roleInfoArray.length == 0) {
	    // No role info provided
	    String excMsg = "No role info provided.";
	    throw new InvalidRelationTypeException(excMsg);
	}


	Set<String> roleNames = new HashSet<String>();

	for (int i = 0; i < roleInfoArray.length; i++) {
	    RoleInfo currRoleInfo = roleInfoArray[i];

	    if (currRoleInfo == null) {
		String excMsg = "Null role info provided.";
		throw new InvalidRelationTypeException(excMsg);
	    }

	    String roleName = currRoleInfo.getName();

	    // Checks if the role info has already been described
	    if (roleNames.contains(roleName)) {
		StringBuilder excMsgStrB = new StringBuilder();
		String excMsg = "Two role infos provided for role ";
		excMsgStrB.append(excMsg);
		excMsgStrB.append(roleName);
		throw new InvalidRelationTypeException(excMsgStrB.toString());
	    }
	    roleNames.add(roleName);
	}

	return;
    
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 java.lang.StringgetRelationTypeName()
Returns the relation type name.

return
the relation type name.

	return typeName;
    
public javax.management.relation.RoleInfogetRoleInfo(java.lang.String roleInfoName)
Returns the role info (RoleInfo object) for the given role info name (null if not found).

param
roleInfoName role info name
return
RoleInfo object providing role definition does not exist
exception
IllegalArgumentException if null parameter
exception
RoleInfoNotFoundException if no role info with that name in relation type.


	if (roleInfoName == null) {
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
	    trace("getRoleInfo: entering", roleInfoName);

	// No null RoleInfo allowed, so use get()
	RoleInfo result = roleName2InfoMap.get(roleInfoName);

	if (result == null) {
	    StringBuilder excMsgStrB = new StringBuilder();
	    String excMsg = "No role info for role ";
	    excMsgStrB.append(excMsg);
	    excMsgStrB.append(roleInfoName);
	    throw new RoleInfoNotFoundException(excMsgStrB.toString());
	}

	if (isTraceOn())
	    trace("getRoleInfo: exiting", null);
	return result;
    
public java.util.ListgetRoleInfos()
Returns the list of role definitions (ArrayList of RoleInfo objects).

	return new ArrayList<RoleInfo>(roleName2InfoMap.values());
    
private voidinitMembers(java.lang.String relationTypeName, javax.management.relation.RoleInfo[] roleInfoArray)


	if (relationTypeName == null || roleInfoArray == null) {
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isDebugOn())
	    debug("initMembers: entering", relationTypeName);

	typeName = relationTypeName;

	// Verifies role infos before setting them
	// Can throw InvalidRelationTypeException
	checkRoleInfos(roleInfoArray);

	for (int i = 0; i < roleInfoArray.length; i++) {
	    RoleInfo currRoleInfo = roleInfoArray[i];
	    roleName2InfoMap.put(currRoleInfo.getName(),
				 new RoleInfo(currRoleInfo));
	}

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

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_RELATION);
    
private booleanisTraceOn()


    // trace level
       
        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_RELATION);
    
private voidreadObject(java.io.ObjectInputStream in)
Deserializes a {@link RelationTypeSupport} from an {@link ObjectInputStream}.

      if (compat)
      {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
	typeName = (String) fields.get("myTypeName", null);
	if (fields.defaulted("myTypeName"))
        {
          throw new NullPointerException("myTypeName");
        }
	roleName2InfoMap =
	    (Map<String,RoleInfo>) fields.get("myRoleName2InfoMap", null);
	if (fields.defaulted("myRoleName2InfoMap"))
        {
          throw new NullPointerException("myRoleName2InfoMap");
        }
	isInRelationService = fields.get("myIsInRelServFlg", false);
	if (fields.defaulted("myIsInRelServFlg"))
        {
          throw new NullPointerException("myIsInRelServFlg");
        }
      }
      else
      {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
      }
    
voidsetRelationServiceFlag(boolean flag)

	isInRelationService = flag;
	return;
    
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 voidwriteObject(java.io.ObjectOutputStream out)
Serializes a {@link RelationTypeSupport} to an {@link ObjectOutputStream}.

      if (compat)
      {
        // Serializes this instance in the old serial form
        //
        ObjectOutputStream.PutField fields = out.putFields();
	fields.put("myTypeName", typeName);
	fields.put("myRoleName2InfoMap", roleName2InfoMap);
	fields.put("myIsInRelServFlg", isInRelationService);
	out.writeFields();
      }
      else
      {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
      }