?? rights.java
字號:
package src.com;
import java.util.*;
/**
全局的類,存放所有的role的operationIds
*/
public class Rights {
private Vector roles; // 其每一個元素也是一個vector, 內(nèi)容如下:
// RoleId1, operationId11, operationId12, operationId13, operationId14, ...
// RoleId2, operationId21, operationId22, operationId23, operationId24, ...
// RoleId3, operationId31, operationId32, operationId33, operationId34, ...
public boolean isLoaded;
public Rights(){
roles = new Vector(30, 1);
isLoaded = false;
/************for test begin***************
addRoleRight(1, 20201);
addRoleRight(1, 20401);
addRoleRight(1, 20400);
deleteRole(1);
addRoleRight(1, 20201);
addRoleRight(1, 20401);
************for test end***************/
}
public void addRoleRight(int roleId, int operationId) {
if (isLoaded == false)
isLoaded = true;
Vector operationIds;
// 找出已有的role
for (int i = 0 ; i < roles.size() ; i ++)
{
operationIds = (Vector)roles.elementAt(i);
if ( ((Integer)operationIds.elementAt(0)).intValue() == roleId )
{
operationIds.addElement(new Integer(operationId));
return;
}
}
operationIds = new Vector(20,2);
operationIds.addElement(new Integer(roleId));
operationIds.addElement(new Integer(operationId));
roles.addElement(operationIds);
}
public boolean hasRights(int roleId, int operationId) {
Vector operationIds;
// 找出已有的role
for (int i = 0 ; i < roles.size() ; i ++)
{
operationIds = (Vector)roles.elementAt(i);
if ( ((Integer)operationIds.elementAt(0)).intValue() == roleId )
{
for (int j = 1 ; j < operationIds.size() ; j ++) {
if ( ((Integer)operationIds.elementAt(j)).intValue() == operationId )
return true;
}
}
}
return false;
}
public void deleteRole(int roleId) {
Vector operationIds;
// 找出已有的role
for (int i = 0 ; i < roles.size() ; i ++)
{
operationIds = (Vector)roles.elementAt(i);
if ( ((Integer)operationIds.elementAt(0)).intValue() == roleId )
{
operationIds.removeAllElements();
roles.removeElementAt(i) ;
return;
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -