示例#1
0
  /**
   * Adds <tt>listener</tt> to the list of {@link CapsVerListener}s that we notify when new features
   * occur and the version hash needs to be regenerated. The method would also notify
   * <tt>listener</tt> if our current caps version has been generated and is different than
   * <tt>null</tt>.
   *
   * @param listener the {@link CapsVerListener} we'd like to register.
   */
  public void addCapsVerListener(CapsVerListener listener) {
    synchronized (capsVerListeners) {
      if (capsVerListeners.contains(listener)) return;

      capsVerListeners.add(listener);

      if (currentCapsVersion != null) listener.capsVerUpdated(currentCapsVersion);
    }
  }
示例#2
0
  /**
   * Handles chat room presence status updates.
   *
   * @param evt the <tt>LocalUserChatRoomPresenceChangeEvent</tt> instance containing the chat room
   *     and the type, and reason of the change
   */
  @Override
  public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt) {
    ChatRoom sourceChatRoom = evt.getChatRoom();

    String eventType = evt.getEventType();

    boolean existingContact = false;
    ChatRoomSourceContact foundContact = null;
    synchronized (contactResults) {
      for (ChatRoomSourceContact contact : contactResults) {
        if (contactEqualsChatRoom(contact, sourceChatRoom)) {
          existingContact = true;
          foundContact = contact;
          contactResults.remove(contact);
          break;
        }
      }
    }

    if (LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED.equals(eventType)) {
      if (existingContact) {
        foundContact.setPresenceStatus(ChatRoomPresenceStatus.CHAT_ROOM_ONLINE);
        synchronized (contactResults) {
          contactResults.add(foundContact);
        }
        fireContactChanged(foundContact);
      } else {
        ChatRoomWrapper chatRoom =
            MUCActivator.getMUCService().findChatRoomWrapperFromChatRoom(sourceChatRoom);
        if (chatRoom != null) addChatRoom(sourceChatRoom, false, chatRoom.isAutojoin());
      }
    } else if ((LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT.equals(eventType)
        || LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_KICKED.equals(eventType)
        || LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_DROPPED.equals(eventType))) {
      if (existingContact) {
        foundContact.setPresenceStatus(ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE);
        synchronized (contactResults) {
          contactResults.add(foundContact);
        }
        fireContactChanged(foundContact);
      }
    }
  }
 private void addMetaTypeProviderWrappers(
     String servicePropertyName,
     ServiceReference<Object> serviceReference,
     MetaTypeProvider service,
     boolean factory,
     Set<MetaTypeProviderWrapper> wrappers) {
   String[] pids =
       getStringProperty(servicePropertyName, serviceReference.getProperty(servicePropertyName));
   for (String pid : pids) {
     wrappers.add(new MetaTypeProviderWrapper(service, pid, factory));
   }
 }
示例#4
0
  /**
   * Adds found result to the query results.
   *
   * @param room the chat room.
   * @param addQueryResult indicates whether we should add the chat room to the query results or
   *     fire an event without adding it to the results.
   * @param isAutoJoin the auto join state of the contact.
   */
  private void addChatRoom(ChatRoom room, boolean addQueryResult, boolean isAutoJoin) {
    if (queryString == null
        || ((room.getName().contains(queryString) || room.getIdentifier().contains(queryString)))) {
      ChatRoomSourceContact contact = new ChatRoomSourceContact(room, this, isAutoJoin);
      synchronized (contactResults) {
        contactResults.add(contact);
      }

      if (addQueryResult) {
        addQueryResult(contact, false);
      } else {
        fireContactReceived(contact, false);
      }
    }
  }
 private static Object mapValue(Object v) {
   if ((v == null)
       || v instanceof Number
       || v instanceof Boolean
       || v instanceof Character
       || v instanceof String
       || v instanceof DTO) {
     return v;
   }
   if (v instanceof Map) {
     Map<?, ?> m = (Map<?, ?>) v;
     Map<Object, Object> map = newMap(m.size());
     for (Map.Entry<?, ?> e : m.entrySet()) {
       map.put(mapValue(e.getKey()), mapValue(e.getValue()));
     }
     return map;
   }
   if (v instanceof List) {
     List<?> c = (List<?>) v;
     List<Object> list = newList(c.size());
     for (Object o : c) {
       list.add(mapValue(o));
     }
     return list;
   }
   if (v instanceof Set) {
     Set<?> c = (Set<?>) v;
     Set<Object> set = newSet(c.size());
     for (Object o : c) {
       set.add(mapValue(o));
     }
     return set;
   }
   if (v.getClass().isArray()) {
     final int length = Array.getLength(v);
     final Class<?> componentType = mapComponentType(v.getClass().getComponentType());
     Object array = Array.newInstance(componentType, length);
     for (int i = 0; i < length; i++) {
       Array.set(array, i, mapValue(Array.get(v, i)));
     }
     return array;
   }
   return String.valueOf(v);
 }
示例#6
0
  /**
   * Adds found result to the query results.
   *
   * @param pps the protocol provider associated with the found chat room.
   * @param chatRoomName the name of the chat room.
   * @param chatRoomID the id of the chat room.
   * @param addQueryResult indicates whether we should add the chat room to the query results or
   *     fire an event without adding it to the results.
   * @param isAutoJoin the auto join state of the contact.
   */
  private void addChatRoom(
      ProtocolProviderService pps,
      String chatRoomName,
      String chatRoomID,
      boolean addQueryResult,
      boolean isAutoJoin) {
    if (queryString == null
        || ((chatRoomName.contains(queryString) || chatRoomID.contains(queryString)))) {
      ChatRoomSourceContact contact =
          new ChatRoomSourceContact(chatRoomName, chatRoomID, this, pps, isAutoJoin);
      synchronized (contactResults) {
        contactResults.add(contact);
      }

      if (addQueryResult) {
        addQueryResult(contact, false);
      } else {
        fireContactReceived(contact, false);
      }
    }
  }
示例#7
0
 static Set toImmutableSet(Object obj) {
   Set set = new HashSet();
   set.add(obj);
   set = Collections.unmodifiableSet(set);
   return set;
 }