Smack

org.jivesoftware.smackx
Class ServiceDiscoveryManager

java.lang.Object
  extended by org.jivesoftware.smackx.ServiceDiscoveryManager

public class ServiceDiscoveryManager
extends Object

Manages discovery of services in XMPP entities. This class provides:

  1. A registry of supported features in this XMPP entity.
  2. Automatic response when this XMPP entity is queried for information.
  3. Ability to discover items and information of remote XMPP entities.
  4. Ability to publish publicly available items.

Author:
Gaston Dombiak

Constructor Summary
ServiceDiscoveryManager(XMPPConnection connection)
          Creates a new ServiceDiscoveryManager for a given XMPPConnection.
 
Method Summary
 void addFeature(String feature)
          Registers that a new feature is supported by this XMPP entity.
 boolean canPublishItems(String entityID)
          Returns true if the server supports publishing of items.
 DiscoverInfo discoverInfo(String entityID)
          Returns the discovered information of a given XMPP entity addressed by its JID.
 DiscoverInfo discoverInfo(String entityID, String node)
          Returns the discovered information of a given XMPP entity addressed by its JID and note attribute.
 DiscoverItems discoverItems(String entityID)
          Returns the discovered items of a given XMPP entity addressed by its JID.
 DiscoverItems discoverItems(String entityID, String node)
          Returns the discovered items of a given XMPP entity addressed by its JID and note attribute.
 Iterator getFeatures()
          Returns the supported features by this XMPP entity.
static String getIdentityName()
          Returns the name of the client that will be returned when asked for the client identity in a disco request.
static String getIdentityType()
          Returns the type of client that will be returned when asked for the client identity in a disco request.
static ServiceDiscoveryManager getInstanceFor(XMPPConnection connection)
          Returns the ServiceDiscoveryManager instance associated with a given XMPPConnection.
 boolean includesFeature(String feature)
          Returns true if the specified feature is registered in the ServiceDiscoveryManager.
 void publishItems(String entityID, DiscoverItems discoverItems)
          Publishes new items to a parent entity.
 void publishItems(String entityID, String node, DiscoverItems discoverItems)
          Publishes new items to a parent entity and node.
 void removeFeature(String feature)
          Removes the specified feature from the supported features by this XMPP entity.
 void removeNodeInformationProvider(String node)
          Removes the NodeInformationProvider responsible for providing information (ie items) related to a given node.
static void setIdentityName(String name)
          Sets the name of the client that will be returned when asked for the client identity in a disco request.
static void setIdentityType(String type)
          Sets the type of client that will be returned when asked for the client identity in a disco request.
 void setNodeInformationProvider(String node, NodeInformationProvider listener)
          Sets the NodeInformationProvider responsible for providing information (ie items) related to a given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceDiscoveryManager

public ServiceDiscoveryManager(XMPPConnection connection)
Creates a new ServiceDiscoveryManager for a given XMPPConnection. This means that the service manager will respond to any service discovery request that the connection may receive.

Parameters:
connection - the connection to which a ServiceDiscoveryManager is going to be created.
Method Detail

getInstanceFor

public static ServiceDiscoveryManager getInstanceFor(XMPPConnection connection)
Returns the ServiceDiscoveryManager instance associated with a given XMPPConnection.

Parameters:
connection - the connection used to look for the proper ServiceDiscoveryManager.
Returns:
the ServiceDiscoveryManager associated with a given XMPPConnection.

getIdentityName

public static String getIdentityName()
Returns the name of the client that will be returned when asked for the client identity in a disco request. The name could be any value you need to identity this client.

Returns:
the name of the client that will be returned when asked for the client identity in a disco request.

setIdentityName

public static void setIdentityName(String name)
Sets the name of the client that will be returned when asked for the client identity in a disco request. The name could be any value you need to identity this client.

Parameters:
name - the name of the client that will be returned when asked for the client identity in a disco request.

getIdentityType

public static String getIdentityType()
Returns the type of client that will be returned when asked for the client identity in a disco request. The valid types are defined by the category client. Follow this link to learn the possible types: Jabber::Registrar.

Returns:
the type of client that will be returned when asked for the client identity in a disco request.

setIdentityType

public static void setIdentityType(String type)
Sets the type of client that will be returned when asked for the client identity in a disco request. The valid types are defined by the category client. Follow this link to learn the possible types: Jabber::Registrar.

Parameters:
type - the type of client that will be returned when asked for the client identity in a disco request.

setNodeInformationProvider

public void setNodeInformationProvider(String node,
                                       NodeInformationProvider listener)
Sets the NodeInformationProvider responsible for providing information (ie items) related to a given node. Every time this client receives a disco request regarding the items of a given node, the provider associated to that node will be the responsible for providing the requested information.

In MUC, a node could be 'http://jabber.org/protocol/muc#rooms' which means that the NodeInformationProvider will provide information about the rooms where the user has joined.

Parameters:
node - the node whose items will be provided by the NodeInformationProvider.
listener - the NodeInformationProvider responsible for providing items related to the node.

removeNodeInformationProvider

public void removeNodeInformationProvider(String node)
Removes the NodeInformationProvider responsible for providing information (ie items) related to a given node. This means that no more information will be available for the specified node. In MUC, a node could be 'http://jabber.org/protocol/muc#rooms' which means that the NodeInformationProvider will provide information about the rooms where the user has joined.

Parameters:
node - the node to remove the associated NodeInformationProvider.

getFeatures

public Iterator getFeatures()
Returns the supported features by this XMPP entity.

Returns:
an Iterator on the supported features by this XMPP entity.

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.

Parameters:
feature - the feature to register as supported.

removeFeature

public void removeFeature(String feature)
Removes the specified feature from the supported features by this XMPP entity.

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

includesFeature

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

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

discoverInfo

public DiscoverInfo discoverInfo(String entityID)
                          throws 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:
XMPPException - if the operation failed for some reason.

discoverInfo

public DiscoverInfo discoverInfo(String entityID,
                                 String node)
                          throws XMPPException
Returns the discovered information 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 information.
Throws:
XMPPException - if the operation failed for some reason.

discoverItems

public DiscoverItems discoverItems(String entityID)
                            throws 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:
XMPPException - if the operation failed for some reason.

discoverItems

public DiscoverItems discoverItems(String entityID,
                                   String node)
                            throws 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:
XMPPException - if the operation failed for some reason.

canPublishItems

public boolean canPublishItems(String entityID)
                        throws XMPPException
Returns true if the server supports publishing of items. A client may wish to publish items to the server so that the server can provide items associated to the client. These items will be returned by the server whenever the server receives a disco request targeted to the bare address of the client (i.e. user@host.com).

Parameters:
entityID - the address of the XMPP entity.
Returns:
true if the server supports publishing of items.
Throws:
XMPPException - if the operation failed for some reason.

publishItems

public void publishItems(String entityID,
                         DiscoverItems discoverItems)
                  throws XMPPException
Publishes new items to a parent entity. The item elements to publish MUST have at least a 'jid' attribute specifying the Entity ID of the item, and an action attribute which specifies the action being taken for that item. Possible action values are: "update" and "remove".

Parameters:
entityID - the address of the XMPP entity.
discoverItems - the DiscoveryItems to publish.
Throws:
XMPPException - if the operation failed for some reason.

publishItems

public void publishItems(String entityID,
                         String node,
                         DiscoverItems discoverItems)
                  throws XMPPException
Publishes new items to a parent entity and node. The item elements to publish MUST have at least a 'jid' attribute specifying the Entity ID of the item, and an action attribute which specifies the action being taken for that item. Possible action values are: "update" and "remove".

Parameters:
entityID - the address of the XMPP entity.
node - the attribute that supplements the 'jid' attribute.
discoverItems - the DiscoveryItems to publish.
Throws:
XMPPException - if the operation failed for some reason.

Smack

Copyright © 2003 Jive Software.