mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 14:01:08 +01:00
Introduce StanzaBuilder
As first step to immutable Stanza types.
This commit is contained in:
parent
926c5892ad
commit
5db6191110
134 changed files with 2576 additions and 764 deletions
|
|
@ -21,6 +21,8 @@ import java.util.Collections;
|
|||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.packet.StanzaView;
|
||||
|
||||
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
|
||||
|
||||
|
|
@ -54,7 +56,10 @@ public class JivePropertiesManager {
|
|||
* @param packet the stanza to add the property to.
|
||||
* @param name the name of the property to add.
|
||||
* @param value the value of the property to add.
|
||||
* @deprecated use {@link #addProperty(StanzaBuilder, String, Object)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.5.
|
||||
public static void addProperty(Stanza packet, String name, Object value) {
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
|
||||
if (jpe == null) {
|
||||
|
|
@ -64,6 +69,22 @@ public class JivePropertiesManager {
|
|||
jpe.setProperty(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to add a property to a stanza.
|
||||
*
|
||||
* @param stanzaBuilder the stanza to add the property to.
|
||||
* @param name the name of the property to add.
|
||||
* @param value the value of the property to add.
|
||||
*/
|
||||
public static void addProperty(StanzaBuilder<?> stanzaBuilder, String name, Object value) {
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) stanzaBuilder.getExtension(JivePropertiesExtension.QNAME);
|
||||
if (jpe == null) {
|
||||
jpe = new JivePropertiesExtension();
|
||||
stanzaBuilder.addExtension(jpe);
|
||||
}
|
||||
jpe.setProperty(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get a property from a packet. Will return null if the stanza contains
|
||||
* not property with the given name.
|
||||
|
|
@ -72,9 +93,9 @@ public class JivePropertiesManager {
|
|||
* @param name TODO javadoc me please
|
||||
* @return the property or <code>null</code> if none found.
|
||||
*/
|
||||
public static Object getProperty(Stanza packet, String name) {
|
||||
public static Object getProperty(StanzaView packet, String name) {
|
||||
Object res = null;
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.QNAME);
|
||||
if (jpe != null) {
|
||||
res = jpe.getProperty(name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import java.util.Map;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
|
@ -47,6 +49,8 @@ public class JivePropertiesExtension implements ExtensionElement {
|
|||
|
||||
public static final String ELEMENT = "properties";
|
||||
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JivePropertiesExtension.class.getName());
|
||||
|
||||
private final Map<String, Object> properties;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue