Example #1
0
		/**
     * 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;
		}