mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-23 06:42:05 +01:00
Allows to retrieve items for entity nodes. SMACK-134
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2307 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
fbd6043c5c
commit
1da02cbfd8
1 changed files with 70 additions and 14 deletions
|
@ -76,6 +76,7 @@ public class ServiceDiscoveryManager {
|
|||
|
||||
private XMPPConnection connection;
|
||||
private List features = new ArrayList();
|
||||
private Map nodeInformationProviders = new Hashtable();
|
||||
|
||||
// Create a new ServiceDiscoveryManager on every established connection
|
||||
static {
|
||||
|
@ -105,7 +106,7 @@ public class ServiceDiscoveryManager {
|
|||
* @return the ServiceDiscoveryManager associated with a given XMPPConnection
|
||||
*/
|
||||
public static ServiceDiscoveryManager getInstanceFor(XMPPConnection connection) {
|
||||
return (ServiceDiscoveryManager)instances.get(connection);
|
||||
return (ServiceDiscoveryManager) instances.get(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,13 +135,22 @@ public class ServiceDiscoveryManager {
|
|||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
DiscoverItems discoverItems = (DiscoverItems) packet;
|
||||
// Answer an empty result if the request is of the GET type
|
||||
// Note: In a future version Smack will enable to have items defined in the client
|
||||
// Send back the items defined in the client if the request is of type GET
|
||||
if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) {
|
||||
DiscoverItems response = new DiscoverItems();
|
||||
response.setType(IQ.Type.RESULT);
|
||||
response.setTo(discoverItems.getFrom());
|
||||
response.setPacketID(discoverItems.getPacketID());
|
||||
|
||||
// Add the defined items related to the requested node. Look for
|
||||
// the NodeInformationProvider associated with the requested node.
|
||||
if (getNodeInformationProvider(discoverItems.getNode()) != null) {
|
||||
Iterator items =
|
||||
getNodeInformationProvider(discoverItems.getNode()).getNodeItems();
|
||||
while (items.hasNext()) {
|
||||
response.addItem((DiscoverItems.Item) items.next());
|
||||
}
|
||||
}
|
||||
connection.sendPacket(response);
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +171,7 @@ public class ServiceDiscoveryManager {
|
|||
response.setPacketID(discoverInfo.getPacketID());
|
||||
// Add the registered features to the response
|
||||
synchronized (features) {
|
||||
for (Iterator it=getFeatures(); it.hasNext();) {
|
||||
for (Iterator it = getFeatures(); it.hasNext();) {
|
||||
response.addFeature((String) it.next());
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +182,52 @@ public class ServiceDiscoveryManager {
|
|||
connection.addPacketListener(packetListener, packetFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NodeInformationProvider responsible for providing information
|
||||
* (i.e. items) related to a given node or <tt>null</null> if none.<p>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param node the node that contains items associated with an entity not addressable as a JID
|
||||
* @return the NodeInformationProvider responsible for providing information related
|
||||
* to a given node
|
||||
*/
|
||||
private NodeInformationProvider getNodeInformationProvider(String node) {
|
||||
return (NodeInformationProvider) nodeInformationProviders.get(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NodeInformationProvider responsible for providing information
|
||||
* (i.e. 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.<p>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param node the node whose items will be provided by the NodeInformationProvider
|
||||
* @return the NodeInformationProvider responsible for providing items related
|
||||
* to the node
|
||||
*/
|
||||
public void setNodeInformationProvider(String node, NodeInformationProvider listener) {
|
||||
nodeInformationProviders.put(node, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the NodeInformationProvider responsible for providing information
|
||||
* (i.e. 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.
|
||||
*
|
||||
* @param node the node to remove the associated NodeInformationProvider
|
||||
*/
|
||||
public void removeNodeInformationProvider(String node) {
|
||||
nodeInformationProviders.remove(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the supported features by this XMPP entity.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue