Exemple #1
0
  /**
   * Deletes a group from the system.
   *
   * @param group the group to delete.
   */
  public void deleteGroup(Group group) {
    // Fire event.
    GroupEventDispatcher.dispatchEvent(
        group, GroupEventDispatcher.EventType.group_deleting, Collections.emptyMap());

    // Delete the group.
    provider.deleteGroup(group.getName());

    // Expire all relevant caches.
    groupCache.remove(group.getName());
  }
Exemple #2
0
 /**
  * Returns a Group by name.
  *
  * @param name The name of the group to retrieve
  * @return The group corresponding to that name
  * @throws GroupNotFoundException if the group does not exist.
  */
 public Group getGroup(String name) throws GroupNotFoundException {
   Group group = (Group) groupCache.get(name);
   // If ID wan't found in cache, load it up and put it there.
   if (group == null) {
     synchronized (name.intern()) {
       group = (Group) groupCache.get(name);
       // If ID wan't found in cache, load it up and put it there.
       if (group == null) {
         group = provider.getGroup(name);
         groupCache.put(name, group);
       }
     }
   }
   return group;
 }
Exemple #3
0
  /**
   * Factory method for creating a new Group. A unique name is the only required field.
   *
   * @param name the new and unique name for the group.
   * @return a new Group.
   * @throws GroupAlreadyExistsException if the group name already exists in the system.
   */
  public Group createGroup(String name) throws GroupAlreadyExistsException {
    synchronized (name.intern()) {
      Group newGroup = null;
      try {
        getGroup(name);
        // The group already exists since now exception, so:
        throw new GroupAlreadyExistsException();
      } catch (GroupNotFoundException unfe) {
        // The group doesn't already exist so we can create a new group
        newGroup = provider.createGroup(name);
        groupCache.put(name, newGroup);

        // Fire event.
        GroupEventDispatcher.dispatchEvent(
            newGroup, GroupEventDispatcher.EventType.group_created, Collections.emptyMap());
      }
      return newGroup;
    }
  }
Exemple #4
0
 /**
  * Returns an iterator for all groups that the entity with the specified JID is a member of.
  *
  * @param user the JID of the entity to get a list of groups for.
  * @return all groups that an entity belongs to.
  */
 public Collection<Group> getGroups(JID user) {
   // TODO: add caching
   return provider.getGroups(user);
 }
Exemple #5
0
 /**
  * Returns an iterator for all groups according to a filter.
  *
  * <p>This is useful to support pagination in a GUI where you may only want to display a certain
  * number of results per page. It is possible that the number of results returned will be less
  * than that specified by numResults if numResults is greater than the number of records left in
  * the system to display.
  *
  * @param startIndex start index in results.
  * @param numResults number of results to return.
  * @return an Iterator for all groups in the specified range.
  */
 public Collection<Group> getGroups(int startIndex, int numResults) {
   // TODO: add caching
   return provider.getGroups(startIndex, numResults);
 }
Exemple #6
0
 /**
  * Returns the total number of groups in the system.
  *
  * @return the total number of groups.
  */
 public int getGroupCount() {
   // TODO: add caching
   return provider.getGroupCount();
 }