KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > web > security > impl > RoleImpl


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package web.security.impl;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import web.security.Privilege;
23 import web.security.Role;
24
25
26 /**
27  * 角色的实现类
28  * @author liudong
29  */

30 public class RoleImpl implements Role, Serializable JavaDoc {
31
32     protected List JavaDoc privileges;
33     protected String JavaDoc name;
34     protected String JavaDoc desc;
35     
36     public RoleImpl(){
37         this(null,null);
38     }
39     
40     public RoleImpl(String JavaDoc name, String JavaDoc desc){
41         this.name = name;
42         this.desc = desc;
43         this.privileges = new Vector JavaDoc();
44     }
45
46     /* (non-Javadoc)
47      * @see com.clickcom.web.security.Role#privileges()
48      */

49     public Privilege[] privileges() {
50         if(privileges==null)
51             return null;
52         return (Privilege[])privileges.toArray(new Privilege[privileges.size()]);
53     }
54     
55     /* (non-Javadoc)
56      * @see com.clickcom.web.security.Role#canDo(com.clickcom.web.security.Privilege)
57      */

58     public boolean canDo(Privilege pvg) {
59         for(int i=0;privileges!=null&&i<privileges.size();i++){
60             Privilege p = (Privilege)privileges.get(i);
61             boolean bEqual = p.equals(pvg);
62             //System.out.println(getClass().getName()+"("+name+"): " + p.getResource()+","+p.getOperation()+","+p.getRange()+","+bEqual);
63
if(bEqual)
64                 return true;
65             break;
66         }
67         return false;
68     }
69
70     /* (non-Javadoc)
71      * @see com.clickcom.web.security.Role#getName()
72      */

73     public String JavaDoc getName() {
74         return name;
75     }
76
77     /* (non-Javadoc)
78      * @see com.clickcom.web.security.Role#getDesc()
79      */

80     public String JavaDoc getDesc() {
81         return desc;
82     }
83
84     public void setDesc(String JavaDoc desc) {
85         this.desc = desc;
86     }
87     public void setName(String JavaDoc name) {
88         this.name = name;
89     }
90
91     public List JavaDoc getPrivileges() {
92         return privileges;
93     }
94     public void setPrivileges(List JavaDoc privileges) {
95         this.privileges = privileges;
96     }
97     public String JavaDoc toString() {
98         return "ROLE:("+name+','+desc+')';
99     }
100 }
101
Popular Tags