1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

Merge branch '4.1'

Conflicts:
	smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
	smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java
	smack-core/src/main/java/org/jivesoftware/smack/PacketListener.java
	smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
	smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java
	smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java
	smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java
	smack-core/src/test/java/org/jivesoftware/smack/ThreadedDummyConnection.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/address/provider/MultipleAddressesProvider.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java
	smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java
	smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java
	smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java
	smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java
	smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/UserID.java
	smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/provider/RosterExchangeProvider.java
	smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
	version.gradle
This commit is contained in:
Florian Schmaus 2015-03-04 22:42:36 +01:00
commit 701aa7d9c4
298 changed files with 2402 additions and 1562 deletions

View file

@ -7,6 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'org.kordamp:markdown-gradle-plugin:0.1.1' classpath 'org.kordamp:markdown-gradle-plugin:0.1.1'
classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.1.0'
} }
} }
apply plugin: 'org.kordamp.gradle.markdown' apply plugin: 'org.kordamp.gradle.markdown'
@ -95,7 +96,6 @@ allprojects {
options.addStringOption('Xdoclint:none', '-quiet') options.addStringOption('Xdoclint:none', '-quiet')
} }
} }
} }
gradle.taskGraph.whenReady { taskGraph -> gradle.taskGraph.whenReady { taskGraph ->
@ -181,6 +181,7 @@ subprojects {
apply plugin: 'osgi' apply plugin: 'osgi'
apply plugin: 'signing' apply plugin: 'signing'
apply plugin: 'checkstyle' apply plugin: 'checkstyle'
apply plugin: 'org.kordamp.gradle.clirr'
checkstyle { checkstyle {
configFile = new File(rootConfigDir, 'checkstyle.xml') configFile = new File(rootConfigDir, 'checkstyle.xml')
@ -280,6 +281,11 @@ subprojects {
required { signingRequired } required { signingRequired }
sign configurations.archives sign configurations.archives
} }
clirr {
baseline = [group, name, clirrBaseline].join(':')
failOnErrors clirrFailOnErrors
}
} }
subprojects*.jar { subprojects*.jar {
@ -288,6 +294,12 @@ subprojects*.jar {
} }
} }
// Important to specify this task after the subprojects block
task clirrRootReport(type: org.kordamp.gradle.clirr.ClirrReportTask) {
dependsOn = subprojects.tasks.clirr
reports = files(subprojects.tasks.clirr.xmlReport)
}
def getGitCommit() { def getGitCommit() {
def dotGit = new File("$projectDir/.git") def dotGit = new File("$projectDir/.git")
if (!dotGit.isDirectory()) return 'non-git build' if (!dotGit.isDirectory()) return 'non-git build'

View file

@ -42,9 +42,9 @@ connection. The window will contain the following information:
* XMPPConnection tabs -- each tab shows debugging information related to the connection. * XMPPConnection tabs -- each tab shows debugging information related to the connection.
* Smack info tab -- shows information about Smack (e.g. Smack version, installed components, etc.). The connection tab will contain the following information: * Smack info tab -- shows information about Smack (e.g. Smack version, installed components, etc.). The connection tab will contain the following information:
* All Packets -- shows sent and received packets information parsed by Smack. * All Stanzas -- shows sent and received packets information parsed by Smack.
* Raw Sent Packets -- raw XML traffic generated by Smack and sent to the server. * Raw Sent Stanzas -- raw XML traffic generated by Smack and sent to the server.
* Raw Received Packets -- raw XML traffic sent by the server to the client. * Raw Received Stanzas -- raw XML traffic sent by the server to the client.
* Ad-hoc message -- allows to send ad-hoc packets of any type. * Ad-hoc message -- allows to send ad-hoc packets of any type.
* Information -- shows connection state and statistics. * Information -- shows connection state and statistics.
@ -57,6 +57,6 @@ contain the following information:
* Client Traffic (red text) -- raw XML traffic generated by Smack and sent to the server. * Client Traffic (red text) -- raw XML traffic generated by Smack and sent to the server.
* Server Traffic (blue text) -- raw XML traffic sent by the server to the client. * Server Traffic (blue text) -- raw XML traffic sent by the server to the client.
* Interpreted Packets (green text) -- shows XML packets from the server as parsed by Smack. Right click on any of the panes to bring up a menu with the choices to copy of the contents to the system clipboard or to clear the contents of the pane. * Interpreted Stanzas (green text) -- shows XML packets from the server as parsed by Smack. Right click on any of the panes to bring up a menu with the choices to copy of the contents to the system clipboard or to clear the contents of the pane.
Copyright (C) Jive Software 2002-2008 Copyright (C) Jive Software 2002-2008

View file

@ -1,7 +1,7 @@
PacketExtension PacketExtension
=============== ===============
The static `from(Packet)` Method The static `from(Stanza)` Method
-------------------------------- --------------------------------
Every PacketExtension class must have a static `from()` method that retrieves that extension for a given Stanza (if any). Every PacketExtension class must have a static `from()` method that retrieves that extension for a given Stanza (if any).
@ -9,7 +9,7 @@ Every PacketExtension class must have a static `from()` method that retrieves th
Sample Code Sample Code
```java ```java
public static RSMSet from(Packet) { public static RSMSet from(Stanza) {
return packet.getExtension(ELEMENT, NAMESPACE); return packet.getExtension(ELEMENT, NAMESPACE);
} }
``` ```

View file

@ -89,7 +89,7 @@ req.setTo("juliet@capulet.com/balcony");
// send it // send it
connection.sendIqWithResponseCallback(req, new PacketListener() { connection.sendIqWithResponseCallback(req, new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Stanza packet) {
HttpOverXmppResp resp = (HttpOverXmppResp) iq; HttpOverXmppResp resp = (HttpOverXmppResp) iq;
// check HTTP response code // check HTTP response code
if (resp.getStatusCode() == 200) { if (resp.getStatusCode() == 200) {

View file

@ -1,7 +1,7 @@
Group Chat Invitations Group Chat Invitations
====================== ======================
The group chat invitation packet extension is used to invite other users to a The group chat invitation extension is used to invite other users to a
group chat room. group chat room.
* Inviting Other Users * Inviting Other Users
@ -20,7 +20,7 @@ appropriately, as in the following code example:
Message message = new Message("user@chat.example.com"); Message message = new Message("user@chat.example.com");
message.setBody("Join me for a group chat!"); message.setBody("Join me for a group chat!");
message.addExtension(new GroupChatInvitation("room@chat.example.com")); message.addExtension(new GroupChatInvitation("room@chat.example.com"));
con.sendPacket(message); con.sendStanza(message);
``` ```
The XML generated for the invitation portion of the code above would be: The XML generated for the invitation portion of the code above would be:
@ -32,11 +32,11 @@ The XML generated for the invitation portion of the code above would be:
Listening for Invitations Listening for Invitations
------------------------- -------------------------
To listen for group chat invitations, use a PacketExtensionFilter for the `x` To listen for group chat invitations, use a StanzaExtensionFilter for the `x`
element name and `jabber:x:conference` namespace, as in the following code element name and `jabber:x:conference` namespace, as in the following code
example: example:
``` ```
PacketFilter filter = new PacketExtensionFilter("x", "jabber:x:conference"); StanzaFilter filter = new StanzaExtensionFilter("x", "jabber:x:conference");
// Create a packet collector or packet listeners using the filter... // Create a packet collector or packet listeners using the filter...
``` ```

View file

@ -1,4 +1,4 @@
Packet Properties Stanza Properties
================= =================
Smack provides an easy mechanism for attaching arbitrary properties to Smack provides an easy mechanism for attaching arbitrary properties to
@ -20,7 +20,7 @@ jpe.setProperty("favoriteColor", new Color(0, 0, 255));
// Add an int as a property._ // Add an int as a property._
jpe.setProperty("favoriteNumber", 4); jpe.setProperty("favoriteNumber", 4);
// Add the JivePropertiesExtension to the message packet_ // Add the JivePropertiesExtension to the message packet_
message.addPacketExtension(jpe); message.addStanzaExtension(jpe);
chat.sendMessage(message); chat.sendMessage(message);
``` ```
@ -39,8 +39,8 @@ int favoriteNumber = ((Integer)jpe.getProperty("favoriteNumber")).intValue();
``` ```
For convenience `JivePropertiesManager` contains two helper methods namely For convenience `JivePropertiesManager` contains two helper methods namely
`addProperty(Packet packet, String name, Object value)` and `addProperty(Stanza packet, String name, Object value)` and
`getProperty(Packet packet, String name)`. `getProperty(Stanza packet, String name)`.
Objects as Properties Objects as Properties
--------------------- ---------------------

View file

@ -98,7 +98,7 @@ done. The last step is to send the message as you do with any other message.
An XHTML message is like any regular message, therefore to send the message An XHTML message is like any regular message, therefore to send the message
you can follow the usual steps you do in order to send a message. For example, you can follow the usual steps you do in order to send a message. For example,
to send a message as part of a chat just use the message **#send(Message)** of to send a message as part of a chat just use the message **#send(Message)** of
_**Chat**_ or you can use the message **#send(Packet)** of _**Chat**_ or you can use the message **#send(Stanza)** of
_**XMPPConnection**_. _**XMPPConnection**_.
**Example** **Example**
@ -143,7 +143,7 @@ XHTML bodies of any received message.
``` ```
// Create a listener for the chat and display any XHTML content // Create a listener for the chat and display any XHTML content
PacketListener packetListener = new PacketListener() { PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Stanza packet) {
Message message = (Message) packet; Message message = (Message) packet;
// Obtain the XHTML bodies of the message // Obtain the XHTML bodies of the message
List<CharSequence> bodies = XHTMLManager.getBodies(message); List<CharSequence> bodies = XHTMLManager.getBodies(message);

View file

@ -83,7 +83,7 @@ Retrieve the roster using the `Roster.getInstanceFor(XMPPConnection)` method. Th
class allows you to find all the roster entries, the groups they belong to, class allows you to find all the roster entries, the groups they belong to,
and the current presence status of each entry. and the current presence status of each entry.
Reading and Writing Packets Reading and Writing Stanzas
Each message to the XMPP server from a client is called a packet and is sent Each message to the XMPP server from a client is called a packet and is sent
as XML. The `org.jivesoftware.smack.packet` package contains classes that as XML. The `org.jivesoftware.smack.packet` package contains classes that
@ -98,11 +98,11 @@ your presence to let people know you're unavailable and "out fishing":
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
presence.setStatus("Gone fishing"); presence.setStatus("Gone fishing");
// Send the packet (assume we have an XMPPConnection instance called "con"). // Send the packet (assume we have an XMPPConnection instance called "con").
con.sendPacket(presence); con.sendStanza(presence);
``` ```
Smack provides two ways to read incoming packets: `PacketListener`, and Smack provides two ways to read incoming packets: `PacketListener`, and
`PacketCollector`. Both use `PacketFilter` instances to determine which `PacketCollector`. Both use `StanzaFilter` instances to determine which
packets should be processed. A packet listener is used for event style packets should be processed. A packet listener is used for event style
programming, while a packet collector has a result queue of packets that you programming, while a packet collector has a result queue of packets that you
can do polling and blocking operations on. So, a packet listener is useful can do polling and blocking operations on. So, a packet listener is useful

View file

@ -7,7 +7,7 @@
* [Managing Connections](connections.html) * [Managing Connections](connections.html)
* [Messaging Basics](messaging.html) * [Messaging Basics](messaging.html)
* [Roster and Presence](roster.html) * [Roster and Presence](roster.html)
* [Processing Incoming Packets](processing.html) * [Processing Incoming Stanzas](processing.html)
* [Provider Architecture](providers.html) * [Provider Architecture](providers.html)
* [Debugging with Smack](debugging.html) * [Debugging with Smack](debugging.html)

View file

@ -1,4 +1,4 @@
Processing Incoming Packets Processing Incoming Stanzas
=========================== ===========================
[Back](index.html) [Back](index.html)
@ -9,7 +9,7 @@ constructs:
* `org.jivesoftware.smack.PacketCollector` -- a class that lets you synchronously wait for new packets. * `org.jivesoftware.smack.PacketCollector` -- a class that lets you synchronously wait for new packets.
* `org.jivesoftware.smack.PacketListener` -- an interface for asynchronously notifying you of incoming packets. A packet listener is used for event style programming, while a packet collector has a result queue of packets that you can do polling and blocking operations on. So, a packet listener is useful when you want to take some action whenever a packet happens to come in, while a packet collector is useful when you want to wait for a specific packet to arrive. Packet collectors and listeners can be created using an `XMPPConnection` instance. * `org.jivesoftware.smack.PacketListener` -- an interface for asynchronously notifying you of incoming packets. A packet listener is used for event style programming, while a packet collector has a result queue of packets that you can do polling and blocking operations on. So, a packet listener is useful when you want to take some action whenever a packet happens to come in, while a packet collector is useful when you want to wait for a specific packet to arrive. Packet collectors and listeners can be created using an `XMPPConnection` instance.
The `org.jivesoftware.smack.filter.PacketFilter` interface determines which The `org.jivesoftware.smack.filter.StanzaFilter` interface determines which
specific packets will be delivered to a `PacketCollector` or `PacketListener`. specific packets will be delivered to a `PacketCollector` or `PacketListener`.
Many pre-defined filters can be found in the `org.jivesoftware.smack.filter` Many pre-defined filters can be found in the `org.jivesoftware.smack.filter`
package. package.
@ -20,7 +20,7 @@ and a packet listener:
``` ```
// Create a packet filter to listen for new messages from a particular // Create a packet filter to listen for new messages from a particular
// user. We use an AndFilter to combine two other filters._ // user. We use an AndFilter to combine two other filters._
PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class), StanzaFilter filter = new AndFilter(new StanzaTypeFilter(Message.class),
new FromContainsFilter("mary@jivesoftware.com")); new FromContainsFilter("mary@jivesoftware.com"));
// Assume we've created an XMPPConnection name "connection". // Assume we've created an XMPPConnection name "connection".
@ -38,19 +38,19 @@ PacketListener myListener = new PacketListener() {
connection.addPacketListener(myListener, filter); connection.addPacketListener(myListener, filter);
``` ```
Standard Packet Filters Standard Stanza Filters
----------------------- -----------------------
A rich set of packet filters are included with Smack, or you can create your A rich set of packet filters are included with Smack, or you can create your
own filters by coding to the `PacketFilter` interface. The default set of own filters by coding to the `StanzaFilter` interface. The default set of
filters includes: filters includes:
* `PacketTypeFilter` -- filters for packets that are a particular Class type. * `StanzaTypeFilter` -- filters for packets that are a particular Class type.
* `StanzaIdFilter` -- filters for packets with a particular packet ID. * `StanzaIdFilter` -- filters for packets with a particular packet ID.
* `ThreadFilter` -- filters for message packets with a particular thread ID. * `ThreadFilter` -- filters for message packets with a particular thread ID.
* `ToContainsFilter` -- filters for packets that are sent to a particular address. * `ToContainsFilter` -- filters for packets that are sent to a particular address.
* `FromContainsFilter` -- filters for packets that are sent to a particular address. * `FromContainsFilter` -- filters for packets that are sent to a particular address.
* `PacketExtensionFilter` -- filters for packets that have a particular packet extension. * `StanzaExtensionFilter` -- filters for packets that have a particular packet extension.
* `AndFilter` -- implements the logical AND operation over two filters. * `AndFilter` -- implements the logical AND operation over two filters.
* `OrFilter` -- implements the logical OR operation over two filters. * `OrFilter` -- implements the logical OR operation over two filters.
* `NotFilter` -- implements the logical NOT operation on a filter. * `NotFilter` -- implements the logical NOT operation on a filter.

View file

@ -1,4 +1,4 @@
Provider Architecture: Packet Extensions and Custom IQ's Provider Architecture: Stanza Extensions and Custom IQ's
======================================================== ========================================================
[Back](index.html) [Back](index.html)
@ -73,7 +73,7 @@ an XMPP time packet resembles the following:
### Introspection ### Introspection
_Time Packet_ _Time Stanza_
<iq type='result' to='joe@example.com' from='mary@example.com' id='time_1'> <iq type='result' to='joe@example.com' from='mary@example.com' id='time_1'>
@ -190,7 +190,7 @@ public class MyIQProvider extends IQProvider<MyIQ> {
### DiscoItemsProvider ### DiscoItemsProvider
_Disco Items Packet_ _Disco Items Stanza_
@ -264,11 +264,11 @@ _Disco Items IQProvider_
Extension Providers Extension Providers
------------------- -------------------
Packet extension providers are responsible for parsing packet extensions, Stanza extension providers are responsible for parsing packet extensions,
which are child elements in a custom namespace of IQ, message and presence which are child elements in a custom namespace of IQ, message and presence
packets. packets.
_Pubsub Subscription Packet_ _Pubsub Subscription Stanza_
<iq type='result' from='pubsub.shakespeare.lit' to='francisco@denmark.lit/barracks' id='sub1'> <iq type='result' from='pubsub.shakespeare.lit' to='francisco@denmark.lit/barracks' id='sub1'>

View file

@ -1,3 +1,8 @@
// The name of the root project.
// If we would not set the name, then gradle would use the directory
// name of the root directory
rootProject.name = 'Smack'
include 'smack-core', include 'smack-core',
'smack-im', 'smack-im',
'smack-tcp', 'smack-tcp',

View file

@ -159,7 +159,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
initDebugger(); initDebugger();
if (isFirstInitialization) { if (isFirstInitialization) {
if (debugger.getReaderListener() != null) { if (debugger.getReaderListener() != null) {
addAsyncPacketListener(debugger.getReaderListener(), null); addAsyncStanzaListener(debugger.getReaderListener(), null);
} }
if (debugger.getWriterListener() != null) { if (debugger.getWriterListener() != null) {
addPacketSendingListener(debugger.getWriterListener(), null); addPacketSendingListener(debugger.getWriterListener(), null);
@ -256,7 +256,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
} }
@Override @Override
protected void sendPacketInternal(Stanza packet) throws NotConnectedException { protected void sendStanzaInternal(Stanza packet) throws NotConnectedException {
sendElement(packet); sendElement(packet);
} }
@ -268,7 +268,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
} }
} }
catch (BOSHException e) { catch (BOSHException e) {
LOGGER.log(Level.SEVERE, "BOSHException in sendPacketInternal", e); LOGGER.log(Level.SEVERE, "BOSHException in sendStanzaInternal", e);
} }
} }

View file

@ -20,7 +20,7 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter; import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.SmackTestCase; import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.packet.Version; import org.jivesoftware.smackx.packet.Version;
@ -51,10 +51,10 @@ public class IQTest extends SmackTestCase {
}; };
PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()), PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()),
new PacketTypeFilter(IQ.class)); new StanzaTypeFilter(IQ.class));
PacketCollector collector = getConnection(0).createPacketCollector(filter); PacketCollector collector = getConnection(0).createPacketCollector(filter);
// Send the iq packet with an invalid namespace // Send the iq packet with an invalid namespace
getConnection(0).sendPacket(iq); getConnection(0).sendStanza(iq);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results // Stop queuing results
@ -85,7 +85,7 @@ public class IQTest extends SmackTestCase {
PacketCollector collector = getConnection(0).createPacketCollector( PacketCollector collector = getConnection(0).createPacketCollector(
new PacketIDFilter(versionRequest.getStanzaId())); new PacketIDFilter(versionRequest.getStanzaId()));
getConnection(0).sendPacket(versionRequest); getConnection(0).sendStanza(versionRequest);
// Wait up to 5 seconds for a result. // Wait up to 5 seconds for a result.
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

View file

@ -42,11 +42,11 @@ public class MessageTest extends SmackTestCase {
* message? * message?
*/ */
public void testDirectPresence() { public void testDirectPresence() {
getConnection(1).sendPacket(new Presence(Presence.Type.available)); getConnection(1).sendStanza(new Presence(Presence.Type.available));
Presence presence = new Presence(Presence.Type.available); Presence presence = new Presence(Presence.Type.available);
presence.setTo(getBareJID(1)); presence.setTo(getBareJID(1));
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
PacketCollector collector = getConnection(0) PacketCollector collector = getConnection(0)
.createPacketCollector(new MessageTypeFilter(Message.Type.chat)); .createPacketCollector(new MessageTypeFilter(Message.Type.chat));
@ -67,10 +67,10 @@ public class MessageTest extends SmackTestCase {
* the client becomes available again the offline messages are received. * the client becomes available again the offline messages are received.
*/ */
public void testOfflineMessage() { public void testOfflineMessage() {
getConnection(0).sendPacket(new Presence(Presence.Type.available)); getConnection(0).sendStanza(new Presence(Presence.Type.available));
getConnection(1).sendPacket(new Presence(Presence.Type.available)); getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Make user2 unavailable // Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable)); getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
try { try {
Thread.sleep(500); Thread.sleep(500);
@ -86,7 +86,7 @@ public class MessageTest extends SmackTestCase {
// User2 becomes available again // User2 becomes available again
getConnection(1).sendPacket(new Presence(Presence.Type.available)); getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Check that offline messages are retrieved by user2 which is now available // Check that offline messages are retrieved by user2 which is now available
Message message = (Message) collector.nextResult(2500); Message message = (Message) collector.nextResult(2500);
@ -112,7 +112,7 @@ public class MessageTest extends SmackTestCase {
*/ */
/*public void testOfflineMessageInvalidXML() { /*public void testOfflineMessageInvalidXML() {
// Make user2 unavailable // Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable)); getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
try { try {
Thread.sleep(500); Thread.sleep(500);
@ -128,7 +128,7 @@ public class MessageTest extends SmackTestCase {
// User2 becomes available again // User2 becomes available again
getConnection(1).sendPacket(new Presence(Presence.Type.available)); getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Check that offline messages are retrieved by user2 which is now available // Check that offline messages are retrieved by user2 which is now available
Message message = (Message) collector.nextResult(2500); Message message = (Message) collector.nextResult(2500);
@ -150,8 +150,8 @@ public class MessageTest extends SmackTestCase {
* connections are not being closed. * connections are not being closed.
*/ */
public void testHugeMessage() { public void testHugeMessage() {
getConnection(0).sendPacket(new Presence(Presence.Type.available)); getConnection(0).sendStanza(new Presence(Presence.Type.available));
getConnection(1).sendPacket(new Presence(Presence.Type.available)); getConnection(1).sendStanza(new Presence(Presence.Type.available));
// User2 becomes available again // User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector( PacketCollector collector = getConnection(1).createPacketCollector(
new MessageTypeFilter(Message.Type.chat)); new MessageTypeFilter(Message.Type.chat));
@ -165,7 +165,7 @@ public class MessageTest extends SmackTestCase {
msg.setBody(sb.toString()); msg.setBody(sb.toString());
// Send the first message // Send the first message
getConnection(0).sendPacket(msg); getConnection(0).sendStanza(msg);
// Check that the connection that sent the message is still connected // Check that the connection that sent the message is still connected
assertTrue("XMPPConnection was closed", getConnection(0).isConnected()); assertTrue("XMPPConnection was closed", getConnection(0).isConnected());
// Check that the message was received // Check that the message was received
@ -173,7 +173,7 @@ public class MessageTest extends SmackTestCase {
assertNotNull("No Message was received", rcv); assertNotNull("No Message was received", rcv);
// Send the second message // Send the second message
getConnection(0).sendPacket(msg); getConnection(0).sendStanza(msg);
// Check that the connection that sent the message is still connected // Check that the connection that sent the message is still connected
assertTrue("XMPPConnection was closed", getConnection(0).isConnected()); assertTrue("XMPPConnection was closed", getConnection(0).isConnected());
// Check that the second message was received // Check that the second message was received
@ -200,11 +200,11 @@ public class MessageTest extends SmackTestCase {
// Set this connection as highest priority // Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available); Presence presence = new Presence(Presence.Type.available);
presence.setPriority(10); presence.setPriority(10);
conn3.sendPacket(presence); conn3.sendStanza(presence);
// Set this connection as highest priority // Set this connection as highest priority
presence = new Presence(Presence.Type.available); presence = new Presence(Presence.Type.available);
presence.setPriority(5); presence.setPriority(5);
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
// Let the server process the change in presences // Let the server process the change in presences
Thread.sleep(200); Thread.sleep(200);
@ -249,11 +249,11 @@ public class MessageTest extends SmackTestCase {
// Set this connection as highest priority // Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available); Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.away); presence.setMode(Presence.Mode.away);
conn3.sendPacket(presence); conn3.sendStanza(presence);
// Set this connection as highest priority // Set this connection as highest priority
presence = new Presence(Presence.Type.available); presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available); presence.setMode(Presence.Mode.available);
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
// Let the server process the change in presences // Let the server process the change in presences
Thread.sleep(200); Thread.sleep(200);
@ -299,12 +299,12 @@ public class MessageTest extends SmackTestCase {
Presence presence = new Presence(Presence.Type.available); Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available); presence.setMode(Presence.Mode.available);
presence.setPriority(10); presence.setPriority(10);
conn3.sendPacket(presence); conn3.sendStanza(presence);
// Set this connection as highest priority // Set this connection as highest priority
presence = new Presence(Presence.Type.available); presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available); presence.setMode(Presence.Mode.available);
presence.setPriority(10); presence.setPriority(10);
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
connectionConfiguration = connectionConfiguration =
new ConnectionConfiguration(getHost(), getPort(), getServiceName()); new ConnectionConfiguration(getHost(), getPort(), getServiceName());
@ -314,7 +314,7 @@ public class MessageTest extends SmackTestCase {
presence = new Presence(Presence.Type.available); presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available); presence.setMode(Presence.Mode.available);
presence.setPriority(4); presence.setPriority(4);
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
// Let the server process the change in presences // Let the server process the change in presences
@ -326,7 +326,7 @@ public class MessageTest extends SmackTestCase {
PacketCollector coll4 = conn4.createPacketCollector(new MessageTypeFilter(Message.Type.chat)); PacketCollector coll4 = conn4.createPacketCollector(new MessageTypeFilter(Message.Type.chat));
// Send a message from this resource to indicate most recent activity // Send a message from this resource to indicate most recent activity
conn3.sendPacket(new Message("admin@" + getServiceName())); conn3.sendStanza(new Message("admin@" + getServiceName()));
// User1 sends a message to the bare JID of User0 // User1 sends a message to the bare JID of User0
Chat chat = getConnection(1).getChatManager().createChat(getBareJID(0), null); Chat chat = getConnection(1).getChatManager().createChat(getBareJID(0), null);
@ -362,7 +362,7 @@ public class MessageTest extends SmackTestCase {
Presence presence = new Presence(Presence.Type.available); Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available); presence.setMode(Presence.Mode.available);
presence.setPriority(-1); presence.setPriority(-1);
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
// Let the server process the change in presences // Let the server process the change in presences
Thread.sleep(200); Thread.sleep(200);
@ -383,7 +383,7 @@ public class MessageTest extends SmackTestCase {
presence = new Presence(Presence.Type.available); presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available); presence.setMode(Presence.Mode.available);
presence.setPriority(1); presence.setPriority(1);
getConnection(0).sendPacket(presence); getConnection(0).sendStanza(presence);
// Let the server process the change in presences // Let the server process the change in presences
Thread.sleep(200); Thread.sleep(200);

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.filter.FromMatchesFilter; import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.PacketIDFilter; import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.*; import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.test.SmackTestCase; import org.jivesoftware.smack.test.SmackTestCase;
@ -84,7 +84,7 @@ public class PacketReaderTest extends SmackTestCase {
// Send the IQ and wait for the answer // Send the IQ and wait for the answer
PacketCollector collector = getConnection(0).createPacketCollector( PacketCollector collector = getConnection(0).createPacketCollector(
new PacketIDFilter(iqPacket.getStanzaId())); new PacketIDFilter(iqPacket.getStanzaId()));
getConnection(0).sendPacket(iqPacket); getConnection(0).sendStanza(iqPacket);
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) { if (response == null) {
fail("No response from the other user."); fail("No response from the other user.");
@ -114,7 +114,7 @@ public class PacketReaderTest extends SmackTestCase {
Message msg = new Message(getConnection(0).getUser(), Message.Type.normal); Message msg = new Message(getConnection(0).getUser(), Message.Type.normal);
getConnection(1).sendPacket(msg); getConnection(1).sendStanza(msg);
// Remove the listener // Remove the listener
getConnection(0).removeAsyncPacketListener(listener); getConnection(0).removeAsyncPacketListener(listener);
@ -141,15 +141,15 @@ public class PacketReaderTest extends SmackTestCase {
Message message = new Message(packet.getFrom()); Message message = new Message(packet.getFrom());
message.setFrom(getFullJID(1)); message.setFrom(getFullJID(1));
message.setBody("HELLO"); message.setBody("HELLO");
getConnection(1).sendPacket(message); getConnection(1).sendStanza(message);
} }
}, new PacketTypeFilter(Message.class)); }, new StanzaTypeFilter(Message.class));
// User0 listen for replies from user1 // User0 listen for replies from user1
PacketCollector collector = getConnection(0).createPacketCollector( PacketCollector collector = getConnection(0).createPacketCollector(
new FromMatchesFilter(getFullJID(1))); new FromMatchesFilter(getFullJID(1)));
// User0 sends the regular message to user1 // User0 sends the regular message to user1
getConnection(0).sendPacket(packet); getConnection(0).sendStanza(packet);
// Check that user0 got a reply from user1 // Check that user0 got a reply from user1
assertNotNull("No message was received", collector.nextResult(1000)); assertNotNull("No message was received", collector.nextResult(1000));
@ -159,7 +159,7 @@ public class PacketReaderTest extends SmackTestCase {
packet.setTo(getFullJID(1)); packet.setTo(getFullJID(1));
packet.setBody("aloha"); packet.setBody("aloha");
packet.setError(new XMPPError(XMPPError.Condition.feature_not_implemented, null)); packet.setError(new XMPPError(XMPPError.Condition.feature_not_implemented, null));
getConnection(0).sendPacket(packet); getConnection(0).sendStanza(packet);
// Check that user0 got a reply from user1 // Check that user0 got a reply from user1
assertNotNull("No message was received", collector.nextResult(1000)); assertNotNull("No message was received", collector.nextResult(1000));
} }
@ -213,8 +213,8 @@ public class PacketReaderTest extends SmackTestCase {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
getConnection(1).sendPacket(msg0); getConnection(1).sendStanza(msg0);
getConnection(0).sendPacket(msg1); getConnection(0).sendStanza(msg1);
} }
try { try {
@ -236,8 +236,8 @@ public class PacketReaderTest extends SmackTestCase {
} }
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
getConnection(0).sendPacket(msg1); getConnection(0).sendStanza(msg1);
getConnection(1).sendPacket(msg0); getConnection(1).sendStanza(msg0);
} }
try { try {

View file

@ -46,9 +46,9 @@ public class PresenceTest extends SmackTestCase {
conn.connect(); conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace"); conn.login(getUsername(1), getUsername(1), "OtherPlace");
// Change the presence priorities of User_1 // Change the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 1, getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available)); Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 2, conn.sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available)); Presence.Mode.available));
Thread.sleep(150); Thread.sleep(150);
// Create the chats between the participants // Create the chats between the participants
@ -64,9 +64,9 @@ public class PresenceTest extends SmackTestCase {
chat1.nextMessage(1000));*/ chat1.nextMessage(1000));*/
// Invert the presence priorities of User_1 // Invert the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 2, getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available)); Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 1, conn.sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available)); Presence.Mode.available));
Thread.sleep(150); Thread.sleep(150);
@ -86,14 +86,14 @@ public class PresenceTest extends SmackTestCase {
/*assertNotNull("Resource with highest priority didn't receive the message", /*assertNotNull("Resource with highest priority didn't receive the message",
chat1.nextMessage(2000));*/ chat1.nextMessage(2000));*/
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 2, getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available)); Presence.Mode.available));
// User_1 will log in again using another resource // User_1 will log in again using another resource
conn = createConnection(); conn = createConnection();
conn.connect(); conn.connect();
conn.login(getUsername(1), getPassword(1), "OtherPlace"); conn.login(getUsername(1), getPassword(1), "OtherPlace");
conn.sendPacket(new Presence(Presence.Type.available, null, 1, conn.sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available)); Presence.Mode.available));
chat2 = conn.getChatManager().createChat(getBareJID(0), chat0.getThreadID(), null); chat2 = conn.getChatManager().createChat(getBareJID(0), chat0.getThreadID(), null);
@ -106,9 +106,9 @@ public class PresenceTest extends SmackTestCase {
chat2.nextMessage(1000));*/ chat2.nextMessage(1000));*/
// Invert the presence priorities of User_1 // Invert the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 1, getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available)); Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 2, conn.sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available)); Presence.Mode.available));
Thread.sleep(150); Thread.sleep(150);
@ -139,7 +139,7 @@ public class PresenceTest extends SmackTestCase {
*/ */
public void testNotAvailablePresence() throws XMPPException { public void testNotAvailablePresence() throws XMPPException {
// Change the presence to unavailable of User_1 // Change the presence to unavailable of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable)); getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
// User_1 will log in again using another resource (that is going to be available) // User_1 will log in again using another resource (that is going to be available)
XMPPTCPConnection conn = createConnection(); XMPPTCPConnection conn = createConnection();

View file

@ -21,9 +21,9 @@ import junit.framework.TestCase;
import org.jivesoftware.smack.packet.*; import org.jivesoftware.smack.packet.*;
/** /**
* Test cases for the PacketTypeFilter class. * Test cases for the StanzaTypeFilter class.
*/ */
public class PacketTypeFilterTest extends TestCase { public class StanzaTypeFilterTest extends TestCase {
private class InnerClassDummy { private class InnerClassDummy {
public class DummyPacket extends Packet { public class DummyPacket extends Packet {
@ -48,20 +48,20 @@ public class PacketTypeFilterTest extends TestCase {
} }
/** /**
* Test case for the constructor of PacketTypeFilter objects. * Test case for the constructor of StanzaTypeFilter objects.
*/ */
public void testConstructor() { public void testConstructor() {
// We dont need to test this since PacketTypeFilter(Class<? extends Packet> packetType) only excepts Packets // We dont need to test this since StanzaTypeFilter(Class<? extends Packet> packetType) only excepts Packets
// Test a class that is not a subclass of Packet // Test a class that is not a subclass of Packet
// try { // try {
// new PacketTypeFilter(Dummy.class); // new StanzaTypeFilter(Dummy.class);
// fail("Parameter must be a subclass of Packet."); // fail("Parameter must be a subclass of Packet.");
// } // }
// catch (IllegalArgumentException e) {} // catch (IllegalArgumentException e) {}
// Test a class that is a subclass of Packet // Test a class that is a subclass of Packet
try { try {
new PacketTypeFilter(MockPacket.class); new StanzaTypeFilter(MockPacket.class);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
fail(); fail();
@ -69,7 +69,7 @@ public class PacketTypeFilterTest extends TestCase {
// Test another class which is a subclass of Packet // Test another class which is a subclass of Packet
try { try {
new PacketTypeFilter(IQ.class); new StanzaTypeFilter(IQ.class);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
fail(); fail();
@ -77,7 +77,7 @@ public class PacketTypeFilterTest extends TestCase {
// Test an internal class which is a subclass of Packet // Test an internal class which is a subclass of Packet
try { try {
new PacketTypeFilter(InnerClassDummy.DummyPacket.class); new StanzaTypeFilter(InnerClassDummy.DummyPacket.class);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
fail(); fail();
@ -85,7 +85,7 @@ public class PacketTypeFilterTest extends TestCase {
// Test an internal static class which is a static subclass of Packet // Test an internal static class which is a static subclass of Packet
try { try {
new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class); new StanzaTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
fail(); fail();
@ -93,19 +93,19 @@ public class PacketTypeFilterTest extends TestCase {
} }
/** /**
* Test case to test the accept() method of PacketTypeFilter objects. * Test case to test the accept() method of StanzaTypeFilter objects.
*/ */
public void testAccept() { public void testAccept() {
Packet packet = new MockPacket(); Packet packet = new MockPacket();
PacketTypeFilter filter = new PacketTypeFilter(MockPacket.class); StanzaTypeFilter filter = new PacketTypeFilter(MockPacket.class);
assertTrue(filter.accept(packet)); assertTrue(filter.accept(packet));
packet = (new InnerClassDummy()).getInnerInstance(); packet = (new InnerClassDummy()).getInnerInstance();
filter = new PacketTypeFilter(InnerClassDummy.DummyPacket.class); filter = new StanzaTypeFilter(InnerClassDummy.DummyPacket.class);
assertTrue(filter.accept(packet)); assertTrue(filter.accept(packet));
packet = StaticInnerClassDummy.getInnerInstance(); packet = StaticInnerClassDummy.getInnerInstance();
filter = new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class); filter = new StanzaTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
assertTrue(filter.accept(packet)); assertTrue(filter.accept(packet));
} }
} }

View file

@ -32,9 +32,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -56,7 +55,7 @@ import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.compression.XMPPInputOutputStream; import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger; import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.IQReplyFilter; import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter; import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler; import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.Bind; import org.jivesoftware.smack.packet.Bind;
@ -64,7 +63,7 @@ import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms; import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.StartTls; import org.jivesoftware.smack.packet.StartTls;
@ -72,7 +71,7 @@ import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback; import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.parsing.UnparsablePacket; import org.jivesoftware.smack.parsing.UnparsablePacket;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.util.DNSUtil; import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
@ -134,30 +133,30 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
/** /**
* List of PacketListeners that will be notified synchronously when a new packet was received. * List of PacketListeners that will be notified synchronously when a new packet was received.
*/ */
private final Map<PacketListener, ListenerWrapper> syncRecvListeners = new LinkedHashMap<>(); private final Map<StanzaListener, ListenerWrapper> syncRecvListeners = new LinkedHashMap<>();
/** /**
* List of PacketListeners that will be notified asynchronously when a new packet was received. * List of PacketListeners that will be notified asynchronously when a new packet was received.
*/ */
private final Map<PacketListener, ListenerWrapper> asyncRecvListeners = new LinkedHashMap<>(); private final Map<StanzaListener, ListenerWrapper> asyncRecvListeners = new LinkedHashMap<>();
/** /**
* List of PacketListeners that will be notified when a new packet was sent. * List of PacketListeners that will be notified when a new packet was sent.
*/ */
private final Map<PacketListener, ListenerWrapper> sendListeners = private final Map<StanzaListener, ListenerWrapper> sendListeners =
new HashMap<PacketListener, ListenerWrapper>(); new HashMap<StanzaListener, ListenerWrapper>();
/** /**
* List of PacketListeners that will be notified when a new packet is about to be * List of PacketListeners that will be notified when a new packet is about to be
* sent to the server. These interceptors may modify the packet before it is being * sent to the server. These interceptors may modify the packet before it is being
* actually sent to the server. * actually sent to the server.
*/ */
private final Map<PacketListener, InterceptorWrapper> interceptors = private final Map<StanzaListener, InterceptorWrapper> interceptors =
new HashMap<PacketListener, InterceptorWrapper>(); new HashMap<StanzaListener, InterceptorWrapper>();
protected final Lock connectionLock = new ReentrantLock(); protected final Lock connectionLock = new ReentrantLock();
protected final Map<String, PacketExtension> streamFeatures = new HashMap<String, PacketExtension>(); protected final Map<String, ExtensionElement> streamFeatures = new HashMap<String, ExtensionElement>();
/** /**
* The full JID of the authenticated user, as returned by the resource binding response of the server. * The full JID of the authenticated user, as returned by the resource binding response of the server.
@ -247,49 +246,15 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
/** /**
* This scheduled thread pool executor is used to remove pending callbacks. * This scheduled thread pool executor is used to remove pending callbacks.
*/ */
private final ScheduledThreadPoolExecutor removeCallbacksService = new ScheduledThreadPoolExecutor(1, private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor(
new SmackExecutorThreadFactory(connectionCounterValue, "Remove Callbacks")); new SmackExecutorThreadFactory(connectionCounterValue, "Remove Callbacks"));
private static int concurrencyLevel = Runtime.getRuntime().availableProcessors() + 1;
/** /**
* Set the concurrency level used by newly created connections. * A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set
* <p>
* The concurrency level determines the maximum pool size of the executor service that is used to e.g. invoke
* callbacks and IQ request handlers.
* </p>
* <p>
* The default value is <code>Runtime.getRuntime().availableProcessors() + 1</code>. Note that the number of
* available processors may change at runtime. So you may need to adjust it to your enviornment, although in most
* cases this should not be necessary.
* </p>
*
* @param concurrencyLevel the concurrency level used by new connections.
*/
public static void setConcurrencyLevel(int concurrencyLevel) {
if (concurrencyLevel < 1) {
throw new IllegalArgumentException("concurrencyLevel must be greater than zero");
}
AbstractXMPPConnection.concurrencyLevel = concurrencyLevel;
}
/**
* The constant long '120'.
*/
private static final long THREAD_KEEP_ALIVE_SECONDS = 60L * 2;
/**
* Creates an executor service just as {@link Executors#newCachedThreadPool()} would do, but with a keep alive time
* of 2 minutes instead of 60 seconds. And a custom thread factory to set meaningful names on the threads and set
* them 'daemon'. * them 'daemon'.
*/ */
private final ExecutorService cachedExecutorService = new ThreadPoolExecutor( private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool(
// @formatter:off // @formatter:off
0, // corePoolSize
concurrencyLevel, // maximumPoolSize
THREAD_KEEP_ALIVE_SECONDS, // keepAliveTime
TimeUnit.SECONDS, // keepAliveTime unit, note that MINUTES is Android API 9
new LinkedBlockingQueue<Runnable>(), // workQueue
new SmackExecutorThreadFactory( // threadFactory new SmackExecutorThreadFactory( // threadFactory
connectionCounterValue, connectionCounterValue,
"Cached Executor" "Cached Executor"
@ -336,8 +301,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
protected AbstractXMPPConnection(ConnectionConfiguration configuration) { protected AbstractXMPPConnection(ConnectionConfiguration configuration) {
config = configuration; config = configuration;
removeCallbacksService.setMaximumPoolSize(concurrencyLevel);
removeCallbacksService.setKeepAliveTime(THREAD_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS);
} }
protected ConnectionConfiguration getConfiguration() { protected ConnectionConfiguration getConfiguration() {
@ -365,7 +328,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override @Override
public abstract boolean isSecureConnection(); public abstract boolean isSecureConnection();
protected abstract void sendPacketInternal(Stanza packet) throws NotConnectedException, InterruptedException; protected abstract void sendStanzaInternal(Stanza packet) throws NotConnectedException, InterruptedException;
@Override @Override
public abstract void send(PlainStreamElement element) throws NotConnectedException, InterruptedException; public abstract void send(PlainStreamElement element) throws NotConnectedException, InterruptedException;
@ -583,7 +546,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// eventually load the roster. And we should load the roster before we // eventually load the roster. And we should load the roster before we
// send the initial presence. // send the initial presence.
if (config.isSendPresence() && !resumed) { if (config.isSendPresence() && !resumed) {
sendPacket(new Presence(Presence.Type.available)); sendStanza(new Presence(Presence.Type.available));
} }
} }
@ -641,8 +604,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
@Deprecated
@Override @Override
public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException { public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException {
sendStanza(packet);
}
@Override
public void sendStanza(Stanza packet) throws NotConnectedException, InterruptedException {
Objects.requireNonNull(packet, "Packet must not be null"); Objects.requireNonNull(packet, "Packet must not be null");
throwNotConnectedExceptionIfAppropriate(); throwNotConnectedExceptionIfAppropriate();
@ -660,7 +629,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// Invoke interceptors for the new packet that is about to be sent. Interceptors may modify // Invoke interceptors for the new packet that is about to be sent. Interceptors may modify
// the content of the packet. // the content of the packet.
firePacketInterceptors(packet); firePacketInterceptors(packet);
sendPacketInternal(packet); sendStanzaInternal(packet);
} }
/** /**
@ -702,7 +671,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException { public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException {
try { try {
sendPacket(unavailablePresence); sendStanza(unavailablePresence);
} }
catch (InterruptedException e) { catch (InterruptedException e) {
LOGGER.log(Level.FINE, "Was interrupted while sending unavailable presence. Continuing to disconnect the connection", e); LOGGER.log(Level.FINE, "Was interrupted while sending unavailable presence. Continuing to disconnect the connection", e);
@ -731,20 +700,20 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override @Override
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException { public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException {
PacketFilter packetFilter = new IQReplyFilter(packet, this); StanzaFilter packetFilter = new IQReplyFilter(packet, this);
// Create the packet collector before sending the packet // Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet); PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet);
return packetCollector; return packetCollector;
} }
@Override @Override
public PacketCollector createPacketCollectorAndSend(PacketFilter packetFilter, Stanza packet) public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
throws NotConnectedException, InterruptedException { throws NotConnectedException, InterruptedException {
// Create the packet collector before sending the packet // Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollector(packetFilter); PacketCollector packetCollector = createPacketCollector(packetFilter);
try { try {
// Now we can send the packet as the collector has been created // Now we can send the packet as the collector has been created
sendPacket(packet); sendStanza(packet);
} }
catch (InterruptedException | NotConnectedException | RuntimeException e) { catch (InterruptedException | NotConnectedException | RuntimeException e) {
packetCollector.cancel(); packetCollector.cancel();
@ -754,8 +723,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
@Override @Override
public PacketCollector createPacketCollector(PacketFilter packetFilter) { public PacketCollector createPacketCollector(StanzaFilter packetFilter) {
PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setPacketFilter(packetFilter); PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setStanzaFilter(packetFilter);
return createPacketCollector(configuration); return createPacketCollector(configuration);
} }
@ -774,18 +743,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override @Override
@Deprecated @Deprecated
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) { public void addPacketListener(StanzaListener packetListener, StanzaFilter packetFilter) {
addAsyncPacketListener(packetListener, packetFilter); addAsyncStanzaListener(packetListener, packetFilter);
} }
@Override @Override
@Deprecated @Deprecated
public boolean removePacketListener(PacketListener packetListener) { public boolean removePacketListener(StanzaListener packetListener) {
return removeAsyncPacketListener(packetListener); return removeAsyncStanzaListener(packetListener);
} }
@Override @Override
public void addSyncPacketListener(PacketListener packetListener, PacketFilter packetFilter) { public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) { if (packetListener == null) {
throw new NullPointerException("Packet listener is null."); throw new NullPointerException("Packet listener is null.");
} }
@ -796,14 +765,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
@Override @Override
public boolean removeSyncPacketListener(PacketListener packetListener) { public boolean removeSyncStanzaListener(StanzaListener packetListener) {
synchronized (syncRecvListeners) { synchronized (syncRecvListeners) {
return syncRecvListeners.remove(packetListener) != null; return syncRecvListeners.remove(packetListener) != null;
} }
} }
@Override @Override
public void addAsyncPacketListener(PacketListener packetListener, PacketFilter packetFilter) { public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) { if (packetListener == null) {
throw new NullPointerException("Packet listener is null."); throw new NullPointerException("Packet listener is null.");
} }
@ -814,14 +783,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
@Override @Override
public boolean removeAsyncPacketListener(PacketListener packetListener) { public boolean removeAsyncStanzaListener(StanzaListener packetListener) {
synchronized (asyncRecvListeners) { synchronized (asyncRecvListeners) {
return asyncRecvListeners.remove(packetListener) != null; return asyncRecvListeners.remove(packetListener) != null;
} }
} }
@Override @Override
public void addPacketSendingListener(PacketListener packetListener, PacketFilter packetFilter) { public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) { if (packetListener == null) {
throw new NullPointerException("Packet listener is null."); throw new NullPointerException("Packet listener is null.");
} }
@ -832,7 +801,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
@Override @Override
public void removePacketSendingListener(PacketListener packetListener) { public void removePacketSendingListener(StanzaListener packetListener) {
synchronized (sendListeners) { synchronized (sendListeners) {
sendListeners.remove(packetListener); sendListeners.remove(packetListener);
} }
@ -848,7 +817,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
protected void firePacketSendingListeners(final Stanza packet) { protected void firePacketSendingListeners(final Stanza packet) {
final List<PacketListener> listenersToNotify = new LinkedList<PacketListener>(); final List<StanzaListener> listenersToNotify = new LinkedList<StanzaListener>();
synchronized (sendListeners) { synchronized (sendListeners) {
for (ListenerWrapper listenerWrapper : sendListeners.values()) { for (ListenerWrapper listenerWrapper : sendListeners.values()) {
if (listenerWrapper.filterMatches(packet)) { if (listenerWrapper.filterMatches(packet)) {
@ -863,7 +832,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
asyncGo(new Runnable() { asyncGo(new Runnable() {
@Override @Override
public void run() { public void run() {
for (PacketListener listener : listenersToNotify) { for (StanzaListener listener : listenersToNotify) {
try { try {
listener.processPacket(packet); listener.processPacket(packet);
} }
@ -876,8 +845,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
@Override @Override
public void addPacketInterceptor(PacketListener packetInterceptor, public void addPacketInterceptor(StanzaListener packetInterceptor,
PacketFilter packetFilter) { StanzaFilter packetFilter) {
if (packetInterceptor == null) { if (packetInterceptor == null) {
throw new NullPointerException("Packet interceptor is null."); throw new NullPointerException("Packet interceptor is null.");
} }
@ -888,7 +857,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
@Override @Override
public void removePacketInterceptor(PacketListener packetInterceptor) { public void removePacketInterceptor(StanzaListener packetInterceptor) {
synchronized (interceptors) { synchronized (interceptors) {
interceptors.remove(packetInterceptor); interceptors.remove(packetInterceptor);
} }
@ -903,7 +872,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @param packet the packet that is going to be sent to the server * @param packet the packet that is going to be sent to the server
*/ */
private void firePacketInterceptors(Stanza packet) { private void firePacketInterceptors(Stanza packet) {
List<PacketListener> interceptorsToInvoke = new LinkedList<PacketListener>(); List<StanzaListener> interceptorsToInvoke = new LinkedList<StanzaListener>();
synchronized (interceptors) { synchronized (interceptors) {
for (InterceptorWrapper interceptorWrapper : interceptors.values()) { for (InterceptorWrapper interceptorWrapper : interceptors.values()) {
if (interceptorWrapper.filterMatches(packet)) { if (interceptorWrapper.filterMatches(packet)) {
@ -911,7 +880,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
} }
for (PacketListener interceptor : interceptorsToInvoke) { for (StanzaListener interceptor : interceptorsToInvoke) {
try { try {
interceptor.processPacket(packet); interceptor.processPacket(packet);
} catch (Exception e) { } catch (Exception e) {
@ -1073,7 +1042,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
ErrorIQ errorIQ = IQ.createErrorResponse(iq, new XMPPError( ErrorIQ errorIQ = IQ.createErrorResponse(iq, new XMPPError(
XMPPError.Condition.feature_not_implemented)); XMPPError.Condition.feature_not_implemented));
try { try {
sendPacket(errorIQ); sendStanza(errorIQ);
} }
catch (InterruptedException | NotConnectedException e) { catch (InterruptedException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Exception while sending error IQ to unkown IQ request", e); LOGGER.log(Level.WARNING, "Exception while sending error IQ to unkown IQ request", e);
@ -1102,7 +1071,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return; return;
} }
try { try {
sendPacket(response); sendStanza(response);
} }
catch (InterruptedException | NotConnectedException e) { catch (InterruptedException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Exception while sending response to IQ request", e); LOGGER.log(Level.WARNING, "Exception while sending response to IQ request", e);
@ -1122,7 +1091,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// First handle the async recv listeners. Note that this code is very similar to what follows a few lines below, // First handle the async recv listeners. Note that this code is very similar to what follows a few lines below,
// the only difference is that asyncRecvListeners is used here and that the packet listeners are started in // the only difference is that asyncRecvListeners is used here and that the packet listeners are started in
// their own thread. // their own thread.
final Collection<PacketListener> listenersToNotify = new LinkedList<PacketListener>(); final Collection<StanzaListener> listenersToNotify = new LinkedList<StanzaListener>();
synchronized (asyncRecvListeners) { synchronized (asyncRecvListeners) {
for (ListenerWrapper listenerWrapper : asyncRecvListeners.values()) { for (ListenerWrapper listenerWrapper : asyncRecvListeners.values()) {
if (listenerWrapper.filterMatches(packet)) { if (listenerWrapper.filterMatches(packet)) {
@ -1131,7 +1100,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
for (final PacketListener listener : listenersToNotify) { for (final StanzaListener listener : listenersToNotify) {
asyncGo(new Runnable() { asyncGo(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1164,7 +1133,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
singleThreadedExecutorService.execute(new Runnable() { singleThreadedExecutorService.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
for (PacketListener listener : listenersToNotify) { for (StanzaListener listener : listenersToNotify) {
try { try {
listener.processPacket(packet); listener.processPacket(packet);
} catch(NotConnectedException e) { } catch(NotConnectedException e) {
@ -1258,8 +1227,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
protected static class ListenerWrapper { protected static class ListenerWrapper {
private final PacketListener packetListener; private final StanzaListener packetListener;
private final PacketFilter packetFilter; private final StanzaFilter packetFilter;
/** /**
* Create a class which associates a packet filter with a listener. * Create a class which associates a packet filter with a listener.
@ -1267,7 +1236,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @param packetListener the packet listener. * @param packetListener the packet listener.
* @param packetFilter the associated filter or null if it listen for all packets. * @param packetFilter the associated filter or null if it listen for all packets.
*/ */
public ListenerWrapper(PacketListener packetListener, PacketFilter packetFilter) { public ListenerWrapper(StanzaListener packetListener, StanzaFilter packetFilter) {
this.packetListener = packetListener; this.packetListener = packetListener;
this.packetFilter = packetFilter; this.packetFilter = packetFilter;
} }
@ -1276,7 +1245,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return packetFilter == null || packetFilter.accept(packet); return packetFilter == null || packetFilter.accept(packet);
} }
public PacketListener getListener() { public StanzaListener getListener() {
return packetListener; return packetListener;
} }
} }
@ -1286,8 +1255,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
protected static class InterceptorWrapper { protected static class InterceptorWrapper {
private final PacketListener packetInterceptor; private final StanzaListener packetInterceptor;
private final PacketFilter packetFilter; private final StanzaFilter packetFilter;
/** /**
* Create a class which associates a packet filter with an interceptor. * Create a class which associates a packet filter with an interceptor.
@ -1295,7 +1264,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @param packetInterceptor the interceptor. * @param packetInterceptor the interceptor.
* @param packetFilter the associated filter or null if it intercepts all packets. * @param packetFilter the associated filter or null if it intercepts all packets.
*/ */
public InterceptorWrapper(PacketListener packetInterceptor, PacketFilter packetFilter) { public InterceptorWrapper(StanzaListener packetInterceptor, StanzaFilter packetFilter) {
this.packetInterceptor = packetInterceptor; this.packetInterceptor = packetInterceptor;
this.packetFilter = packetFilter; this.packetFilter = packetFilter;
} }
@ -1304,7 +1273,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return packetFilter == null || packetFilter.accept(packet); return packetFilter == null || packetFilter.accept(packet);
} }
public PacketListener getInterceptor() { public StanzaListener getInterceptor() {
return packetInterceptor; return packetInterceptor;
} }
} }
@ -1354,7 +1323,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) { if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
PacketExtension streamFeature = null; ExtensionElement streamFeature = null;
String name = parser.getName(); String name = parser.getName();
String namespace = parser.getNamespace(); String namespace = parser.getNamespace();
switch (name) { switch (name) {
@ -1374,7 +1343,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeature = PacketParserUtils.parseCompressionFeature(parser); streamFeature = PacketParserUtils.parseCompressionFeature(parser);
break; break;
default: default:
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getStreamFeatureProvider(name, namespace); ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (provider != null) { if (provider != null) {
streamFeature = provider.parse(parser); streamFeature = provider.parse(parser);
} }
@ -1416,7 +1385,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <F extends PacketExtension> F getFeature(String element, String namespace) { public <F extends ExtensionElement> F getFeature(String element, String namespace) {
return (F) streamFeatures.get(XmppStringUtils.generateKey(element, namespace)); return (F) streamFeatures.get(XmppStringUtils.generateKey(element, namespace));
} }
@ -1425,28 +1394,28 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return getFeature(element, namespace) != null; return getFeature(element, namespace) != null;
} }
private void addStreamFeature(PacketExtension feature) { private void addStreamFeature(ExtensionElement feature) {
String key = XmppStringUtils.generateKey(feature.getElementName(), feature.getNamespace()); String key = XmppStringUtils.generateKey(feature.getElementName(), feature.getNamespace());
streamFeatures.put(key, feature); streamFeatures.put(key, feature);
} }
@Override @Override
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
PacketListener callback) throws NotConnectedException, InterruptedException { StanzaListener callback) throws NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, null); sendStanzaWithResponseCallback(stanza, replyFilter, callback, null);
} }
@Override @Override
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
PacketListener callback, ExceptionCallback exceptionCallback) StanzaListener callback, ExceptionCallback exceptionCallback)
throws NotConnectedException, InterruptedException { throws NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback, sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback,
getPacketReplyTimeout()); getPacketReplyTimeout());
} }
@Override @Override
public void sendStanzaWithResponseCallback(Stanza stanza, final PacketFilter replyFilter, public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter replyFilter,
final PacketListener callback, final ExceptionCallback exceptionCallback, final StanzaListener callback, final ExceptionCallback exceptionCallback,
long timeout) throws NotConnectedException, InterruptedException { long timeout) throws NotConnectedException, InterruptedException {
Objects.requireNonNull(stanza, "stanza must not be null"); Objects.requireNonNull(stanza, "stanza must not be null");
// While Smack allows to add PacketListeners with a PacketFilter value of 'null', we // While Smack allows to add PacketListeners with a PacketFilter value of 'null', we
@ -1454,7 +1423,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
Objects.requireNonNull(replyFilter, "replyFilter must not be null"); Objects.requireNonNull(replyFilter, "replyFilter must not be null");
Objects.requireNonNull(callback, "callback must not be null"); Objects.requireNonNull(callback, "callback must not be null");
final PacketListener packetListener = new PacketListener() { final StanzaListener packetListener = new StanzaListener() {
@Override @Override
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException { public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
try { try {
@ -1467,14 +1436,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
finally { finally {
removeAsyncPacketListener(this); removeAsyncStanzaListener(this);
} }
} }
}; };
removeCallbacksService.schedule(new Runnable() { removeCallbacksService.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
boolean removed = removeAsyncPacketListener(packetListener); boolean removed = removeAsyncStanzaListener(packetListener);
// If the packetListener got removed, then it was never run and // If the packetListener got removed, then it was never run and
// we never received a response, inform the exception callback // we never received a response, inform the exception callback
if (removed && exceptionCallback != null) { if (removed && exceptionCallback != null) {
@ -1482,47 +1451,47 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
}, timeout, TimeUnit.MILLISECONDS); }, timeout, TimeUnit.MILLISECONDS);
addAsyncPacketListener(packetListener, replyFilter); addAsyncStanzaListener(packetListener, replyFilter);
sendPacket(stanza); sendStanza(stanza);
} }
@Override @Override
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback) public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback)
throws NotConnectedException, InterruptedException { throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, null); sendIqWithResponseCallback(iqRequest, callback, null);
} }
@Override @Override
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback, public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException { ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getPacketReplyTimeout()); sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getPacketReplyTimeout());
} }
@Override @Override
public void sendIqWithResponseCallback(IQ iqRequest, final PacketListener callback, public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
final ExceptionCallback exceptionCallback, long timeout) final ExceptionCallback exceptionCallback, long timeout)
throws NotConnectedException, InterruptedException { throws NotConnectedException, InterruptedException {
PacketFilter replyFilter = new IQReplyFilter(iqRequest, this); StanzaFilter replyFilter = new IQReplyFilter(iqRequest, this);
sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout); sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout);
} }
@Override @Override
public void addOneTimeSyncCallback(final PacketListener callback, final PacketFilter packetFilter) { public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
final PacketListener packetListener = new PacketListener() { final StanzaListener packetListener = new StanzaListener() {
@Override @Override
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException { public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
try { try {
callback.processPacket(packet); callback.processPacket(packet);
} finally { } finally {
removeSyncPacketListener(this); removeSyncStanzaListener(this);
} }
} }
}; };
addSyncPacketListener(packetListener, packetFilter); addSyncStanzaListener(packetListener, packetFilter);
removeCallbacksService.schedule(new Runnable() { removeCallbacksService.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
removeSyncPacketListener(packetListener); removeSyncStanzaListener(packetListener);
} }
}, getPacketReplyTimeout(), TimeUnit.MILLISECONDS); }, getPacketReplyTimeout(), TimeUnit.MILLISECONDS);
} }

View file

@ -22,26 +22,27 @@ import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
/** /**
* Provides a mechanism to collect packets into a result queue that pass a * Provides a mechanism to collect packets into a result queue that pass a
* specified filter. The collector lets you perform blocking and polling * specified filter. The collector lets you perform blocking and polling
* operations on the result queue. So, a PacketCollector is more suitable to * operations on the result queue. So, a PacketCollector is more suitable to
* use than a {@link PacketListener} when you need to wait for a specific * use than a {@link StanzaListener} when you need to wait for a specific
* result.<p> * result.<p>
* *
* Each packet collector will queue up a configured number of packets for processing before * Each packet collector will queue up a configured number of packets for processing before
* older packets are automatically dropped. The default number is retrieved by * older packets are automatically dropped. The default number is retrieved by
* {@link SmackConfiguration#getPacketCollectorSize()}. * {@link SmackConfiguration#getPacketCollectorSize()}.
* *
* @see XMPPConnection#createPacketCollector(PacketFilter) * @see XMPPConnection#createPacketCollector(StanzaFilter)
* @author Matt Tucker * @author Matt Tucker
*/ */
public class PacketCollector { public class PacketCollector {
private final PacketFilter packetFilter; private final StanzaFilter packetFilter;
private final ArrayBlockingQueue<Stanza> resultQueue; private final ArrayBlockingQueue<Stanza> resultQueue;
/** /**
@ -85,8 +86,20 @@ public class PacketCollector {
* filter is used to determine what packets are queued as results. * filter is used to determine what packets are queued as results.
* *
* @return the packet filter. * @return the packet filter.
* @deprecated use {@link #getStanzaFilter()} instead.
*/ */
public PacketFilter getPacketFilter() { @Deprecated
public StanzaFilter getPacketFilter() {
return getStanzaFilter();
}
/**
* Returns the stanza filter associated with this stanza collector. The stanza
* filter is used to determine what stanzas are queued as results.
*
* @return the stanza filter.
*/
public StanzaFilter getStanzaFilter() {
return packetFilter; return packetFilter;
} }
@ -257,7 +270,7 @@ public class PacketCollector {
} }
public static class Configuration { public static class Configuration {
private PacketFilter packetFilter; private StanzaFilter packetFilter;
private int size = SmackConfiguration.getPacketCollectorSize(); private int size = SmackConfiguration.getPacketCollectorSize();
private PacketCollector collectorToReset; private PacketCollector collectorToReset;
@ -270,9 +283,22 @@ public class PacketCollector {
* *
* @param packetFilter * @param packetFilter
* @return a reference to this configuration. * @return a reference to this configuration.
* @deprecated use {@link #setStanzaFilter(StanzaFilter)} instead.
*/ */
public Configuration setPacketFilter(PacketFilter packetFilter) { @Deprecated
this.packetFilter = packetFilter; public Configuration setPacketFilter(StanzaFilter packetFilter) {
return setStanzaFilter(packetFilter);
}
/**
* Set the stanza filter used by this collector. If <code>null</code>, then all stanzas will
* get collected by this collector.
*
* @param stanzaFilter
* @return a reference to this configuration.
*/
public Configuration setStanzaFilter(StanzaFilter stanzaFilter) {
this.packetFilter = stanzaFilter;
return this; return this;
} }

View file

@ -17,38 +17,10 @@
package org.jivesoftware.smack; package org.jivesoftware.smack;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Stanza;
/** /**
* Provides a mechanism to listen for packets that pass a specified filter. * @deprecated use {@link StanzaListener} instead
* This allows event-style programming -- every time a new packet is found,
* the {@link #processPacket(Stanza)} method will be called. This is the
* opposite approach to the functionality provided by a {@link PacketCollector}
* which lets you block while waiting for results.
* <p>
* Additionally you are able to intercept Packets that are going to be send and
* make modifications to them. You can register a PacketListener as interceptor
* by using {@link XMPPConnection#addPacketInterceptor(PacketListener,
* org.jivesoftware.smack.filter.PacketFilter)}
* </p>
*
* @see XMPPConnection#addAsyncPacketListener(PacketListener, org.jivesoftware.smack.filter.PacketFilter)
* @author Matt Tucker
*/ */
public interface PacketListener { @Deprecated
public interface PacketListener extends StanzaListener {
/**
* Process the next packet sent to this packet listener.
* <p>
* A single thread is responsible for invoking all listeners, so
* it's very important that implementations of this method not block
* for any extended period of time.
* </p>
*
* @param packet the packet to process.
* @throws InterruptedException
*/
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException;
} }

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.util.dns.HostAddress; import org.jivesoftware.smack.util.dns.HostAddress;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
@ -66,9 +66,9 @@ public class SmackException extends Exception {
*/ */
private static final long serialVersionUID = -6523363748984543636L; private static final long serialVersionUID = -6523363748984543636L;
private final PacketFilter filter; private final StanzaFilter filter;
private NoResponseException(String message, PacketFilter filter) { private NoResponseException(String message, StanzaFilter filter) {
super(message); super(message);
this.filter = filter; this.filter = filter;
} }
@ -78,20 +78,20 @@ public class SmackException extends Exception {
* *
* @return the used filter or <code>null</code>. * @return the used filter or <code>null</code>.
*/ */
public PacketFilter getFilter() { public StanzaFilter getFilter() {
return filter; return filter;
} }
public static NoResponseException newWith(XMPPConnection connection) { public static NoResponseException newWith(XMPPConnection connection) {
return newWith(connection, (PacketFilter) null); return newWith(connection, (StanzaFilter) null);
} }
public static NoResponseException newWith(XMPPConnection connection, public static NoResponseException newWith(XMPPConnection connection,
PacketCollector collector) { PacketCollector collector) {
return newWith(connection, collector.getPacketFilter()); return newWith(connection, collector.getStanzaFilter());
} }
public static NoResponseException newWith(XMPPConnection connection, PacketFilter filter) { public static NoResponseException newWith(XMPPConnection connection, StanzaFilter filter) {
final long replyTimeout = connection.getPacketReplyTimeout(); final long replyTimeout = connection.getPacketReplyTimeout();
final StringBuilder sb = new StringBuilder(256); final StringBuilder sb = new StringBuilder(256);
sb.append("No response received within reply timeout. Timeout was " sb.append("No response received within reply timeout. Timeout was "

View file

@ -0,0 +1,55 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Stanza;
/**
* Provides a mechanism to listen for packets that pass a specified filter.
* This allows event-style programming -- every time a new packet is found,
* the {@link #processPacket(Stanza)} method will be called. This is the
* opposite approach to the functionality provided by a {@link PacketCollector}
* which lets you block while waiting for results.
* <p>
* Additionally you are able to intercept Packets that are going to be send and
* make modifications to them. You can register a PacketListener as interceptor
* by using {@link XMPPConnection#addPacketInterceptor(StanzaListener,
* org.jivesoftware.smack.filter.StanzaFilter)}
* </p>
*
* @see XMPPConnection#addAsyncStanzaListener(StanzaListener, org.jivesoftware.smack.filter.StanzaFilter)
* @author Matt Tucker
*/
public interface StanzaListener {
/**
* Process the next packet sent to this packet listener.
* <p>
* A single thread is responsible for invoking all listeners, so
* it's very important that implementations of this method not block
* for any extended period of time.
* </p>
*
* @param packet the packet to process.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException;
}

View file

@ -62,7 +62,7 @@ public class SynchronizationPoint<E extends Exception> {
try { try {
if (request != null) { if (request != null) {
if (request instanceof Stanza) { if (request instanceof Stanza) {
connection.sendPacket((Stanza) request); connection.sendStanza((Stanza) request);
} }
else if (request instanceof PlainStreamElement){ else if (request instanceof PlainStreamElement){
connection.send((PlainStreamElement) request); connection.send((PlainStreamElement) request);

View file

@ -20,11 +20,11 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.filter.IQReplyFilter; import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler; import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.PlainStreamElement; import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid; import org.jxmpp.jid.FullJid;
@ -161,9 +161,20 @@ public interface XMPPConnection {
* @param packet the packet to send. * @param packet the packet to send.
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
* @deprecated use {@link #sendStanza(Stanza)} instead.
*/ */
@Deprecated
public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException; public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException;
/**
* Sends the specified stanza to the server.
*
* @param stanza the stanza to send.
* @throws NotConnectedException if the connection is not connected.
* @throws InterruptedException
* */
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException;
/** /**
* Send a PlainStreamElement. * Send a PlainStreamElement.
* <p> * <p>
@ -209,7 +220,7 @@ public interface XMPPConnection {
/** /**
* Creates a new packet collector for this connection. A packet filter determines * Creates a new packet collector for this connection. A packet filter determines
* which packets will be accumulated by the collector. A PacketCollector is * which packets will be accumulated by the collector. A PacketCollector is
* more suitable to use than a {@link PacketListener} when you need to wait for * more suitable to use than a {@link StanzaListener} when you need to wait for
* a specific result. * a specific result.
* *
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
@ -218,18 +229,18 @@ public interface XMPPConnection {
* @throws InterruptedException * @throws InterruptedException
* @throws NotConnectedException * @throws NotConnectedException
*/ */
public PacketCollector createPacketCollectorAndSend(PacketFilter packetFilter, Stanza packet) public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
throws NotConnectedException, InterruptedException; throws NotConnectedException, InterruptedException;
/** /**
* Creates a new packet collector for this connection. A packet filter * Creates a new packet collector for this connection. A packet filter
* determines which packets will be accumulated by the collector. A * determines which packets will be accumulated by the collector. A
* PacketCollector is more suitable to use than a {@link PacketListener} * PacketCollector is more suitable to use than a {@link StanzaListener}
* when you need to wait for a specific result. * when you need to wait for a specific result.
* <p> * <p>
* <b>Note:</b> If you send a Packet right after using this method, then * <b>Note:</b> If you send a Packet right after using this method, then
* consider using * consider using
* {@link #createPacketCollectorAndSend(PacketFilter, Stanza)} instead. * {@link #createPacketCollectorAndSend(StanzaFilter, Stanza)} instead.
* Otherwise make sure cancel the PacketCollector in every case, e.g. even * Otherwise make sure cancel the PacketCollector in every case, e.g. even
* if an exception is thrown, or otherwise you may leak the PacketCollector. * if an exception is thrown, or otherwise you may leak the PacketCollector.
* </p> * </p>
@ -237,13 +248,13 @@ public interface XMPPConnection {
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
* @return a new packet collector. * @return a new packet collector.
*/ */
public PacketCollector createPacketCollector(PacketFilter packetFilter); public PacketCollector createPacketCollector(StanzaFilter packetFilter);
/** /**
* Create a new packet collector with the given packet collector configuration. * Create a new packet collector with the given packet collector configuration.
* <p> * <p>
* Please make sure to cancel the collector when it is no longer required. See also * Please make sure to cancel the collector when it is no longer required. See also
* {@link #createPacketCollector(PacketFilter)}. * {@link #createPacketCollector(StanzaFilter)}.
* </p> * </p>
* *
* @param configuration the packet collector configuration. * @param configuration the packet collector configuration.
@ -264,27 +275,27 @@ public interface XMPPConnection {
* <p> * <p>
* This method has been deprecated. It is important to differentiate between using an asynchronous packet listener * This method has been deprecated. It is important to differentiate between using an asynchronous packet listener
* (preferred where possible) and a synchronous packet lister. Refer * (preferred where possible) and a synchronous packet lister. Refer
* {@link #addAsyncPacketListener(PacketListener, PacketFilter)} and * {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} and
* {@link #addSyncPacketListener(PacketListener, PacketFilter)} for more information. * {@link #addSyncStanzaListener(StanzaListener, StanzaFilter)} for more information.
* </p> * </p>
* *
* @param packetListener the packet listener to notify of new received packets. * @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
* @deprecated use {@link #addAsyncPacketListener(PacketListener, PacketFilter)} or * @deprecated use {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} or
* {@link #addSyncPacketListener(PacketListener, PacketFilter)}. * {@link #addSyncStanzaListener(StanzaListener, StanzaFilter)}.
*/ */
@Deprecated @Deprecated
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter); public void addPacketListener(StanzaListener packetListener, StanzaFilter packetFilter);
/** /**
* Removes a packet listener for received packets from this connection. * Removes a packet listener for received packets from this connection.
* *
* @param packetListener the packet listener to remove. * @param packetListener the packet listener to remove.
* @return true if the packet listener was removed * @return true if the packet listener was removed
* @deprecated use {@link #removeAsyncPacketListener(PacketListener)} or {@link #removeSyncPacketListener(PacketListener)}. * @deprecated use {@link #removeAsyncStanzaListener(StanzaListener)} or {@link #removeSyncStanzaListener(StanzaListener)}.
*/ */
@Deprecated @Deprecated
public boolean removePacketListener(PacketListener packetListener); public boolean removePacketListener(StanzaListener packetListener);
/** /**
* Registers a <b>synchronous</b> packet listener with this connection. A packet listener will be invoked only when * Registers a <b>synchronous</b> packet listener with this connection. A packet listener will be invoked only when
@ -293,17 +304,17 @@ public interface XMPPConnection {
* <p> * <p>
* <b>Important:</b> This packet listeners will be called in the same <i>single</i> thread that processes all * <b>Important:</b> This packet listeners will be called in the same <i>single</i> thread that processes all
* incoming stanzas. Only use this kind of packet filter if it does not perform any XMPP activity that waits for a * incoming stanzas. Only use this kind of packet filter if it does not perform any XMPP activity that waits for a
* response. Consider using {@link #addAsyncPacketListener(PacketListener, PacketFilter)} when possible, i.e. when * response. Consider using {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} when possible, i.e. when
* the invocation order doesn't have to be the same as the order of the arriving packets. If the order of the * the invocation order doesn't have to be the same as the order of the arriving packets. If the order of the
* arriving packets, consider using a {@link PacketCollector} when possible. * arriving packets, consider using a {@link PacketCollector} when possible.
* </p> * </p>
* *
* @param packetListener the packet listener to notify of new received packets. * @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
* @see #addPacketInterceptor(PacketListener, PacketFilter) * @see #addPacketInterceptor(StanzaListener, StanzaFilter)
* @since 4.1 * @since 4.1
*/ */
public void addSyncPacketListener(PacketListener packetListener, PacketFilter packetFilter); public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter);
/** /**
* Removes a packet listener for received packets from this connection. * Removes a packet listener for received packets from this connection.
@ -312,24 +323,24 @@ public interface XMPPConnection {
* @return true if the packet listener was removed * @return true if the packet listener was removed
* @since 4.1 * @since 4.1
*/ */
public boolean removeSyncPacketListener(PacketListener packetListener); public boolean removeSyncStanzaListener(StanzaListener packetListener);
/** /**
* Registers an <b>asynchronous</b> packet listener with this connection. A packet listener will be invoked only * Registers an <b>asynchronous</b> packet listener with this connection. A packet listener will be invoked only
* when an incoming packet is received. A packet filter determines which packets will be delivered to the listener. * when an incoming packet is received. A packet filter determines which packets will be delivered to the listener.
* If the same packet listener is added again with a different filter, only the new filter will be used. * If the same packet listener is added again with a different filter, only the new filter will be used.
* <p> * <p>
* Unlike {@link #addAsyncPacketListener(PacketListener, PacketFilter)} packet listeners added with this method will be * Unlike {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} packet listeners added with this method will be
* invoked asynchronously in their own thread. Use this method if the order of the packet listeners must not depend * invoked asynchronously in their own thread. Use this method if the order of the packet listeners must not depend
* on the order how the stanzas where received. * on the order how the stanzas where received.
* </p> * </p>
* *
* @param packetListener the packet listener to notify of new received packets. * @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
* @see #addPacketInterceptor(PacketListener, PacketFilter) * @see #addPacketInterceptor(StanzaListener, StanzaFilter)
* @since 4.1 * @since 4.1
*/ */
public void addAsyncPacketListener(PacketListener packetListener, PacketFilter packetFilter); public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter);
/** /**
* Removes an <b>asynchronous</b> packet listener for received packets from this connection. * Removes an <b>asynchronous</b> packet listener for received packets from this connection.
@ -338,7 +349,7 @@ public interface XMPPConnection {
* @return true if the packet listener was removed * @return true if the packet listener was removed
* @since 4.1 * @since 4.1
*/ */
public boolean removeAsyncPacketListener(PacketListener packetListener); public boolean removeAsyncStanzaListener(StanzaListener packetListener);
/** /**
* Registers a packet listener with this connection. The listener will be * Registers a packet listener with this connection. The listener will be
@ -351,14 +362,14 @@ public interface XMPPConnection {
* @param packetListener the packet listener to notify of sent packets. * @param packetListener the packet listener to notify of sent packets.
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
*/ */
public void addPacketSendingListener(PacketListener packetListener, PacketFilter packetFilter); public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter);
/** /**
* Removes a packet listener for sending packets from this connection. * Removes a packet listener for sending packets from this connection.
* *
* @param packetListener the packet listener to remove. * @param packetListener the packet listener to remove.
*/ */
public void removePacketSendingListener(PacketListener packetListener); public void removePacketSendingListener(StanzaListener packetListener);
/** /**
* Registers a packet interceptor with this connection. The interceptor will be * Registers a packet interceptor with this connection. The interceptor will be
@ -367,19 +378,19 @@ public interface XMPPConnection {
* will be delivered to the interceptor. * will be delivered to the interceptor.
* *
* <p> * <p>
* NOTE: For a similar functionality on incoming packets, see {@link #addAsyncPacketListener(PacketListener, PacketFilter)}. * NOTE: For a similar functionality on incoming packets, see {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)}.
* *
* @param packetInterceptor the packet interceptor to notify of packets about to be sent. * @param packetInterceptor the packet interceptor to notify of packets about to be sent.
* @param packetFilter the packet filter to use. * @param packetFilter the packet filter to use.
*/ */
public void addPacketInterceptor(PacketListener packetInterceptor, PacketFilter packetFilter); public void addPacketInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter);
/** /**
* Removes a packet interceptor. * Removes a packet interceptor.
* *
* @param packetInterceptor the packet interceptor to remove. * @param packetInterceptor the packet interceptor to remove.
*/ */
public void removePacketInterceptor(PacketListener packetInterceptor); public void removePacketInterceptor(StanzaListener packetInterceptor);
/** /**
* Returns the current value of the reply timeout in milliseconds for request for this * Returns the current value of the reply timeout in milliseconds for request for this
@ -446,7 +457,7 @@ public interface XMPPConnection {
* @param namespace * @param namespace
* @return a packet extensions of the feature or <code>null</code> * @return a packet extensions of the feature or <code>null</code>
*/ */
public <F extends PacketExtension> F getFeature(String element, String namespace); public <F extends ExtensionElement> F getFeature(String element, String namespace);
/** /**
* Return true if the server supports the given stream feature. * Return true if the server supports the given stream feature.
@ -471,8 +482,8 @@ public interface XMPPConnection {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
PacketListener callback) throws NotConnectedException, InterruptedException; StanzaListener callback) throws NotConnectedException, InterruptedException;
/** /**
* Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>. * Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
@ -489,7 +500,7 @@ public interface XMPPConnection {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, PacketListener callback, public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException; ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
/** /**
@ -508,8 +519,8 @@ public interface XMPPConnection {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
final PacketListener callback, final ExceptionCallback exceptionCallback, final StanzaListener callback, final ExceptionCallback exceptionCallback,
long timeout) throws NotConnectedException, InterruptedException; long timeout) throws NotConnectedException, InterruptedException;
/** /**
@ -522,7 +533,7 @@ public interface XMPPConnection {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback) throws NotConnectedException, InterruptedException; public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback) throws NotConnectedException, InterruptedException;
/** /**
* Send a IQ stanza and invoke <code>callback</code> if there is a result of * Send a IQ stanza and invoke <code>callback</code> if there is a result of
@ -538,7 +549,7 @@ public interface XMPPConnection {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback, public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException; ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
/** /**
@ -556,7 +567,7 @@ public interface XMPPConnection {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendIqWithResponseCallback(IQ iqRequest, final PacketListener callback, public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
final ExceptionCallback exceptionCallback, long timeout) final ExceptionCallback exceptionCallback, long timeout)
throws NotConnectedException, InterruptedException; throws NotConnectedException, InterruptedException;
@ -567,7 +578,7 @@ public interface XMPPConnection {
* @param callback the callback invoked once the packet filter matches a stanza. * @param callback the callback invoked once the packet filter matches a stanza.
* @param packetFilter the filter to match stanzas or null to match all. * @param packetFilter the filter to match stanzas or null to match all.
*/ */
public void addOneTimeSyncCallback(PacketListener callback, PacketFilter packetFilter); public void addOneTimeSyncCallback(StanzaListener callback, StanzaFilter packetFilter);
/** /**
* Register an IQ request handler with this connection. * Register an IQ request handler with this connection.

View file

@ -152,7 +152,9 @@ public abstract class XMPPException extends Exception {
* @param streamError the root cause of the exception. * @param streamError the root cause of the exception.
*/ */
public StreamErrorException(StreamError streamError) { public StreamErrorException(StreamError streamError) {
super(streamError.toString()); super(streamError.getCondition().toString()
+ " You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions\n"
+ streamError.toString());
this.streamError = streamError; this.streamError = streamError;
} }

View file

@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.packet.FullStreamElement; import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
public class Compress extends FullStreamElement { public class Compress extends FullStreamElement {
@ -53,7 +53,7 @@ public class Compress extends FullStreamElement {
return xml; return xml;
} }
public static class Feature implements PacketExtension { public static class Feature implements ExtensionElement {
public static final String ELEMENT = "compression"; public static final String ELEMENT = "compression";
public final List<String> methods; public final List<String> methods;

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smack.debugger; package org.jivesoftware.smack.debugger;
import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.ObservableReader; import org.jivesoftware.smack.util.ObservableReader;
@ -35,7 +35,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
private final XMPPConnection connection; private final XMPPConnection connection;
private final PacketListener listener; private final StanzaListener listener;
private final ConnectionListener connListener; private final ConnectionListener connListener;
private final ReaderListener readerListener; private final ReaderListener readerListener;
private final WriterListener writerListener; private final WriterListener writerListener;
@ -67,7 +67,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// Create a thread that will listen for all incoming packets and write them to // Create a thread that will listen for all incoming packets and write them to
// the GUI. This is what we call "interpreted" packet data, since it's the packet // the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML. // data as Smack sees it and not as it's coming in as raw XML.
listener = new PacketListener() { listener = new StanzaListener() {
public void processPacket(Stanza packet) { public void processPacket(Stanza packet) {
if (printInterpreted) { if (printInterpreted) {
log("RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML()); log("RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML());
@ -167,11 +167,11 @@ public abstract class AbstractDebugger implements SmackDebugger {
return writer; return writer;
} }
public PacketListener getReaderListener() { public StanzaListener getReaderListener() {
return listener; return listener;
} }
public PacketListener getWriterListener() { public StanzaListener getWriterListener() {
return null; return null;
} }
} }

View file

@ -20,7 +20,7 @@ package org.jivesoftware.smack.debugger;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jxmpp.jid.FullJid; import org.jxmpp.jid.FullJid;
/** /**
@ -85,7 +85,7 @@ public interface SmackDebugger {
* @return the PacketListener that will listen for all incoming packets and write them to * @return the PacketListener that will listen for all incoming packets and write them to
* the GUI * the GUI
*/ */
public abstract PacketListener getReaderListener(); public abstract StanzaListener getReaderListener();
/** /**
* Returns the thread that will listen for all outgoing packets and write them to the GUI. * Returns the thread that will listen for all outgoing packets and write them to the GUI.
@ -93,5 +93,5 @@ public interface SmackDebugger {
* @return the PacketListener that will listen for all sent packets and write them to * @return the PacketListener that will listen for all sent packets and write them to
* the GUI * the GUI
*/ */
public abstract PacketListener getWriterListener(); public abstract StanzaListener getWriterListener();
} }

View file

@ -19,6 +19,7 @@ package org.jivesoftware.smack.filter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
@ -26,18 +27,18 @@ import org.jivesoftware.smack.util.Objects;
/** /**
* *
*/ */
public abstract class AbstractListFilter implements PacketFilter { public abstract class AbstractListFilter implements StanzaFilter {
/** /**
* The list of filters. * The list of filters.
*/ */
protected final List<PacketFilter> filters; protected final List<StanzaFilter> filters;
/** /**
* Creates an empty filter. * Creates an empty filter.
*/ */
protected AbstractListFilter() { protected AbstractListFilter() {
filters = new ArrayList<PacketFilter>(); filters = new ArrayList<StanzaFilter>();
} }
/** /**
@ -45,12 +46,12 @@ public abstract class AbstractListFilter implements PacketFilter {
* *
* @param filters the filters to add. * @param filters the filters to add.
*/ */
protected AbstractListFilter(PacketFilter... filters) { protected AbstractListFilter(StanzaFilter... filters) {
Objects.requireNonNull(filters, "Parameter must not be null."); Objects.requireNonNull(filters, "Parameter must not be null.");
for(PacketFilter filter : filters) { for(StanzaFilter filter : filters) {
Objects.requireNonNull(filter, "Parameter must not be null."); Objects.requireNonNull(filter, "Parameter must not be null.");
} }
this.filters = new ArrayList<PacketFilter>(Arrays.asList(filters)); this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters));
} }
/** /**
@ -59,7 +60,7 @@ public abstract class AbstractListFilter implements PacketFilter {
* *
* @param filter a filter to add to the filter list. * @param filter a filter to add to the filter list.
*/ */
public void addFilter(PacketFilter filter) { public void addFilter(StanzaFilter filter) {
Objects.requireNonNull(filter, "Parameter must not be null."); Objects.requireNonNull(filter, "Parameter must not be null.");
filters.add(filter); filters.add(filter);
} }
@ -68,9 +69,13 @@ public abstract class AbstractListFilter implements PacketFilter {
public final String toString() { public final String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName()); sb.append(getClass().getSimpleName());
sb.append(" ("); sb.append(": (");
for (PacketFilter filter : filters) { for (Iterator<StanzaFilter> it = filters.iterator(); it.hasNext();) {
sb.append(' ' + filter.toString() + ','); StanzaFilter filter = it.next();
sb.append(filter.toString());
if (it.hasNext()) {
sb.append(", ");
}
} }
sb.append(")"); sb.append(")");
return sb.toString(); return sb.toString();

View file

@ -25,11 +25,11 @@ import org.jivesoftware.smack.packet.Stanza;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class AndFilter extends AbstractListFilter implements PacketFilter { public class AndFilter extends AbstractListFilter implements StanzaFilter {
/** /**
* Creates an empty AND filter. Filters should be added using the * Creates an empty AND filter. Filters should be added using the
* {@link #addFilter(PacketFilter)} method. * {@link #addFilter(StanzaFilter)} method.
*/ */
public AndFilter() { public AndFilter() {
super(); super();
@ -40,12 +40,12 @@ public class AndFilter extends AbstractListFilter implements PacketFilter {
* *
* @param filters the filters to add. * @param filters the filters to add.
*/ */
public AndFilter(PacketFilter... filters) { public AndFilter(StanzaFilter... filters) {
super(filters); super(filters);
} }
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
for (PacketFilter filter : filters) { for (StanzaFilter filter : filters) {
if (!filter.accept(packet)) { if (!filter.accept(packet)) {
return false; return false;
} }

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2014 Florian Schmaus * Copyright 2014-2015 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,39 +23,36 @@ import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
/** /**
* Filters for packets of a particular type and allows a custom method to further filter the packets. * Filters for stanzas of a particular type and allows a custom method to further filter the packets.
* *
* @author Florian Schmaus * @author Florian Schmaus
*/ */
public abstract class FlexiblePacketTypeFilter<P extends Stanza> implements PacketFilter { public abstract class FlexibleStanzaTypeFilter<S extends Stanza> implements StanzaFilter {
protected final Class<P> packetType; protected final Class<S> stanzaType;
public FlexiblePacketTypeFilter(Class<P> packetType) { public FlexibleStanzaTypeFilter(Class<S> packetType) {
this.packetType = Objects.requireNonNull(packetType, "Type must not be null"); this.stanzaType = Objects.requireNonNull(packetType, "Type must not be null");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public FlexiblePacketTypeFilter() { public FlexibleStanzaTypeFilter() {
packetType = (Class<P>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; stanzaType = (Class<S>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public boolean accept(Stanza packet) { public final boolean accept(Stanza packet) {
if (packetType.isInstance(packet)) { if (stanzaType.isInstance(packet)) {
return acceptSpecific((P) packet); return acceptSpecific((S) packet);
} }
return false; return false;
} }
protected abstract boolean acceptSpecific(P packet); protected abstract boolean acceptSpecific(S packet);
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return getClass().getSimpleName() + ": " + stanzaType.toString();
sb.append(getClass().getSimpleName());
sb.append(" (" + packetType.toString() + ')');
return sb.toString();
} }
} }

View file

@ -28,7 +28,7 @@ import org.jxmpp.jid.Jid;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class FromMatchesFilter implements PacketFilter { public class FromMatchesFilter implements StanzaFilter {
private final Jid address; private final Jid address;

View file

@ -49,10 +49,10 @@ import org.jxmpp.jid.Jid;
* @author Lars Noschinski * @author Lars Noschinski
* *
*/ */
public class IQReplyFilter implements PacketFilter { public class IQReplyFilter implements StanzaFilter {
private static final Logger LOGGER = Logger.getLogger(IQReplyFilter.class.getName()); private static final Logger LOGGER = Logger.getLogger(IQReplyFilter.class.getName());
private final PacketFilter iqAndIdFilter; private final StanzaFilter iqAndIdFilter;
private final OrFilter fromFilter; private final OrFilter fromFilter;
private final Jid to; private final Jid to;
private final FullJid local; private final FullJid local;
@ -94,8 +94,8 @@ public class IQReplyFilter implements PacketFilter {
server = conn.getServiceName(); server = conn.getServiceName();
packetId = iqPacket.getStanzaId(); packetId = iqPacket.getStanzaId();
PacketFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT); StanzaFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
PacketFilter idFilter = new StanzaIdFilter(iqPacket); StanzaFilter idFilter = new StanzaIdFilter(iqPacket);
iqAndIdFilter = new AndFilter(iqFilter, idFilter); iqAndIdFilter = new AndFilter(iqFilter, idFilter);
fromFilter = new OrFilter(); fromFilter = new OrFilter();
fromFilter.addFilter(FromMatchesFilter.createFull(to)); fromFilter.addFilter(FromMatchesFilter.createFull(to));

View file

@ -27,13 +27,13 @@ import org.jivesoftware.smack.util.Objects;
* @author Alexander Wenckus * @author Alexander Wenckus
* *
*/ */
public class IQTypeFilter extends FlexiblePacketTypeFilter<IQ> { public class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {
public static final PacketFilter GET = new IQTypeFilter(Type.get); public static final StanzaFilter GET = new IQTypeFilter(Type.get);
public static final PacketFilter SET = new IQTypeFilter(Type.set); public static final StanzaFilter SET = new IQTypeFilter(Type.set);
public static final PacketFilter RESULT = new IQTypeFilter(Type.result); public static final StanzaFilter RESULT = new IQTypeFilter(Type.result);
public static final PacketFilter ERROR = new IQTypeFilter(Type.error); public static final StanzaFilter ERROR = new IQTypeFilter(Type.error);
public static final PacketFilter GET_OR_SET = new OrFilter(GET, SET); public static final StanzaFilter GET_OR_SET = new OrFilter(GET, SET);
private final IQ.Type type; private final IQ.Type type;

View file

@ -27,15 +27,15 @@ import org.jivesoftware.smack.packet.Message.Type;
* @see org.jivesoftware.smack.packet.Message.Type * @see org.jivesoftware.smack.packet.Message.Type
* @author Ward Harold * @author Ward Harold
*/ */
public class MessageTypeFilter extends FlexiblePacketTypeFilter<Message> { public class MessageTypeFilter extends FlexibleStanzaTypeFilter<Message> {
public static final PacketFilter NORMAL = new MessageTypeFilter(Type.normal); public static final StanzaFilter NORMAL = new MessageTypeFilter(Type.normal);
public static final PacketFilter CHAT = new MessageTypeFilter(Type.chat); public static final StanzaFilter CHAT = new MessageTypeFilter(Type.chat);
public static final PacketFilter GROUPCHAT = new MessageTypeFilter(Type.groupchat); public static final StanzaFilter GROUPCHAT = new MessageTypeFilter(Type.groupchat);
public static final PacketFilter HEADLINE = new MessageTypeFilter(Type.headline); public static final StanzaFilter HEADLINE = new MessageTypeFilter(Type.headline);
public static final PacketFilter ERROR = new MessageTypeFilter(Type.error); public static final StanzaFilter ERROR = new MessageTypeFilter(Type.error);
public static final PacketFilter NORMAL_OR_CHAT = new OrFilter(NORMAL, CHAT); public static final StanzaFilter NORMAL_OR_CHAT = new OrFilter(NORMAL, CHAT);
public static final PacketFilter NORMAL_OR_CHAT_OR_HEADLINE = new OrFilter(NORMAL_OR_CHAT, public static final StanzaFilter NORMAL_OR_CHAT_OR_HEADLINE = new OrFilter(NORMAL_OR_CHAT,
HEADLINE); HEADLINE);
private final Message.Type type; private final Message.Type type;

View file

@ -22,9 +22,9 @@ import org.jivesoftware.smack.packet.Message;
/** /**
* Filters message stanzas which have at least one body * Filters message stanzas which have at least one body
*/ */
public class MessageWithBodiesFilter extends FlexiblePacketTypeFilter<Message> { public class MessageWithBodiesFilter extends FlexibleStanzaTypeFilter<Message> {
public static final PacketFilter INSTANCE = new MessageWithBodiesFilter(); public static final StanzaFilter INSTANCE = new MessageWithBodiesFilter();
private MessageWithBodiesFilter() { private MessageWithBodiesFilter() {
super(Message.class); super(Message.class);

View file

@ -22,9 +22,9 @@ import org.jivesoftware.smack.packet.Message;
/** /**
* Filters message stanzas which have at least one body * Filters message stanzas which have at least one body
*/ */
public class MessageWithSubjectFilter extends FlexiblePacketTypeFilter<Message> { public class MessageWithSubjectFilter extends FlexibleStanzaTypeFilter<Message> {
public static final PacketFilter INSTANCE = new MessageWithSubjectFilter(); public static final StanzaFilter INSTANCE = new MessageWithSubjectFilter();
private MessageWithSubjectFilter() { private MessageWithSubjectFilter() {
super(Message.class); super(Message.class);

View file

@ -26,16 +26,16 @@ import org.jivesoftware.smack.util.Objects;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class NotFilter implements PacketFilter { public class NotFilter implements StanzaFilter {
private final PacketFilter filter; private final StanzaFilter filter;
/** /**
* Creates a NOT filter using the specified filter. * Creates a NOT filter using the specified filter.
* *
* @param filter the filter. * @param filter the filter.
*/ */
public NotFilter(PacketFilter filter) { public NotFilter(StanzaFilter filter) {
this.filter = Objects.requireNonNull(filter, "Parameter must not be null."); this.filter = Objects.requireNonNull(filter, "Parameter must not be null.");
} }

View file

@ -25,11 +25,11 @@ import org.jivesoftware.smack.packet.Stanza;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class OrFilter extends AbstractListFilter implements PacketFilter { public class OrFilter extends AbstractListFilter implements StanzaFilter {
/** /**
* Creates an empty OR filter. Filters should be added using the * Creates an empty OR filter. Filters should be added using the
* {@link #addFilter(PacketFilter)} method. * {@link #addFilter(StanzaFilter)} method.
*/ */
public OrFilter() { public OrFilter() {
super(); super();
@ -40,13 +40,13 @@ public class OrFilter extends AbstractListFilter implements PacketFilter {
* *
* @param filters the filters to add. * @param filters the filters to add.
*/ */
public OrFilter(PacketFilter... filters) { public OrFilter(StanzaFilter... filters) {
super(filters); super(filters);
} }
@Override @Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
for (PacketFilter filter : filters) { for (StanzaFilter filter : filters) {
if (filter.accept(packet)) { if (filter.accept(packet)) {
return true; return true;
} }

View file

@ -18,15 +18,17 @@
package org.jivesoftware.smack.filter; package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
/** /**
* Filters for packets with a particular type of packet extension. * Filters for packets with a particular type of packet extension.
* *
* @author Matt Tucker * @author Matt Tucker
* @deprecated use {@link StanzaExtensionFilter} instead.
*/ */
public class PacketExtensionFilter implements PacketFilter { @Deprecated
public class PacketExtensionFilter implements StanzaFilter {
private final String elementName; private final String elementName;
private final String namespace; private final String namespace;
@ -61,7 +63,7 @@ public class PacketExtensionFilter implements PacketFilter {
* *
* @param packetExtension * @param packetExtension
*/ */
public PacketExtensionFilter(PacketExtension packetExtension) { public PacketExtensionFilter(ExtensionElement packetExtension) {
this(packetExtension.getElementName(), packetExtension.getNamespace()); this(packetExtension.getElementName(), packetExtension.getNamespace());
} }

View file

@ -17,8 +17,6 @@
package org.jivesoftware.smack.filter; package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
/** /**
* Defines a way to filter packets for particular attributes. Packet filters are used when * Defines a way to filter packets for particular attributes. Packet filters are used when
* constructing packet listeners or collectors -- the filter defines what packets match the criteria * constructing packet listeners or collectors -- the filter defines what packets match the criteria
@ -43,16 +41,11 @@ import org.jivesoftware.smack.packet.Stanza;
* </pre> * </pre>
* *
* @see org.jivesoftware.smack.PacketCollector * @see org.jivesoftware.smack.PacketCollector
* @see org.jivesoftware.smack.PacketListener * @see org.jivesoftware.smack.StanzaListener
* @author Matt Tucker * @author Matt Tucker
* @deprecated use {@link StanzaFilter}
*/ */
public interface PacketFilter { @Deprecated
public interface PacketFilter extends StanzaFilter {
/**
* Tests whether or not the specified packet should pass the filter.
*
* @param packet the packet to test.
* @return true if and only if <tt>packet</tt> passes the filter.
*/
public boolean accept(Stanza packet);
} }

View file

@ -27,7 +27,7 @@ import org.jivesoftware.smack.util.StringUtils;
* @deprecated use {@link StanzaIdFilter} instead. * @deprecated use {@link StanzaIdFilter} instead.
*/ */
@Deprecated @Deprecated
public class PacketIDFilter implements PacketFilter { public class PacketIDFilter implements StanzaFilter {
private final String packetID; private final String packetID;
@ -35,7 +35,7 @@ public class PacketIDFilter implements PacketFilter {
* Creates a new packet ID filter using the specified packet's ID. * Creates a new packet ID filter using the specified packet's ID.
* *
* @param packet the packet which the ID is taken from. * @param packet the packet which the ID is taken from.
* @deprecated use {@link StanzaIdfilter(Stanza)} instead. * @deprecated use {@link StanzaIdFilter#StanzaIdFilter(Stanza)} instead.
*/ */
@Deprecated @Deprecated
public PacketIDFilter(Stanza packet) { public PacketIDFilter(Stanza packet) {
@ -46,7 +46,7 @@ public class PacketIDFilter implements PacketFilter {
* Creates a new packet ID filter using the specified packet ID. * Creates a new packet ID filter using the specified packet ID.
* *
* @param packetID the packet ID to filter for. * @param packetID the packet ID to filter for.
* @deprecated use {@link StanzaIdFilter(String)} instead. * @deprecated use {@link StanzaIdFilter#StanzaIdFilter(Stanza)} instead.
*/ */
@Deprecated @Deprecated
public PacketIDFilter(String packetID) { public PacketIDFilter(String packetID) {

View file

@ -31,8 +31,10 @@ import org.jivesoftware.smack.packet.Presence;
* </ul> * </ul>
* *
* @author Matt Tucker * @author Matt Tucker
* @deprecated use {@link StanzaTypeFilter} instead.
*/ */
public class PacketTypeFilter implements PacketFilter { @Deprecated
public class PacketTypeFilter implements StanzaFilter {
public static final PacketTypeFilter PRESENCE = new PacketTypeFilter(Presence.class); public static final PacketTypeFilter PRESENCE = new PacketTypeFilter(Presence.class);
public static final PacketTypeFilter MESSAGE = new PacketTypeFilter(Message.class); public static final PacketTypeFilter MESSAGE = new PacketTypeFilter(Message.class);

View file

@ -24,7 +24,7 @@ import org.jivesoftware.smack.util.Objects;
* A filter for Presence types. Returns true only if the stanza is an Presence packet and it matches the type provided in the * A filter for Presence types. Returns true only if the stanza is an Presence packet and it matches the type provided in the
* constructor. * constructor.
*/ */
public class PresenceTypeFilter extends FlexiblePacketTypeFilter<Presence> { public class PresenceTypeFilter extends FlexibleStanzaTypeFilter<Presence> {
public static final PresenceTypeFilter AVAILABLE = new PresenceTypeFilter(Type.available); public static final PresenceTypeFilter AVAILABLE = new PresenceTypeFilter(Type.available);
public static final PresenceTypeFilter UNAVAILABLE = new PresenceTypeFilter(Type.unavailable); public static final PresenceTypeFilter UNAVAILABLE = new PresenceTypeFilter(Type.unavailable);

View file

@ -0,0 +1,76 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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.filter;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.StringUtils;
/**
* Filters for stanzas with a particular type of stanza extension.
*
* @author Matt Tucker
*/
public class StanzaExtensionFilter implements StanzaFilter {
private final String elementName;
private final String namespace;
/**
* Creates a new stanza extension filter. Stanzas will pass the filter if
* they have a stanza extension that matches the specified element name
* and namespace.
*
* @param elementName the XML element name of the stanza extension.
* @param namespace the XML namespace of the stanza extension.
*/
public StanzaExtensionFilter(String elementName, String namespace) {
StringUtils.requireNotNullOrEmpty(namespace, "namespace must not be null or empty");
this.elementName = elementName;
this.namespace = namespace;
}
/**
* Creates a new stanza extension filter. Stanzas will pass the filter if they have a stanza
* extension that matches the specified namespace.
*
* @param namespace the XML namespace of the stanza extension.
*/
public StanzaExtensionFilter(String namespace) {
this(null, namespace);
}
/**
* Creates a new stanza extension filter for the given stanza extension.
*
* @param packetExtension
*/
public StanzaExtensionFilter(ExtensionElement packetExtension) {
this(packetExtension.getElementName(), packetExtension.getNamespace());
}
public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace);
}
@Override
public String toString() {
return getClass().getSimpleName() + ": element=" + elementName + " namespace=" + namespace;
}
}

View file

@ -0,0 +1,58 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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.filter;
import org.jivesoftware.smack.packet.Stanza;
/**
* Defines a way to filter stanzas for particular attributes. Stanza filters are used when
* constructing stanza listeners or collectors -- the filter defines what stanzas match the criteria
* of the collector or listener for further stanza processing.
* <p>
* Several simple filters are pre-defined. These filters can be logically combined for more complex
* stanza filtering by using the {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
* {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible to define
* your own filters by implementing this interface. The code example below creates a trivial filter
* for stanzas with a specific ID (real code should use {@link StanzaIdFilter} instead).
*
* <pre>
* // Use an anonymous inner class to define a stanza filter that returns
* // all stanzas that have a stanza ID of &quot;RS145&quot;.
* StanzaFilter myFilter = new StanzaFilter() {
* public boolean accept(Stanza stanza) {
* return &quot;RS145&quot;.equals(stanza.getStanzaId());
* }
* };
* // Create a new stanza collector using the filter we created.
* PacketCollector myCollector = connection.createPacketCollector(myFilter);
* </pre>
*
* @see org.jivesoftware.smack.PacketCollector
* @see org.jivesoftware.smack.StanzaListener
* @author Matt Tucker
*/
public interface StanzaFilter {
/**
* Tests whether or not the specified stanza should pass the filter.
*
* @param stanza the packet to test.
* @return true if and only if <tt>stanza</tt> passes the filter.
*/
public boolean accept(Stanza stanza);
}

View file

@ -25,7 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class StanzaIdFilter implements PacketFilter { public class StanzaIdFilter implements StanzaFilter {
private final String stanzaId; private final String stanzaId;

View file

@ -0,0 +1,62 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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.filter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.IQ;
/**
* Filters for Stanzas of a particular type. The type is given as a Class object, so
* example types would:
* <ul>
* <li><tt>Message.class</tt>
* <li><tt>IQ.class</tt>
* <li><tt>Presence.class</tt>
* </ul>
*
* @author Matt Tucker
*/
public final class StanzaTypeFilter implements StanzaFilter {
public static final StanzaTypeFilter PRESENCE = new StanzaTypeFilter(Presence.class);
public static final StanzaTypeFilter MESSAGE = new StanzaTypeFilter(Message.class);
public static final StanzaTypeFilter IQ = new StanzaTypeFilter(IQ.class);
private final Class<? extends Stanza> packetType;
/**
* Creates a new packet type filter that will filter for packets that are the
* same type as <tt>packetType</tt>.
*
* @param packetType the Class type.
*/
public StanzaTypeFilter(Class<? extends Stanza> packetType) {
this.packetType = packetType;
}
public boolean accept(Stanza packet) {
return packetType.isInstance(packet);
}
@Override
public String toString() {
return getClass().getSimpleName() + ": " + packetType.getName();
}
}

View file

@ -25,7 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class ThreadFilter extends FlexiblePacketTypeFilter<Message> implements PacketFilter { public class ThreadFilter extends FlexibleStanzaTypeFilter<Message> implements StanzaFilter {
private final String thread; private final String thread;

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
public class ToFilter implements PacketFilter { public class ToFilter implements StanzaFilter {
private final Jid to; private final Jid to;

View file

@ -28,18 +28,18 @@ public class AbstractError {
private final String textNamespace; private final String textNamespace;
protected final Map<String, String> descriptiveTexts; protected final Map<String, String> descriptiveTexts;
private final List<PacketExtension> extensions; private final List<ExtensionElement> extensions;
protected AbstractError(Map<String, String> descriptiveTexts) { protected AbstractError(Map<String, String> descriptiveTexts) {
this(descriptiveTexts, null); this(descriptiveTexts, null);
} }
protected AbstractError(Map<String, String> descriptiveTexts, List<PacketExtension> extensions) { protected AbstractError(Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
this(descriptiveTexts, null, extensions); this(descriptiveTexts, null, extensions);
} }
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<PacketExtension> extensions) { protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<ExtensionElement> extensions) {
if (descriptiveTexts != null) { if (descriptiveTexts != null) {
this.descriptiveTexts = descriptiveTexts; this.descriptiveTexts = descriptiveTexts;
} else { } else {
@ -91,7 +91,7 @@ public class AbstractError {
* @param namespace the XML element namespace of the packet extension. * @param namespace the XML element namespace of the packet extension.
* @return the extension, or <tt>null</tt> if it doesn't exist. * @return the extension, or <tt>null</tt> if it doesn't exist.
*/ */
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace) { public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
return PacketUtil.extensionElementFrom(extensions, elementName, namespace); return PacketUtil.extensionElementFrom(extensions, elementName, namespace);
} }
@ -104,7 +104,7 @@ public class AbstractError {
xml.escape(text); xml.escape(text);
xml.closeElement("text"); xml.closeElement("text");
} }
for (PacketExtension packetExtension : extensions) { for (ExtensionElement packetExtension : extensions) {
xml.append(packetExtension.toXML()); xml.append(packetExtension.toXML());
} }
} }

View file

@ -70,7 +70,7 @@ public class Bind extends IQ {
return xml; return xml;
} }
public static class Feature implements PacketExtension { public static class Feature implements ExtensionElement {
public static final Feature INSTANCE = new Feature(); public static final Feature INSTANCE = new Feature();

View file

@ -25,7 +25,7 @@ import java.util.Map;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
/** /**
* Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider * Default implementation of the ExtensionElement interface. Unless a ExtensionElementProvider
* is registered with {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager}, * is registered with {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager},
* instances of this class will be returned when getting packet extensions.<p> * instances of this class will be returned when getting packet extensions.<p>
* *
@ -42,11 +42,11 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* In this case, getValue("color") would return "blue", and getValue("food") would * In this case, getValue("color") would return "blue", and getValue("food") would
* return "pizza". This parsing mechanism mechanism is very simplistic and will not work * return "pizza". This parsing mechanism mechanism is very simplistic and will not work
* as desired in all cases (for example, if some of the elements have attributes. In those * as desired in all cases (for example, if some of the elements have attributes. In those
* cases, a custom PacketExtensionProvider should be used. * cases, a custom ExtensionElementProvider should be used.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class DefaultPacketExtension implements PacketExtension { public class DefaultExtensionElement implements ExtensionElement {
private String elementName; private String elementName;
private String namespace; private String namespace;
@ -58,7 +58,7 @@ public class DefaultPacketExtension implements PacketExtension {
* @param elementName the name of the element of the XML sub-document. * @param elementName the name of the element of the XML sub-document.
* @param namespace the namespace of the element. * @param namespace the namespace of the element.
*/ */
public DefaultPacketExtension(String elementName, String namespace) { public DefaultExtensionElement(String elementName, String namespace) {
this.elementName = elementName; this.elementName = elementName;
this.namespace = namespace; this.namespace = namespace;
} }

View file

@ -18,7 +18,7 @@
package org.jivesoftware.smack.packet; package org.jivesoftware.smack.packet;
/** /**
* Interface to represent a XML element. This is similar to {@link PacketExtension}, but does not * Interface to represent a XML element. This is similar to {@link ExtensionElement}, but does not
* carry a namespace and is usually included as child element of an packet extension. * carry a namespace and is usually included as child element of an packet extension.
*/ */
public interface Element { public interface Element {

View file

@ -0,0 +1,46 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* Interface to represent extension elements.
* <p>
* An extension element is an XML subdocument
* with a root element name and namespace. Extension elements are used to provide
* extended functionality beyond what is in the base XMPP specification. Examples of
* extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements.
* <p>
* This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more
* information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>.
* </p>
*
* @see DefaultExtensionElement
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @author Matt Tucker
*/
public interface ExtensionElement extends NamedElement {
/**
* Returns the root element XML namespace.
*
* @return the namespace.
*/
public String getNamespace();
}

View file

@ -23,6 +23,6 @@ package org.jivesoftware.smack.packet;
* *
* @author Florian Schmaus * @author Florian Schmaus
*/ */
public abstract class FullStreamElement implements PlainStreamElement, PacketExtension { public abstract class FullStreamElement implements PlainStreamElement, ExtensionElement {
} }

View file

@ -302,7 +302,7 @@ public abstract class IQ extends Stanza {
this(iq.getChildElementName(), iq.getChildElementNamespace()); this(iq.getChildElementName(), iq.getChildElementNamespace());
} }
public IQChildElementXmlStringBuilder(PacketExtension pe) { public IQChildElementXmlStringBuilder(ExtensionElement pe) {
this(pe.getElementName(), pe.getNamespace()); this(pe.getElementName(), pe.getNamespace());
} }

View file

@ -23,7 +23,7 @@ import java.util.List;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
public class Mechanisms implements PacketExtension { public class Mechanisms implements ExtensionElement {
public static final String ELEMENT = "mechanisms"; public static final String ELEMENT = "mechanisms";
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-sasl"; public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-sasl";

View file

@ -51,7 +51,7 @@ import org.jxmpp.jid.Jid;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public final class Message extends Stanza { public final class Message extends Stanza implements Cloneable {
public static final String ELEMENT = "message"; public static final String ELEMENT = "message";
public static final String BODY = "body"; public static final String BODY = "body";
@ -99,6 +99,23 @@ public final class Message extends Stanza {
setBody(body); setBody(body);
} }
/**
* Copy constructor.
* <p>
* This does not perform a deep clone, as extension elements are shared between the new and old
* instance.
* </p>
*
* @param other
*/
public Message(Message other) {
super(other);
this.type = other.type;
this.thread = other.thread;
this.subjects.addAll(other.subjects);
this.bodies.addAll(other.bodies);
}
/** /**
* Returns the type of the message. If no type has been set this method will return {@link * Returns the type of the message. If no type has been set this method will return {@link
* org.jivesoftware.smack.packet.Message.Type#normal}. * org.jivesoftware.smack.packet.Message.Type#normal}.
@ -446,6 +463,19 @@ public final class Message extends Stanza {
return buf; return buf;
} }
/**
* Creates and returns a copy of this message stanza.
* <p>
* This does not perform a deep clone, as extension elements are shared between the new and old
* instance.
* </p>
* @return a clone of this message.
*/
@Override
public Message clone() {
return new Message(this);
}
/** /**
* Represents a message subject, its language and the content of the subject. * Represents a message subject, its language and the content of the subject.
*/ */

View file

@ -18,7 +18,7 @@
package org.jivesoftware.smack.packet; package org.jivesoftware.smack.packet;
/** /**
* Interface to represent a XML element. This is similar to {@link PacketExtension}, but does not * Interface to represent a XML element. This is similar to {@link ExtensionElement}, but does not
* carry a namespace and is usually included as child element of an packet extension. * carry a namespace and is usually included as child element of an packet extension.
*/ */
public interface NamedElement extends Element { public interface NamedElement extends Element {

View file

@ -0,0 +1,232 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* Deprecated interface of pre Smack 4.1 Stanzas.
* @deprecated use {@link Stanza} instead
*/
@Deprecated
public interface Packet extends TopLevelStreamElement {
public static final String TEXT = "text";
public static final String ITEM = "item";
/**
* Returns the unique ID of the stanza. The returned value could be <code>null</code>.
*
* @return the packet's unique ID or <code>null</code> if the id is not available.
*/
public String getStanzaId();
/**
*
* @return the stanza id.
* @deprecated use {@link #getStanzaId()} instead.
*/
@Deprecated
public String getPacketID();
/**
* Sets the unique ID of the packet. To indicate that a packet has no id
* pass <code>null</code> as the packet's id value.
*
* @param id the unique ID for the packet.
*/
public void setStanzaId(String id);
/**
*
* @param packetID
* @deprecated use {@link #setStanzaId(String)} instead.
*/
@Deprecated
public void setPacketID(String packetID);
/**
* Returns who the packet is being sent "to", or <tt>null</tt> if
* the value is not set. The XMPP protocol often makes the "to"
* attribute optional, so it does not always need to be set.<p>
*
* @return who the packet is being sent to, or <tt>null</tt> if the
* value has not been set.
*/
public String getTo();
/**
* Sets who the packet is being sent "to". The XMPP protocol often makes
* the "to" attribute optional, so it does not always need to be set.
*
* @param to who the packet is being sent to.
*/
public void setTo(String to);
/**
* Returns who the packet is being sent "from" or <tt>null</tt> if
* the value is not set. The XMPP protocol often makes the "from"
* attribute optional, so it does not always need to be set.<p>
*
* @return who the packet is being sent from, or <tt>null</tt> if the
* value has not been set.
*/
public String getFrom();
/**
* Sets who the packet is being sent "from". The XMPP protocol often
* makes the "from" attribute optional, so it does not always need to
* be set.
*
* @param from who the packet is being sent to.
*/
public void setFrom(String from);
/**
* Returns the error associated with this packet, or <tt>null</tt> if there are
* no errors.
*
* @return the error sub-packet or <tt>null</tt> if there isn't an error.
*/
public XMPPError getError();
/**
* Sets the error for this packet.
*
* @param error the error to associate with this packet.
*/
public void setError(XMPPError error);
/**
* Returns the xml:lang of this Stanza, or null if one has not been set.
*
* @return the xml:lang of this Stanza, or null.
*/
public String getLanguage();
/**
* Sets the xml:lang of this Stanza.
*
* @param language the xml:lang of this Stanza.
*/
public void setLanguage(String language);
/**
* Returns a copy of the packet extensions attached to the packet.
*
* @return the packet extensions.
*/
public List<ExtensionElement> getExtensions();
/**
* Return a set of all extensions with the given element name <emph>and</emph> namespace.
* <p>
* Changes to the returned set will update the packet extensions, if the returned set is not the empty set.
* </p>
*
* @param elementName the element name, must not be null.
* @param namespace the namespace of the element(s), must not be null.
* @return a set of all matching extensions.
* @since 4.1
*/
public Set<ExtensionElement> getExtensions(String elementName, String namespace);
/**
* Returns the first extension of this packet that has the given namespace.
* <p>
* When possible, use {@link #getExtension(String,String)} instead.
* </p>
*
* @param namespace the namespace of the extension that is desired.
* @return the packet extension with the given namespace.
*/
public ExtensionElement getExtension(String namespace);
/**
* Returns the first packet extension that matches the specified element name and
* namespace, or <tt>null</tt> if it doesn't exist. If the provided elementName is null,
* only the namespace is matched. Packet extensions are
* are arbitrary XML sub-documents in standard XMPP packets. By default, a
* DefaultPacketExtension instance will be returned for each extension. However,
* PacketExtensionProvider instances can be registered with the
* {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager}
* class to handle custom parsing. In that case, the type of the Object
* will be determined by the provider.
*
* @param elementName the XML element name of the packet extension. (May be null)
* @param namespace the XML element namespace of the packet extension.
* @return the extension, or <tt>null</tt> if it doesn't exist.
*/
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace);
/**
* Adds a packet extension to the packet. Does nothing if extension is null.
*
* @param extension a packet extension.
*/
public void addExtension(ExtensionElement extension);
/**
* Adds a collection of packet extensions to the packet. Does nothing if extensions is null.
*
* @param extensions a collection of packet extensions
*/
public void addExtensions(Collection<ExtensionElement> extensions);
/**
* Check if a packet extension with the given element and namespace exists.
* <p>
* The argument <code>elementName</code> may be null.
* </p>
*
* @param elementName
* @param namespace
* @return true if a packet extension exists, false otherwise.
*/
public boolean hasExtension(String elementName, String namespace);
/**
* Check if a packet extension with the given namespace exists.
*
* @param namespace
* @return true if a packet extension exists, false otherwise.
*/
public boolean hasExtension(String namespace);
/**
* Remove the packet extension with the given elementName and namespace.
*
* @param elementName
* @param namespace
* @return the removed packet extension or null.
*/
public ExtensionElement removeExtension(String elementName, String namespace);
/**
* Removes a packet extension from the packet.
*
* @param extension the packet extension to remove.
* @return the removed packet extension or null.
*/
public ExtensionElement removeExtension(ExtensionElement extension);
@Override
// NOTE When Smack is using Java 8, then this method should be moved in Element as "Default Method".
public String toString();
}

View file

@ -18,27 +18,24 @@
package org.jivesoftware.smack.packet; package org.jivesoftware.smack.packet;
/** /**
* Interface to represent packet extensions. A packet extension is an XML subdocument * Interface to represent extension elements.
* with a root element name and namespace. Packet extensions are used to provide * <p>
* An extension element is an XML subdocument
* with a root element name and namespace. Extension elements are used to provide
* extended functionality beyond what is in the base XMPP specification. Examples of * extended functionality beyond what is in the base XMPP specification. Examples of
* packet extensions include message events, message properties, and extra presence data. * extensions elements include message events, message properties, and extra presence data.
* IQ packets cannot contain packet extensions. * IQ stanzas have limited support for extension elements.
* <p> * <p>
* This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more * This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more
* information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>. * information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>.
* </p> * </p>
* *
* @see DefaultPacketExtension * @see DefaultExtensionElement
* @see org.jivesoftware.smack.provider.PacketExtensionProvider * @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @author Matt Tucker * @author Matt Tucker
* @deprecated use {@link ExtensionElement} instead.
*/ */
public interface PacketExtension extends NamedElement { @Deprecated
public interface PacketExtension extends ExtensionElement {
/**
* Returns the root element XML namespace.
*
* @return the namespace.
*/
public String getNamespace();
} }

View file

@ -55,7 +55,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public final class Presence extends Stanza { public final class Presence extends Stanza implements Cloneable {
public static final String ELEMENT = "presence"; public static final String ELEMENT = "presence";
@ -88,6 +88,23 @@ public final class Presence extends Stanza {
setMode(mode); setMode(mode);
} }
/**
* Copy constructor.
* <p>
* This does not perform a deep clone, as extension elements are shared between the new and old
* instance.
* </p>
*
* @param other
*/
public Presence(Presence other) {
super(other);
this.type = other.type;
this.status = other.status;
this.priority = other.priority;
this.mode = other.mode;
}
/** /**
* Returns true if the {@link Type presence type} is available (online) and * Returns true if the {@link Type presence type} is available (online) and
* false if the user is unavailable (offline), or if this is a presence packet * false if the user is unavailable (offline), or if this is a presence packet
@ -228,6 +245,19 @@ public final class Presence extends Stanza {
return buf; return buf;
} }
/**
* Creates and returns a copy of this presence stanza.
* <p>
* This does not perform a deep clone, as extension elements are shared between the new and old
* instance.
* </p>
* @return a clone of this presence.
*/
@Override
public Presence clone() {
return new Presence(this);
}
/** /**
* An enum to represent the presence type. Note that presence type is often confused * An enum to represent the presence type. Note that presence type is often confused
* with presence mode. Generally, if a user is signed in to a server, they have a presence * with presence mode. Generally, if a user is signed in to a server, they have a presence

View file

@ -42,7 +42,7 @@ public class Session extends SimpleIQ {
setType(IQ.Type.set); setType(IQ.Type.set);
} }
public static class Feature implements PacketExtension { public static class Feature implements ExtensionElement {
public static final String OPTIONAL_ELEMENT = "optional"; public static final String OPTIONAL_ELEMENT = "optional";

View file

@ -56,7 +56,7 @@ public abstract class Stanza implements TopLevelStreamElement {
protected static final String DEFAULT_LANGUAGE = protected static final String DEFAULT_LANGUAGE =
java.util.Locale.getDefault().getLanguage().toLowerCase(Locale.US); java.util.Locale.getDefault().getLanguage().toLowerCase(Locale.US);
private final MultiMap<String, PacketExtension> packetExtensions = new MultiMap<>(); private final MultiMap<String, ExtensionElement> packetExtensions = new MultiMap<>();
private String id = null; private String id = null;
private Jid to; private Jid to;
@ -75,22 +75,22 @@ public abstract class Stanza implements TopLevelStreamElement {
*/ */
protected String language; protected String language;
public Stanza() { protected Stanza() {
this(StanzaIdUtil.newStanzaId()); this(StanzaIdUtil.newStanzaId());
} }
public Stanza(String stanzaId) { protected Stanza(String stanzaId) {
setStanzaId(stanzaId); setStanzaId(stanzaId);
} }
public Stanza(Stanza p) { protected Stanza(Stanza p) {
id = p.getStanzaId(); id = p.getStanzaId();
to = p.getTo(); to = p.getTo();
from = p.getFrom(); from = p.getFrom();
error = p.error; error = p.error;
// Copy extensions // Copy extensions
for (PacketExtension pe : p.getExtensions()) { for (ExtensionElement pe : p.getExtensions()) {
addExtension(pe); addExtension(pe);
} }
} }
@ -273,12 +273,13 @@ public abstract class Stanza implements TopLevelStreamElement {
} }
/** /**
* Returns a copy of the packet extensions attached to the packet. * Returns a list of all extension elements of this stanza.
* *
* @return the packet extensions. * @return a list of all extension elements of this stanza.
*/ */
public List<PacketExtension> getExtensions() { public List<ExtensionElement> getExtensions() {
synchronized (packetExtensions) { synchronized (packetExtensions) {
// No need to create a new list, values() will already create a new one for us
return packetExtensions.values(); return packetExtensions.values();
} }
} }
@ -294,7 +295,7 @@ public abstract class Stanza implements TopLevelStreamElement {
* @return a set of all matching extensions. * @return a set of all matching extensions.
* @since 4.1 * @since 4.1
*/ */
public Set<PacketExtension> getExtensions(String elementName, String namespace) { public Set<ExtensionElement> getExtensions(String elementName, String namespace) {
requireNotNullOrEmpty(elementName, "elementName must not be null or empty"); requireNotNullOrEmpty(elementName, "elementName must not be null or empty");
requireNotNullOrEmpty(namespace, "namespace must not be null or empty"); requireNotNullOrEmpty(namespace, "namespace must not be null or empty");
String key = XmppStringUtils.generateKey(elementName, namespace); String key = XmppStringUtils.generateKey(elementName, namespace);
@ -310,32 +311,32 @@ public abstract class Stanza implements TopLevelStreamElement {
* @param namespace the namespace of the extension that is desired. * @param namespace the namespace of the extension that is desired.
* @return the packet extension with the given namespace. * @return the packet extension with the given namespace.
*/ */
public PacketExtension getExtension(String namespace) { public ExtensionElement getExtension(String namespace) {
return PacketUtil.extensionElementFrom(getExtensions(), null, namespace); return PacketUtil.extensionElementFrom(getExtensions(), null, namespace);
} }
/** /**
* Returns the first packet extension that matches the specified element name and * Returns the first extension that matches the specified element name and
* namespace, or <tt>null</tt> if it doesn't exist. If the provided elementName is null, * namespace, or <tt>null</tt> if it doesn't exist. If the provided elementName is null,
* only the namespace is matched. Packet extensions are * only the namespace is matched. Extensions are
* are arbitrary XML sub-documents in standard XMPP packets. By default, a * are arbitrary XML sub-documents in standard XMPP packets. By default, a
* DefaultPacketExtension instance will be returned for each extension. However, * {@link DefaultExtensionElement} instance will be returned for each extension. However,
* PacketExtensionProvider instances can be registered with the * ExtensionElementProvider instances can be registered with the
* {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager} * {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager}
* class to handle custom parsing. In that case, the type of the Object * class to handle custom parsing. In that case, the type of the Object
* will be determined by the provider. * will be determined by the provider.
* *
* @param elementName the XML element name of the packet extension. (May be null) * @param elementName the XML element name of the extension. (May be null)
* @param namespace the XML element namespace of the packet extension. * @param namespace the XML element namespace of the extension.
* @return the extension, or <tt>null</tt> if it doesn't exist. * @return the extension, or <tt>null</tt> if it doesn't exist.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace) { public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
if (namespace == null) { if (namespace == null) {
return null; return null;
} }
String key = XmppStringUtils.generateKey(elementName, namespace); String key = XmppStringUtils.generateKey(elementName, namespace);
PacketExtension packetExtension; ExtensionElement packetExtension;
synchronized (packetExtensions) { synchronized (packetExtensions) {
packetExtension = packetExtensions.getFirst(key); packetExtension = packetExtensions.getFirst(key);
} }
@ -350,7 +351,7 @@ public abstract class Stanza implements TopLevelStreamElement {
* *
* @param extension a packet extension. * @param extension a packet extension.
*/ */
public void addExtension(PacketExtension extension) { public void addExtension(ExtensionElement extension) {
if (extension == null) return; if (extension == null) return;
String key = XmppStringUtils.generateKey(extension.getElementName(), extension.getNamespace()); String key = XmppStringUtils.generateKey(extension.getElementName(), extension.getNamespace());
synchronized (packetExtensions) { synchronized (packetExtensions) {
@ -363,9 +364,9 @@ public abstract class Stanza implements TopLevelStreamElement {
* *
* @param extensions a collection of packet extensions * @param extensions a collection of packet extensions
*/ */
public void addExtensions(Collection<PacketExtension> extensions) { public void addExtensions(Collection<ExtensionElement> extensions) {
if (extensions == null) return; if (extensions == null) return;
for (PacketExtension packetExtension : extensions) { for (ExtensionElement packetExtension : extensions) {
addExtension(packetExtension); addExtension(packetExtension);
} }
} }
@ -398,7 +399,7 @@ public abstract class Stanza implements TopLevelStreamElement {
*/ */
public boolean hasExtension(String namespace) { public boolean hasExtension(String namespace) {
synchronized (packetExtensions) { synchronized (packetExtensions) {
for (PacketExtension packetExtension : packetExtensions.values()) { for (ExtensionElement packetExtension : packetExtensions.values()) {
if (packetExtension.getNamespace().equals(namespace)) { if (packetExtension.getNamespace().equals(namespace)) {
return true; return true;
} }
@ -414,7 +415,7 @@ public abstract class Stanza implements TopLevelStreamElement {
* @param namespace * @param namespace
* @return the removed packet extension or null. * @return the removed packet extension or null.
*/ */
public PacketExtension removeExtension(String elementName, String namespace) { public ExtensionElement removeExtension(String elementName, String namespace) {
String key = XmppStringUtils.generateKey(elementName, namespace); String key = XmppStringUtils.generateKey(elementName, namespace);
synchronized (packetExtensions) { synchronized (packetExtensions) {
return packetExtensions.remove(key); return packetExtensions.remove(key);
@ -427,7 +428,7 @@ public abstract class Stanza implements TopLevelStreamElement {
* @param extension the packet extension to remove. * @param extension the packet extension to remove.
* @return the removed packet extension or null. * @return the removed packet extension or null.
*/ */
public PacketExtension removeExtension(PacketExtension extension) { public ExtensionElement removeExtension(ExtensionElement extension) {
return removeExtension(extension.getElementName(), extension.getNamespace()); return removeExtension(extension.getElementName(), extension.getNamespace());
} }
@ -447,7 +448,7 @@ public abstract class Stanza implements TopLevelStreamElement {
protected final XmlStringBuilder getExtensionsXML() { protected final XmlStringBuilder getExtensionsXML() {
XmlStringBuilder xml = new XmlStringBuilder(); XmlStringBuilder xml = new XmlStringBuilder();
// Add in all standard extension sub-packets. // Add in all standard extension sub-packets.
for (PacketExtension extension : getExtensions()) { for (ExtensionElement extension : getExtensions()) {
xml.append(extension.toXML()); xml.append(extension.toXML());
} }
return xml; return xml;

View file

@ -104,7 +104,7 @@ public class StreamError extends AbstractError implements PlainStreamElement {
private final Condition condition; private final Condition condition;
private final String conditionText; private final String conditionText;
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<PacketExtension> extensions) { public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
super(descriptiveTexts, extensions); super(descriptiveTexts, extensions);
// Some implementations may send the condition as non-empty element containing the empty string, that is // Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string // <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string

View file

@ -99,7 +99,7 @@ public class XMPPError extends AbstractError {
this(condition, null, null, null, null, null); this(condition, null, null, null, null, null);
} }
public XMPPError(Condition condition, PacketExtension applicationSpecificCondition) { public XMPPError(Condition condition, ExtensionElement applicationSpecificCondition) {
this(condition, null, null, null, null, Arrays.asList(applicationSpecificCondition)); this(condition, null, null, null, null, Arrays.asList(applicationSpecificCondition));
} }
@ -115,7 +115,7 @@ public class XMPPError extends AbstractError {
* @param extensions list of packet extensions * @param extensions list of packet extensions
*/ */
public XMPPError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts, public XMPPError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
List<PacketExtension> extensions) { List<ExtensionElement> extensions) {
super(descriptiveTexts, NAMESPACE, extensions); super(descriptiveTexts, NAMESPACE, extensions);
this.condition = condition; this.condition = condition;
// Some implementations may send the condition as non-empty element containing the empty string, that is // Some implementations may send the condition as non-empty element containing the empty string, that is

View file

@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -61,7 +61,7 @@ import org.xmlpull.v1.XmlPullParserException;
* <tt>ItemsProvider</tt> extends {@link EmbeddedExtensionProvider} * <tt>ItemsProvider</tt> extends {@link EmbeddedExtensionProvider}
* <tt>ItemProvider</tt> extends {@link EmbeddedExtensionProvider} * <tt>ItemProvider</tt> extends {@link EmbeddedExtensionProvider}
* and * and
* AtomProvider extends {@link PacketExtensionProvider} * AtomProvider extends {@link ExtensionElementProvider}
* *
* These classes are then registered in the meta-inf/smack.providers file * These classes are then registered in the meta-inf/smack.providers file
* as follows. * as follows.
@ -81,7 +81,7 @@ import org.xmlpull.v1.XmlPullParserException;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public abstract class EmbeddedExtensionProvider<PE extends PacketExtension> extends PacketExtensionProvider<PE> { public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
@Override @Override
public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
@ -95,13 +95,13 @@ public abstract class EmbeddedExtensionProvider<PE extends PacketExtension> exte
attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i)); attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
} }
List<PacketExtension> extensions = new ArrayList<>(); List<ExtensionElement> extensions = new ArrayList<>();
int event; int event;
do { do {
event = parser.next(); event = parser.next();
if (event == XmlPullParser.START_TAG) if (event == XmlPullParser.START_TAG)
PacketParserUtils.addPacketExtension(extensions, parser); PacketParserUtils.addExtensionElement(extensions, parser);
} }
while (!(event == XmlPullParser.END_TAG && parser.getDepth() == initialDepth)); while (!(event == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
@ -109,5 +109,5 @@ public abstract class EmbeddedExtensionProvider<PE extends PacketExtension> exte
} }
protected abstract PE createReturnExtension(String currentElement, String currentNamespace, protected abstract PE createReturnExtension(String currentElement, String currentNamespace,
Map<String, String> attributeMap, List<? extends PacketExtension> content); Map<String, String> attributeMap, List<? extends ExtensionElement> content);
} }

View file

@ -18,15 +18,15 @@
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
/** /**
* An abstract class for parsing custom packets extensions. Each PacketExtensionProvider must * An abstract class for parsing custom extensions elements. Each ExtensionElementProvider must
* be registered with the ProviderManager class for it to be used. Every implementation * be registered with the ProviderManager class for it to be used. Every implementation
* of this abstract class <b>must</b> have a public, no-argument constructor. * of this abstract class <b>must</b> have a public, no-argument constructor.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public abstract class PacketExtensionProvider<PE extends PacketExtension> extends Provider<PE> { public abstract class ExtensionElementProvider<EE extends ExtensionElement> extends Provider<EE> {
} }

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
/** /**
* Defines the information required to register a packet extension Provider with the {@link ProviderManager} when using the * Defines the information required to register a packet extension Provider with the {@link ProviderManager} when using the
@ -28,13 +28,13 @@ import org.jivesoftware.smack.packet.PacketExtension;
public final class ExtensionProviderInfo extends AbstractProviderInfo { public final class ExtensionProviderInfo extends AbstractProviderInfo {
/** /**
* Defines an extension provider which implements the <code>PacketExtensionProvider</code> interface. * Defines an extension provider which implements the <code>ExtensionElementProvider</code> interface.
* *
* @param elementName Element that provider parses. * @param elementName Element that provider parses.
* @param namespace Namespace that provider parses. * @param namespace Namespace that provider parses.
* @param extProvider The provider implementation. * @param extProvider The provider implementation.
*/ */
public ExtensionProviderInfo(String elementName, String namespace, PacketExtensionProvider<PacketExtension> extProvider) { public ExtensionProviderInfo(String elementName, String namespace, ExtensionElementProvider<ExtensionElement> extProvider) {
super(elementName, namespace, extProvider); super(elementName, namespace, extProvider);
} }

View file

@ -21,7 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.ParserUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -51,7 +51,7 @@ public class IntrospectionProvider{
} }
} }
public static abstract class PacketExtensionIntrospectionProvider<PE extends PacketExtension> extends PacketExtensionProvider<PE> { public static abstract class PacketExtensionIntrospectionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
private final Class<PE> elementClass; private final Class<PE> elementClass;
protected PacketExtensionIntrospectionProvider(Class<PE> elementClass) { protected PacketExtensionIntrospectionProvider(Class<PE> elementClass) {

View file

@ -25,12 +25,12 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
/** /**
* Loads the {@link IQProvider} and {@link PacketExtensionProvider} information from a standard provider file in preparation * Loads the {@link IQProvider} and {@link ExtensionElementProvider} information from a standard provider file in preparation
* for loading into the {@link ProviderManager}. * for loading into the {@link ProviderManager}.
* *
* @author Robin Collier * @author Robin Collier
@ -95,8 +95,8 @@ public class ProviderFileLoader implements ProviderLoader {
// a PacketExtension, add the class object itself and // a PacketExtension, add the class object itself and
// then we'll use reflection later to create instances // then we'll use reflection later to create instances
// of the class. // of the class.
if (PacketExtensionProvider.class.isAssignableFrom(provider)) { if (ExtensionElementProvider.class.isAssignableFrom(provider)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, (PacketExtensionProvider<PacketExtension>) provider.newInstance())); extProviders.add(new ExtensionProviderInfo(elementName, namespace, (ExtensionElementProvider<ExtensionElement>) provider.newInstance()));
} }
else { else {
exceptions.add(new IllegalArgumentException(className exceptions.add(new IllegalArgumentException(className
@ -106,7 +106,7 @@ public class ProviderFileLoader implements ProviderLoader {
case "streamFeatureProvider": case "streamFeatureProvider":
sfProviders.add(new StreamFeatureProviderInfo(elementName, sfProviders.add(new StreamFeatureProviderInfo(elementName,
namespace, namespace,
(PacketExtensionProvider<PacketExtension>) provider.newInstance())); (ExtensionElementProvider<ExtensionElement>) provider.newInstance()));
break; break;
default: default:
LOGGER.warning("Unknown provider type: " + typeName); LOGGER.warning("Unknown provider type: " + typeName);

View file

@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jxmpp.util.XmppStringUtils; import org.jxmpp.util.XmppStringUtils;
@ -109,9 +109,9 @@ import org.jxmpp.util.XmppStringUtils;
*/ */
public final class ProviderManager { public final class ProviderManager {
private static final Map<String, PacketExtensionProvider<PacketExtension>> extensionProviders = new ConcurrentHashMap<String, PacketExtensionProvider<PacketExtension>>(); private static final Map<String, ExtensionElementProvider<ExtensionElement>> extensionProviders = new ConcurrentHashMap<String, ExtensionElementProvider<ExtensionElement>>();
private static final Map<String, IQProvider<IQ>> iqProviders = new ConcurrentHashMap<String, IQProvider<IQ>>(); private static final Map<String, IQProvider<IQ>> iqProviders = new ConcurrentHashMap<String, IQProvider<IQ>>();
private static final Map<String, PacketExtensionProvider<PacketExtension>> streamFeatureProviders = new ConcurrentHashMap<String, PacketExtensionProvider<PacketExtension>>(); private static final Map<String, ExtensionElementProvider<ExtensionElement>> streamFeatureProviders = new ConcurrentHashMap<String, ExtensionElementProvider<ExtensionElement>>();
static { static {
// Ensure that Smack is initialized by calling getVersion, so that user // Ensure that Smack is initialized by calling getVersion, so that user
@ -138,7 +138,7 @@ public final class ProviderManager {
if (loader.getStreamFeatureProviderInfo() != null) { if (loader.getStreamFeatureProviderInfo() != null) {
for (StreamFeatureProviderInfo info : loader.getStreamFeatureProviderInfo()) { for (StreamFeatureProviderInfo info : loader.getStreamFeatureProviderInfo()) {
addStreamFeatureProvider(info.getElementName(), info.getNamespace(), addStreamFeatureProvider(info.getElementName(), info.getNamespace(),
(PacketExtensionProvider<PacketExtension>) info.getProvider()); (ExtensionElementProvider<ExtensionElement>) info.getProvider());
} }
} }
} }
@ -238,7 +238,7 @@ public final class ProviderManager {
* @param namespace namespace associated with extension provider. * @param namespace namespace associated with extension provider.
* @return the extenion provider. * @return the extenion provider.
*/ */
public static PacketExtensionProvider<PacketExtension> getExtensionProvider(String elementName, String namespace) { public static ExtensionElementProvider<ExtensionElement> getExtensionProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
return extensionProviders.get(key); return extensionProviders.get(key);
} }
@ -259,8 +259,8 @@ public final class ProviderManager {
validate(elementName, namespace); validate(elementName, namespace);
// First remove existing providers // First remove existing providers
String key = removeExtensionProvider(elementName, namespace); String key = removeExtensionProvider(elementName, namespace);
if (provider instanceof PacketExtensionProvider) { if (provider instanceof ExtensionElementProvider) {
extensionProviders.put(key, (PacketExtensionProvider<PacketExtension>) provider); extensionProviders.put(key, (ExtensionElementProvider<ExtensionElement>) provider);
} else { } else {
throw new IllegalArgumentException("Provider must be a PacketExtensionProvider"); throw new IllegalArgumentException("Provider must be a PacketExtensionProvider");
} }
@ -288,18 +288,18 @@ public final class ProviderManager {
* *
* @return all PacketExtensionProvider instances. * @return all PacketExtensionProvider instances.
*/ */
public static List<PacketExtensionProvider<PacketExtension>> getExtensionProviders() { public static List<ExtensionElementProvider<ExtensionElement>> getExtensionProviders() {
List<PacketExtensionProvider<PacketExtension>> providers = new ArrayList<>(extensionProviders.size()); List<ExtensionElementProvider<ExtensionElement>> providers = new ArrayList<>(extensionProviders.size());
providers.addAll(extensionProviders.values()); providers.addAll(extensionProviders.values());
return providers; return providers;
} }
public static PacketExtensionProvider<PacketExtension> getStreamFeatureProvider(String elementName, String namespace) { public static ExtensionElementProvider<ExtensionElement> getStreamFeatureProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
return streamFeatureProviders.get(key); return streamFeatureProviders.get(key);
} }
public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider<PacketExtension> provider) { public static void addStreamFeatureProvider(String elementName, String namespace, ExtensionElementProvider<ExtensionElement> provider) {
validate(elementName, namespace); validate(elementName, namespace);
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
streamFeatureProviders.put(key, provider); streamFeatureProviders.put(key, provider);

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
/** /**
* *
@ -31,7 +31,7 @@ public final class StreamFeatureProviderInfo extends AbstractProviderInfo {
* @param extProvider The provider implementation. * @param extProvider The provider implementation.
*/ */
public StreamFeatureProviderInfo(String elementName, String namespace, public StreamFeatureProviderInfo(String elementName, String namespace,
PacketExtensionProvider<PacketExtension> extProvider) { ExtensionElementProvider<ExtensionElement> extProvider) {
super(elementName, namespace, extProvider); super(elementName, namespace, extProvider);
} }

View file

@ -73,7 +73,7 @@ public class SASLXOauth2Mechanism extends SASLMechanism {
@Override @Override
protected byte[] getAuthenticationText() throws SmackException { protected byte[] getAuthenticationText() throws SmackException {
// base64("\0" + user_name + "\0" + oauth_token) // base64("\0" + user_name + "\0" + oauth_token)
return Base64.decode('\u0000' + authenticationId + '\u0000' + password); return Base64.encode(toBytes('\u0000' + authenticationId + '\u0000' + password));
} }
@Override @Override

View file

@ -0,0 +1,97 @@
/**
*
* Copyright 2015 Florian Schmaus
*
* 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.util;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* The event manager class is used to perform actions and wait for an event, which is usually caused by the action (or maybe never occurs).
* <p>
* Events are distinguished by an unique event key. They can produce an event result, which can simply be null.
* </p>
* <p>
* The action is able to throw an exception.
* </p>
*
* @param <K> the event key.
* @param <R> the event result.
* @param <E> the exception which could be thrown by the action.
*/
public class EventManger<K, R, E extends Exception> {
private final Map<K,Reference<R>> events = new ConcurrentHashMap<>();
/**
* Perform an action and wait for an event.
* <p>
* The event is signaled with {@link #signalEvent(Object, Object)}.
* </p>
*
* @param eventKey the event key, must not be null.
* @param timeout the timeout to wait for the event in milliseconds.
* @param action the action to perform prior waiting for the event, must not be null.
* @return the event value, may be null.
* @throws InterruptedException if interrupted while waiting for the event.
* @throws E
*/
public R performActionAndWaitForEvent(K eventKey, long timeout, Callback<E> action) throws InterruptedException, E {
final Reference<R> reference = new Reference<>();
events.put(eventKey, reference);
try {
synchronized (reference) {
action.action();
reference.wait(timeout);
}
return reference.eventResult;
}
finally {
events.remove(eventKey);
}
}
/**
* Signal an event and the event result.
* <p>
* This method will return <code>false</code> if the event was not created with
* {@link #performActionAndWaitForEvent(Object, long, Callback)}.
* </p>
*
* @param eventKey the event key, must not be null.
* @param eventResult the event result, may be null.
* @return true if the event was found and signaled, false otherwise.
*/
public boolean signalEvent(K eventKey, R eventResult) {
final Reference<R> reference = events.get(eventKey);
if (reference == null) {
return false;
}
reference.eventResult = eventResult;
synchronized(reference) {
reference.notifyAll();
}
return true;
}
private static class Reference<V> {
volatile V eventResult;
}
public interface Callback<E extends Exception> {
public void action() throws E;
}
}

View file

@ -184,6 +184,11 @@ public class MultiMap<K,V> {
return map.keySet(); return map.keySet();
} }
/**
* Returns a new list containing all values of this multi map.
*
* @return a new list with all values.
*/
public List<V> values() { public List<V> values() {
List<V> values = new ArrayList<>(size()); List<V> values = new ArrayList<>(size());
for (Set<V> set : map.values()) { for (Set<V> set : map.values()) {

View file

@ -30,13 +30,13 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.compress.packet.Compress; import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.packet.DefaultPacketExtension; import org.jivesoftware.smack.packet.DefaultExtensionElement;
import org.jivesoftware.smack.packet.EmptyResultIQ; import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ErrorIQ; import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.StartTls; import org.jivesoftware.smack.packet.StartTls;
@ -44,7 +44,7 @@ import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.UnparsedIQ; import org.jivesoftware.smack.packet.UnparsedIQ;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
@ -285,7 +285,7 @@ public class PacketParserUtils {
message.setError(parseError(parser)); message.setError(parseError(parser));
break; break;
default: default:
PacketParserUtils.addPacketExtension(message, parser, elementName, namespace); PacketParserUtils.addExtensionElement(message, parser, elementName, namespace);
break; break;
} }
break; break;
@ -575,7 +575,7 @@ public class PacketParserUtils {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of // Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information. // failing completely here. See SMACK-390 for more information.
try { try {
PacketParserUtils.addPacketExtension(presence, parser, elementName, namespace); PacketParserUtils.addExtensionElement(presence, parser, elementName, namespace);
} catch (Exception e) { } catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to parse extension packet in Presence packet.", e); LOGGER.log(Level.WARNING, "Failed to parse extension packet in Presence packet.", e);
} }
@ -798,7 +798,7 @@ public class PacketParserUtils {
public static StreamError parseStreamError(XmlPullParser parser) throws IOException, XmlPullParserException, public static StreamError parseStreamError(XmlPullParser parser) throws IOException, XmlPullParserException,
SmackException { SmackException {
final int initialDepth = parser.getDepth(); final int initialDepth = parser.getDepth();
List<PacketExtension> extensions = new ArrayList<PacketExtension>(); List<ExtensionElement> extensions = new ArrayList<ExtensionElement>();
Map<String, String> descriptiveTexts = null; Map<String, String> descriptiveTexts = null;
StreamError.Condition condition = null; StreamError.Condition condition = null;
String conditionText = null; String conditionText = null;
@ -825,7 +825,7 @@ public class PacketParserUtils {
} }
break; break;
default: default:
PacketParserUtils.addPacketExtension(extensions, parser, name, namespace); PacketParserUtils.addExtensionElement(extensions, parser, name, namespace);
break; break;
} }
break; break;
@ -854,7 +854,7 @@ public class PacketParserUtils {
Map<String, String> descriptiveTexts = null; Map<String, String> descriptiveTexts = null;
XMPPError.Condition condition = null; XMPPError.Condition condition = null;
String conditionText = null; String conditionText = null;
List<PacketExtension> extensions = new ArrayList<PacketExtension>(); List<ExtensionElement> extensions = new ArrayList<ExtensionElement>();
// Parse the error header // Parse the error header
XMPPError.Type errorType = XMPPError.Type.fromString(parser.getAttributeValue("", "type")); XMPPError.Type errorType = XMPPError.Type.fromString(parser.getAttributeValue("", "type"));
@ -881,7 +881,7 @@ public class PacketParserUtils {
} }
break; break;
default: default:
PacketParserUtils.addPacketExtension(extensions, parser, name, namespace); PacketParserUtils.addExtensionElement(extensions, parser, name, namespace);
} }
break; break;
case XmlPullParser.END_TAG: case XmlPullParser.END_TAG:
@ -894,26 +894,36 @@ public class PacketParserUtils {
} }
/** /**
* Parses a packet extension sub-packet. * @deprecated use {@link #parseExtensionElement(String, String, XmlPullParser)} instead.
*/
@Deprecated
public static ExtensionElement parsePacketExtension(String elementName, String namespace,
XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
return parseExtensionElement(elementName, namespace, parser);
}
/**
* Parses an extension element.
* *
* @param elementName the XML element name of the packet extension. * @param elementName the XML element name of the extension element.
* @param namespace the XML namespace of the packet extension. * @param namespace the XML namespace of the packet extension.
* @param parser the XML parser, positioned at the starting element of the extension. * @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension. * @return an extension element.
*/ */
public static PacketExtension parsePacketExtension(String elementName, String namespace, public static ExtensionElement parseExtensionElement(String elementName, String namespace,
XmlPullParser parser) throws XmlPullParserException, XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException { IOException, SmackException {
ParserUtils.assertAtStartTag(parser); ParserUtils.assertAtStartTag(parser);
// See if a provider is registered to handle the extension. // See if a provider is registered to handle the extension.
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getExtensionProvider(elementName, namespace); ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(elementName, namespace);
if (provider != null) { if (provider != null) {
return provider.parse(parser); return provider.parse(parser);
} }
final int initialDepth = parser.getDepth(); final int initialDepth = parser.getDepth();
// No providers registered, so use a default extension. // No providers registered, so use a default extension.
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace); DefaultExtensionElement extension = new DefaultExtensionElement(elementName, namespace);
outerloop: while (true) { outerloop: while (true) {
int eventType = parser.next(); int eventType = parser.next();
switch (eventType) { switch (eventType) {
@ -1006,27 +1016,53 @@ public class PacketParserUtils {
return null; return null;
} }
@Deprecated
public static void addPacketExtension(Stanza packet, XmlPullParser parser) throws XmlPullParserException, public static void addPacketExtension(Stanza packet, XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException { IOException, SmackException {
ParserUtils.assertAtStartTag(parser); addExtensionElement(packet, parser);
addPacketExtension(packet, parser, parser.getName(), parser.getNamespace());
} }
@Deprecated
public static void addPacketExtension(Stanza packet, XmlPullParser parser, String elementName, String namespace) public static void addPacketExtension(Stanza packet, XmlPullParser parser, String elementName, String namespace)
throws XmlPullParserException, IOException, SmackException { throws XmlPullParserException, IOException, SmackException {
PacketExtension packetExtension = parsePacketExtension(elementName, namespace, parser); addExtensionElement(packet, parser, elementName, namespace);
}
@Deprecated
public static void addPacketExtension(Collection<ExtensionElement> collection, XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
}
@Deprecated
public static void addPacketExtension(Collection<ExtensionElement> collection, XmlPullParser parser,
String elementName, String namespace) throws XmlPullParserException, IOException, SmackException {
addExtensionElement(collection, parser, elementName, namespace);
}
public static void addExtensionElement(Stanza packet, XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
addExtensionElement(packet, parser, parser.getName(), parser.getNamespace());
}
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
String namespace) throws XmlPullParserException, IOException, SmackException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
packet.addExtension(packetExtension); packet.addExtension(packetExtension);
} }
public static void addPacketExtension(Collection<PacketExtension> collection, XmlPullParser parser) public static void addExtensionElement(Collection<ExtensionElement> collection,
throws XmlPullParserException, IOException, SmackException { XmlPullParser parser) throws XmlPullParserException, IOException,
addPacketExtension(collection, parser, parser.getName(), parser.getNamespace()); SmackException {
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
} }
public static void addPacketExtension(Collection<PacketExtension> collection, XmlPullParser parser, public static void addExtensionElement(Collection<ExtensionElement> collection,
String elementName, String namespace) throws XmlPullParserException, IOException, SmackException { XmlPullParser parser, String elementName, String namespace)
PacketExtension packetExtension = parsePacketExtension(elementName, namespace, parser); throws XmlPullParserException, IOException, SmackException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
collection.add(packetExtension); collection.add(packetExtension);
} }
} }

View file

@ -18,7 +18,7 @@ package org.jivesoftware.smack.util;
import java.util.Collection; import java.util.Collection;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
public class PacketUtil { public class PacketUtil {
@ -32,8 +32,8 @@ public class PacketUtil {
* @deprecated use {@link #extensionElementFrom(Collection, String, String)} instead * @deprecated use {@link #extensionElementFrom(Collection, String, String)} instead
*/ */
@Deprecated @Deprecated
public static <PE extends PacketExtension> PE packetExtensionfromCollection( public static <PE extends ExtensionElement> PE packetExtensionfromCollection(
Collection<PacketExtension> collection, String element, Collection<ExtensionElement> collection, String element,
String namespace) { String namespace) {
return extensionElementFrom(collection, element, namespace); return extensionElementFrom(collection, element, namespace);
} }
@ -47,9 +47,9 @@ public class PacketUtil {
* @return the extension element * @return the extension element
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <PE extends PacketExtension> PE extensionElementFrom(Collection<PacketExtension> collection, public static <PE extends ExtensionElement> PE extensionElementFrom(Collection<ExtensionElement> collection,
String element, String namespace) { String element, String namespace) {
for (PacketExtension packetExtension : collection) { for (ExtensionElement packetExtension : collection) {
if ((element == null || packetExtension.getElementName().equals( if ((element == null || packetExtension.getElementName().equals(
element)) element))
&& packetExtension.getNamespace().equals(namespace)) { && packetExtension.getNamespace().equals(namespace)) {

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2014 Florian Schmaus * Copyright 2014-2015 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ public final class SmackExecutorThreadFactory implements ThreadFactory {
@Override @Override
public Thread newThread(Runnable runnable) { public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable); Thread thread = new Thread(runnable);
thread.setName("Smack Executor - " + name + ' ' + count++ + " (" + connectionCounterValue + ")"); thread.setName("Smack-" + name + ' ' + count++ + " (" + connectionCounterValue + ")");
thread.setDaemon(true); thread.setDaemon(true);
return thread; return thread;
} }

View file

@ -20,7 +20,7 @@ import java.util.Collection;
import org.jivesoftware.smack.packet.Element; import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.NamedElement; import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
public class XmlStringBuilder implements Appendable, CharSequence { public class XmlStringBuilder implements Appendable, CharSequence {
public static final String RIGHT_ANGLE_BRACKET = Character.toString('>'); public static final String RIGHT_ANGLE_BRACKET = Character.toString('>');
@ -31,7 +31,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
sb = new LazyStringBuilder(); sb = new LazyStringBuilder();
} }
public XmlStringBuilder(PacketExtension pe) { public XmlStringBuilder(ExtensionElement pe) {
this(); this();
prelude(pe); prelude(pe);
} }
@ -276,7 +276,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return escape(text.toString()); return escape(text.toString());
} }
public XmlStringBuilder prelude(PacketExtension pe) { public XmlStringBuilder prelude(ExtensionElement pe) {
return prelude(pe.getElementName(), pe.getNamespace()); return prelude(pe.getElementName(), pe.getNamespace());
} }

View file

@ -37,7 +37,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
* unit tests. * unit tests.
* *
* Instances store any packets that are delivered to be send using the * Instances store any packets that are delivered to be send using the
* {@link #sendPacket(Stanza)} method in a blocking queue. The content of this queue * {@link #sendStanza(Stanza)} method in a blocking queue. The content of this queue
* can be inspected using {@link #getSentPacket()}. Typically these queues are * can be inspected using {@link #getSentPacket()}. Typically these queues are
* used to retrieve a message that was generated by the client. * used to retrieve a message that was generated by the client.
* *
@ -141,7 +141,7 @@ public class DummyConnection extends AbstractXMPPConnection {
} }
@Override @Override
protected void sendPacketInternal(Stanza packet) { protected void sendStanzaInternal(Stanza packet) {
if (SmackConfiguration.DEBUG) { if (SmackConfiguration.DEBUG) {
System.out.println("[SEND]: " + packet.toXML()); System.out.println("[SEND]: " + packet.toXML());
} }
@ -149,7 +149,7 @@ public class DummyConnection extends AbstractXMPPConnection {
} }
/** /**
* Returns the number of packets that's sent through {@link #sendPacket(Stanza)} and * Returns the number of packets that's sent through {@link #sendStanza(Stanza)} and
* that has not been returned by {@link #getSentPacket()}. * that has not been returned by {@link #getSentPacket()}.
* *
* @return the number of packets which are in the queue. * @return the number of packets which are in the queue.
@ -159,7 +159,7 @@ public class DummyConnection extends AbstractXMPPConnection {
} }
/** /**
* Returns the first packet that's sent through {@link #sendPacket(Stanza)} * Returns the first packet that's sent through {@link #sendStanza(Stanza)}
* and that has not been returned by earlier calls to this method. * and that has not been returned by earlier calls to this method.
* *
* @return a sent packet. * @return a sent packet.
@ -169,7 +169,7 @@ public class DummyConnection extends AbstractXMPPConnection {
} }
/** /**
* Returns the first packet that's sent through {@link #sendPacket(Stanza)} * Returns the first packet that's sent through {@link #sendStanza(Stanza)}
* and that has not been returned by earlier calls to this method. This * and that has not been returned by earlier calls to this method. This
* method will block for up to the specified number of seconds if no packets * method will block for up to the specified number of seconds if no packets
* have been sent yet. * have been sent yet.

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.junit.Test; import org.junit.Test;
@ -176,7 +176,7 @@ public class PacketCollectorTest
assertNull(collector.pollResult()); assertNull(collector.pollResult());
} }
class OKEverything implements PacketFilter class OKEverything implements StanzaFilter
{ {
@Override @Override
public boolean accept(Stanza packet) public boolean accept(Stanza packet)
@ -188,9 +188,9 @@ public class PacketCollectorTest
class TestPacketCollector extends PacketCollector class TestPacketCollector extends PacketCollector
{ {
protected TestPacketCollector(XMPPConnection conection, PacketFilter packetFilter, int size) protected TestPacketCollector(XMPPConnection conection, StanzaFilter packetFilter, int size)
{ {
super(conection, PacketCollector.newConfiguration().setPacketFilter(packetFilter).setSize(size)); super(conection, PacketCollector.newConfiguration().setStanzaFilter(packetFilter).setSize(size));
} }
} }

View file

@ -38,8 +38,8 @@ public class ThreadedDummyConnection extends DummyConnection {
private volatile boolean timeout = false; private volatile boolean timeout = false;
@Override @Override
public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException { public void sendStanza(Stanza packet) throws NotConnectedException, InterruptedException {
super.sendPacket(packet); super.sendStanza(packet);
if (packet instanceof IQ && !timeout) { if (packet instanceof IQ && !timeout) {
timeout = false; timeout = false;
@ -62,7 +62,7 @@ public class ThreadedDummyConnection extends DummyConnection {
} }
/** /**
* Calling this method will cause the next sendPacket call with an IQ packet to timeout. * Calling this method will cause the next sendStanza call with an IQ packet to timeout.
* This is accomplished by simply stopping the auto creating of the reply packet * This is accomplished by simply stopping the auto creating of the reply packet
* or processing one that was entered via {@link #processPacket(Stanza)}. * or processing one that was entered via {@link #processPacket(Stanza)}.
*/ */

View file

@ -0,0 +1,42 @@
/**
*
* Copyright 2015 Florian Schmaus
*
* 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.filters;
import static org.junit.Assert.assertEquals;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.filter.ThreadFilter;
import org.junit.Test;
/**
*
*/
public class FilterToStringTest {
@Test
public void abstractListFilterToStringTest() {
AndFilter andFilter = new AndFilter();
andFilter.addFilter(new StanzaIdFilter("foo"));
andFilter.addFilter(new ThreadFilter("42"));
andFilter.addFilter(MessageWithBodiesFilter.INSTANCE);
final String res =andFilter.toString();
assertEquals("AndFilter: (StanzaIdFilter: id=foo, ThreadFilter: thread=42, MessageWithBodiesFilter)", res);
}
}

View file

@ -99,7 +99,7 @@ public class StreamErrorTest {
assertNotNull(error); assertNotNull(error);
assertEquals(Condition.conflict, error.getCondition()); assertEquals(Condition.conflict, error.getCondition());
assertEquals("Replaced by new connection", error.getDescriptiveText()); assertEquals("Replaced by new connection", error.getDescriptiveText());
PacketExtension appSpecificElement = error.getExtension("appSpecificElement", "myns"); ExtensionElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
assertNotNull(appSpecificElement); assertNotNull(appSpecificElement);
} }

View file

@ -20,8 +20,8 @@ import static org.junit.Assert.assertThat;
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence; import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.test.util.TestUtils; import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
@ -72,12 +72,12 @@ public class ParsingExceptionTest {
assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content)); assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
} }
static class ThrowException extends PacketExtensionProvider<PacketExtension> { static class ThrowException extends ExtensionElementProvider<ExtensionElement> {
public static final String ELEMENT = "exception"; public static final String ELEMENT = "exception";
public static final String NAMESPACE = "http://smack.jivesoftware.org/exception"; public static final String NAMESPACE = "http://smack.jivesoftware.org/exception";
@Override @Override
public PacketExtension parse(XmlPullParser parser, int initialDepth) throws SmackException { public ExtensionElement parse(XmlPullParser parser, int initialDepth) throws SmackException {
throw new SmackException("Test Exception"); throw new SmackException("Test Exception");
} }

View file

@ -20,7 +20,10 @@ import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -40,6 +43,10 @@ final public class TestUtils {
return getParser(stanza, "presence"); return getParser(stanza, "presence");
} }
public static XmlPullParser getParser(String string) {
return getParser(string, null);
}
public static XmlPullParser getParser(String string, String startTag) { public static XmlPullParser getParser(String string, String startTag) {
return getParser(new StringReader(string), startTag); return getParser(new StringReader(string), startTag);
} }
@ -49,6 +56,9 @@ final public class TestUtils {
try { try {
parser = PacketParserUtils.newXmppParser(reader); parser = PacketParserUtils.newXmppParser(reader);
if (startTag == null) { if (startTag == null) {
while (parser.getEventType() != XmlPullParser.START_TAG) {
parser.next();
}
return parser; return parser;
} }
boolean found = false; boolean found = false;
@ -68,4 +78,17 @@ final public class TestUtils {
return parser; return parser;
} }
public static <EE extends ExtensionElement> EE parseExtensionElement(String elementString)
throws XmlPullParserException, IOException, SmackException {
return parseExtensionElement(getParser(elementString));
}
@SuppressWarnings("unchecked")
public static <EE extends ExtensionElement> EE parseExtensionElement(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
final String elementName = parser.getName();
final String namespace = parser.getNamespace();
return (EE) PacketParserUtils.parseExtensionElement(elementName, namespace, parser);
}
} }

View file

@ -19,11 +19,11 @@ package org.jivesoftware.smack.test.util;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
public class WaitForPacketListener implements PacketListener { public class WaitForPacketListener implements StanzaListener {
private CountDownLatch latch = new CountDownLatch(1); private CountDownLatch latch = new CountDownLatch(1);

View file

@ -17,12 +17,12 @@
package org.jivesoftware.smackx.debugger.slf4j; package org.jivesoftware.smackx.debugger.slf4j;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.slf4j.Logger; import org.slf4j.Logger;
class SLF4JLoggingPacketListener implements PacketListener { class SLF4JLoggingPacketListener implements StanzaListener {
private final Logger logger; private final Logger logger;
private final String prefix; private final String prefix;

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.debugger.slf4j; package org.jivesoftware.smackx.debugger.slf4j;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.debugger.SmackDebugger; import org.jivesoftware.smack.debugger.SmackDebugger;
@ -47,8 +47,8 @@ public class SLF4JSmackDebugger implements SmackDebugger {
private final XMPPConnection connection; private final XMPPConnection connection;
private final PacketListener receivedListener = new SLF4JLoggingPacketListener(logger, RECEIVED_TAG); private final StanzaListener receivedListener = new SLF4JLoggingPacketListener(logger, RECEIVED_TAG);
private final PacketListener sentListener = new SLF4JLoggingPacketListener(logger, SENT_TAG); private final StanzaListener sentListener = new SLF4JLoggingPacketListener(logger, SENT_TAG);
private final SLF4JRawXmlListener slf4JRawXmlListener = new SLF4JRawXmlListener(logger); private final SLF4JRawXmlListener slf4JRawXmlListener = new SLF4JRawXmlListener(logger);
private ObservableWriter writer; private ObservableWriter writer;
@ -110,12 +110,12 @@ public class SLF4JSmackDebugger implements SmackDebugger {
} }
@Override @Override
public PacketListener getReaderListener() { public StanzaListener getReaderListener() {
return receivedListener; return receivedListener;
} }
@Override @Override
public PacketListener getWriterListener() { public StanzaListener getWriterListener() {
return sentListener; return sentListener;
} }
} }

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smackx.debugger;
import org.jivesoftware.smack.AbstractConnectionListener; import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.debugger.SmackDebugger; import org.jivesoftware.smack.debugger.SmackDebugger;
@ -150,8 +150,8 @@ public class EnhancedDebugger implements SmackDebugger {
private XMPPConnection connection = null; private XMPPConnection connection = null;
private PacketListener packetReaderListener = null; private StanzaListener packetReaderListener = null;
private PacketListener packetWriterListener = null; private StanzaListener packetWriterListener = null;
private ConnectionListener connListener = null; private ConnectionListener connListener = null;
private Writer writer; private Writer writer;
@ -205,7 +205,7 @@ public class EnhancedDebugger implements SmackDebugger {
// Create a thread that will listen for all incoming packets and write them to // Create a thread that will listen for all incoming packets and write them to
// the GUI. This is what we call "interpreted" packet data, since it's the packet // the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML. // data as Smack sees it and not as it's coming in as raw XML.
packetReaderListener = new PacketListener() { packetReaderListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss:SS aaa"); SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss:SS aaa");
public void processPacket(final Stanza packet) { public void processPacket(final Stanza packet) {
@ -220,7 +220,7 @@ public class EnhancedDebugger implements SmackDebugger {
// Create a thread that will listen for all outgoing packets and write them to // Create a thread that will listen for all outgoing packets and write them to
// the GUI. // the GUI.
packetWriterListener = new PacketListener() { packetWriterListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss:SS aaa"); SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss:SS aaa");
public void processPacket(final Stanza packet) { public void processPacket(final Stanza packet) {
@ -580,7 +580,7 @@ public class EnhancedDebugger implements SmackDebugger {
if (!"".equals(adhocMessages.getText())) { if (!"".equals(adhocMessages.getText())) {
AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText()); AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
try { try {
connection.sendPacket(packetToSend); connection.sendStanza(packetToSend);
} }
catch (InterruptedException | NotConnectedException e1) { catch (InterruptedException | NotConnectedException e1) {
e1.printStackTrace(); e1.printStackTrace();
@ -760,11 +760,11 @@ public class EnhancedDebugger implements SmackDebugger {
return writer; return writer;
} }
public PacketListener getReaderListener() { public StanzaListener getReaderListener() {
return packetReaderListener; return packetReaderListener;
} }
public PacketListener getWriterListener() { public StanzaListener getWriterListener() {
return packetWriterListener; return packetWriterListener;
} }
@ -959,7 +959,7 @@ public class EnhancedDebugger implements SmackDebugger {
*/ */
void cancel() { void cancel() {
connection.removeConnectionListener(connListener); connection.removeConnectionListener(connListener);
connection.removeAsyncPacketListener(packetReaderListener); connection.removeAsyncStanzaListener(packetReaderListener);
connection.removePacketSendingListener(packetWriterListener); connection.removePacketSendingListener(packetWriterListener);
((ObservableReader) reader).removeReaderListener(readerListener); ((ObservableReader) reader).removeReaderListener(readerListener);
((ObservableWriter) writer).removeWriterListener(writerListener); ((ObservableWriter) writer).removeWriterListener(writerListener);

View file

@ -40,7 +40,7 @@ import javax.swing.JScrollPane;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.debugger.SmackDebugger; import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
@ -63,7 +63,7 @@ public class LiteDebugger implements SmackDebugger {
private JFrame frame = null; private JFrame frame = null;
private XMPPConnection connection = null; private XMPPConnection connection = null;
private PacketListener listener = null; private StanzaListener listener = null;
private Writer writer; private Writer writer;
private Reader reader; private Reader reader;
@ -261,7 +261,7 @@ public class LiteDebugger implements SmackDebugger {
// Create a thread that will listen for all incoming packets and write them to // Create a thread that will listen for all incoming packets and write them to
// the GUI. This is what we call "interpreted" packet data, since it's the packet // the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML. // data as Smack sees it and not as it's coming in as raw XML.
listener = new PacketListener() { listener = new StanzaListener() {
public void processPacket(Stanza packet) { public void processPacket(Stanza packet) {
interpretedText1.append(packet.toXML().toString()); interpretedText1.append(packet.toXML().toString());
interpretedText2.append(packet.toXML().toString()); interpretedText2.append(packet.toXML().toString());
@ -278,7 +278,7 @@ public class LiteDebugger implements SmackDebugger {
* @param evt the event that indicates that the root window is closing * @param evt the event that indicates that the root window is closing
*/ */
public void rootWindowClosing(WindowEvent evt) { public void rootWindowClosing(WindowEvent evt) {
connection.removeAsyncPacketListener(listener); connection.removeAsyncStanzaListener(listener);
((ObservableReader)reader).removeReaderListener(readerListener); ((ObservableReader)reader).removeReaderListener(readerListener);
((ObservableWriter)writer).removeWriterListener(writerListener); ((ObservableWriter)writer).removeWriterListener(writerListener);
} }
@ -340,11 +340,11 @@ public class LiteDebugger implements SmackDebugger {
return writer; return writer;
} }
public PacketListener getReaderListener() { public StanzaListener getReaderListener() {
return listener; return listener;
} }
public PacketListener getWriterListener() { public StanzaListener getWriterListener() {
return null; return null;
} }
} }

View file

@ -25,7 +25,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.XMPPException.XMPPErrorException;
@ -121,7 +121,7 @@ public class CarbonManager extends Manager {
public void sendCarbonsEnabled(final boolean new_state) throws NotConnectedException, InterruptedException { public void sendCarbonsEnabled(final boolean new_state) throws NotConnectedException, InterruptedException {
IQ setIQ = carbonsEnabledIQ(new_state); IQ setIQ = carbonsEnabledIQ(new_state);
connection().sendIqWithResponseCallback(setIQ, new PacketListener() { connection().sendIqWithResponseCallback(setIQ, new StanzaListener() {
public void processPacket(Stanza packet) { public void processPacket(Stanza packet) {
enabled_state = new_state; enabled_state = new_state;
} }

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.carbons.packet; package org.jivesoftware.smackx.carbons.packet;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.forward.packet.Forwarded; import org.jivesoftware.smackx.forward.packet.Forwarded;
@ -32,7 +32,7 @@ import org.jivesoftware.smackx.forward.packet.Forwarded;
* *
* @author Georg Lukas * @author Georg Lukas
*/ */
public class CarbonExtension implements PacketExtension { public class CarbonExtension implements ExtensionElement {
public static final String NAMESPACE = Carbon.NAMESPACE; public static final String NAMESPACE = Carbon.NAMESPACE;
private final Direction dir; private final Direction dir;
@ -131,7 +131,7 @@ public class CarbonExtension implements PacketExtension {
* Packet extension indicating that a message may not be carbon-copied. Adding this * Packet extension indicating that a message may not be carbon-copied. Adding this
* extension to any message will disallow that message from being copied. * extension to any message will disallow that message from being copied.
*/ */
public static class Private implements PacketExtension { public static class Private implements ExtensionElement {
public static final Private INSTANCE = new Private(); public static final Private INSTANCE = new Private();
public static final String ELEMENT = "private"; public static final String ELEMENT = "private";

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smackx.carbons.provider;
import java.io.IOException; import java.io.IOException;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension; import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction; import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction;
import org.jivesoftware.smackx.forward.packet.Forwarded; import org.jivesoftware.smackx.forward.packet.Forwarded;
@ -28,13 +28,13 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
/** /**
* This class implements the {@link PacketExtensionProvider} to parse * This class implements the {@link ExtensionElementProvider} to parse
* carbon copied messages from a packet. It will return a {@link CarbonExtension} packet extension. * carbon copied messages from a packet. It will return a {@link CarbonExtension} packet extension.
* *
* @author Georg Lukas * @author Georg Lukas
* *
*/ */
public class CarbonManagerProvider extends PacketExtensionProvider<CarbonExtension> { public class CarbonManagerProvider extends ExtensionElementProvider<CarbonExtension> {
private static final ForwardedProvider FORWARDED_PROVIDER = new ForwardedProvider(); private static final ForwardedProvider FORWARDED_PROVIDER = new ForwardedProvider();

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.csi.packet; package org.jivesoftware.smackx.csi.packet;
import org.jivesoftware.smack.packet.FullStreamElement; import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
/** /**
* *
@ -73,7 +73,7 @@ public class ClientStateIndication {
} }
} }
public static class Feature implements PacketExtension { public static class Feature implements ExtensionElement {
public static final Feature INSTANCE = new Feature(); public static final Feature INSTANCE = new Feature();
public static final String ELEMENT = "csi"; public static final String ELEMENT = "csi";

View file

@ -19,12 +19,12 @@ package org.jivesoftware.smackx.csi.provider;
import java.io.IOException; import java.io.IOException;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.csi.packet.ClientStateIndication; import org.jivesoftware.smackx.csi.packet.ClientStateIndication;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
public class ClientStateIndicationFeatureProvider extends PacketExtensionProvider<ClientStateIndication.Feature> { public class ClientStateIndicationFeatureProvider extends ExtensionElementProvider<ClientStateIndication.Feature> {
@Override @Override
public ClientStateIndication.Feature parse(XmlPullParser parser, int initialDepth) public ClientStateIndication.Feature parse(XmlPullParser parser, int initialDepth)

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smackx.hoxt.packet; package org.jivesoftware.smackx.hoxt.packet;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smackx.hoxt.HOXTManager; import org.jivesoftware.smackx.hoxt.HOXTManager;
/** /**
@ -26,7 +26,7 @@ import org.jivesoftware.smackx.hoxt.HOXTManager;
* @author Andriy Tsykholyas * @author Andriy Tsykholyas
* @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
*/ */
public class Base64BinaryChunk implements PacketExtension { public class Base64BinaryChunk implements ExtensionElement {
public static final String ELEMENT_CHUNK = "chunk"; public static final String ELEMENT_CHUNK = "chunk";
public static final String ATTRIBUTE_STREAM_ID = "streamId"; public static final String ATTRIBUTE_STREAM_ID = "streamId";

Some files were not shown because too many files have changed in this diff Show more