Example #1
0
 /** Entity Capabilities */
 public void setEntityCapsManager(EntityCapsManager manager) {
   capsManager = manager;
   if (connection.getCapsNode() != null && connection.getHost() != null) {
     capsManager.addUserCapsNode(connection.getHost(), connection.getCapsNode());
   }
   capsManager.addPacketListener(connection);
 }
Example #2
0
  /**
   * Returns the discovered information of a given XMPP entity addressed by its JID.
   *
   * @param entityID the address of the XMPP entity.
   * @return the discovered information.
   * @throws XMPPException if the operation failed for some reason.
   */
  public DiscoverInfo discoverInfo(String entityID) throws XMPPException {
    // Check if the have it cached in the Entity Capabilities Manager
    DiscoverInfo info = discoverInfoByCaps(entityID);

    if (info != null) {
      return info;
    } else {
      // If the caps node is known, use it in the request.
      String node = null;

      if (capsManager != null) {
        // Get the newest node#version
        node = capsManager.getNodeVersionByUser(entityID);
      }

      // Check if we cached DiscoverInfo for nonCaps entity
      if (cacheNonCaps && node == null && nonCapsCache.containsKey(entityID)) {
        return nonCapsCache.get(entityID);
      }
      // Discover by requesting from the remote client
      info = discoverInfo(entityID, node);

      // If the node version is known, store the new entry.
      if (node != null && capsManager != null) {
        EntityCapsManager.addDiscoverInfoByNode(node, info);
      }
      // If this is a non caps entity store the discover in nonCapsCache map
      else if (cacheNonCaps && node == null) {
        nonCapsCache.put(entityID, info);
      }
      return info;
    }
  }
Example #3
0
 private String getEntityCapsVersion() {
   if (capsManager != null) {
     return capsManager.getCapsVersion();
   } else {
     return null;
   }
 }
Example #4
0
  /**
   * Get a DiscoverInfo for the current entity caps node.
   *
   * @return a DiscoverInfo for the current entity caps node
   */
  public DiscoverInfo getOwnDiscoverInfo() {
    DiscoverInfo di = new DiscoverInfo();
    di.setType(IQ.Type.RESULT);
    di.setNode(capsManager.getNode() + "#" + getEntityCapsVersion());

    // Add discover info
    addDiscoverInfoTo(di);

    return di;
  }
Example #5
0
 private void renewEntityCapsVersion() {
   // If a XMPPConnection is the managed one, see that the new
   // version is updated
   if (connection instanceof XMPPConnection) {
     if (capsManager != null) {
       capsManager.calculateEntityCapsVersion(
           getOwnDiscoverInfo(), identityType, identityName, features, extendedInfo);
       // capsManager.notifyCapsVerListeners();
     }
   }
 }
Example #6
0
  /**
   * Returns the discovered information of a given XMPP entity addressed by its JID if it's known by
   * the entity caps manager.
   *
   * @param entityID the address of the XMPP entity
   * @return the disovered info or null if no such info is available from the entity caps manager.
   * @throws XMPPException if the operation failed for some reason.
   */
  public DiscoverInfo discoverInfoByCaps(String entityID) throws XMPPException {
    DiscoverInfo info = capsManager.getDiscoverInfoByUser(entityID);

    if (info != null) {
      DiscoverInfo newInfo = cloneDiscoverInfo(info);
      newInfo.setFrom(entityID);
      return newInfo;
    } else {
      return null;
    }
  }
Example #7
0
  /**
   * Creates a new ServiceDiscoveryManager for a given connection. This means that the service
   * manager will respond to any service discovery request that the connection may receive.
   *
   * @param connection the connection to which a ServiceDiscoveryManager is going to be created.
   */
  public ServiceDiscoveryManager(Connection connection) {
    this.connection = connection;

    // For every XMPPConnection, add one EntityCapsManager.
    if (connection instanceof XMPPConnection) {
      setEntityCapsManager(new EntityCapsManager());
      capsManager.addCapsVerListener(new CapsPresenceRenewer());
    }

    renewEntityCapsVersion();

    init();
  }