]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/service/dto/RoleDTO.java
Salome HOME
Update copyrights 2014.
[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          * 
36          * @param username
37          *            user name
38          * @param role
39          *            role name
40          */
41         protected RoleDTO(final String username, final String role) {
42                 this._username = username;
43                 this._name = role;
44         }
45
46         // ==============================================================================================================================
47         // Protected member functions
48         // ==============================================================================================================================
49
50         /**
51          * Add a role.
52          * 
53          * @param role
54          *            the role to add
55          */
56         protected void addRole(final String role) {
57                 this._name = this._name + "," + role;
58         }
59
60         /**
61          * Get roles as an array of separate DTOs.
62          * 
63          * @return array of roles
64          */
65         protected RoleDTO[] toArray() {
66                 String[] name = _name.split(",");
67                 List<RoleDTO> role = new ArrayList<RoleDTO>();
68
69                 for (int i = 0; i < name.length; i++) {
70                         role.add(new RoleDTO(_username, name[i]));
71                 }
72                 return role.toArray(new RoleDTO[name.length]);
73         }
74
75         // ==============================================================================================================================
76         // Public member functions
77         // ==============================================================================================================================
78         // In functions below, the role is supposed having previously been extracted as an array.
79
80         /**
81          * Get role name.
82          * 
83          * @return the role name
84          */
85         public String getName() {
86                 return _name;
87         }
88
89         /**
90          * Set role name.
91          * 
92          * @param name
93          *            the role name to set
94          */
95         public void setName(final String name) {
96                 _name = name;
97         }
98 }