Exemple #1
0
 @Override
 public boolean accept(Activation activation) {
   String ruleName = activation.getRule().getName();
   if (ruleName.startsWith(this.startPrefix)) {
     return true;
   }
   return false;
 }
Exemple #2
0
  public SituationCast(Activation activation, Class<?> type) throws Exception {

    int counter;
    String roleLabel;
    Object obj;

    Rule rule = (Rule) activation.getRule();
    List<String> LHSIdentifiers = new ArrayList<String>(rule.getDeclarations().keySet());
    List<Field> situationRoleFields = SituationUtils.getSituationRoleFields(type);

    for (Field field : situationRoleFields) {
      Role role = field.getAnnotation(Role.class);
      if (role != null) {

        if (role.label() != "") {
          roleLabel = new String(role.label());
        } else {
          roleLabel = new String(field.getName());
        }

        if (field.getType().equals(java.util.Set.class)) {
          Set<Object> set = new HashSet<Object>();
          counter = 1;
          do {
            obj = null;
            roleLabel = new String(roleLabel + "$" + counter);
            if (LHSIdentifiers.contains(roleLabel)) {
              obj = activation.getDeclarationValue(roleLabel);
              set.add(obj);
            }
            counter++;
          } while (obj != null);
          if (set.size() < 2) throw new Exception();
          this.put(field.getName(), set);
        } else {
          this.put(roleLabel, activation.getDeclarationValue(roleLabel));
        }
      }
    }
  }