1
0
Fork 0
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:
Gaston Dombiak 2004-05-09 19:18:02 +00:00 committed by gdombiak
parent fbd6043c5c
commit 1da02cbfd8

View file

@ -76,6 +76,7 @@ public class ServiceDiscoveryManager {
private XMPPConnection connection; private XMPPConnection connection;
private List features = new ArrayList(); private List features = new ArrayList();
private Map nodeInformationProviders = new Hashtable();
// Create a new ServiceDiscoveryManager on every established connection // Create a new ServiceDiscoveryManager on every established connection
static { static {
@ -134,13 +135,22 @@ public class ServiceDiscoveryManager {
PacketListener packetListener = new PacketListener() { PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
DiscoverItems discoverItems = (DiscoverItems) packet; DiscoverItems discoverItems = (DiscoverItems) packet;
// Answer an empty result if the request is of the GET type // Send back the items defined in the client if the request is of type GET
// Note: In a future version Smack will enable to have items defined in the client
if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) { if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) {
DiscoverItems response = new DiscoverItems(); DiscoverItems response = new DiscoverItems();
response.setType(IQ.Type.RESULT); response.setType(IQ.Type.RESULT);
response.setTo(discoverItems.getFrom()); response.setTo(discoverItems.getFrom());
response.setPacketID(discoverItems.getPacketID()); 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); connection.sendPacket(response);
} }
} }
@ -172,6 +182,52 @@ public class ServiceDiscoveryManager {
connection.addPacketListener(packetListener, packetFilter); 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. * Returns the supported features by this XMPP entity.
* *