From b28037bc79fd8f88fdf73360c20607c2a9a7e297 Mon Sep 17 00:00:00 2001 From: rcollier Date: Tue, 2 Apr 2013 00:23:55 +0000 Subject: [PATCH] SMACK-331 Changed methods to existing Smack conventions and moved interface to top level. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13601 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/receipts/DeliveryReceipt.java | 5 +++- .../receipts/DeliveryReceiptManager.java | 20 +++----------- .../receipts/ReceiptReceivedListener.java | 26 +++++++++++++++++++ .../smackx/receipts/DeliveryReceiptTest.java | 14 +++++----- 4 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java diff --git a/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java b/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java index 14f4456d2..902055671 100644 --- a/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java +++ b/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java @@ -1,4 +1,4 @@ -/* +/** * All rights reserved. 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 @@ -42,16 +42,19 @@ public class DeliveryReceipt implements PacketExtension return id; } + @Override public String getElementName() { return ELEMENT; } + @Override public String getNamespace() { return NAMESPACE; } + @Override public String toXML() { return ""; diff --git a/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index eaac5a4c4..125b87e63 100644 --- a/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -24,20 +24,16 @@ import java.util.WeakHashMap; import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.ConnectionCreationListener; -import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.PacketExtensionFilter; -import org.jivesoftware.smack.filter.PacketIDFilter; -import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.packet.DiscoverInfo; /** - * Packet extension for XEP-0184: Message Delivery Receipts. This class implements + * Manager for XEP-0184: Message Delivery Receipts. This class implements * the manager for {@link DeliveryReceipt} support, enabling and disabling of * automatic DeliveryReceipt transmission. * @@ -167,7 +163,7 @@ public class DeliveryReceiptManager implements PacketListener { * * @param listener the listener to be informed about new receipts */ - public void registerReceiptReceivedListener(ReceiptReceivedListener listener) { + public void addReceiptReceivedListener(ReceiptReceivedListener listener) { receiptReceivedListeners.add(listener); } @@ -176,20 +172,10 @@ public class DeliveryReceiptManager implements PacketListener { * * @param listener the listener to be removed */ - public void unregisterReceiptReceivedListener(ReceiptReceivedListener listener) { + public void removeReceiptReceivedListener(ReceiptReceivedListener listener) { receiptReceivedListeners.remove(listener); } - /** - * Interface for received receipt notifications. - * - * Implement this and add a listener to get notified. - */ - public static interface ReceiptReceivedListener { - void onReceiptReceived(String fromJid, String toJid, String receiptId); - } - - /** * Test if a packet requires a delivery receipt. * diff --git a/source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java b/source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java new file mode 100644 index 000000000..318311371 --- /dev/null +++ b/source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java @@ -0,0 +1,26 @@ +/** + * Copyright 2013 Georg Lukas + * + * All rights reserved. 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.smackx.receipts; + +/** + * Interface for received receipt notifications. + * + * Implement this and add a listener to get notified. + */ +public interface ReceiptReceivedListener { + void onReceiptReceived(String fromJid, String toJid, String receiptId); +} \ No newline at end of file diff --git a/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index d6e51d740..6b0425a60 100644 --- a/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -13,16 +13,14 @@ */ package org.jivesoftware.smackx.receipts; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringReader; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; import java.util.Properties; -import java.util.TimeZone; import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.packet.Message; @@ -76,7 +74,7 @@ public class DeliveryReceiptTest { DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c); TestReceiptReceivedListener rrl = new TestReceiptReceivedListener(); - drm.registerReceiptReceivedListener(rrl); + drm.addReceiptReceivedListener(rrl); Message m = new Message("romeo@montague.com", Message.Type.normal); m.setFrom("julia@capulet.com"); @@ -88,7 +86,7 @@ public class DeliveryReceiptTest { assertEquals("original-test-id", rrl.receiptId); } - private static class TestReceiptReceivedListener implements DeliveryReceiptManager.ReceiptReceivedListener { + private static class TestReceiptReceivedListener implements ReceiptReceivedListener { public String receiptId = null; @Override public void onReceiptReceived(String fromJid, String toJid, String receiptId) {