Author: tv
Date: Fri Sep 7 14:34:42 2012
New Revision: 1382049
URL: http://svn.apache.org/viewvc?rev=1382049&view=rev
Log:
Fix generic return types
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/basic/BasicACLFactory.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicACLFactory.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractGroupManager.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractPermissionManager.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractRoleManager.java
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/basic/BasicACLFactory.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/basic/BasicACLFactory.java?rev=1382049&r1=1382048&r2=1382049&view=diff
==============================================================================
---
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/basic/BasicACLFactory.java
(original)
+++
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/basic/BasicACLFactory.java
Fri Sep 7 14:34:42 2012
@@ -27,9 +27,9 @@ import org.apache.fulcrum.security.util.
import org.apache.fulcrum.security.util.UnknownEntityException;
/**
- *
+ *
* This factory creates instance of the DynamicAccessControlList
- *
+ *
* @author <a href="mailto:[email protected]">Eric Pugh</a>
* @version $Id$
*/
@@ -37,49 +37,44 @@ public class BasicACLFactory extends Abs
{
/**
* Construct a new ACL object.
- *
+ *
* This constructs a new ACL object from the configured class and
* initializes it with the supplied roles and permissions.
- *
+ *
* @param roles
* The roles that this ACL should contain
* @param permissions
* The permissions for this ACL
- *
+ *
* @return an object implementing ACL interface.
* @throws UnknownEntityException
* if the object could not be instantiated.
*/
- private AccessControlList getAclInstance(GroupSet groupSet) throws
UnknownEntityException
+ private BasicAccessControlListImpl getAclInstance(GroupSet groupSet)
throws UnknownEntityException
{
- // Object[] objects = { groupSet};
- // String[] signatures = { GroupSet.class.getName()};
- AccessControlList accessControlList;
+ BasicAccessControlListImpl accessControlList;
+
try
{
- /*
- *
- * @todo I think this is overkill for now.. accessControlList =
- * (AccessControlList)
- * aclFactoryService.getInstance(aclClass.getName(), objects,
- * signatures);
- */
accessControlList = new BasicAccessControlListImpl(groupSet);
}
catch (Exception e)
{
throw new UnknownEntityException("Failed to instantiate an ACL
implementation object", e);
}
+
return accessControlList;
}
- public AccessControlList getAccessControlList(User user)
+ public <T extends AccessControlList> T getAccessControlList(User user)
{
GroupSet groupSet = ((BasicUser) user).getGroups();
try
{
- return getAclInstance(groupSet);
+ @SuppressWarnings("unchecked")
+ T aclInstance = (T) getAclInstance(groupSet);
+ return aclInstance;
}
catch (UnknownEntityException uue)
{
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicACLFactory.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicACLFactory.java?rev=1382049&r1=1382048&r2=1382049&view=diff
==============================================================================
---
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicACLFactory.java
(original)
+++
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicACLFactory.java
Fri Sep 7 14:34:42 2012
@@ -37,9 +37,9 @@ import org.apache.fulcrum.security.util.
import org.apache.fulcrum.security.util.UnknownEntityException;
/**
- *
+ *
* This factory creates instance of the DynamicAccessControlList
- *
+ *
* @author <a href="mailto:[email protected]">Eric Pugh </a>
* @author <a href="mailto:[email protected]">Ben Gidley </a>
* @version $Id$
@@ -49,7 +49,7 @@ public class DynamicACLFactory extends A
/**
* @see
org.apache.fulcrum.security.model.ACLFactory#getAccessControlList(org.apache.fulcrum.security.entity.User)
*/
- public AccessControlList getAccessControlList(User user)
+ public <T extends AccessControlList> T getAccessControlList(User user)
{
Map<Group, RoleSet> roleSets = new HashMap<Group, RoleSet>();
Map<Role, PermissionSet> permissionSets = new HashMap<Role,
PermissionSet>();
@@ -67,7 +67,9 @@ public class DynamicACLFactory extends A
try
{
- return getAclInstance(roleSets, permissionSets);
+ @SuppressWarnings("unchecked")
+ T aclInstance = (T) getAclInstance(roleSets,
permissionSets);
+ return aclInstance;
}
catch (UnknownEntityException uue)
{
@@ -77,35 +79,25 @@ public class DynamicACLFactory extends A
/**
* Construct a new ACL object.
- *
+ *
* This constructs a new ACL object from the configured class and
* initializes it with the supplied roles and permissions.
- *
+ *
* @param roles
* The roles that this ACL should contain
* @param permissions
* The permissions for this ACL
- *
+ *
* @return an object implementing ACL interface.
* @throws UnknownEntityException
* if the object could not be instantiated.
*/
- private AccessControlList getAclInstance(Map<? extends Group, ? extends
RoleSet> roles,
+ private DynamicAccessControlList getAclInstance(Map<? extends Group, ?
extends RoleSet> roles,
Map<? extends Role, ? extends PermissionSet> permissions) throws
UnknownEntityException
{
- AccessControlList accessControlList;
+ DynamicAccessControlList accessControlList;
try
{
- // Object[] objects = { roles, permissions };
- // String[] signatures = { Map.class.getName(), Map.class.getName()
- // };
- /*
- *
- * @todo I think this is overkill for now.. accessControlList =
- * (AccessControlList)
- * aclFactoryService.getInstance(aclClass.getName(), objects,
- * signatures);
- */
accessControlList = new DynamicAccessControlListImpl(roles,
permissions);
}
catch (Exception e)
@@ -117,7 +109,7 @@ public class DynamicACLFactory extends A
/**
* Add delegators to the user list
- *
+ *
* @param user
* the user to add to
* @param users
@@ -142,7 +134,7 @@ public class DynamicACLFactory extends A
* Adds the passed users roles and permissions to the sets As maps
overwrite
* duplicates we just put it in an let it overwrite it is probably quicker
* than checking for duplicates
- *
+ *
* @param user
* @param roleSets
* @param permissionSets
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java?rev=1382049&r1=1382048&r2=1382049&view=diff
==============================================================================
---
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java
(original)
+++
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java
Fri Sep 7 14:34:42 2012
@@ -30,7 +30,7 @@ import org.apache.fulcrum.security.util.
/**
* This is a control class that makes it easy to find out if a particular User
* has a given Permission. It also determines if a User has a a particular
Role.
- *
+ *
* @todo Need to rethink the two maps.. Why not just a single list of groups?
* That would then cascade down to all the other roles and so on..
* @author <a href="mailto:[email protected]">Eric Pugh</a>
@@ -57,7 +57,7 @@ public class DynamicAccessControlListImp
/**
* Constructs a new AccessControlList.
- *
+ *
* This class follows 'immutable' pattern - it's objects can't be modified
* once they are created. This means that the permissions the users have
are
* in effect form the moment they log in to the moment they log out, and
@@ -66,7 +66,7 @@ public class DynamicAccessControlListImp
* need to invalidate his session. <br>
* The objects that constructs an AccessControlList must supply hashtables
* of role/permission sets keyed with group objects. <br>
- *
+ *
* @param roleSets
* a hashtable containing RoleSet objects keyed with Group
* objects
@@ -97,7 +97,7 @@ public class DynamicAccessControlListImp
/**
* Retrieves a set of Roles an user is assigned in a Group.
- *
+ *
* @param group
* the Group
* @return the set of Roles this user has within the Group.
@@ -114,7 +114,7 @@ public class DynamicAccessControlListImp
/**
* Retrieves a set of Roles an user is assigned in the global Group.
- *
+ *
* @return the set of Roles this user has within the global Group.
*/
public RoleSet getRoles()
@@ -124,7 +124,7 @@ public class DynamicAccessControlListImp
/**
* Retrieves a set of Permissions an user is assigned in a Group.
- *
+ *
* @param group
* the Group
* @return the set of Permissions this user has within the Group.
@@ -147,7 +147,7 @@ public class DynamicAccessControlListImp
/**
* Retrieves a set of Permissions an user is assigned in the global Group.
- *
+ *
* @return the set of Permissions this user has within the global Group.
*/
public PermissionSet getPermissions()
@@ -157,7 +157,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Role in the Group.
- *
+ *
* @param role
* the Role
* @param group
@@ -176,7 +176,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Role in any of the given
Groups
- *
+ *
* @param role
* the Role
* @param groupset
@@ -204,7 +204,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Role in the Group.
- *
+ *
* @param role
* the Role
* @param group
@@ -235,7 +235,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Role in any of the given
Groups
- *
+ *
* @param rolename
* the name of the Role
* @param groupset
@@ -271,7 +271,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Role
- *
+ *
* @param role
* the Role
* @return <code>true</code> if the user is assigned the Role in the global
@@ -284,7 +284,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Role .
- *
+ *
* @param role
* the Role
* @return <code>true</code> if the user is assigned the Role .
@@ -303,7 +303,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Permission in the Group.
- *
+ *
* @param permission
* the Permission
* @param group
@@ -324,7 +324,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Permission in any of the given
* Groups
- *
+ *
* @param permission
* the Permission
* @param groupset
@@ -351,7 +351,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Permission in the Group.
- *
+ *
* @param permission
* the Permission
* @param group
@@ -373,7 +373,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Permission in the Group.
- *
+ *
* @param permission
* the Permission
* @param group
@@ -394,9 +394,9 @@ public class DynamicAccessControlListImp
}
/**
- * Checks if the user is assigned a specifie Permission in any of the given
+ * Checks if the user is assigned a specific Permission in any of the given
* Groups
- *
+ *
* @param permissionName
* the name of the Permission
* @param groupset
@@ -435,7 +435,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Permission.
- *
+ *
* @param permission
* the Permission
* @return <code>true</code> if the user is assigned the Permission .
@@ -447,7 +447,7 @@ public class DynamicAccessControlListImp
/**
* Checks if the user is assigned a specific Permission in the global
Group.
- *
+ *
* @param permission
* the Permission
* @return <code>true</code> if the user is assigned the Permission in the
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractGroupManager.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractGroupManager.java?rev=1382049&r1=1382048&r2=1382049&view=diff
==============================================================================
---
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractGroupManager.java
(original)
+++
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractGroupManager.java
Fri Sep 7 14:34:42 2012
@@ -28,63 +28,62 @@ import org.apache.fulcrum.security.util.
/**
* This implementation keeps all objects in memory. This is mostly meant to
help
* with testing and prototyping of ideas.
- *
+ *
* @author <a href="mailto:[email protected]">Eric Pugh</a>
* @version $Id$
*/
public abstract class AbstractGroupManager extends AbstractEntityManager
implements GroupManager
{
- protected abstract Group persistNewGroup(Group group) throws
DataBackendException;
+ protected abstract <T extends Group> T persistNewGroup(T group) throws
DataBackendException;
/**
* Construct a blank Group object.
- *
+ *
* This method calls getGroupClass, and then creates a new object using the
* default constructor.
- *
+ *
* @return an object implementing Group interface.
* @throws DataBackendException
* if the object could not be instantiated.
*/
- public Group getGroupInstance() throws DataBackendException
+ public <T extends Group> T getGroupInstance() throws DataBackendException
{
- Group group;
try
{
- group = (Group) Class.forName(getClassName()).newInstance();
+ @SuppressWarnings("unchecked")
+ T group = (T)
Class.forName(getClassName()).newInstance();
+ return group;
}
catch (Exception e)
{
throw new DataBackendException("Problem creating instance of class
" + getClassName(), e);
}
-
- return group;
}
/**
* Construct a blank Group object.
- *
+ *
* This method calls getGroupClass, and then creates a new object using the
* default constructor.
- *
+ *
* @param groupName
* The name of the Group
- *
+ *
* @return an object implementing Group interface.
- *
+ *
* @throws DataBackendException
* if the object could not be instantiated.
*/
- public Group getGroupInstance(String groupName) throws DataBackendException
+ public <T extends Group> T getGroupInstance(String groupName) throws
DataBackendException
{
- Group group = getGroupInstance();
+ T group = getGroupInstance();
group.setName(groupName);
return group;
}
/**
* Retrieve a Group object with specified name.
- *
+ *
* @param name
* the name of the Group.
* @return an object representing the Group with specified name.
@@ -93,9 +92,10 @@ public abstract class AbstractGroupManag
* @throws UnknownEntityException
* if the group does not exist.
*/
- public Group getGroupByName(String name) throws DataBackendException,
UnknownEntityException
+ public <T extends Group> T getGroupByName(String name) throws
DataBackendException, UnknownEntityException
{
- Group group = getAllGroups().getByName(name);
+ @SuppressWarnings("unchecked")
+ T group = (T) getAllGroups().getByName(name);
if (group == null)
{
throw new UnknownEntityException("The specified group does not
exist");
@@ -105,20 +105,21 @@ public abstract class AbstractGroupManag
/**
* Retrieve a Group object with specified Id.
- *
+ *
* @param name
* the name of the Group.
- *
+ *
* @return an object representing the Group with specified name.
- *
+ *
* @throws UnknownEntityException
* if the permission does not exist in the database.
* @throws DataBackendException
* if there is a problem accessing the storage.
*/
- public Group getGroupById(Object id) throws DataBackendException,
UnknownEntityException
+ public <T extends Group> T getGroupById(Object id) throws
DataBackendException, UnknownEntityException
{
- Group group = getAllGroups().getById(id);
+ @SuppressWarnings("unchecked")
+ T group = (T) getAllGroups().getById(id);
if (group == null)
{
throw new UnknownEntityException("The specified group does not
exist");
@@ -128,7 +129,7 @@ public abstract class AbstractGroupManag
/**
* Creates a new group with specified attributes.
- *
+ *
* @param group
* the object describing the group to be created.
* @return a new Group object that has id set up properly.
@@ -137,7 +138,7 @@ public abstract class AbstractGroupManag
* @throws EntityExistsException
* if the group already exists.
*/
- public synchronized Group addGroup(Group group) throws
DataBackendException, EntityExistsException
+ public synchronized <T extends Group> T addGroup(T group) throws
DataBackendException, EntityExistsException
{
boolean groupExists = false;
if (StringUtils.isEmpty(group.getName()))
@@ -163,9 +164,9 @@ public abstract class AbstractGroupManag
/**
* Check whether a specified group exists.
- *
+ *
* The name is used for looking up the group
- *
+ *
* @param role
* The group to be checked.
* @return true if the specified group exists
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractPermissionManager.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractPermissionManager.java?rev=1382049&r1=1382048&r2=1382049&view=diff
==============================================================================
---
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractPermissionManager.java
(original)
+++
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractPermissionManager.java
Fri Sep 7 14:34:42 2012
@@ -28,62 +28,62 @@ import org.apache.fulcrum.security.util.
/**
* This implementation keeps all objects in memory. This is mostly meant to
help
* with testing and prototyping of ideas.
- *
+ *
* @author <a href="mailto:[email protected]">Eric Pugh</a>
* @version $Id: AbstractPermissionManager.java 1372918 2012-08-14 15:19:40Z tv
* $
*/
public abstract class AbstractPermissionManager extends AbstractEntityManager
implements PermissionManager
{
- protected abstract Permission persistNewPermission(Permission permission)
throws DataBackendException;
+ protected abstract <T extends Permission> T persistNewPermission(T
permission) throws DataBackendException;
/**
* Construct a blank Permission object.
- *
+ *
* This method calls getPermissionClass, and then creates a new object
using
* the default constructor.
- *
+ *
* @return an object implementing Permission interface.
* @throws UnknownEntityException
* if the object could not be instantiated.
*/
- public Permission getPermissionInstance() throws UnknownEntityException
+ public <T extends Permission> T getPermissionInstance() throws
UnknownEntityException
{
- Permission permission;
try
{
- permission = (Permission)
Class.forName(getClassName()).newInstance();
+ @SuppressWarnings("unchecked")
+ T permission = (T)
Class.forName(getClassName()).newInstance();
+ return permission;
}
catch (Exception e)
{
throw new UnknownEntityException("Failed to instantiate a
Permission implementation object", e);
}
- return permission;
}
/**
* Construct a blank Permission object.
- *
+ *
* This method calls getPermissionClass, and then creates a new object
using
* the default constructor.
- *
+ *
* @param permName
* The name of the permission.
- *
+ *
* @return an object implementing Permission interface.
* @throws UnknownEntityException
* if the object could not be instantiated.
*/
- public Permission getPermissionInstance(String permName) throws
UnknownEntityException
+ public <T extends Permission> T getPermissionInstance(String permName)
throws UnknownEntityException
{
- Permission perm = getPermissionInstance();
+ T perm = getPermissionInstance();
perm.setName(permName);
return perm;
}
/**
* Retrieve a Permission object with specified name.
- *
+ *
* @param name
* the name of the Permission.
* @return an object representing the Permission with specified name.
@@ -92,9 +92,10 @@ public abstract class AbstractPermission
* @throws UnknownEntityException
* if the permission does not exist.
*/
- public Permission getPermissionByName(String name) throws
DataBackendException, UnknownEntityException
+ public <T extends Permission> T getPermissionByName(String name) throws
DataBackendException, UnknownEntityException
{
- Permission permission = getAllPermissions().getByName(name);
+ @SuppressWarnings("unchecked")
+ T permission = (T) getAllPermissions().getByName(name);
if (permission == null)
{
throw new UnknownEntityException("The specified permission does
not exist");
@@ -104,20 +105,21 @@ public abstract class AbstractPermission
/**
* Retrieve a Permission object with specified Id.
- *
+ *
* @param name
* the name of the Permission.
- *
+ *
* @return an object representing the Permission with specified name.
- *
+ *
* @throws UnknownEntityException
* if the permission does not exist in the database.
* @throws DataBackendException
* if there is a problem accessing the storage.
*/
- public Permission getPermissionById(Object id) throws
DataBackendException, UnknownEntityException
+ public <T extends Permission> T getPermissionById(Object id) throws
DataBackendException, UnknownEntityException
{
- Permission permission = getAllPermissions().getById(id);
+ @SuppressWarnings("unchecked")
+ T permission = (T) getAllPermissions().getById(id);
if (permission == null)
{
throw new UnknownEntityException("The specified permission does
not exist");
@@ -127,7 +129,7 @@ public abstract class AbstractPermission
/**
* Creates a new permission with specified attributes.
- *
+ *
* @param permission
* the object describing the permission to be created.
* @return a new Permission object that has id set up properly.
@@ -136,7 +138,7 @@ public abstract class AbstractPermission
* @throws EntityExistsException
* if the permission already exists.
*/
- public synchronized Permission addPermission(Permission permission) throws
DataBackendException, EntityExistsException
+ public synchronized <T extends Permission> T addPermission(T permission)
throws DataBackendException, EntityExistsException
{
boolean permissionExists = false;
if (StringUtils.isEmpty(permission.getName()))
@@ -165,10 +167,10 @@ public abstract class AbstractPermission
}
/**
- * Check whether a specifieds permission exists.
- *
+ * Check whether a specified permission exists.
+ *
* The name is used for looking up the permission
- *
+ *
* @param role
* The permission to be checked.
* @return true if the specified permission exists
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractRoleManager.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractRoleManager.java?rev=1382049&r1=1382048&r2=1382049&view=diff
==============================================================================
---
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractRoleManager.java
(original)
+++
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractRoleManager.java
Fri Sep 7 14:34:42 2012
@@ -26,66 +26,65 @@ import org.apache.fulcrum.security.util.
import org.apache.fulcrum.security.util.UnknownEntityException;
/**
- *
+ *
* This implementation keeps all objects in memory. This is mostly meant to
help
* with testing and prototyping of ideas.
- *
+ *
* @author <a href="mailto:[email protected]">Eric Pugh</a>
* @version $Id$
*/
public abstract class AbstractRoleManager extends AbstractEntityManager
implements RoleManager
{
- protected abstract Role persistNewRole(Role role) throws
DataBackendException;
+ protected abstract <T extends Role> T persistNewRole(T role) throws
DataBackendException;
/**
* Construct a blank Role object.
- *
+ *
* This method calls getRoleClass, and then creates a new object using the
* default constructor.
- *
+ *
* @return an object implementing Role interface.
* @throws DataBackendException
* if the object could not be instantiated.
*/
- public Role getRoleInstance() throws DataBackendException
+ public <T extends Role> T getRoleInstance() throws DataBackendException
{
- Role role;
try
{
- role = (Role) Class.forName(getClassName()).newInstance();
+ @SuppressWarnings("unchecked")
+ T role = (T)
Class.forName(getClassName()).newInstance();
+ return role;
}
catch (Exception e)
{
throw new DataBackendException("Problem creating instance of class
" + getClassName(), e);
}
-
- return role;
}
/**
* Construct a blank Role object.
- *
+ *
* This method calls getRoleClass, and then creates a new object using the
* default constructor.
- *
+ *
* @param roleName
* The name of the role.
- *
+ *
* @return an object implementing Role interface.
- *
+ *
* @throws DataBackendException
* if the object could not be instantiated.
*/
- public Role getRoleInstance(String roleName) throws DataBackendException
+ public <T extends Role> T getRoleInstance(String roleName) throws
DataBackendException
{
- Role role = getRoleInstance();
+ T role = getRoleInstance();
role.setName(roleName);
return role;
}
/**
* Retrieve a Role object with specified name.
- *
+ *
* @param name
* the name of the Role.
* @return an object representing the Role with specified name.
@@ -94,9 +93,10 @@ public abstract class AbstractRoleManage
* @throws UnknownEntityException
* if the role does not exist.
*/
- public Role getRoleByName(String name) throws DataBackendException,
UnknownEntityException
+ public <T extends Role> T getRoleByName(String name) throws
DataBackendException, UnknownEntityException
{
- Role role = getAllRoles().getByName(name);
+ @SuppressWarnings("unchecked")
+ T role = (T) getAllRoles().getByName(name);
if (role == null)
{
throw new UnknownEntityException("The specified role does not
exist");
@@ -106,20 +106,21 @@ public abstract class AbstractRoleManage
/**
* Retrieve a Role object with specified Id.
- *
+ *
* @param name
* the name of the Role.
- *
+ *
* @return an object representing the Role with specified name.
- *
+ *
* @throws UnknownEntityException
* if the permission does not exist in the database.
* @throws DataBackendException
* if there is a problem accessing the storage.
*/
- public Role getRoleById(Object id) throws DataBackendException,
UnknownEntityException
+ public <T extends Role> T getRoleById(Object id) throws
DataBackendException, UnknownEntityException
{
- Role role = getAllRoles().getById(id);
+ @SuppressWarnings("unchecked")
+ T role = (T) getAllRoles().getById(id);
if (role == null)
{
throw new UnknownEntityException("The specified role does not
exist");
@@ -129,7 +130,7 @@ public abstract class AbstractRoleManage
/**
* Creates a new role with specified attributes.
- *
+ *
* @param role
* the object describing the role to be created.
* @return a new Role object that has id set up properly.
@@ -138,7 +139,7 @@ public abstract class AbstractRoleManage
* @throws EntityExistsException
* if the role already exists.
*/
- public synchronized Role addRole(Role role) throws DataBackendException,
EntityExistsException
+ public synchronized <T extends Role> T addRole(T role) throws
DataBackendException, EntityExistsException
{
boolean roleExists = false;
if (StringUtils.isEmpty(role.getName()))
@@ -169,9 +170,9 @@ public abstract class AbstractRoleManage
/**
* Check whether a specified role exists.
- *
+ *
* The name is used for looking up the role
- *
+ *
* @param role
* The role to be checked.
* @return true if the specified role exists
@@ -182,5 +183,4 @@ public abstract class AbstractRoleManage
{
return checkExists(role.getName());
}
-
}