2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
2021-04-18 17:19:32 +02:00
|
|
|
* Copyright 2003-2007 Jive Software, 2015-2021 Florian Schmaus.
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smack.packet;
|
|
|
|
|
2021-04-18 17:19:32 +02:00
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2015-05-27 19:29:51 +02:00
|
|
|
import org.jxmpp.jid.EntityFullJid;
|
2015-05-04 20:14:45 +02:00
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
2015-02-14 17:15:02 +01:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* IQ stanza used by Smack to bind a resource and to obtain the jid assigned by the server.
|
|
|
|
* There are two ways to bind a resource. One is simply sending an empty Bind stanza where the
|
2014-02-17 23:58:40 +01:00
|
|
|
* server will assign a new resource for this connection. The other option is to set a desired
|
|
|
|
* resource but the server may return a modified version of the sent resource.<p>
|
|
|
|
*
|
|
|
|
* For more information refer to the following
|
2018-05-09 23:06:12 +02:00
|
|
|
* <a href=http://www.xmpp.org/specs/rfc3920.html#bind>link</a>.
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2016-05-25 22:42:46 +02:00
|
|
|
public final class Bind extends IQ {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-08-04 18:01:05 +02:00
|
|
|
public static final String ELEMENT = "bind";
|
|
|
|
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-bind";
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-05-04 20:14:45 +02:00
|
|
|
private final Resourcepart resource;
|
2015-05-27 19:29:51 +02:00
|
|
|
private final EntityFullJid jid;
|
2014-08-04 18:01:05 +02:00
|
|
|
|
2016-05-25 22:42:46 +02:00
|
|
|
private Bind(Resourcepart resource, EntityFullJid jid) {
|
2014-11-07 21:12:01 +01:00
|
|
|
super(ELEMENT, NAMESPACE);
|
2014-08-04 18:01:05 +02:00
|
|
|
this.resource = resource;
|
2014-08-23 18:24:53 +02:00
|
|
|
this.jid = jid;
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
2015-05-04 20:14:45 +02:00
|
|
|
public Resourcepart getResource() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2015-05-27 19:29:51 +02:00
|
|
|
public EntityFullJid getJid() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return jid;
|
|
|
|
}
|
|
|
|
|
2015-05-04 20:14:45 +02:00
|
|
|
public static Bind newSet(Resourcepart resource) {
|
2014-09-11 09:49:16 +02:00
|
|
|
Bind bind = new Bind(resource, null);
|
|
|
|
bind.setType(IQ.Type.set);
|
|
|
|
return bind;
|
|
|
|
}
|
|
|
|
|
2015-05-27 19:29:51 +02:00
|
|
|
public static Bind newResult(EntityFullJid jid) {
|
2014-09-11 09:49:16 +02:00
|
|
|
return new Bind(null, jid);
|
|
|
|
}
|
|
|
|
|
2014-03-21 09:51:52 +01:00
|
|
|
@Override
|
2014-11-07 21:12:01 +01:00
|
|
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
|
|
|
xml.rightAngleBracket();
|
2014-03-21 09:51:52 +01:00
|
|
|
xml.optElement("resource", resource);
|
|
|
|
xml.optElement("jid", jid);
|
|
|
|
return xml;
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
2014-08-04 18:01:05 +02:00
|
|
|
|
2015-04-06 10:45:12 +02:00
|
|
|
public static final class Feature implements ExtensionElement {
|
2014-09-11 09:49:16 +02:00
|
|
|
|
2021-04-18 17:19:32 +02:00
|
|
|
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
2014-09-11 09:49:16 +02:00
|
|
|
public static final Feature INSTANCE = new Feature();
|
|
|
|
|
|
|
|
private Feature() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getNamespace() {
|
|
|
|
return NAMESPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2014-09-11 09:49:16 +02:00
|
|
|
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
|
|
|
}
|
2014-08-04 18:01:05 +02:00
|
|
|
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|