public class Roleright
{
private static Hashtable rightlist = new Hashtable ();
/**
*<br> Method Description: Initializing Data
*<br> input Parameters:
*<br> return type:
*/
public void init ()
{
string[] accrolelist = {"Admin", "satrap", "manager", "User", "Guest"};
string[] rightcodelist = {"10001", "10011", "10021", "20011", "24011"};
for (int i=0;i<accrolelist.length;i++)
{
rightlist.put (Accrolelist[i],rightcodelist[i]);
}
}
/**
*<br> Method Description: Get the role permission code
*<br> input parameter: String accrole role name
*<br> return type: String permission code
*/
public String GetRight (string accrole)
{
if (Rightlist.containskey (accrole))
Return (String) rightlist.get (accrole);
Else
return null;
}
/**
*<br> Method Description: Add roles and code information
*<br> input parameter: String accrole role name
*<br> input parameter: String rightcode role Permission Code
*<br> return type: void (none)
*/
public void Insert (String accrole,string rightcode)
{
Rightlist.put (Accrole,rightcode);
}
/**
*<br> Method Description: Remove role Permissions
*<br> input parameter: String accrole role name
*<br> return type: void (none)
*/
public void Delete (String accrole)
{
if (Rightlist.containskey (accrole))
Rightlist.remove (Accrole);
}
/**
*<br> Method Description: Modify the role permission code
*<br> input parameter: String accrole role name
*<br> input parameter: String rightcode role Permission Code
*<br> return type: void (none)
*/
public void Update (String accrole,string rightcode)
{
//this.delete (Accrole);
This.insert (Accrole,rightcode);
}
/**
*<br> Method Description: Print the roles and code corresponding tables in the hash table
*<br> Input parameters: no
*<br> return type: No
*/
public void print ()
{
Enumeration Rlkey = Rightlist.keys ();
while (rlkey.hasmoreelements ())
{
String accrole = Rlkey.nextelement (). toString ();
print (accrole+ "=" +this.getright (accrole));
}
}
/**
*<br> Method Description: Print information (overload)
*<br> Input parameters: Object Opara printed information content
*<br> return type: No
*/
public void print (Object Opara)
{
System.out.println (Opara);
}
/**
*<br> Method Description: Main method,
*<br> input Parameters:
*<br> return type:
*/
public static void Main (string[] args)
{
roleright RR = new Roleright ();
Rr.init ();
Rr.print ();
rr.print ("___________________________");
Rr.insert ("Presider", "10110");
Rr.print ();
rr.print ("___________________________");
rr.update ("Presider", "10100");
Rr.print ();
rr.print ("___________________________");
rr.delete ("Presider");
Rr.print ();
}
}//end:) ~