]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/service/dto/RoleDTO.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / dto / RoleDTO.java
1 package org.splat.service.dto;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 /**
7  * DTO for keeping roles of a user.
8  * 
9  * @see UserDTO
10  */
11 public class RoleDTO {
12
13         /**
14          * User name.
15          */
16         private transient String _username;
17         /**
18          * Roles names.
19          */
20         private String _name;
21
22         // ==============================================================================================================================
23         // Constructors
24         // ==============================================================================================================================
25
26         /**
27          * Bean replication constructor.
28          */
29         protected RoleDTO() {
30                 // Bean replication constructor
31         }
32
33         /**
34          * Initialization constructor.
35          * @param username user name
36          * @param role role name
37          */
38         protected RoleDTO(final String username, final String role) {
39                 this._username = username;
40                 this._name = role;
41         }
42
43         // ==============================================================================================================================
44         // Protected member functions
45         // ==============================================================================================================================
46
47         /**
48          * Add a role.
49          * @param role the role to add
50          */
51         protected void addRole(final String role) {
52                 this._name = this._name + "," + role;
53         }
54
55         /**
56          * Get roles as an array of separate DTOs.
57          * @return array of roles
58          */
59         protected RoleDTO[] toArray() {
60                 String[] name = _name.split(",");
61                 List<RoleDTO> role = new ArrayList<RoleDTO>();
62
63                 for (int i = 0; i < name.length; i++) {
64                         role.add(new RoleDTO(_username, name[i]));
65                 }
66                 return role.toArray(new RoleDTO[name.length]);
67         }
68
69         // ==============================================================================================================================
70         // Public member functions
71         // ==============================================================================================================================
72         // In functions below, the role is supposed having previously been extracted as an array.
73
74         public String getName() {
75                 return _name;
76         }
77
78         public void setName(final String name) {
79                 _name = name;
80         }
81
82         public boolean is(final String name) {
83                 return this._name.equals(name);
84         }
85
86         public boolean isSame(final RoleDTO other) {
87                 return this._name.equals(other._name);
88         }
89 }