Package org.jivesoftware.openfire.group
Class Group
- java.lang.Object
-
- org.jivesoftware.openfire.group.Group
-
- All Implemented Interfaces:
Externalizable
,Serializable
,Cacheable
public class Group extends Object implements Cacheable, Externalizable
Groups organize users into a single entity for easier management. As grouped entities are thought to represent end-user entities, a group can be thought of as a collection of bare (not full) JIDs. The method of the Group class and its associated API will accept both bare and full JIDs, but are expected to 'cast down' a full JID to a bare JID prior to processing it. The actual group implementation is controlled by theGroupProvider
, which includes things like the group name, the members, and administrators. Each group also has properties, which are always stored in the Openfire database.- Author:
- Matt Tucker
- See Also:
GroupManager.createGroup(String)
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
SHARED_ROSTER_DISPLAY_NAME_PROPERTY_KEY
static String
SHARED_ROSTER_GROUP_LIST_PROPERTY_KEY
static String
SHARED_ROSTER_SHOW_IN_ROSTER_PROPERTY_KEY
-
Constructor Summary
Constructors Constructor Description Group()
Constructor added for Externalizable.Group(String name, String description, Collection<org.xmpp.packet.JID> members, Collection<org.xmpp.packet.JID> administrators)
Constructs a new group.Group(String name, String description, Collection<org.xmpp.packet.JID> members, Collection<org.xmpp.packet.JID> administrators, Map<String,String> properties)
Constructs a new group.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object object)
Collection<org.xmpp.packet.JID>
getAdmins()
Returns a Collection of the group administrators.Collection<org.xmpp.packet.JID>
getAll()
Returns a read-only, unmodifiable collection of everyone in the group.int
getCachedSize()
Returns the approximate size of the Object in bytes.String
getDescription()
Returns the description of the group.GroupJID
getJID()
Returns a JID for the group based on the group name.Collection<org.xmpp.packet.JID>
getMembers()
Returns a Collection of the group members.String
getName()
Returns the name of the group.PersistableMap<String,String>
getProperties()
Returns all extended properties of the group.String
getSharedDisplayName()
When contact list group sharing has been enabled, the users in his group will be added to the contact list of every entity that the group is shared with.SharedGroupVisibility
getSharedWith()
Defines to which entities this group is shared, using the contact list group sharing.List<String>
getSharedWithUsersInGroupNames()
Defines the groups of users with which this group is shared if contact list group sharing is enabled and this group is shared with (other) groups (as defined bygetSharedWith()
).int
hashCode()
boolean
isUser(String username)
Returns true if the provided username belongs to a user of the group.boolean
isUser(org.xmpp.packet.JID user)
Returns true if the provided JID belongs to a user that is part of the group.void
readExternal(ObjectInput in)
static Group
resolveFrom(Object proxy)
Attempt to resolve the given object into a Group.static boolean
search(org.xmpp.packet.JID needle, Object haystack)
Search for a JID within a group.void
setDescription(String description)
Sets the description of the group.void
setName(String name)
Sets the name of the group.void
shareWithEverybody(String displayName)
Enable contact list group sharing for this group.void
shareWithNobody()
Disable contact list group sharing for this group.void
shareWithUsersInGroups(List<String> groupNames, String displayName)
Enable contact list group sharing for this group.void
shareWithUsersInSameGroup(String displayName)
Enable contact list group sharing for this group.String
toString()
void
writeExternal(ObjectOutput out)
-
-
-
Field Detail
-
SHARED_ROSTER_SHOW_IN_ROSTER_PROPERTY_KEY
public static final String SHARED_ROSTER_SHOW_IN_ROSTER_PROPERTY_KEY
- See Also:
- Constant Field Values
-
SHARED_ROSTER_DISPLAY_NAME_PROPERTY_KEY
public static final String SHARED_ROSTER_DISPLAY_NAME_PROPERTY_KEY
- See Also:
- Constant Field Values
-
SHARED_ROSTER_GROUP_LIST_PROPERTY_KEY
public static final String SHARED_ROSTER_GROUP_LIST_PROPERTY_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Group
public Group()
Constructor added for Externalizable. Do not use this constructor.
-
Group
public Group(String name, String description, Collection<org.xmpp.packet.JID> members, Collection<org.xmpp.packet.JID> administrators)
Constructs a new group. Note: this constructor is intended for implementors of theGroupProvider
interface. To create a new group, use theGroupManager.createGroup(String)
method.- Parameters:
name
- the name.description
- the description.members
- a Collection of the group members.administrators
- a Collection of the group administrators.
-
Group
public Group(String name, String description, Collection<org.xmpp.packet.JID> members, Collection<org.xmpp.packet.JID> administrators, Map<String,String> properties)
Constructs a new group. Note: this constructor is intended for implementors of theGroupProvider
interface. To create a new group, use theGroupManager.createGroup(String)
method.- Parameters:
name
- the name.description
- the description.members
- a Collection of the group members.administrators
- a Collection of the group administrators.properties
- a Map of properties with names and its values.
-
-
Method Detail
-
getJID
public GroupJID getJID()
Returns a JID for the group based on the group name. This instance will be of class GroupJID to distinguish it from other types of JIDs in the system. This method is synchronized to ensure each group has only a single JID instance created via lazy instantiation.- Returns:
- A JID for the group.
-
getName
public String getName()
Returns the name of the group. For example, 'XYZ Admins'.- Returns:
- the name of the group.
-
setName
public void setName(String name)
Sets the name of the group. For example, 'XYZ Admins'. This method is restricted to those with group administration permission.- Parameters:
name
- the name for the group.
-
getDescription
public String getDescription()
Returns the description of the group. The description often summarizes a group's function, such as 'Administrators of the XYZ forum'.- Returns:
- the description of the group.
-
setDescription
public void setDescription(String description)
Sets the description of the group. The description often summarizes a group's function, such as 'Administrators of the XYZ forum'. This method is restricted to those with group administration permission.- Parameters:
description
- the description of the group.
-
getProperties
public PersistableMap<String,String> getProperties()
Returns all extended properties of the group. Groups have an arbitrary number of extended properties. The returned collection can be modified to add new properties or remove existing ones.- Returns:
- the extended properties.
-
shareWithNobody
public void shareWithNobody()
Disable contact list group sharing for this group.
-
shareWithEverybody
public void shareWithEverybody(@Nonnull String displayName)
Enable contact list group sharing for this group. The group is shared on the contact list of all users defined in Openfire: every user in this group is added to the contact list of every user in Openfire, grouped by the provided display name.- Parameters:
displayName
- The name of the group that as shown in the contact lists of users.
-
shareWithUsersInSameGroup
public void shareWithUsersInSameGroup(@Nonnull String displayName)
Enable contact list group sharing for this group. The group is shared on the contact list of all users in the same group: every user in this group is added to the contact list of every other user in the group, grouped by the provided display name.- Parameters:
displayName
- The name of the group that as shown in the contact lists of users.
-
shareWithUsersInGroups
public void shareWithUsersInGroups(@Nonnull List<String> groupNames, @Nonnull String displayName)
Enable contact list group sharing for this group. The group is shared on the contact list of all users in each of the provided group: every user in this group is added to the contact list of every user in each of the provided other groups, grouped by the provided display name.- Parameters:
groupNames
- Name of groups for which all users shoulddisplayName
- The name of the group that as shown in the contact lists of users.
-
getSharedDisplayName
@Nullable public String getSharedDisplayName()
When contact list group sharing has been enabled, the users in his group will be added to the contact list of every entity that the group is shared with. On their contact lists, the users from this group will be added to a group by a name that is equal to the return value of this method. This method may return a null value when contact list sharing has not yet been configured, or an empty string when it has explicitly been configured to be disabled ("share with nobody").- Returns:
- A name to be used for a contact list group when sharing is enabled.
-
getSharedWith
@Nullable public SharedGroupVisibility getSharedWith()
Defines to which entities this group is shared, using the contact list group sharing. This method can return 'nobody', which differs from a 'null' value, which is returned when contact list sharing has not yet been configured. When 'usersOfGroups' is returned,getSharedWithUsersInGroupNames()
should be used to determine which to which groups this group is shared.- Returns:
- To which users this group is shared with.
-
getSharedWithUsersInGroupNames
@Nonnull public List<String> getSharedWithUsersInGroupNames()
Defines the groups of users with which this group is shared if contact list group sharing is enabled and this group is shared with (other) groups (as defined bygetSharedWith()
).- Returns:
- A collection of group names, possibly empty.
-
getAll
public Collection<org.xmpp.packet.JID> getAll()
Returns a read-only, unmodifiable collection of everyone in the group.- Returns:
- a read-only Collection of the group administrators + members.
-
getAdmins
public Collection<org.xmpp.packet.JID> getAdmins()
Returns a Collection of the group administrators. Changes made the collection will be applied and persisted via the GroupProvider.- Returns:
- a Collection of the group administrators.
-
getMembers
public Collection<org.xmpp.packet.JID> getMembers()
Returns a Collection of the group members. Changes made the collection will be applied and persisted via the GroupProvider.- Returns:
- a Collection of the group members.
-
isUser
public boolean isUser(org.xmpp.packet.JID user)
Returns true if the provided JID belongs to a user that is part of the group.- Parameters:
user
- the JID address of the user to check.- Returns:
- true if the specified user is a group user.
-
isUser
public boolean isUser(String username)
Returns true if the provided username belongs to a user of the group.- Parameters:
username
- the username to check.- Returns:
- true if the provided username belongs to a user of the group.
-
getCachedSize
public int getCachedSize() throws CannotCalculateSizeException
Description copied from interface:Cacheable
Returns the approximate size of the Object in bytes. The size should be considered to be a best estimate of how much memory the Object occupies and may be based on empirical trials or dynamic calculations.- Specified by:
getCachedSize
in interfaceCacheable
- Returns:
- the size of the Object in bytes.
- Throws:
CannotCalculateSizeException
- if the size cannot be calculated
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
search
public static boolean search(org.xmpp.packet.JID needle, Object haystack)
Search for a JID within a group. If the given haystack is not resolvable to a group, this method returns false.- Parameters:
needle
- A JID, possibly a member/admin of the given grouphaystack
- Presumably a Group, a Group name, or a JID that represents a Group- Returns:
- true if the JID (needle) is found in the group (haystack)
-
-