Salome HOME
Copyrights update 2015.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / kernel / Role.java
1 package org.splat.dal.bo.kernel;
2 /**
3  * Class of objects representing the role of users.
4  * A role is named by an application-dependent string (reason why role names are not defined by an enumeration).
5  * A user may have several roles, user roles being stored into the database as a list of role names separated by a comma.
6  * 
7  * @see User
8  * @author    Daniel Brunier-Coulin
9  * @copyright OPEN CASCADE 2012-2015
10  */
11
12 import java.util.Vector;
13
14
15 public class Role {
16         
17     private String  username;
18     private String  role;
19
20 //  ==============================================================================================================================
21 //  Constructors
22 //  ==============================================================================================================================
23
24 //  Database fetch constructor
25     protected Role () {
26     }
27 //  Initialization constructor
28     protected Role (final String username, final String role) {
29 //  ---------------------------------------------
30       this.username = username;
31       this.role     = role;
32     }
33
34 //  ==============================================================================================================================
35 //  Protected member functions
36 //  ==============================================================================================================================
37
38     protected void addRole (final String role) {
39 //  ------------------------------------
40       this.role = this.role + "," + role;
41     }
42     
43     protected Role[] toArray () {
44 //  ---------------------------
45       String[]     name = role.split(",");
46       Vector<Role> role = new Vector<Role>();
47       
48       for (int i=0; i<name.length; i++) role.add(new Role(username, name[i]));
49       return role.toArray(new Role[name.length]);
50     }
51
52 //  ==============================================================================================================================
53 //  Public member functions
54 //  ==============================================================================================================================
55 //  In functions bellow, the role is supposed having previously been extracted as an array.
56
57     public String getName () {
58 //  ------------------------
59       return role;
60     }
61
62     public boolean is (final String name) {
63 //  -------------------------------
64       return  this.role.equals(name);
65     }
66
67     public boolean isSame (final Role other) {
68 //  ----------------------------------          
69       return  this.role.equals(other.role);
70     }
71     
72 }