1 package org.splat.service.dto;
3 import java.util.ArrayList;
7 * DTO for keeping roles of a user.
11 public class RoleDTO {
16 private transient String _username;
22 // ==============================================================================================================================
24 // ==============================================================================================================================
27 * Bean replication constructor.
30 // Bean replication constructor
34 * Initialization constructor.
35 * @param username user name
36 * @param role role name
38 protected RoleDTO(final String username, final String role) {
39 this._username = username;
43 // ==============================================================================================================================
44 // Protected member functions
45 // ==============================================================================================================================
49 * @param role the role to add
51 protected void addRole(final String role) {
52 this._name = this._name + "," + role;
56 * Get roles as an array of separate DTOs.
57 * @return array of roles
59 protected RoleDTO[] toArray() {
60 String[] name = _name.split(",");
61 List<RoleDTO> role = new ArrayList<RoleDTO>();
63 for (int i = 0; i < name.length; i++) {
64 role.add(new RoleDTO(_username, name[i]));
66 return role.toArray(new RoleDTO[name.length]);
69 // ==============================================================================================================================
70 // Public member functions
71 // ==============================================================================================================================
72 // In functions below, the role is supposed having previously been extracted as an array.
74 public String getName() {
78 public void setName(final String name) {
82 public boolean is(final String name) {
83 return this._name.equals(name);
86 public boolean isSame(final RoleDTO other) {
87 return this._name.equals(other._name);