Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber
Class ScServiceDiscoveryManager

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.jabber.ScServiceDiscoveryManager
All Implemented Interfaces:
org.jivesoftware.smack.PacketInterceptor, org.jivesoftware.smackx.NodeInformationProvider

public class ScServiceDiscoveryManager
extends Object
implements org.jivesoftware.smack.PacketInterceptor, org.jivesoftware.smackx.NodeInformationProvider

An wrapper to smack's default ServiceDiscoveryManager that adds support for XEP-0115 - Entity Capabilities. This work is based on Jonas Adahl's smack fork.

Author:
Emil Ivov, Lubomir Marinov

Constructor Summary
ScServiceDiscoveryManager(ProtocolProviderServiceJabberImpl parentProvider, String[] featuresToRemove, String[] featuresToAdd)
          Creates a new ScServiceDiscoveryManager wrapping the default discovery manager of the specified connection.
 
Method Summary
 void addExtFeature(String ext)
          Add feature to put in "ext" attribute.
 void addFeature(String feature)
          Registers that a new feature is supported by this XMPP entity.
 org.jivesoftware.smackx.packet.DiscoverInfo discoverInfo(String entityID)
          Returns the discovered information of a given XMPP entity addressed by its JID.
 org.jivesoftware.smackx.packet.DiscoverInfo discoverInfoNonBlocking(String entityID)
          Returns the discovered information of a given XMPP entity addressed by its JID if locally cached, otherwise schedules for retrieval.
 org.jivesoftware.smackx.packet.DiscoverItems discoverItems(String entityID)
          Returns the discovered items of a given XMPP entity addressed by its JID.
 org.jivesoftware.smackx.packet.DiscoverItems discoverItems(String entityID, String node)
          Returns the discovered items of a given XMPP entity addressed by its JID and note attribute.
 EntityCapsManager getCapsManager()
          Gets the EntityCapsManager which handles the entity capabilities for this ScServiceDiscoveryManager.
 String getExtFeatures()
          Get "ext" value.
 List<String> getFeatures()
          Returns a reference to our local copy of the feature list supported by this implementation.
 List<String> getNodeFeatures()
          Returns a list of the features defined in the node.
 List<org.jivesoftware.smackx.packet.DiscoverInfo.Identity> getNodeIdentities()
          Returns a list of the identities defined in the node.
 List<org.jivesoftware.smackx.packet.DiscoverItems.Item> getNodeItems()
          Returns a list of the Items DiscoverItems.Item defined in the node or in other words null since we don't support any.
 org.jivesoftware.smackx.packet.DiscoverInfo getOwnDiscoverInfo()
          Get a DiscoverInfo for the current entity caps node.
 boolean includesFeature(String feature)
          Returns true if the specified feature is registered in our ServiceDiscoveryManager and false otherwise.
 void interceptPacket(org.jivesoftware.smack.packet.Packet packet)
          Intercepts outgoing presence packets and adds entity capabilities at their ends.
 void removeExtFeature(String ext)
          Remove "ext" feature.
 void removeFeature(String feature)
          Removes the specified feature from the supported features by the encapsulated ServiceDiscoveryManager.
 void stop()
          Clears/stops what's needed.
 boolean supportsFeature(String jid, String feature)
          Returns true if jid supports the specified feature and false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScServiceDiscoveryManager

public ScServiceDiscoveryManager(ProtocolProviderServiceJabberImpl parentProvider,
                                 String[] featuresToRemove,
                                 String[] featuresToAdd)
Creates a new ScServiceDiscoveryManager wrapping the default discovery manager of the specified connection.

Parameters:
parentProvider - the parent provider that creates discovery manager.
featuresToRemove - an array of Strings representing the features to be removed from the ServiceDiscoveryManager of the specified connection which is to be wrapped by the new instance
featuresToAdd - an array of Strings representing the features to be added to the new instance and to the ServiceDiscoveryManager of the specified connection which is to be wrapped by the new instance
Method Detail

addFeature

public void addFeature(String feature)
Registers that a new feature is supported by this XMPP entity. When this client is queried for its information the registered features will be answered.

Since no packet is actually sent to the server it is safe to perform this operation before logging to the server. In fact, you may want to configure the supported features before logging to the server so that the information is already available if it is required upon login.

Parameters:
feature - the feature to register as supported.

getFeatures

public List<String> getFeatures()
Returns a reference to our local copy of the feature list supported by this implementation.

Returns:
a reference to our local copy of the feature list supported by this implementation.

getOwnDiscoverInfo

public org.jivesoftware.smackx.packet.DiscoverInfo getOwnDiscoverInfo()
Get a DiscoverInfo for the current entity caps node.

Returns:
a DiscoverInfo for the current entity caps node

includesFeature

public boolean includesFeature(String feature)
Returns true if the specified feature is registered in our ServiceDiscoveryManager and false otherwise.

Parameters:
feature - the feature to look for.
Returns:
a boolean indicating if the specified featured is registered or not.

removeFeature

public void removeFeature(String feature)
Removes the specified feature from the supported features by the encapsulated ServiceDiscoveryManager.

Since no packet is actually sent to the server it is safe to perform this operation before logging to the server.

Parameters:
feature - the feature to remove from the supported features.

addExtFeature

public void addExtFeature(String ext)
Add feature to put in "ext" attribute.

Parameters:
ext - ext feature to add

removeExtFeature

public void removeExtFeature(String ext)
Remove "ext" feature.

Parameters:
ext - ext feature to remove

getExtFeatures

public String getExtFeatures()
Get "ext" value.

Returns:
string that represents "ext" value

interceptPacket

public void interceptPacket(org.jivesoftware.smack.packet.Packet packet)
Intercepts outgoing presence packets and adds entity capabilities at their ends.

Specified by:
interceptPacket in interface org.jivesoftware.smack.PacketInterceptor
Parameters:
packet - the (hopefully presence) packet we need to add a "c" element to.

getNodeItems

public List<org.jivesoftware.smackx.packet.DiscoverItems.Item> getNodeItems()
Returns a list of the Items DiscoverItems.Item defined in the node or in other words null since we don't support any.

Specified by:
getNodeItems in interface org.jivesoftware.smackx.NodeInformationProvider
Returns:
always null since we don't support items.

getNodeFeatures

public List<String> getNodeFeatures()
Returns a list of the features defined in the node. For example, the entity caps protocol specifies that an XMPP client should answer with each feature supported by the client version or extension.

Specified by:
getNodeFeatures in interface org.jivesoftware.smackx.NodeInformationProvider
Returns:
a list of the feature strings defined in the node.

getNodeIdentities

public List<org.jivesoftware.smackx.packet.DiscoverInfo.Identity> getNodeIdentities()
Returns a list of the identities defined in the node. For example, the x-command protocol must provide an identity of category automation and type command-node for each command.

Specified by:
getNodeIdentities in interface org.jivesoftware.smackx.NodeInformationProvider
Returns:
a list of the Identities defined in the node.

discoverInfo

public org.jivesoftware.smackx.packet.DiscoverInfo discoverInfo(String entityID)
                                                         throws org.jivesoftware.smack.XMPPException
Returns the discovered information of a given XMPP entity addressed by its JID.

Parameters:
entityID - the address of the XMPP entity.
Returns:
the discovered information.
Throws:
org.jivesoftware.smack.XMPPException - if the operation failed for some reason.

discoverInfoNonBlocking

public org.jivesoftware.smackx.packet.DiscoverInfo discoverInfoNonBlocking(String entityID)
                                                                    throws org.jivesoftware.smack.XMPPException
Returns the discovered information of a given XMPP entity addressed by its JID if locally cached, otherwise schedules for retrieval.

Parameters:
entityID - the address of the XMPP entity.
Returns:
the discovered information.
Throws:
org.jivesoftware.smack.XMPPException - if the operation failed for some reason.

discoverItems

public org.jivesoftware.smackx.packet.DiscoverItems discoverItems(String entityID)
                                                           throws org.jivesoftware.smack.XMPPException
Returns the discovered items of a given XMPP entity addressed by its JID.

Parameters:
entityID - the address of the XMPP entity.
Returns:
the discovered information.
Throws:
org.jivesoftware.smack.XMPPException - if the operation failed for some reason.

discoverItems

public org.jivesoftware.smackx.packet.DiscoverItems discoverItems(String entityID,
                                                                  String node)
                                                           throws org.jivesoftware.smack.XMPPException
Returns the discovered items of a given XMPP entity addressed by its JID and note attribute. Use this message only when trying to query information which is not directly addressable.

Parameters:
entityID - the address of the XMPP entity.
node - the attribute that supplements the 'jid' attribute.
Returns:
the discovered items.
Throws:
org.jivesoftware.smack.XMPPException - if the operation failed for some reason.

supportsFeature

public boolean supportsFeature(String jid,
                               String feature)
Returns true if jid supports the specified feature and false otherwise. The method may check the information locally if we've already cached this jid's disco info, or retrieve it from the network.

Parameters:
jid - the jabber ID we'd like to test for support
feature - the URN feature we are interested in
Returns:
true if jid is discovered to support feature and false otherwise.

getCapsManager

public EntityCapsManager getCapsManager()
Gets the EntityCapsManager which handles the entity capabilities for this ScServiceDiscoveryManager.

Returns:
the EntityCapsManager which handles the entity capabilities for this ScServiceDiscoveryManager

stop

public void stop()
Clears/stops what's needed.


Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.