/** * 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()); } }
/** * 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); } } }
/** * 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); } }
/** * 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; }
/** * Formats a Bean to a string. * * @param bean the bean * @return the formatted string of the Bean */ public String beanToString(XMPPBean bean) { String str = "XMPPBean: [NS=" + bean.getNamespace() + " id=" + bean.getId() + " from=" + bean.getFrom() + " to=" + bean.getTo() + " type=" + bean.getType() + " payload=" + bean.payloadToXML(); if (bean.errorCondition != null) str += " errorCondition=" + bean.errorCondition; if (bean.errorText != null) str += " errorText=" + bean.errorText; if (bean.errorType != null) str += " errorType=" + bean.errorType; str += "]"; return str; }
/** * 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; }