bammodule.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 763 行 · 第 1/2 页

JAVA
763
字号
  public static void bam_send_presence_subscribe(Env env,                                                  String to,                                                  Serializable value)  {    getBrokerStream(env).presenceSubscribe(to, getJid(env), value);  }  public static void bam_send_presence_subscribed(Env env,                                                   String to,                                                   Serializable value)  {    getBrokerStream(env).presenceSubscribed(to, getJid(env), value);  }  public static void bam_send_presence_unsubscribe(Env env,                                                    String to,                                                    Serializable value)  {    getBrokerStream(env).presenceUnsubscribe(to, getJid(env), value);  }  public static void bam_send_presence_unsubscribed(Env env,                                                     String to,                                                     Serializable value)  {    getBrokerStream(env).presenceUnsubscribed(to, getJid(env), value);  }  public static void bam_send_presence_error(Env env,                                              String to,                                              Serializable value,                                             BamError error)  {    getBrokerStream(env).presenceError(to, getJid(env), value, error);  }  public static Value im_send_message(Env env,                                       String to,                                       String from,                                       Value body,                                      @Optional("chat") String type,                                      @Optional Value subject,                                      @Optional String thread,                                      @Optional Serializable[] extras)  {    Text[] subjects = null;    // extract subject text    if (subject != null) {      if (subject.isArray()) {        subjects = new Text[subject.getSize()];        int i = 0;        Iterator<Value> iterator = subject.getValueIterator(env);        while (iterator.hasNext()) {          Value subjectValue = iterator.next();          if (! subjectValue.isString())            return env.error("subject values must be strings");          subjects[i++] = new Text(subjectValue.toString());        }      }      else if (subject.isString()) {        if (! subject.isString())          return env.error("subject values must be strings");        subjects = new Text[] { new Text(subject.toString()) };      }    }    // extract body text    Text[] bodies = null;    if (body.isArray()) {      bodies = new Text[body.getSize()];      int i = 0;      Iterator<Value> iterator = body.getValueIterator(env);      while (iterator.hasNext()) {        Value bodyValue = iterator.next();        if (! bodyValue.isString())          return env.error("body values must be strings");        bodies[i++] = new Text(bodyValue.toString());      }    }    else if (body.isString()) {      if (! body.isString())        return env.error("body values must be strings");      bodies = new Text[] { new Text(body.toString()) };    }    ImMessage message = new ImMessage(to, from, type,                                       subjects, bodies, thread, extras);        bam_send_message(env, to, message);    return BooleanValue.TRUE;  }  public static RosterItem im_create_roster_item(Env env,                                                  String jid,                                                 @Optional String name,                                                 @Optional String subscription,                                                 @Optional                                                  ArrayList<String> groupList)  {    if ("".equals(subscription))      subscription = "to";    return new RosterItem(null, jid, name, subscription, groupList);  }  public static void im_send_roster(Env env,                                     long id, String to,                                     ArrayList<RosterItem> roster)  {    bam_send_query_result(env, id, to, new RosterQuery(roster));  }    private static ImPresence createPresence(Env env,                                            String to,                                            String from,                                           String show,                                           String status,                                           int priority,                                           ArrayList<Serializable> extras)  {    if ("".equals(from))      from = getJid(env);    if ("".equals(show))      show = null;    Text statusText = null;    if (! "".equals(status))      statusText = new Text(status);    return new ImPresence(to, from, show, statusText, priority, extras);  }  public static void im_send_presence(Env env,                                       String to,                                       @Optional String from,                                      @Optional String show,                                      @Optional String status,                                      @Optional int priority,                                      @Optional ArrayList<Serializable> extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence(env, to, presence);  }  public static void im_send_presence_unavailable(Env env,                                                   String to,                                                   @Optional String from,                                                  @Optional String show,                                                  @Optional String status,                                                  @Optional int priority,                                                  @Optional                                                   ArrayList<Serializable>                                                   extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence_unavailable(env, to, presence);  }  /**   * Makes a subscription request.   **/  public static void im_send_presence_subscribe(Env env,                                                 String to,                                                 @Optional String from,                                                @Optional String show,                                                @Optional String status,                                                @Optional int priority,                                                @Optional                                                 ArrayList<Serializable> extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence_subscribe(env, to, presence);  }  /**   * Approves a subscription request.   **/  public static void im_send_presence_subscribed(Env env,                                                  String to,                                                  @Optional String from,                                                 @Optional String show,                                                 @Optional String status,                                                 @Optional int priority,                                                 @Optional                                                  ArrayList<Serializable> extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence_subscribed(env, to, presence);  }  /**   * Makes an unsubscription request.   **/  public static void im_send_presence_unsubscribe(Env env,                                                   String to,                                                   @Optional String from,                                                  @Optional String show,                                                  @Optional String status,                                                  @Optional int priority,                                                  @Optional                                                   ArrayList<Serializable>                                                   extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence_unsubscribe(env, to, presence);  }  /**   * Rejects a subscription request.   **/  public static void im_send_presence_unsubscribed(Env env,                                                    String to,                                                    @Optional String from,                                                   @Optional String show,                                                   @Optional String status,                                                   @Optional int priority,                                                   @Optional                                                    ArrayList<Serializable>                                                    extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence_unsubscribed(env, to, presence);  }  public static void im_send_presence_probe(Env env,                                             String to,                                             @Optional String from,                                            @Optional String show,                                            @Optional String status,                                            @Optional int priority,                                            @Optional                                             ArrayList<Serializable> extras)  {    ImPresence presence =       createPresence(env, to, from, show, status, priority, extras);    bam_send_presence_probe(env, to, presence);  }  /**   * Dispatches messages, queries, and presences to handler functions based   * on their prefixes.   **/  public static Value bam_dispatch(Env env)  {    // manager script dispatch    BamPhpServiceManager manager = getServiceManager(env);    if (manager != null) {      AbstractFunction function = null;      if (env.getGlobalValue("_quercus_bam_start_service") != null) {        function = env.findFunction("bam_start_service");      }       else if (env.getGlobalValue("_quercus_bam_stop_service") != null) {        function = env.findFunction("bam_stop_service");      }      if (function == null) {        env.setGlobalValue("_quercus_bam_function_return", BooleanValue.FALSE);        return BooleanValue.FALSE;      }      Value jid = env.getGlobalValue("_quercus_bam_service_jid");      Value ret = function.call(env, jid);      env.setGlobalValue("_quercus_bam_function_return", ret);      return BooleanValue.TRUE;    }    // agent script dispatch    Value eventTypeValue = env.getGlobalValue("_quercus_bam_event_type");    if (eventTypeValue == null)      return BooleanValue.FALSE;    BamEventType eventType = (BamEventType) eventTypeValue.toJavaObject();    Value to = env.getGlobalValue("_quercus_bam_to");    Value from = env.getGlobalValue("_quercus_bam_from");    Value value = env.getGlobalValue("_quercus_bam_value");    AbstractFunction function = findFunction(env, eventType.getPrefix(), value);    if (function == null) {      log.fine(L.l("bam handler function not found for {0}", eventType));      return BooleanValue.FALSE;    }    Value functionReturn = BooleanValue.FALSE;    if (eventType.hasId() && eventType.hasError()) {      Value id = env.getGlobalValue("_quercus_bam_id");      Value error = env.getGlobalValue("_quercus_bam_error");      functionReturn = function.call(env, id, to, from, value, error);    }     else if (! eventType.hasId() && eventType.hasError()) {      Value error = env.getGlobalValue("_quercus_bam_error");      functionReturn = function.call(env, to, from, value, error);    }    else if (eventType.hasId() && ! eventType.hasError()) {      Value id = env.getGlobalValue("_quercus_bam_id");      functionReturn = function.call(env, id, to, from, value);    }    else {      functionReturn = function.call(env, to, from, value);    }    env.setGlobalValue("_quercus_bam_function_return", functionReturn);    return functionReturn;  }  /**   * Finds the handler function for a value with the given prefix.  If there   * is a specific handler for a specific value type, that is returned    * otherwise the generic handler (with the name of the prefix) is returned   * if found.   **/  private static AbstractFunction findFunction(Env env,                                                String prefix,                                                Value value)  {    if (value == null)      return env.findFunction(prefix);    Object obj = value.toJavaObject();    if (obj == null)      return env.findFunction(prefix);    String typeName = obj.getClass().getSimpleName().toLowerCase();    String functionName = prefix + '_' + typeName;    AbstractFunction function = env.findFunction(functionName);    if (function == null)      function = env.findFunction(prefix);    return function;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?