From e08c8afe4480cab7c8af2bd95e6dcc90ae8dc348 Mon Sep 17 00:00:00 2001 From: rcollier Date: Fri, 26 Oct 2012 10:47:55 +0000 Subject: [PATCH] SMACK-363 Applied code cleanup patches for many generics related issues. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13325 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/jingle/JingleException.java | 5 +- .../smackx/jingle/JingleManager.java | 6 +- .../smackx/jingle/JingleSession.java | 33 +-------- .../smackx/jingle/SmackLogger.java | 8 +-- .../smackx/jingle/media/MediaNegotiator.java | 4 +- .../smackx/jingle/mediaimpl/JMFInit.java | 14 ++-- .../smackx/jingle/mediaimpl/demo/Demo.java | 11 ++- .../mediaimpl/sshare/api/ImageReceiver.java | 3 +- .../sshare/api/OctTreeQuantizer.java | 8 +-- .../smackx/jingle/nat/BasicResolver.java | 14 ++-- .../smackx/jingle/nat/BridgedResolver.java | 8 +-- .../smackx/jingle/nat/ICECandidate.java | 22 +++--- .../smackx/jingle/nat/ICEResolver.java | 9 ++- .../smackx/jingle/nat/RTPBridge.java | 12 ++-- .../jivesoftware/smackx/jingle/nat/STUN.java | 4 +- .../smackx/jingle/nat/STUNResolver.java | 26 ++++--- .../smackx/jingle/nat/TransportCandidate.java | 9 +-- .../jingle/nat/TransportNegotiator.java | 27 ++++---- .../smackx/jingle/nat/TransportResolver.java | 28 +++++--- .../jivesoftware/smackx/packet/Jingle.java | 2 +- .../packet/JingleContentDescription.java | 28 ++++---- .../smackx/packet/JingleDescription.java | 2 +- .../smackx/packet/JingleTransport.java | 7 +- .../smackx/jingle/PayloadTypeTest.java | 13 ++-- .../smackx/jingle/nat/STUNResolverTest.java | 12 ++-- .../jingle/nat/TransportCandidateTest.java | 15 ++-- .../smack/SASLAuthentication.java | 20 +++--- .../smack/SmackConfiguration.java | 4 +- .../jivesoftware/smack/XMPPConnection.java | 2 +- .../smack/filter/PacketTypeFilter.java | 4 +- .../jivesoftware/smack/packet/Privacy.java | 2 +- .../smack/provider/ProviderManager.java | 10 +-- .../smack/sasl/SASLGSSAPIMechanism.java | 5 +- source/org/jivesoftware/smack/util/Cache.java | 2 +- .../org/jivesoftware/smack/util/DNSUtil.java | 9 +-- .../smack/util/ObservableReader.java | 2 +- .../smack/util/ObservableWriter.java | 2 +- .../smack/util/PacketParserUtils.java | 10 +-- source/org/jivesoftware/smackx/Form.java | 4 +- source/org/jivesoftware/smackx/FormField.java | 4 +- .../smackx/MessageEventManager.java | 8 +-- .../smackx/MultipleRecipientInfo.java | 8 +-- .../smackx/MultipleRecipientManager.java | 52 +++++++------- .../smackx/OfflineMessageManager.java | 4 +- .../smackx/PrivateDataManager.java | 2 +- .../smackx/RemoteRosterEntry.java | 2 +- .../smackx/RosterExchangeListener.java | 2 +- .../smackx/RosterExchangeManager.java | 2 +- .../smackx/SharedGroupManager.java | 2 +- .../org/jivesoftware/smackx/XHTMLManager.java | 2 +- .../smackx/commands/AdHocCommandManager.java | 4 +- .../smackx/debugger/EnhancedDebugger.java | 2 +- .../debugger/EnhancedDebuggerWindow.java | 4 +- .../smackx/muc/MultiUserChat.java | 16 ++--- .../jivesoftware/smackx/packet/DataForm.java | 18 ++--- .../smackx/packet/DefaultPrivateData.java | 14 ++-- .../jivesoftware/smackx/packet/MUCAdmin.java | 12 ++-- .../jivesoftware/smackx/packet/MUCOwner.java | 6 +- .../smackx/packet/MessageEvent.java | 4 +- .../smackx/packet/MultipleAddresses.java | 10 +-- .../smackx/packet/OfflineMessageRequest.java | 8 +-- .../smackx/packet/RosterExchange.java | 10 +-- .../smackx/packet/SharedGroupsInfo.java | 6 +- .../org/jivesoftware/smackx/packet/VCard.java | 43 ++++++------ .../smackx/packet/XHTMLExtension.java | 10 +-- .../smackx/provider/DataFormProvider.java | 4 +- .../provider/RosterExchangeProvider.java | 4 +- .../smackx/provider/VCardProvider.java | 4 +- .../org/jivesoftware/smackx/pubsub/Node.java | 2 +- .../smackx/pubsub/PubSubManager.java | 6 +- .../smackx/search/SimpleUserSearch.java | 4 +- .../smackx/search/UserSearchManager.java | 2 +- .../smackx/workgroup/MetaData.java | 7 +- .../smackx/workgroup/WorkgroupInvitation.java | 7 +- .../smackx/workgroup/agent/AgentRoster.java | 8 +-- .../smackx/workgroup/agent/AgentSession.java | 25 +++---- .../smackx/workgroup/agent/Offer.java | 7 +- .../workgroup/agent/QueueUsersListener.java | 4 +- .../workgroup/agent/WorkgroupQueue.java | 10 +-- .../ext/history/AgentChatHistory.java | 4 +- .../workgroup/ext/history/ChatMetadata.java | 9 +-- .../workgroup/packet/MetaDataProvider.java | 3 +- .../packet/OfferRequestProvider.java | 9 +-- .../workgroup/settings/ChatSettings.java | 12 ++-- .../workgroup/settings/GenericSettings.java | 6 +- .../smackx/workgroup/user/Workgroup.java | 40 ++++++----- .../util/ListenerEventDispatcher.java | 11 +-- .../smackx/workgroup/util/MetaDataUtils.java | 34 ++++------ .../smackx/workgroup/util/ModelUtil.java | 20 +++--- .../jivesoftware/smack/SmackConfigTest.java | 32 --------- test-unit/org/jivesoftware/util/Protocol.java | 4 +- test/config/test-case.xml | 4 +- .../org/jivesoftware/smack/PrivacyClient.java | 3 +- .../smack/filter/PacketTypeFilterTest.java | 13 ++-- .../jivesoftware/smack/packet/MockPacket.java | 2 - .../smack/packet/PrivacyTest.java | 12 ++-- .../smack/test/SmackTestCase.java | 6 +- .../smackx/MultipleRecipientManagerTest.java | 24 +++---- .../smackx/OfflineMessageManagerTest.java | 12 ++-- .../smackx/RosterExchangeManagerTest.java | 9 ++- .../smackx/ServiceDiscoveryManagerTest.java | 5 +- .../jivesoftware/smackx/SharedGroupsTest.java | 2 +- .../jivesoftware/smackx/XHTMLManagerTest.java | 8 +-- .../smackx/muc/MultiUserChatTest.java | 54 +++++++-------- .../smackx/packet/RosterExchangeTest.java | 4 +- .../smackx/packet/XHTMLExtensionTest.java | 8 +-- .../smackx/pubsub/EntityUseCases.java | 3 +- .../smackx/pubsub/PublisherUseCases.java | 6 +- .../smackx/pubsub/SubscriberUseCases.java | 68 +++++++++++++------ 109 files changed, 577 insertions(+), 605 deletions(-) delete mode 100644 test-unit/org/jivesoftware/smack/SmackConfigTest.java diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java index acf45a9c2..dd1c58d3b 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java @@ -10,8 +10,9 @@ import org.jivesoftware.smackx.packet.JingleError; * @author Alvaro Saurin */ public class JingleException extends XMPPException { - - private final JingleError error; + private static final long serialVersionUID = -1521230401958103382L; + + private final JingleError error; /** * Default constructor. diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java index a57cf104a..3f131a8c8 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java @@ -215,13 +215,13 @@ public class JingleManager implements JingleSessionListener { connection.getRoster().addRosterListener(new RosterListener() { - public void entriesAdded(Collection addresses) { + public void entriesAdded(Collection addresses) { } - public void entriesUpdated(Collection addresses) { + public void entriesUpdated(Collection addresses) { } - public void entriesDeleted(Collection addresses) { + public void entriesDeleted(Collection addresses) { } public void presenceChanged(Presence presence) { diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java index 5eb8a72e8..f9458fbae 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java @@ -96,7 +96,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleSession.class); // static - private static final HashMap sessions = new HashMap(); + private static final HashMap sessions = new HashMap(); private static final Random randomGenerator = new Random(); @@ -116,14 +116,10 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList protected List jingleMediaManagers = null; - private boolean closed = false; - private JingleSessionState sessionState; private List contentNegotiators; - private JingleSessionRequest sessionRequest; - private Connection connection; private String sessionInitPacketID; @@ -181,7 +177,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList public JingleSession(Connection conn, JingleSessionRequest request, String initiator, String responder, List jingleMediaManagers) { this(conn, initiator, responder, generateSessionId(), jingleMediaManagers); - sessionRequest = request; + //sessionRequest = request; // unused } /** @@ -525,29 +521,6 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList // throw new IllegalStateException("Only session-initiate allowed in the UNKNOWN state."); // } // } - /** - * @param inJingle - * @param inAction - */ - private void sendPendingStateAction(Jingle inJingle, JingleActionEnum inAction) { - - } - - /** - * @param inJingle - * @param inAction - */ - private void sendActiveStateAction(Jingle inJingle, JingleActionEnum inAction) { - - } - - /** - * @param inJingle - * @param inAction - */ - private void sendEndedStateAction(Jingle inJingle, JingleActionEnum inAction) { - - } /** * Acknowledge a IQ packet. @@ -670,7 +643,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList JingleSession result = null; synchronized (sessions) { if (sessions.containsKey(con)) { - result = (JingleSession) sessions.get(con); + result = sessions.get(con); } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/SmackLogger.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/SmackLogger.java index 4ef16946f..84b9591d2 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/SmackLogger.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/SmackLogger.java @@ -44,7 +44,7 @@ public class SmackLogger { * @param classToLog This is the class that wants to log. (This gives commons-logging a means to control log-level by class.) * @return An instance of a SmackLogger for the class that wants logging. */ - public static SmackLogger getLogger(Class classToLog) { + public static SmackLogger getLogger(Class classToLog) { return new SmackLogger(classToLog); } @@ -53,7 +53,7 @@ public class SmackLogger { * This is private to make it impossible to instantiate a new SmackLogger outside of the getLogger() static method. * @param classToLog This is the class that wants to log. (This gives commons-logging a means to control log-level by class.) */ - public SmackLogger(Class classToLog) { + public SmackLogger(Class classToLog) { setupSmackLogger(classToLog); } @@ -63,9 +63,9 @@ public class SmackLogger { * @param classToLog * @return */ - private void setupSmackLogger(Class classToLog) { + private void setupSmackLogger(Class classToLog) { try { - Class logFactoryClass = SmackLogger.class.getClassLoader().loadClass("org.apache.commons.logging.LogFactory"); + Class logFactoryClass = SmackLogger.class.getClassLoader().loadClass("org.apache.commons.logging.LogFactory"); Method method = logFactoryClass.getMethod("getLog", Class.class); //Constructor constructor = Log.class.getConstructor(new Class[] { Object.class }); commonsLogger = (Log) method.invoke(null, classToLog); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java index b0dd60446..2fa61ed2b 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/media/MediaNegotiator.java @@ -310,7 +310,7 @@ public class MediaNegotiator extends JingleNegotiator { private IQ receiveSessionAcceptAction(Jingle jingle, JingleDescription description) throws JingleException { IQ response = null; PayloadType.Audio agreedCommonAudioPt; - List offeredPayloads = new ArrayList(); + List offeredPayloads = new ArrayList(); if (bestCommonAudioPt == null) { // Update the best common audio PT @@ -358,7 +358,7 @@ public class MediaNegotiator extends JingleNegotiator { // Payload types - private PayloadType calculateBestCommonAudioPt(List remoteAudioPts) { + private PayloadType calculateBestCommonAudioPt(List remoteAudioPts) { final ArrayList commonAudioPtsHere = new ArrayList(); final ArrayList commonAudioPtsThere = new ArrayList(); PayloadType result = null; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java index 5a7571af3..1ad056b38 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java @@ -17,6 +17,8 @@ import com.sun.media.util.Registry; public class JMFInit extends Frame implements Runnable { + private static final long serialVersionUID = 6476412003260641680L; + private static final SmackLogger LOGGER = SmackLogger.getLogger(JMFInit.class); private String tempDir = "/tmp"; @@ -89,7 +91,7 @@ public class JMFInit extends Frame implements Runnable { private void detectCaptureDevices() { // check if JavaSound capture is available message("Looking for Audio capturer"); - Class dsauto; + Class dsauto; try { dsauto = Class.forName("DirectSoundAuto"); dsauto.newInstance(); @@ -102,7 +104,7 @@ public class JMFInit extends Frame implements Runnable { //Do nothing } - Class jsauto; + Class jsauto; try { jsauto = Class.forName("JavaSoundAuto"); jsauto.newInstance(); @@ -166,7 +168,7 @@ public class JMFInit extends Frame implements Runnable { } private void detectDirectAudio() { - Class cls; + Class cls; int plType = PlugInManager.RENDERER; String dar = "com.sun.media.renderer.audio.DirectAudioRenderer"; try { @@ -190,7 +192,7 @@ public class JMFInit extends Frame implements Runnable { PlugInManager.addPlugIn(dar, inputFormats, new Format[0], plType); // Move it to the top of the list - Vector rendList = PlugInManager.getPlugInList(null, null, + Vector rendList = PlugInManager.getPlugInList(null, null, plType); int listSize = rendList.size(); if (rendList.elementAt(listSize - 1).equals(dar)) { @@ -212,7 +214,7 @@ public class JMFInit extends Frame implements Runnable { } private void detectS8DirectAudio() { - Class cls; + Class cls; int plType = PlugInManager.RENDERER; String dar = "com.sun.media.renderer.audio.DirectAudioRenderer"; try { @@ -227,7 +229,7 @@ public class JMFInit extends Frame implements Runnable { if (rend instanceof ExclusiveUse && !((ExclusiveUse) rend).isExclusive()) { // sol8+, DAR supports mixing - Vector rendList = PlugInManager.getPlugInList(null, null, + Vector rendList = PlugInManager.getPlugInList(null, null, plType); int listSize = rendList.size(); boolean found = false; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/demo/Demo.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/demo/Demo.java index 8e76d2c0a..3e47deb59 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/demo/Demo.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/demo/Demo.java @@ -43,7 +43,8 @@ import java.util.List; */ public class Demo extends JFrame { - private JingleTransportManager transportManager = null; + private static final long serialVersionUID = -6584021277434403855L; + private JingleTransportManager transportManager = null; private Connection xmppConnection = null; private String server = null; @@ -117,7 +118,9 @@ public class Demo extends JFrame { jPanel.add(jid); jPanel.add(new JButton(new AbstractAction("Call") { - public void actionPerformed(ActionEvent e) { + private static final long serialVersionUID = 4308448034795312815L; + + public void actionPerformed(ActionEvent e) { if (outgoing != null) return; try { outgoing = jm.createOutgoingJingleSession(jid.getText()); @@ -130,7 +133,9 @@ public class Demo extends JFrame { })); jPanel.add(new JButton(new AbstractAction("Hangup") { - public void actionPerformed(ActionEvent e) { + private static final long serialVersionUID = -4508007389146723587L; + + public void actionPerformed(ActionEvent e) { if (outgoing != null) try { outgoing.terminate(); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java index a77070938..eba671290 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java @@ -17,7 +17,8 @@ import java.net.SocketException; */ public class ImageReceiver extends Canvas { - private boolean on = true; + private static final long serialVersionUID = -7000112305305269025L; + private boolean on = true; private DatagramSocket socket; private BufferedImage tiles[][]; private static final int tileWidth = ImageTransmitter.tileWidth; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/OctTreeQuantizer.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/OctTreeQuantizer.java index 1b8fa9d3c..f92eda853 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/OctTreeQuantizer.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/OctTreeQuantizer.java @@ -72,13 +72,13 @@ public class OctTreeQuantizer implements Quantizer { private int reduceColors; private int maximumColors; private int colors = 0; - private Vector[] colorList; + private Vector[] colorList; public OctTreeQuantizer() { setup(256); colorList = new Vector[MAX_LEVEL+1]; for (int i = 0; i < MAX_LEVEL+1; i++) - colorList[i] = new Vector(); + colorList[i] = new Vector(); root = new OctTreeNode(); } @@ -200,10 +200,10 @@ public class OctTreeQuantizer implements Quantizer { private void reduceTree(int numColors) { for (int level = MAX_LEVEL-1; level >= 0; level--) { - Vector v = colorList[level]; + Vector v = colorList[level]; if (v != null && v.size() > 0) { for (int j = 0; j < v.size(); j++) { - OctTreeNode node = (OctTreeNode)v.elementAt(j); + OctTreeNode node = v.elementAt(j); if (node.children > 0) { for (int i = 0; i < 8; i++) { OctTreeNode child = node.leaf[i]; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java index 7fad63435..176444279 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java @@ -54,7 +54,7 @@ public class BasicResolver extends TransportResolver { clearCandidates(); - Enumeration ifaces = null; + Enumeration ifaces = null; try { ifaces = NetworkInterface.getNetworkInterfaces(); @@ -64,11 +64,11 @@ public class BasicResolver extends TransportResolver { while (ifaces.hasMoreElements()) { - NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); - Enumeration iaddresses = iface.getInetAddresses(); + NetworkInterface iface = ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); while (iaddresses.hasMoreElements()) { - InetAddress iaddress = (InetAddress) iaddresses.nextElement(); + InetAddress iaddress = iaddresses.nextElement(); if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress()) { TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort()); tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName()); @@ -87,11 +87,11 @@ public class BasicResolver extends TransportResolver { while (ifaces.hasMoreElements()) { - NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); - Enumeration iaddresses = iface.getInetAddresses(); + NetworkInterface iface = ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); while (iaddresses.hasMoreElements()) { - InetAddress iaddress = (InetAddress) iaddresses.nextElement(); + InetAddress iaddress = iaddresses.nextElement(); if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress()) { TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort()); tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName()); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java index b7b513c92..f96c5fd46 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java @@ -114,7 +114,7 @@ public class BridgedResolver extends TransportResolver { } public static String getLocalHost() { - Enumeration ifaces = null; + Enumeration ifaces = null; try { ifaces = NetworkInterface.getNetworkInterfaces(); @@ -125,11 +125,11 @@ public class BridgedResolver extends TransportResolver { while (ifaces.hasMoreElements()) { - NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); - Enumeration iaddresses = iface.getInetAddresses(); + NetworkInterface iface = ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); while (iaddresses.hasMoreElements()) { - InetAddress iaddress = (InetAddress) iaddresses.nextElement(); + InetAddress iaddress = iaddresses.nextElement(); if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress() && !(iaddress instanceof Inet6Address)) { return iaddress.getHostAddress(); } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java index 980130eb6..4999b1b52 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java @@ -65,7 +65,7 @@ import org.jivesoftware.smackx.jingle.SmackLogger; * * @author Thiago Camargo */ -public class ICECandidate extends TransportCandidate implements Comparable { +public class ICECandidate extends TransportCandidate implements Comparable { private static final SmackLogger LOGGER = SmackLogger.getLogger(ICECandidate.class); @@ -438,18 +438,14 @@ public class ICECandidate extends TransportCandidate implements Comparable { * object is less than, equal to, or greater than the specified * object */ - public int compareTo(Object arg) { - if (arg instanceof ICECandidate) { - ICECandidate tc = (ICECandidate) arg; - if (getPreference() < tc.getPreference()) { - return -1; - } - else if (getPreference() > tc.getPreference()) { - return 1; - } - } - return 0; - } + public int compareTo(ICECandidate arg) { + if (getPreference() < arg.getPreference()) { + return -1; + } else if (getPreference() > arg.getPreference()) { + return 1; + } + return 0; + } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java index af5d49c54..4ab5b3111 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java @@ -136,7 +136,6 @@ public class ICEResolver extends TransportResolver { i++; } } catch (SocketException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } @@ -225,7 +224,7 @@ public class ICEResolver extends TransportResolver { if (publicIp != null && !publicIp.equals("")) { - Enumeration ifaces = null; + Enumeration ifaces = null; try { ifaces = NetworkInterface.getNetworkInterfaces(); @@ -240,11 +239,11 @@ public class ICEResolver extends TransportResolver { while (ifaces.hasMoreElements() && !false) { - NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); - Enumeration iaddresses = iface.getInetAddresses(); + NetworkInterface iface = ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); while (iaddresses.hasMoreElements()) { - InetAddress iaddress = (InetAddress) iaddresses.nextElement(); + InetAddress iaddress = iaddresses.nextElement(); if (iaddress.getHostAddress().indexOf(publicIp) > -1) { found = true; break; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/RTPBridge.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/RTPBridge.java index a839c3921..e9df33bf2 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/RTPBridge.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/RTPBridge.java @@ -442,9 +442,9 @@ public class RTPBridge extends IQ { // } DiscoverInfo discoInfo = disco.discoverInfo(connection.getServiceName()); - Iterator iter = discoInfo.getIdentities(); + Iterator iter = discoInfo.getIdentities(); while (iter.hasNext()) { - DiscoverInfo.Identity identity = (DiscoverInfo.Identity) iter.next(); + DiscoverInfo.Identity identity = iter.next(); if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) { return true; } @@ -528,7 +528,7 @@ public class RTPBridge extends IQ { if (response.getIp() == null || response.getIp().equals("")) return null; - Enumeration ifaces = null; + Enumeration ifaces = null; try { ifaces = NetworkInterface.getNetworkInterfaces(); } @@ -537,11 +537,11 @@ public class RTPBridge extends IQ { } while (ifaces!=null&&ifaces.hasMoreElements()) { - NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); - Enumeration iaddresses = iface.getInetAddresses(); + NetworkInterface iface = ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); while (iaddresses.hasMoreElements()) { - InetAddress iaddress = (InetAddress) iaddresses.nextElement(); + InetAddress iaddress = iaddresses.nextElement(); if (!iaddress.isLoopbackAddress()) if (iaddress.getHostAddress().indexOf(response.getIp()) >= 0) return null; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java index c41680dbb..eaa9a7c16 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java @@ -230,9 +230,9 @@ public class STUN extends IQ { try { DiscoverItems items = disco.discoverItems(connection.getServiceName()); - Iterator iter = items.getItems(); + Iterator iter = items.getItems(); while (iter.hasNext()) { - DiscoverItems.Item item = (DiscoverItems.Item) iter.next(); + DiscoverItems.Item item = iter.next(); DiscoverInfo info = disco.discoverInfo(item.getEntityID()); Iterator iter2 = info.getIdentities(); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java index 496dc7578..f7c52efa5 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java @@ -134,8 +134,8 @@ public class STUNResolver extends TransportResolver { * @param stunConfigStream An InputStream with the configuration file. * @return A list of loaded servers */ - public ArrayList loadSTUNServers(java.io.InputStream stunConfigStream) { - ArrayList serversList = new ArrayList(); + public ArrayList loadSTUNServers(java.io.InputStream stunConfigStream) { + ArrayList serversList = new ArrayList(); String serverName; int serverPort; @@ -216,8 +216,8 @@ public class STUNResolver extends TransportResolver { * * @return a list of services */ - public ArrayList loadSTUNServers() { - ArrayList serversList = new ArrayList(); + public ArrayList loadSTUNServers() { + ArrayList serversList = new ArrayList(); // Load the STUN configuration try { @@ -228,11 +228,11 @@ public class STUNResolver extends TransportResolver { classLoaders[1] = Thread.currentThread().getContextClassLoader(); for (int i = 0; i < classLoaders.length; i++) { - Enumeration stunConfigEnum = classLoaders[i] + Enumeration stunConfigEnum = classLoaders[i] .getResources(STUNSERVERS_FILENAME); while (stunConfigEnum.hasMoreElements() && serversList.isEmpty()) { - URL url = (URL) stunConfigEnum.nextElement(); + URL url = stunConfigEnum.nextElement(); java.io.InputStream stunConfigStream = null; stunConfigStream = url.openStream(); @@ -253,12 +253,12 @@ public class STUNResolver extends TransportResolver { * * @return the best STUN server that can be used. */ - private STUNService bestSTUNServer(ArrayList listServers) { + private STUNService bestSTUNServer(ArrayList listServers) { if (listServers.isEmpty()) { return null; } else { // TODO: this should use some more advanced criteria... - return (STUNService) listServers.get(0); + return listServers.get(0); } } @@ -305,19 +305,17 @@ public class STUNResolver extends TransportResolver { // Iterate through the list of interfaces, and ask // to the STUN server for our address. try { - Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); + Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); String candAddress; int candPort; while (ifaces.hasMoreElements()) { - NetworkInterface iface = (NetworkInterface) ifaces - .nextElement(); - Enumeration iaddresses = iface.getInetAddresses(); + NetworkInterface iface = ifaces.nextElement(); + Enumeration iaddresses = iface.getInetAddresses(); while (iaddresses.hasMoreElements()) { - InetAddress iaddress = (InetAddress) iaddresses - .nextElement(); + InetAddress iaddress = iaddresses.nextElement(); if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress()) { diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java index 95df4fded..1f746e9d7 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java @@ -66,6 +66,7 @@ import java.util.List; import org.jivesoftware.smack.Connection; import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.SmackLogger; +import org.jivesoftware.smackx.jingle.nat.TransportResolverListener.Checker; /** * Transport candidate. @@ -103,7 +104,7 @@ public abstract class TransportCandidate { private Thread echoThread = null; // Listeners for events - private final List listeners = new ArrayList(); + private final List listeners = new ArrayList(); public void addCandidateEcho(JingleSession session) throws SocketException, UnknownHostException { candidateEcho = new CandidateEcho(this, session); @@ -387,9 +388,9 @@ public abstract class TransportCandidate { public void run() { boolean isUsable; - InetAddress candAddress; + try { - candAddress = InetAddress.getByName(getIp()); + InetAddress candAddress = InetAddress.getByName(getIp()); isUsable = true;//candAddress.isReachable(TransportResolver.CHECK_TIMEOUT); } catch (Exception e) { @@ -425,7 +426,7 @@ public abstract class TransportCandidate { */ public List getListenersList() { synchronized (listeners) { - return new ArrayList(listeners); + return new ArrayList(listeners); } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java index a5d4b9a3a..1730cc4aa 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportNegotiator.java @@ -449,9 +449,9 @@ public abstract class TransportNegotiator extends JingleNegotiator { * * @return The list of valid (ie, already checked) remote candidates. */ - final ArrayList getValidRemoteCandidatesList() { + final ArrayList getValidRemoteCandidatesList() { synchronized (validRemoteCandidates) { - return new ArrayList(validRemoteCandidates); + return new ArrayList(validRemoteCandidates); } } @@ -461,7 +461,7 @@ public abstract class TransportNegotiator extends JingleNegotiator { * @return The iterator for the list of valid (ie, already checked) remote * candidates. */ - public final Iterator getValidRemoteCandidates() { + public final Iterator getValidRemoteCandidates() { return Collections.unmodifiableList(getRemoteCandidates()).iterator(); } @@ -471,11 +471,11 @@ public abstract class TransportNegotiator extends JingleNegotiator { * * @param rc the remote candidate to add. */ - private void addRemoteCandidates(List rc) { + private void addRemoteCandidates(List rc) { if (rc != null) { if (rc.size() > 0) { - for (Object aRc : rc) { - addRemoteCandidate((TransportCandidate) aRc); + for (TransportCandidate aRc : rc) { + addRemoteCandidate(aRc); } } } @@ -829,7 +829,7 @@ public abstract class TransportNegotiator extends JingleNegotiator { */ public TransportCandidate getBestRemoteCandidate() { // Hopefully, we only have one validRemoteCandidate - ArrayList cands = getValidRemoteCandidatesList(); + ArrayList cands = getValidRemoteCandidatesList(); if (!cands.isEmpty()) { LOGGER.debug("RAW CAND"); return (TransportCandidate) cands.get(0); @@ -883,14 +883,17 @@ public abstract class TransportNegotiator extends JingleNegotiator { public TransportCandidate getBestRemoteCandidate() { ICECandidate result = null; - ArrayList cands = getValidRemoteCandidatesList(); + ArrayList cands = getValidRemoteCandidatesList(); if (!cands.isEmpty()) { int highest = -1; ICECandidate chose = null; - for (ICECandidate transportCandidate : cands) { - if (transportCandidate.getPreference() > highest) { - chose = transportCandidate; - highest = transportCandidate.getPreference(); + for (TransportCandidate transportCandidate : cands) { + if (transportCandidate instanceof ICECandidate) { + ICECandidate icecandidate = (ICECandidate) transportCandidate; + if (icecandidate.getPreference() > highest) { + chose = icecandidate; + highest = icecandidate.getPreference(); + } } } result = chose; diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java index 747675a9b..de46941b1 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java @@ -233,9 +233,9 @@ public abstract class TransportResolver { * * @return the list of listeners */ - public ArrayList getListenersList() { + public ArrayList getListenersList() { synchronized (listeners) { - return new ArrayList(listeners); + return new ArrayList(listeners); } } @@ -245,9 +245,9 @@ public abstract class TransportResolver { * @param cand The candidate added to the list of candidates. */ protected void triggerCandidateAdded(TransportCandidate cand) { - Iterator iter = getListenersList().iterator(); + Iterator iter = getListenersList().iterator(); while (iter.hasNext()) { - TransportResolverListener trl = (TransportResolverListener) iter.next(); + TransportResolverListener trl = iter.next(); if (trl instanceof TransportResolverListener.Resolver) { TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl; LOGGER.debug("triggerCandidateAdded : " + cand.getLocalIp()); @@ -260,9 +260,9 @@ public abstract class TransportResolver { * Trigger a event notifying the initialization of the resolution process. */ private void triggerResolveInit() { - Iterator iter = getListenersList().iterator(); + Iterator iter = getListenersList().iterator(); while (iter.hasNext()) { - TransportResolverListener trl = (TransportResolverListener) iter.next(); + TransportResolverListener trl = iter.next(); if (trl instanceof TransportResolverListener.Resolver) { TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl; li.init(); @@ -274,9 +274,9 @@ public abstract class TransportResolver { * Trigger a event notifying the obtention of all the candidates. */ private void triggerResolveEnd() { - Iterator iter = getListenersList().iterator(); + Iterator iter = getListenersList().iterator(); while (iter.hasNext()) { - TransportResolverListener trl = (TransportResolverListener) iter.next(); + TransportResolverListener trl = iter.next(); if (trl instanceof TransportResolverListener.Resolver) { TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl; li.end(); @@ -315,9 +315,9 @@ public abstract class TransportResolver { * * @return an iterator */ - public Iterator getCandidates() { + public Iterator getCandidates() { synchronized (candidates) { - return Collections.unmodifiableList(new ArrayList(candidates)).iterator(); + return Collections.unmodifiableList(new ArrayList(candidates)).iterator(); } } @@ -329,7 +329,13 @@ public abstract class TransportResolver { public TransportCandidate getPreferredCandidate() { TransportCandidate result = null; - ArrayList cands = (ArrayList) getCandidatesList(); + ArrayList cands = new ArrayList(); + for (TransportCandidate tpcan : getCandidatesList()) { + if (tpcan instanceof ICECandidate) + cands.add((ICECandidate) tpcan); + } + + // (ArrayList) getCandidatesList(); if (cands.size() > 0) { Collections.sort(cands); // Return the last candidate diff --git a/jingle/extension/source/org/jivesoftware/smackx/packet/Jingle.java b/jingle/extension/source/org/jivesoftware/smackx/packet/Jingle.java index b20fcaa8b..4a0e7dc56 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/packet/Jingle.java +++ b/jingle/extension/source/org/jivesoftware/smackx/packet/Jingle.java @@ -218,7 +218,7 @@ public class Jingle extends IQ { */ public Iterator getContents() { synchronized (contents) { - return Collections.unmodifiableList(new ArrayList(contents)).iterator(); + return Collections.unmodifiableList(new ArrayList(contents)).iterator(); } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/packet/JingleContentDescription.java b/jingle/extension/source/org/jivesoftware/smackx/packet/JingleContentDescription.java index 5c58f9cb5..9783b9c02 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/packet/JingleContentDescription.java +++ b/jingle/extension/source/org/jivesoftware/smackx/packet/JingleContentDescription.java @@ -40,7 +40,7 @@ public abstract class JingleContentDescription implements PacketExtension { // non-static - private final List payloads = new ArrayList(); + private final List payloads = new ArrayList(); /** * Creates a content description.. @@ -81,11 +81,11 @@ public abstract class JingleContentDescription implements PacketExtension { * * @param pts the payloads to add. */ - public void addAudioPayloadTypes(final List pts) { + public void addAudioPayloadTypes(final List pts) { synchronized (payloads) { - Iterator ptIter = pts.iterator(); + Iterator ptIter = pts.iterator(); while (ptIter.hasNext()) { - PayloadType.Audio pt = (PayloadType.Audio) ptIter.next(); + PayloadType.Audio pt = ptIter.next(); addJinglePayloadType(new JinglePayloadType.Audio(pt)); } } @@ -96,7 +96,7 @@ public abstract class JingleContentDescription implements PacketExtension { * * @return an Iterator for the audio payloads in the packet. */ - public Iterator getJinglePayloadTypes() { + public Iterator getJinglePayloadTypes() { return Collections.unmodifiableList(getJinglePayloadTypesList()).iterator(); } @@ -105,9 +105,9 @@ public abstract class JingleContentDescription implements PacketExtension { * * @return a list for the audio payloads in the packet. */ - public ArrayList getJinglePayloadTypesList() { + public ArrayList getJinglePayloadTypesList() { synchronized (payloads) { - return new ArrayList(payloads); + return new ArrayList(payloads); } } @@ -116,15 +116,15 @@ public abstract class JingleContentDescription implements PacketExtension { * * @return a list of PayloadType.Audio */ - public ArrayList getAudioPayloadTypesList() { - ArrayList result = new ArrayList(); - Iterator jinglePtsIter = getJinglePayloadTypes(); + public ArrayList getAudioPayloadTypesList() { + ArrayList result = new ArrayList(); + Iterator jinglePtsIter = getJinglePayloadTypes(); while (jinglePtsIter.hasNext()) { - JinglePayloadType jpt = (JinglePayloadType) jinglePtsIter.next(); + JinglePayloadType jpt = jinglePtsIter.next(); if (jpt instanceof JinglePayloadType.Audio) { JinglePayloadType.Audio jpta = (JinglePayloadType.Audio) jpt; - result.add(jpta.getPayloadType()); + result.add((PayloadType.Audio)jpta.getPayloadType()); } } @@ -155,9 +155,9 @@ public abstract class JingleContentDescription implements PacketExtension { buf.append("<").append(getElementName()); buf.append(" xmlns=\"").append(getNamespace()).append("\" >"); - Iterator pt = payloads.listIterator(); + Iterator pt = payloads.listIterator(); while (pt.hasNext()) { - JinglePayloadType pte = (JinglePayloadType) pt.next(); + JinglePayloadType pte = pt.next(); buf.append(pte.toXML()); } buf.append(""); diff --git a/jingle/extension/source/org/jivesoftware/smackx/packet/JingleDescription.java b/jingle/extension/source/org/jivesoftware/smackx/packet/JingleDescription.java index 212cd503d..d59c513ce 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/packet/JingleDescription.java +++ b/jingle/extension/source/org/jivesoftware/smackx/packet/JingleDescription.java @@ -90,7 +90,7 @@ public abstract class JingleDescription implements PacketExtension { */ public void addAudioPayloadTypes(final List pts) { synchronized (payloads) { - Iterator ptIter = pts.iterator(); + Iterator ptIter = pts.iterator(); while (ptIter.hasNext()) { PayloadType.Audio pt = (PayloadType.Audio) ptIter.next(); addPayloadType(new PayloadType.Audio(pt)); diff --git a/jingle/extension/source/org/jivesoftware/smackx/packet/JingleTransport.java b/jingle/extension/source/org/jivesoftware/smackx/packet/JingleTransport.java index 38eca2b94..8672e1aa4 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/packet/JingleTransport.java +++ b/jingle/extension/source/org/jivesoftware/smackx/packet/JingleTransport.java @@ -95,7 +95,7 @@ public class JingleTransport implements PacketExtension { * * @return an iterator */ - public Iterator getCandidates() { + public Iterator getCandidates() { return Collections.unmodifiableList(getCandidatesList()).iterator(); } @@ -160,11 +160,10 @@ public class JingleTransport implements PacketExtension { synchronized (candidates) { if (getCandidatesCount() > 0) { buf.append(">"); - Iterator iter = getCandidates(); + Iterator iter = getCandidates(); while (iter.hasNext()) { - JingleTransportCandidate candidate = (JingleTransportCandidate) iter - .next(); + JingleTransportCandidate candidate = iter.next(); buf.append(candidate.toXML()); } buf.append(""); diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java index 647e37bb8..1bd266b6f 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.jivesoftware.smack.test.SmackTestCase; import org.jivesoftware.smackx.jingle.media.PayloadType; +import org.jivesoftware.smackx.jingle.media.PayloadType.Audio; public class PayloadTypeTest extends SmackTestCase { @@ -21,8 +22,8 @@ public class PayloadTypeTest extends SmackTestCase { * Test for the difference of payloads. */ public void testDifference() { - ArrayList set1 = new ArrayList(); - ArrayList set2 = new ArrayList(); + ArrayList