⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rights.java

📁 (Java+SQL)-大型企业JAVA的ERP系统
💻 JAVA
字号:
package src.com;

import java.util.*;
/**
全局的类,存放所有的role的operationIds
*/

public class Rights {
	private Vector roles; // 其每一个元素也是一个vector, 内容如下:
// 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;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -