Пример #1
0
  /**
   * 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.
   */
  protected void addRoleInfo(RoleInfo roleInfo)
      throws IllegalArgumentException, InvalidRelationTypeException {

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

    RELATION_LOGGER.entering(RelationTypeSupport.class.getName(), "addRoleInfo", roleInfo);

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

    RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(), "addRoleInfo");
    return;
  }
Пример #2
0
  /**
   * Constructor to be used for subclasses.
   *
   * @param relationTypeName Name of relation type.
   * @exception IllegalArgumentException if null parameter.
   */
  protected RelationTypeSupport(String relationTypeName) {
    if (relationTypeName == null) {
      String excMsg = "Invalid parameter.";
      throw new IllegalArgumentException(excMsg);
    }

    RELATION_LOGGER.entering(
        RelationTypeSupport.class.getName(), "RelationTypeSupport", relationTypeName);

    typeName = relationTypeName;

    RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(), "RelationTypeSupport");
    return;
  }
Пример #3
0
  /**
   * 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:
   *     <p>- the same name has been used for two different roles
   *     <p>- no role info provided
   *     <p>- one null role info provided
   */
  public RelationTypeSupport(String relationTypeName, RoleInfo[] roleInfoArray)
      throws IllegalArgumentException, InvalidRelationTypeException {

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

    RELATION_LOGGER.entering(
        RelationTypeSupport.class.getName(), "RelationTypeSupport", relationTypeName);

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

    RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(), "RelationTypeSupport");
    return;
  }
Пример #4
0
  // Initializes the members, i.e. type name and role info list.
  //
  // -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
  private void initMembers(String relationTypeName, RoleInfo[] roleInfoArray)
      throws IllegalArgumentException, InvalidRelationTypeException {

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

    RELATION_LOGGER.entering(RelationTypeSupport.class.getName(), "initMembers", 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));
    }

    RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(), "initMembers");
    return;
  }
Пример #5
0
  /**
   * 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.
   */
  public RoleInfo getRoleInfo(String roleInfoName)
      throws IllegalArgumentException, RoleInfoNotFoundException {

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

    RELATION_LOGGER.entering(RelationTypeSupport.class.getName(), "getRoleInfo", 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());
    }

    RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(), "getRoleInfo");
    return result;
  }