/** * Convert XMPPIQ to XMPPBean to simplify the handling of the IQ using the beanPrototypes. * * @param iq the XMPPIQ * @return the related XMPPBean or null if something goes wrong */ public XMPPBean convertXMPPIQToBean(XMPPIQ iq) { try { String childElement = iq.element; String namespace = iq.namespace; XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser parser = factory.newPullParser(); parser.setInput(new StringReader(iq.payload)); XMPPBean bean = null; Log.v( TAG, "prototypes contains ns: " + namespace + "? " + this.beanPrototypes.containsKey(namespace)); if (this.beanPrototypes.containsKey(namespace)) Log.v( TAG, "prototypes contains ce: " + childElement + "? " + this.beanPrototypes.get(namespace).containsKey(childElement)); synchronized (this.beanPrototypes) { if (namespace != null && this.beanPrototypes.containsKey(namespace) && this.beanPrototypes.get(namespace).containsKey(childElement)) { bean = (this.beanPrototypes.get(namespace).get(childElement)).clone(); bean.fromXML(parser); bean.setId(iq.packetID); bean.setFrom(iq.from); bean.setTo(iq.to); switch (iq.type) { case XMPPIQ.TYPE_GET: bean.setType(XMPPBean.TYPE_GET); break; case XMPPIQ.TYPE_SET: bean.setType(XMPPBean.TYPE_SET); break; case XMPPIQ.TYPE_RESULT: bean.setType(XMPPBean.TYPE_RESULT); break; case XMPPIQ.TYPE_ERROR: bean.setType(XMPPBean.TYPE_ERROR); break; } return bean; } } } catch (Exception e) { Log.e(TAG, "ERROR while parsing XMPPIQ to XMPPBean: " + e.getMessage()); } return null; }
/** * Send an XMPPBean of type ERROR. * * <p>TODO: Option for custom ERROR tag and text is missing. * * @param inBean the XMPPBean to reply with an ERROR. The playload will be copied. */ public void sendXMPPBeanError(XMPPBean inBean) { XMPPBean resultBean = inBean.clone(); resultBean.setTo(inBean.getFrom()); resultBean.setFrom(mMXAProxy.getXmppJid()); resultBean.setType(XMPPBean.TYPE_ERROR); _proxy.getBindingStub().sendXMPPBean(resultBean); }