diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java b/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java index 2d215f7d0..b9ea9356a 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java @@ -24,7 +24,7 @@ * @author Emil Ivov */ public class ClientCapabilities - implements MethodProcessor + extends MethodProcessorAdapter { private static Logger logger = Logger.getLogger(ClientCapabilities.class); @@ -136,54 +136,6 @@ public boolean processRequest(RequestEvent requestEvent) return true; } - /** - * ignore. don't needed. - * @param dialogTerminatedEvent unused - */ - public boolean processDialogTerminated( - DialogTerminatedEvent dialogTerminatedEvent) - { - return false; - } - - /** - * ignore. don't needed. - * @param exceptionEvent unused - */ - public boolean processIOException(IOExceptionEvent exceptionEvent) - { - return false; - } - - /** - * ignore for the time being - * @param responseEvent unused - */ - public boolean processResponse(ResponseEvent responseEvent) - { - return false; - } - - /** - * ignore for the time being. - * @param timeoutEvent unused - */ - public boolean processTimeout(TimeoutEvent timeoutEvent) - { - disconnect(); - return true; - } - - /** - * ignore for the time being. - * @param transactionTerminatedEvent unused - */ - public boolean processTransactionTerminated( - TransactionTerminatedEvent transactionTerminatedEvent) - { - return false; - } - /** * Returns the next long to use as a cseq header value. * @return the next long to use as a cseq header value. diff --git a/src/net/java/sip/communicator/impl/protocol/sip/MethodProcessorAdapter.java b/src/net/java/sip/communicator/impl/protocol/sip/MethodProcessorAdapter.java new file mode 100644 index 000000000..106e5ed3e --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/MethodProcessorAdapter.java @@ -0,0 +1,73 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import javax.sip.*; + +/** + * Provides a default implementation of MethodProcessor which does + * no processing and exists only as a convenience to extenders so that they can + * override the methods of interest. + * + * @author Lubomir Marinov + */ +public class MethodProcessorAdapter + implements MethodProcessor +{ + + /* + * Implements + * MethodProcessor#processDialogTerminated(DialogTerminatedEvent). + */ + public boolean processDialogTerminated( + DialogTerminatedEvent dialogTerminatedEvent) + { + return false; + } + + /* + * Implements MethodProcessor#processIOException(IOExceptionEvent). + */ + public boolean processIOException(IOExceptionEvent exceptionEvent) + { + return false; + } + + /* + * Implements MethodProcessor#processRequest(RequestEvent). + */ + public boolean processRequest(RequestEvent requestEvent) + { + return false; + } + + /* + * Implements MethodProcessor#processResponse(ResponseEvent). + */ + public boolean processResponse(ResponseEvent responseEvent) + { + return false; + } + + /* + * Implements MethodProcessor#processTimeout(TimeoutEvent). + */ + public boolean processTimeout(TimeoutEvent timeoutEvent) + { + return false; + } + + /* + * Implements + * MethodProcessor#processTransactionTerminated(TransactionTerminatedEvent). + */ + public boolean processTransactionTerminated( + TransactionTerminatedEvent transactionTerminatedEvent) + { + return false; + } +} diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java index 8f834be59..92bc30253 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java @@ -29,19 +29,19 @@ public class OperationSetBasicInstantMessagingSipImpl extends AbstractOperationSetBasicInstantMessaging { - private static final Logger logger = - Logger.getLogger(OperationSetBasicInstantMessagingSipImpl.class); + private static final Logger logger + = Logger.getLogger(OperationSetBasicInstantMessagingSipImpl.class); /** * A list of processors registered for incoming sip messages. */ - private Vector messageProcessors - = new Vector(); + private final List messageProcessors + = new Vector(); /** * The provider that created us. */ - private ProtocolProviderServiceSipImpl sipProvider = null; + private final ProtocolProviderServiceSipImpl sipProvider; /** * A reference to the persistent presence operation set that we use @@ -57,7 +57,8 @@ public class OperationSetBasicInstantMessagingSipImpl /** * Hashtable containing the message sent */ - private Hashtable sentMsg = null; + private final Map sentMsg + = new Hashtable(3); /** * It can be implemented in some servers. @@ -67,7 +68,7 @@ public class OperationSetBasicInstantMessagingSipImpl /** * Gives access to presence states for the Sip protocol. */ - private SipStatusEnum sipStatusEnum; + private final SipStatusEnum sipStatusEnum; /** * Creates an instance of this operation set. @@ -79,7 +80,7 @@ public class OperationSetBasicInstantMessagingSipImpl ProtocolProviderServiceSipImpl provider) { this.sipProvider = provider; - this.sentMsg = new Hashtable(3); + provider.addRegistrationStateChangeListener(new RegistrationStateListener()); @@ -556,45 +557,15 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) * Class for listening incoming packets. */ private class BasicInstantMessagingMethodProcessor - implements MethodProcessor + extends MethodProcessorAdapter { - public boolean processDialogTerminated( - DialogTerminatedEvent dialogTerminatedEvent) - { - // never fired - return false; - } - - public boolean processIOException(IOExceptionEvent exceptionEvent) - { - // never fired - return false; - } - - public boolean processTransactionTerminated( - TransactionTerminatedEvent transactionTerminatedEvent) - { - // nothing to do - return false; - } - - /** - * - * @param timeoutEvent TimeoutEvent - */ public boolean processTimeout(TimeoutEvent timeoutEvent) { synchronized (messageProcessors) { - Iterator iter = messageProcessors.iterator(); - while (iter.hasNext()) - { - SipMessageProcessor listener - = (SipMessageProcessor)iter.next(); - + for (SipMessageProcessor listener : messageProcessors) if(!listener.processTimeout(timeoutEvent, sentMsg)) return true; - } } // this is normaly handled by the SIP stack @@ -647,7 +618,7 @@ public boolean processTimeout(TimeoutEvent timeoutEvent) // try to retrieve the original message String key = ((CallIdHeader)req.getHeader(CallIdHeader.NAME)) .getCallId(); - failedMessage = (Message) sentMsg.get(key); + failedMessage = sentMsg.get(key); if (failedMessage == null) { @@ -686,15 +657,9 @@ public boolean processRequest(RequestEvent requestEvent) { synchronized (messageProcessors) { - Iterator iter = messageProcessors.iterator(); - while (iter.hasNext()) - { - SipMessageProcessor listener - = (SipMessageProcessor)iter.next(); - + for (SipMessageProcessor listener : messageProcessors) if(!listener.processMessage(requestEvent)) return true; - } } // get the content @@ -801,15 +766,9 @@ public boolean processResponse(ResponseEvent responseEvent) { synchronized (messageProcessors) { - Iterator iter = messageProcessors.iterator(); - while (iter.hasNext()) - { - SipMessageProcessor listener - = (SipMessageProcessor)iter.next(); - + for (SipMessageProcessor listener : messageProcessors) if(!listener.processResponse(responseEvent, sentMsg)) return true; - } } Request req = responseEvent.getClientTransaction().getRequest(); @@ -867,7 +826,7 @@ public boolean processResponse(ResponseEvent responseEvent) String key = ((CallIdHeader)req.getHeader(CallIdHeader.NAME)) .getCallId(); - Message newMessage = (Message) sentMsg.get(key); + Message newMessage = sentMsg.get(key); if (newMessage == null) { @@ -1036,4 +995,3 @@ private void processAuthenticationChallenge( } } } - diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java index 986474aed..bc21fe27d 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java @@ -25,7 +25,7 @@ * @author Emil Ivov */ public class SipRegistrarConnection - implements MethodProcessor + extends MethodProcessorAdapter { private static final Logger logger = Logger.getLogger(SipRegistrarConnection.class); @@ -1069,26 +1069,6 @@ private void processForbidden( + response.getReasonPhrase()); } - - /** - * Process an asynchronously reported DialogTerminatedEvent. When a dialog - * transitions to the Terminated state, the stack keeps no further records - * of the dialog. This notification can be used by applications to clean up - * any auxiliary data that is being maintained for the given dialog. - * - * @param dialogTerminatedEvent -- an event that indicates that the dialog - * has transitioned into the terminated state. - * @return true if the specified event has been handled by this - * processor and shouldn't be offered to other processors registered - * for the same method; false, otherwise - * @since v1.2 - */ - public boolean processDialogTerminated(DialogTerminatedEvent - dialogTerminatedEvent) - { - return false; - } - /** * Processes a Request received on a SipProvider upon which this SipListener * is registered. @@ -1128,24 +1108,6 @@ public boolean processTimeout(TimeoutEvent timeoutEvent) return true; } - /** - * Process an asynchronously reported TransactionTerminatedEvent. When a - * transaction transitions to the Terminated state, the stack keeps no - * further records of the transaction. - * - * @param transactionTerminatedEvent an event that indicates that the - * transaction has transitioned into the terminated state. - * @return true if the specified event has been handled by this - * processor and shouldn't be offered to other processors registered - * for the same method; false, otherwise - */ - public boolean processTransactionTerminated(TransactionTerminatedEvent - transactionTerminatedEvent) - { - //doesn't mean anything. we do failure handling in processTimeout - return false; - } - /** * Process an asynchronously reported IO Exception. *