示例#1
0
  /**
   * forward an execute request a rule identified by its unique key
   *
   * @param key a string key identifying the rule instance to be fired
   * @param recipient the recipient of the method from which execution of the rule was triggered or
   *     null if it was a static method
   * @param args the arguments of the method from which execution of the rule was triggered
   */
  public static void execute(String key, Object recipient, Object[] args) throws ExecuteException {
    boolean enabled = isTriggeringEnabled();
    if (!enabled) {
      // we don't trigger code while we are doing rule housekeeping
      return;
    }

    // disable triggering until we get into actual rule code

    disableTriggersInternal();

    try {
      Rule rule = ruleKeyMap.get(key);
      if (Transformer.isVerbose()) {
        System.out.println("Rule.execute called for " + key);
      }

      // if the key is no longer present it just means the rule has been decommissioned so return
      if (rule == null) {
        if (Transformer.isVerbose()) {
          System.out.println("Rule.execute for decommissioned key " + key);
        }
        return;
      }

      rule.execute(recipient, args);
    } finally {
      // restore the status quo -- we must have been enabled if we got to this method
      enableTriggers();
    }
  }