Exemplo n.º 1
0
  /**
   * Unregister a single XMPPBean in MXA.
   *
   * @param callback the callback to be unregistered
   * @param beanNamespace the namespace of the IQ
   * @param beanElement the root element of the IQs payload
   * @throws RemoteException the remote exception if something goes wrong
   */
  public void unregisterXMPPExtension(
      IXMPPIQCallback callback, String beanNamespace, String beanElement) throws RemoteException {
    if (mMXAProxy.isConnected()) {
      XMPPBean bean = getRegisteredBean(beanNamespace, beanElement);

      if (bean != null)
        mMXAProxy
            .getXMPPService()
            .unregisterIQCallback(callback, bean.getChildElement(), bean.getNamespace());
    }
  }
Exemplo n.º 2
0
  /**
   * Unregister an XMPPBean from prototypes.
   *
   * @param prototype the prototype to remove
   */
  public void unregisterXMPPBean(XMPPBean prototype) {
    String namespace = prototype.getNamespace();
    String childElement = prototype.getChildElement();

    synchronized (this.beanPrototypes) {
      if (this.beanPrototypes.containsKey(namespace)) {
        this.beanPrototypes.get(namespace).remove(childElement);

        if (this.beanPrototypes.get(namespace).size() > 0) this.beanPrototypes.remove(namespace);
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Register a prototype of an XMPPBean.
   *
   * @param prototype the prototype XMPPBean
   */
  public void registerXMPPBean(XMPPBean prototype) {
    String namespace = prototype.getNamespace();
    String childElement = prototype.getChildElement();

    synchronized (this.beanPrototypes) {
      if (!this.beanPrototypes.keySet().contains(namespace))
        this.beanPrototypes.put(
            namespace, Collections.synchronizedMap(new HashMap<String, XMPPBean>()));

      this.beanPrototypes.get(namespace).put(childElement, prototype);
    }
  }
Exemplo n.º 4
0
  /**
   * Register an callback extension which is used by the MXAProxy/MXA for listening for this kind of
   * IQ.
   *
   * @param callback the callback which should be notified if IQ is incoming
   * @param beanNamespace the namespace of the IQ
   * @param beanElement the root element tag of the IQ
   * @return true, if callback was registered successful
   * @throws RemoteException the remote exception if something goes wrong
   */
  public boolean registerXMPPExtension(
      IXMPPIQCallback callback, String beanNamespace, String beanElement) throws RemoteException {
    boolean isRegistered = false;

    if (mMXAProxy.isConnected()) {
      XMPPBean bean = getRegisteredBean(beanNamespace, beanElement);

      // if there is no related prototype of this XMPPBean it can not be
      // registered a callback
      if (bean != null) {
        mMXAProxy
            .getXMPPService()
            .registerIQCallback(callback, bean.getChildElement(), bean.getNamespace());

        Log.v(TAG, "child: " + bean.getChildElement() + " ns: " + bean.getNamespace());

        isRegistered = true;
      }
    }

    return isRegistered;
  }
Exemplo n.º 5
0
  /**
   * Convert an XMPPBean to an XMPPIQ to send it via the MXAProxy/MXA.
   *
   * @param bean the bean to convert
   * @param mergePayload true if the playload should be merged
   * @return the XMPPIQ
   */
  public XMPPIQ beanToIQ(XMPPBean bean, boolean mergePayload) {
    // default XMPP IQ type
    int type = XMPPIQ.TYPE_GET;

    switch (bean.getType()) {
      case XMPPBean.TYPE_GET:
        type = XMPPIQ.TYPE_GET;
        break;
      case XMPPBean.TYPE_SET:
        type = XMPPIQ.TYPE_SET;
        break;
      case XMPPBean.TYPE_RESULT:
        type = XMPPIQ.TYPE_RESULT;
        break;
      case XMPPBean.TYPE_ERROR:
        type = XMPPIQ.TYPE_ERROR;
        break;
    }

    XMPPIQ iq;

    if (mergePayload) iq = new XMPPIQ(bean.getFrom(), bean.getTo(), type, null, null, bean.toXML());
    else
      iq =
          new XMPPIQ(
              bean.getFrom(),
              bean.getTo(),
              type,
              bean.getChildElement(),
              bean.getNamespace(),
              bean.payloadToXML());

    iq.packetID = bean.getId();

    return iq;
  }