OfferConfirmation.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.agent;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.SmackException.NotConnectedException;
  20. import org.jivesoftware.smack.XMPPConnection;
  21. import org.jivesoftware.smack.packet.IQ;
  22. import org.jivesoftware.smack.packet.SimpleIQ;
  23. import org.jivesoftware.smack.provider.IQProvider;
  24. import org.jxmpp.jid.Jid;
  25. import org.xmlpull.v1.XmlPullParser;
  26. import org.xmlpull.v1.XmlPullParserException;


  27. public class OfferConfirmation extends SimpleIQ {
  28.     private String userJID;
  29.     private long sessionID;

  30.     public OfferConfirmation() {
  31.         super("offer-confirmation", "http://jabber.org/protocol/workgroup");
  32.     }

  33.     public String getUserJID() {
  34.         return userJID;
  35.     }

  36.     public void setUserJID(String userJID) {
  37.         this.userJID = userJID;
  38.     }

  39.     public long getSessionID() {
  40.         return sessionID;
  41.     }

  42.     public void setSessionID(long sessionID) {
  43.         this.sessionID = sessionID;
  44.     }


  45.     public void notifyService(XMPPConnection con, Jid workgroup, String createdRoomName) throws NotConnectedException, InterruptedException {
  46.         NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName);
  47.         con.sendStanza(packet);
  48.     }

  49.     public static class Provider extends IQProvider<OfferConfirmation> {

  50.         @Override
  51.         public OfferConfirmation parse(XmlPullParser parser, int initialDepth)
  52.                         throws XmlPullParserException, IOException {
  53.             final OfferConfirmation confirmation = new OfferConfirmation();

  54.             boolean done = false;
  55.             while (!done) {
  56.                 parser.next();
  57.                 String elementName = parser.getName();
  58.                 if (parser.getEventType() == XmlPullParser.START_TAG && "user-jid".equals(elementName)) {
  59.                     try {
  60.                         confirmation.setUserJID(parser.nextText());
  61.                     }
  62.                     catch (NumberFormatException nfe) {
  63.                     }
  64.                 }
  65.                 else if (parser.getEventType() == XmlPullParser.START_TAG && "session-id".equals(elementName)) {
  66.                     try {
  67.                         confirmation.setSessionID(Long.valueOf(parser.nextText()));
  68.                     }
  69.                     catch (NumberFormatException nfe) {
  70.                     }
  71.                 }
  72.                 else if (parser.getEventType() == XmlPullParser.END_TAG && "offer-confirmation".equals(elementName)) {
  73.                     done = true;
  74.                 }
  75.             }


  76.             return confirmation;
  77.         }
  78.     }


  79.     /**
  80.      * Packet for notifying server of RoomName
  81.      */
  82.     private class NotifyServicePacket extends IQ {
  83.         String roomName;

  84.         NotifyServicePacket(Jid workgroup, String roomName) {
  85.             super("offer-confirmation", "http://jabber.org/protocol/workgroup");
  86.             this.setTo(workgroup);
  87.             this.setType(IQ.Type.result);

  88.             this.roomName = roomName;
  89.         }

  90.         @Override
  91.         protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  92.             xml.attribute("roomname", roomName);
  93.             xml.setEmptyElement();
  94.             return xml;
  95.         }
  96.     }


  97. }