Package org.jivesoftware.smack.packet
Class StanzaBuilder<B extends StanzaBuilder<B>>
- java.lang.Object
-
- org.jivesoftware.smack.packet.StanzaBuilder<B>
-
- All Implemented Interfaces:
StanzaView
,XmlLangElement
- Direct Known Subclasses:
AbstractIqBuilder
,MessageOrPresenceBuilder
public abstract class StanzaBuilder<B extends StanzaBuilder<B>> extends java.lang.Object implements StanzaView
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
StanzaBuilder(java.lang.String stanzaId)
protected
StanzaBuilder(StanzaIdSource stanzaIdSource)
protected
StanzaBuilder(StanzaBuilder<?> other)
protected
StanzaBuilder(Stanza message, java.lang.String stanzaId)
protected
StanzaBuilder(Stanza message, StanzaIdSource stanzaIdSource)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description B
addExtension(ExtensionElement extensionElement)
B
addExtensions(java.util.Collection<? extends ExtensionElement> extensionElements)
B
addOptExtensions(java.util.Collection<? extends ExtensionElement> extensionElements)
protected abstract void
addStanzaSpecificAttributes(ToStringUtil.Builder builder)
abstract Stanza
build()
static IqData
buildIqData(java.lang.String stanzaId)
static MessageBuilder
buildMessage()
static MessageBuilder
buildMessage(java.lang.String stanzaId)
static MessageBuilder
buildMessageFrom(Message message, java.lang.String stanzaId)
static MessageBuilder
buildMessageFrom(Message message, StanzaIdSource stanzaIdSource)
static PresenceBuilder
buildPresence()
static PresenceBuilder
buildPresence(java.lang.String stanzaId)
static PresenceBuilder
buildPresenceFrom(Presence presence, java.lang.String stanzaId)
static PresenceBuilder
buildPresenceFrom(Presence presence, StanzaIdSource stanzaIdSource)
static <SB extends StanzaBuilder<?>>
SBbuildResponse(StanzaView request, Function<SB,java.lang.String> builderFromStanzaId)
B
from(java.lang.CharSequence from)
Sets who the the stanza is being sent "from".B
from(Jid from)
Sets who the stanza is being sent "from".StanzaError
getError()
Returns the error associated with this packet, ornull
if there are no errors.ExtensionElement
getExtension(javax.xml.namespace.QName qname)
java.util.List<ExtensionElement>
getExtensions()
Returns a list of all extension elements of this stanza.<E extends ExtensionElement>
java.util.List<E>getExtensions(java.lang.Class<E> extensionElementClass)
Return all extension elements of the given type.java.util.List<ExtensionElement>
getExtensions(javax.xml.namespace.QName qname)
Jid
getFrom()
Returns who the stanza is being sent "from" ornull
if the value is not set.java.lang.String
getLanguage()
Returns the xml:lang of this XML element, or null if one has not been set.java.lang.String
getStanzaId()
Returns the unique ID of the stanza.abstract B
getThis()
Jid
getTo()
Returns who the stanza is being sent "to", ornull
if the value is not set.B
overrideExtension(ExtensionElement extensionElement)
B
removeExtension(java.lang.String elementName, java.lang.String namespace)
B
removeExtension(ExtensionElement extension)
B
setError(StanzaError stanzaError)
Sets the error for this stanza.B
setLanguage(java.lang.String language)
Sets the xml:lang for this stanza.void
throwIfNoStanzaId()
B
to(java.lang.CharSequence to)
Set the recipent address of the stanza.B
to(Jid to)
Sets who the stanza is being sent "to".java.lang.String
toString()
boolean
willBuildStanzaWithId()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.StanzaView
getExtension, hasExtension, hasExtension, hasExtension
-
-
-
-
Constructor Detail
-
StanzaBuilder
protected StanzaBuilder(StanzaBuilder<?> other)
-
StanzaBuilder
protected StanzaBuilder(StanzaIdSource stanzaIdSource)
-
StanzaBuilder
protected StanzaBuilder(java.lang.String stanzaId)
-
StanzaBuilder
protected StanzaBuilder(Stanza message, java.lang.String stanzaId)
-
StanzaBuilder
protected StanzaBuilder(Stanza message, StanzaIdSource stanzaIdSource)
-
-
Method Detail
-
to
public final B to(java.lang.CharSequence to) throws XmppStringprepException
Set the recipent address of the stanza.- Parameters:
to
- whoe the stanza is being sent to.- Returns:
- a reference to this builder.
- Throws:
XmppStringprepException
- if the provided character sequence is not a valid XMPP address.- See Also:
to(Jid)
-
to
public final B to(Jid to)
Sets who the stanza is being sent "to". The XMPP protocol often makes the "to" attribute optional, so it does not always need to be set.- Parameters:
to
- who the stanza is being sent to.- Returns:
- a reference to this builder.
-
from
public final B from(java.lang.CharSequence from) throws XmppStringprepException
Sets who the the stanza is being sent "from".- Parameters:
from
- who the stanza is being sent from.- Returns:
- a reference to this builder.
- Throws:
XmppStringprepException
- if the provided character sequence is not a valid XMPP address.- See Also:
from(Jid)
-
from
public final B from(Jid from)
Sets who the stanza is being sent "from". The XMPP protocol often makes the "from" attribute optional, so it does not always need to be set.- Parameters:
from
- who the stanza is being sent from.- Returns:
- a reference to this builder.
-
setError
public final B setError(StanzaError stanzaError)
Sets the error for this stanza.- Parameters:
stanzaError
- the error to associate with this stanza.- Returns:
- a reference to this builder.
-
setLanguage
public final B setLanguage(java.lang.String language)
Sets the xml:lang for this stanza.- Parameters:
language
- the xml:lang of this stanza.- Returns:
- a reference to this builder.
-
addExtension
public final B addExtension(ExtensionElement extensionElement)
-
addOptExtensions
public final B addOptExtensions(java.util.Collection<? extends ExtensionElement> extensionElements)
-
addExtensions
public final B addExtensions(java.util.Collection<? extends ExtensionElement> extensionElements)
-
overrideExtension
public final B overrideExtension(ExtensionElement extensionElement)
-
removeExtension
public final B removeExtension(java.lang.String elementName, java.lang.String namespace)
-
removeExtension
public final B removeExtension(ExtensionElement extension)
-
getStanzaId
public final java.lang.String getStanzaId()
Description copied from interface:StanzaView
Returns the unique ID of the stanza. The returned value could benull
.- Specified by:
getStanzaId
in interfaceStanzaView
- Returns:
- the packet's unique ID or
null
if the id is not available.
-
getTo
public final Jid getTo()
Description copied from interface:StanzaView
Returns who the stanza is being sent "to", ornull
if the value is not set. The XMPP protocol often makes the "to" attribute optional, so it does not always need to be set.- Specified by:
getTo
in interfaceStanzaView
- Returns:
- who the stanza is being sent to, or
null
if the value has not been set.
-
getFrom
public final Jid getFrom()
Description copied from interface:StanzaView
Returns who the stanza is being sent "from" ornull
if the value is not set. The XMPP protocol often makes the "from" attribute optional, so it does not always need to be set.- Specified by:
getFrom
in interfaceStanzaView
- Returns:
- who the stanza is being sent from, or
null
if the value has not been set.
-
getLanguage
public final java.lang.String getLanguage()
Description copied from interface:XmlLangElement
Returns the xml:lang of this XML element, or null if one has not been set.- Specified by:
getLanguage
in interfaceXmlLangElement
- Returns:
- the xml:lang of this XML element, or null.
-
getError
public final StanzaError getError()
Description copied from interface:StanzaView
Returns the error associated with this packet, ornull
if there are no errors.- Specified by:
getError
in interfaceStanzaView
- Returns:
- the error sub-packet or
null
if there isn't an error.
-
getExtension
public final ExtensionElement getExtension(javax.xml.namespace.QName qname)
- Specified by:
getExtension
in interfaceStanzaView
-
getExtensions
public final java.util.List<ExtensionElement> getExtensions()
Description copied from interface:StanzaView
Returns a list of all extension elements of this stanza.- Specified by:
getExtensions
in interfaceStanzaView
- Returns:
- a list of all extension elements of this stanza.
-
getExtensions
public final java.util.List<ExtensionElement> getExtensions(javax.xml.namespace.QName qname)
- Specified by:
getExtensions
in interfaceStanzaView
-
getExtensions
public final <E extends ExtensionElement> java.util.List<E> getExtensions(java.lang.Class<E> extensionElementClass)
Description copied from interface:StanzaView
Return all extension elements of the given type. Returns the empty list if there a none.- Specified by:
getExtensions
in interfaceStanzaView
- Type Parameters:
E
- the type of extension elements.- Parameters:
extensionElementClass
- the class of the type of extension elements.- Returns:
- a list of extension elements of that type, which may be empty.
-
willBuildStanzaWithId
public final boolean willBuildStanzaWithId()
-
throwIfNoStanzaId
public final void throwIfNoStanzaId()
-
addStanzaSpecificAttributes
protected abstract void addStanzaSpecificAttributes(ToStringUtil.Builder builder)
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
buildMessage
public static MessageBuilder buildMessage()
-
buildMessage
public static MessageBuilder buildMessage(java.lang.String stanzaId)
-
buildMessageFrom
public static MessageBuilder buildMessageFrom(Message message, java.lang.String stanzaId)
-
buildMessageFrom
public static MessageBuilder buildMessageFrom(Message message, StanzaIdSource stanzaIdSource)
-
buildPresence
public static PresenceBuilder buildPresence()
-
buildPresence
public static PresenceBuilder buildPresence(java.lang.String stanzaId)
-
buildPresenceFrom
public static PresenceBuilder buildPresenceFrom(Presence presence, java.lang.String stanzaId)
-
buildPresenceFrom
public static PresenceBuilder buildPresenceFrom(Presence presence, StanzaIdSource stanzaIdSource)
-
buildIqData
public static IqData buildIqData(java.lang.String stanzaId)
-
buildResponse
public static <SB extends StanzaBuilder<?>> SB buildResponse(StanzaView request, Function<SB,java.lang.String> builderFromStanzaId)
-
-