1 package org.splat.dal.bo.kernel;
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.
8 * @author Daniel Brunier-Coulin
9 * @copyright OPEN CASCADE 2012
12 import java.util.Vector;
17 private String username;
20 // ==============================================================================================================================
22 // ==============================================================================================================================
24 // Database fetch constructor
27 // Initialization constructor
28 protected Role (String username, String role) {
29 // ---------------------------------------------
30 this.username = username;
34 // ==============================================================================================================================
35 // Protected member functions
36 // ==============================================================================================================================
38 protected void addRole (String role) {
39 // ------------------------------------
40 this.role = this.role + "," + role;
43 protected Role[] toArray () {
44 // ---------------------------
45 String[] name = role.split(",");
46 Vector<Role> role = new Vector<Role>();
48 for (int i=0; i<name.length; i++) role.add(new Role(username, name[i]));
49 return role.toArray(new Role[name.length]);
52 // ==============================================================================================================================
53 // Public member functions
54 // ==============================================================================================================================
55 // In functions bellow, the role is supposed having previously been extracted as an array.
57 public String getName () {
58 // ------------------------
62 public boolean is (String name) {
63 // -------------------------------
64 return this.role.equals(name);
67 public boolean isSame (Role other) {
68 // ----------------------------------
69 return this.role.equals(other.role);