Example #1
0
  /**
   * Retrieves the identifying number of the relation definition that is 'allowed' between two
   * specified node types. The results are dependent on there being only one type of relation
   * between two node types (not enforced, thus unpredictable). Makes use of a typeRelNodes.
   *
   * @param snum The first objectnode type (the source)
   * @param dnum The second objectnode type (the destination)
   * @return the number of the found relation, or -1 if either no relation was found, or more than
   *     one was found.
   */
  public int getAllowedRelationType(int snum, int dnum) {
    Set<MMObjectNode> set =
        new HashSet<MMObjectNode>(typeRelNodes.getBySourceDestination(snum, dnum));
    set.addAll(inverseTypeRelNodes.getByDestinationSource(dnum, snum));

    if (set.size() != 1) {
      return -1;
    } else {
      MMObjectNode n = set.iterator().next();
      return n.getIntValue("rnumber");
    }
  }
Example #2
0
 /**
  * A Set of all allowed relations of a certain role between two builders. Distinction is made
  * between source and destination depending on passed directionality.
  *
  * @since MMBase-1.6.2
  */
 public Set<MMObjectNode> getAllowedRelations(
     int builder1, int builder2, int role, int directionality) {
   Set<MMObjectNode> res = new HashSet<MMObjectNode>();
   if (directionality != RelationStep.DIRECTIONS_SOURCE) {
     res.addAll(typeRelNodes.getBySourceDestinationRole(builder1, builder2, role));
   }
   if (directionality != RelationStep.DIRECTIONS_DESTINATION
       && (directionality != RelationStep.DIRECTIONS_EITHER || res.isEmpty())) {
     res.addAll(inverseTypeRelNodes.getByDestinationSourceRole(builder2, builder1, role));
   }
   return res;
 }