/** * Constructs a new IQ using the specified type. A packet ID will * be automatically generated. * * @param type the IQ type. */ public IQ(IQ.Type type) { this.element = new XElement("iq"); new XDocument(docFactory).Add(element); setType(type); String id = string.Format("{0}-{1}", random.Next(1000), sequence++); setID(id); }
/** * Constructs a new Roster using the specified type and ID. * * @param type the IQ type. * @param ID the packet ID of the IQ. */ public Roster(IQ.Type type, string ID) : base(type, ID) { element.Add(new XElement("query", "jabber:iq:roster")); }
/** * Constructs a new IQ using the specified type and ID. * * @param ID the packet ID of the IQ. * @param type the IQ type. */ public IQ(IQ.Type type, string ID) { this.element = new XElement("iq"); new XDocument(docFactory).Add(element); setType(type); setID(ID); }
/** * Convenience method to create a new {@link Type#result IQ.Type.result} IQ based * on a {@link Type#get IQ.Type.get} or {@link Type#set IQ.Type.set} IQ. The new * packet will be initialized with:<ul> * * <li>The sender set to the recipient of the originating IQ. * <li>The recipient set to the sender of the originating IQ. * <li>The type set to {@link Type#result IQ.Type.result}. * <li>The id set to the id of the originating IQ. * </ul> * * @param iq the {@link Type#get IQ.Type.get} or {@link Type#set IQ.Type.set} IQ packet. * @throws IllegalArgumentException if the IQ packet does not have a type of * {@link Type#get IQ.Type.get} or {@link Type#set IQ.Type.set}. * @return a new {@link Type#result IQ.Type.result} IQ based on the originating IQ. */ public static IQ createResultIQ(IQ iq) { if (!(iq.getType() == Type.get || iq.getType() == Type.set)) { throw new ArgumentException( "IQ must be of type 'set' or 'get'. Original IQ: " + iq.toXML()); } IQ result = new IQ(Type.result, iq.getID()); result.setFrom(iq.getTo()); result.setTo(iq.getFrom()); return result; }
/** * Sets the type of this IQ. * * @param type the IQ type. * @see Type */ public void setType(IQ.Type type) { element.Add(new XAttribute("type", type == null ? null : type.ToString())); }
/** * Constructs a new IQ that is a copy of an existing IQ. * * @param iq the iq packet. * @see #createCopy() */ private IQ(IQ iq) { XElement elementCopy = new XElement(iq.element); new XDocument(docFactory).Add(elementCopy); this.element = elementCopy; // Copy cached JIDs (for performance reasons) this.toJID = iq.toJID; this.fromJID = iq.fromJID; }