|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jasig.portal.groups.GroupMemberImpl
org.jasig.portal.groups.EntityGroupImpl
public class EntityGroupImpl
Reference implementation for IEntityGroup.
Groups do not keep references to their members but instead cache
member keys. The members are cached externally. The rules
for controlling access to the key caches are a bit obscure, but you
should understand them before writing code that updates groups.
Access to the caches themselves is synchronized via the cache
getters and setters. All requests to get group members and to add or
remove group members ultimately go through these methods. The
mutating methods, addMember() and removeMember()
however, do a copy-on-write. That is, they first make a copy of the
cache, add or remove the member key, and then replace the original
cache with the copy. This permits multiple read and write threads to run
concurrently without throwing ConcurrentModificationExceptions.
But it still leaves open the danger of data races because nothing in
this class guarantees serialized write access. You must impose this
from without, either via explicit locking (GroupService.getLockableGroup())
or by synchronizing access from the caller.
IEntityGroup| Field Summary | |
|---|---|
private java.util.HashMap |
addedMembers
|
private java.lang.String |
creatorID
|
private java.lang.String |
description
|
private java.lang.Class |
leafEntityType
|
protected IIndividualGroupService |
localGroupService
|
private java.util.Set |
memberEntityKeys
|
private java.util.Set |
memberGroupKeys
|
private boolean |
memberKeysInitialized
|
private java.lang.String |
name
|
private java.util.HashMap |
removedMembers
|
| Constructor Summary | |
|---|---|
EntityGroupImpl(java.lang.String groupKey,
java.lang.Class entityType)
EntityGroupImpl |
|
| Method Summary | |
|---|---|
void |
addMember(IGroupMember gm)
Adds IGroupMember gm to our member Map and conversely,
adds this to gm's group Map, after checking that the
addition does not violate group rules. |
protected boolean |
areMemberKeysInitialized()
|
private void |
checkProspectiveMember(IGroupMember gm)
A member must share the entityType of its containing IEntityGroup. |
protected void |
clearPendingUpdates()
Clear out caches for pending adds and deletes of group members. |
boolean |
contains(IGroupMember gm)
Checks if GroupMember gm is a member of this. |
private java.util.Set |
copyMemberEntityKeys()
Clone the member entity keys. |
private java.util.Set |
copyMemberGroupKeys()
Clone the member group keys. |
boolean |
deepContains(IGroupMember gm)
Checks recursively if GroupMember gm is a member of this. |
void |
delete()
Delegates to the factory. |
boolean |
equals(java.lang.Object obj)
Answers if Object o is an IGroupMember that refers to the same underlying
entity(ies) as this. |
java.util.HashMap |
getAddedMembers()
|
java.util.Iterator |
getAllEntities()
Returns an Iterator over the Set of this
IEntityGroup's recursively-retrieved members that are
IEntities. |
java.util.Iterator |
getAllMembers()
Returns an Iterator over the Set of recursively-retrieved
IGroupMembers that are members of this IEntityGroup. |
protected CompositeEntityIdentifier |
getCompositeEntityIdentifier()
Returns the EntityIdentifier cast to a
CompositeEntityIdentifier so that its service nodes
can be pushed and popped. |
java.lang.String |
getCreatorID()
Returns the name of the group creator. |
java.lang.String |
getDescription()
Returns the group description, which may be null. |
java.util.Iterator |
getEntities()
Returns an Iterator over this IEntityGroup's
members that are IEntities. |
EntityIdentifier |
getEntityIdentifier()
|
java.lang.String |
getEntityKey()
Returns the key of the underyling entity. |
java.lang.Class |
getEntityType()
Returns the entity type of this groups's leaf members. |
java.lang.String |
getGroupID()
|
java.lang.Class |
getLeafType()
Returns the entity type of this groups's members. |
protected IIndividualGroupService |
getLocalGroupService()
|
java.lang.String |
getLocalKey()
Returns the key from the group service of origin. |
protected java.util.Iterator |
getMemberEntities()
Returns an Iterator over the entities in our member
Collection. |
private java.util.Set |
getMemberEntityKeys()
|
private java.util.Set |
getMemberGroupKeys()
|
IEntityGroup |
getMemberGroupNamed(java.lang.String name)
Returns the named member IEntityGroup. |
protected java.util.Iterator |
getMemberGroups()
Returns an Iterator over the groups in our member
Collection. |
java.util.Iterator |
getMembers()
Returns an Iterator over the GroupMembers in our
member Collection. |
java.lang.String |
getName()
Returns the group name. |
java.util.HashMap |
getRemovedMembers()
|
protected GroupService |
getService()
|
javax.naming.Name |
getServiceName()
Returns the Name of the group service of origin. |
java.lang.Class |
getType()
Returns this object's type for purposes of caching and locking, as opposed to the underlying entity type. |
boolean |
hasAdds()
Answers if there are any added memberships not yet committed to the database. |
boolean |
hasDeletes()
Answers if there are any deleted memberships not yet committed to the database. |
int |
hashCode()
Generates a hash code for the receiver. |
boolean |
hasMembers()
Default implementation, overridden on EntityGroupImpl. |
private void |
initializeMembers()
Cache the IEntityGroup members. |
boolean |
isDirty()
Answers if there are any added or deleted memberships not yet committed to the database. |
boolean |
isEditable()
Answers if this IEntityGroup can be changed or deleted. |
boolean |
isGroup()
|
protected void |
primAddMember(IGroupMember gm)
Adds the IGroupMember key to the appropriate member key
cache by copying the cache, adding to the copy, and then replacing the
original with the copy. |
protected java.util.Set |
primGetAllEntities(java.util.Set entities)
Returns the Set of IEntities in our member Collection
and, recursively, in the Collections of our members. |
protected java.util.Set |
primGetAllMembers(java.util.Set s)
Returns the Set of IGroupMembers in our member
Collection and, recursively, in the Collections
of our members. |
protected void |
primRemoveMember(IGroupMember gm)
Removes the IGroupMember key from the appropriate key cache, by
copying the cache, removing the key from the copy and replacing the original
with the copy. |
void |
primSetName(java.lang.String newName)
|
void |
removeMember(IGroupMember gm)
Removes IGroupMember gm from our member Map and,
conversely, remove this from gm's group Map. |
void |
setCreatorID(java.lang.String newCreatorID)
|
void |
setDescription(java.lang.String newDescription)
|
void |
setLocalGroupService(IIndividualGroupService newIndividualGroupService)
Sets the group service of origin. |
private void |
setMemberEntityKeys(java.util.Set newMemberEntityKeys)
|
private void |
setMemberGroupKeys(java.util.Set newMemberGroupKeys)
|
private void |
setMemberKeysInitialized(boolean newMemberKeysInitialized)
|
void |
setName(java.lang.String newName)
We used to check duplicate sibling names but no longer do. |
void |
setServiceName(javax.naming.Name newServiceName)
Sets the service Name of the group service of origin. |
java.lang.String |
toString()
Returns a String that represents the value of this object. |
void |
update()
Delegate to the factory. |
void |
updateMembers()
Delegate to the factory. |
| Methods inherited from class org.jasig.portal.groups.GroupMemberImpl |
|---|
addGroup, castAndCopyHashSet, getAllContainingGroups, getCacheKey, getCompositeGroupService, getContainingGroups, getKey, getUnderlyingEntityIdentifier, isDeepMemberOf, isEntity, isKnownEntityType, isMemberOf, primGetAllContainingGroups, removeGroup, setGroupKeysInitialized |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.jasig.portal.groups.IGroupMember |
|---|
getAllContainingGroups, getContainingGroups, getKey, getUnderlyingEntityIdentifier, isDeepMemberOf, isEntity, isMemberOf |
| Field Detail |
|---|
private java.lang.String creatorID
private java.lang.String name
private java.lang.String description
protected IIndividualGroupService localGroupService
private java.lang.Class leafEntityType
private java.util.Set memberGroupKeys
private java.util.Set memberEntityKeys
private boolean memberKeysInitialized
private java.util.HashMap addedMembers
private java.util.HashMap removedMembers
| Constructor Detail |
|---|
public EntityGroupImpl(java.lang.String groupKey,
java.lang.Class entityType)
throws GroupsException
GroupsException| Method Detail |
|---|
public void addMember(IGroupMember gm)
throws GroupsException
IGroupMember gm to our member Map and conversely,
adds this to gm's group Map, after checking that the
addition does not violate group rules. Remember that we have added it so we can
update the database if necessary.
addMember in interface IEntityGroupgm - org.jasig.portal.groups.IGroupMember
GroupsException - is thrown if the member is a group and
this group already has a group with the same name or if the addition
of the group creates a circular reference.protected boolean areMemberKeysInitialized()
private void checkProspectiveMember(IGroupMember gm)
throws GroupsException
entityType of its containing IEntityGroup.
If it is a group, it must have a unique name within each of its containing groups and
the resulting group must not contain a circular reference.
Removed the requirement for unique group names. (03-04-2004, de)
gm - org.jasig.portal.groups.IGroupMember
GroupsExceptionprotected void clearPendingUpdates()
private java.util.Set copyMemberEntityKeys()
throws GroupsException
GroupsException
private java.util.Set copyMemberGroupKeys()
throws GroupsException
GroupsException
public boolean contains(IGroupMember gm)
throws GroupsException
GroupMember gm is a member of this.
contains in interface IGroupMembercontains in class GroupMemberImplgm - org.jasig.portal.groups.IGroupMember
GroupsException
public boolean deepContains(IGroupMember gm)
throws GroupsException
GroupMember gm is a member of this.
deepContains in interface IGroupMemberdeepContains in class GroupMemberImplgm - org.jasig.portal.groups.IGroupMember
GroupsException
public void delete()
throws GroupsException
delete in interface IEntityGroupGroupsException - if the delete cannot be performed.public boolean equals(java.lang.Object obj)
IGroupMemberIGroupMember that refers to the same underlying
entity(ies) as this.
equals in interface IGroupMemberequals in class java.lang.Objectobj - the Object to compare with
Hashtablepublic java.util.HashMap getAddedMembers()
public java.util.Iterator getAllEntities()
throws GroupsException
Iterator over the Set of this
IEntityGroup's recursively-retrieved members that are
IEntities.
getAllEntities in interface IGroupMembergetAllEntities in class GroupMemberImplGroupsException
public java.util.Iterator getAllMembers()
throws GroupsException
Iterator over the Set of recursively-retrieved
IGroupMembers that are members of this IEntityGroup.
getAllMembers in interface IGroupMembergetAllMembers in class GroupMemberImplGroupsExceptionprotected CompositeEntityIdentifier getCompositeEntityIdentifier()
EntityIdentifier cast to a
CompositeEntityIdentifier so that its service nodes
can be pushed and popped.
public java.lang.String getCreatorID()
IEntityGroup
getCreatorID in interface IEntityGrouppublic java.lang.String getDescription()
IEntityGroup
getDescription in interface IEntityGroup
public java.util.Iterator getEntities()
throws GroupsException
Iterator over this IEntityGroup's
members that are IEntities.
getEntities in interface IGroupMembergetEntities in class GroupMemberImplGroupsExceptionpublic EntityIdentifier getEntityIdentifier()
getEntityIdentifier in interface IBasicEntitypublic java.lang.String getEntityKey()
public java.lang.Class getEntityType()
getEntityType in interface IGroupMemberEntityTypespublic java.lang.String getGroupID()
public java.lang.Class getLeafType()
getLeafType in interface IGroupMemberEntityTypesprotected IIndividualGroupService getLocalGroupService()
public java.lang.String getLocalKey()
getLocalKey in interface IEntityGroup
protected java.util.Iterator getMemberEntities()
throws GroupsException
Iterator over the entities in our member
Collection.
GroupsException
private java.util.Set getMemberEntityKeys()
throws GroupsException
GroupsException
private java.util.Set getMemberGroupKeys()
throws GroupsException
GroupsException
public IEntityGroup getMemberGroupNamed(java.lang.String name)
throws GroupsException
IEntityGroup.
getMemberGroupNamed in interface IGroupMembergetMemberGroupNamed in class GroupMemberImplname - java.lang.String
GroupsException
protected java.util.Iterator getMemberGroups()
throws GroupsException
Iterator over the groups in our member
Collection.
GroupsException
public java.util.Iterator getMembers()
throws GroupsException
Iterator over the GroupMembers in our
member Collection.
getMembers in interface IGroupMembergetMembers in class GroupMemberImplGroupsExceptionpublic java.lang.String getName()
IEntityGroup
getName in interface IEntityGrouppublic java.util.HashMap getRemovedMembers()
protected GroupService getService()
throws GroupsException
GroupsExceptionpublic javax.naming.Name getServiceName()
getServiceName in interface IEntityGrouppublic java.lang.Class getType()
getType in interface IGroupMembergetType in class GroupMemberImplpublic boolean hasAdds()
public boolean hasDeletes()
public int hashCode()
hashCode in interface IGroupMemberhashCode in class GroupMemberImplHashtable
public boolean hasMembers()
throws GroupsException
GroupMemberImpl
hasMembers in interface IGroupMemberhasMembers in class GroupMemberImplGroupsException
private void initializeMembers()
throws GroupsException
IEntityGroup members.
GroupsExceptionpublic boolean isDirty()
public boolean isEditable()
throws GroupsException
IEntityGroup can be changed or deleted.
isEditable in interface IEntityGroupGroupsExceptionpublic boolean isGroup()
isGroup in interface IGroupMemberisGroup in class GroupMemberImpl
protected void primAddMember(IGroupMember gm)
throws GroupsException
IGroupMember key to the appropriate member key
cache by copying the cache, adding to the copy, and then replacing the
original with the copy. At this point, gm does not yet
have this in its containing group cache. That cache entry
is not added until update(), when changes are committed to the store.
gm - org.jasig.portal.groups.IGroupMember
GroupsException
protected java.util.Set primGetAllEntities(java.util.Set entities)
throws GroupsException
Set of IEntities in our member Collection
and, recursively, in the Collections of our members.
entities - a Set that IEntity-GroupMembers are added to.
GroupsException
protected java.util.Set primGetAllMembers(java.util.Set s)
throws GroupsException
Set of IGroupMembers in our member
Collection and, recursively, in the Collections
of our members.
s - java.lang.Set - a Set that members are added to.
GroupsException
protected void primRemoveMember(IGroupMember gm)
throws GroupsException
IGroupMember key from the appropriate key cache, by
copying the cache, removing the key from the copy and replacing the original
with the copy. At this point, gm still has this
in its containing groups cache. That cache entry is not removed until update(),
when changes are committed to the store.
gm - org.jasig.portal.groups.IGroupMember
GroupsExceptionpublic void primSetName(java.lang.String newName)
newName - java.lang.String
public void removeMember(IGroupMember gm)
throws GroupsException
IGroupMember gm from our member Map and,
conversely, remove this from gm's group Map. Remember that we
have removed it so we can update the database, if necessary.
removeMember in interface IEntityGroupgm - org.jasig.portal.groups.IGroupMember
GroupsExceptionpublic void setCreatorID(java.lang.String newCreatorID)
setCreatorID in interface IEntityGroupnewCreatorID - java.lang.Stringpublic void setDescription(java.lang.String newDescription)
setDescription in interface IEntityGroupnewDescription - java.lang.String
public void setLocalGroupService(IIndividualGroupService newIndividualGroupService)
throws GroupsException
IEntityGroup
setLocalGroupService in interface IEntityGroupnewIndividualGroupService - IIndividualGroupService
GroupsExceptionprivate void setMemberKeysInitialized(boolean newMemberKeysInitialized)
newMemberKeysInitialized - booleanprivate void setMemberEntityKeys(java.util.Set newMemberEntityKeys)
newMemberEntityKeys - Setprivate void setMemberGroupKeys(java.util.Set newMemberGroupKeys)
newMemberGroupKeys - Set
public void setName(java.lang.String newName)
throws GroupsException
setName in interface IEntityGroupnewName - java.lang.String
GroupsException
public void setServiceName(javax.naming.Name newServiceName)
throws GroupsException
GroupsExceptionpublic java.lang.String toString()
toString in class java.lang.Object
public void update()
throws GroupsException
update in interface IEntityGroupGroupsException - if the update cannot be performed.
public void updateMembers()
throws GroupsException
updateMembers in interface IEntityGroupGroupsException - if the update cannot be performed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||