/**
   * 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);
    }

    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;
  }
Esempio n. 2
0
  // Checks the given RoleInfo array to verify that:
  // - the array is not empty
  // - it does not contain a null element
  // - a given role name is used only for one RoleInfo
  //
  // -param roleInfoArray  array to be checked
  //
  // -exception IllegalArgumentException
  // -exception InvalidRelationTypeException  If:
  //  - the same name has been used for two different roles
  //  - no role info provided
  //  - one null role info provided
  static void checkRoleInfos(RoleInfo[] roleInfoArray)
      throws IllegalArgumentException, InvalidRelationTypeException {

    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;
  }
Esempio n. 3
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;
  }