KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > server > Sync4jUser


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.server;
20
21 import java.io.Serializable JavaDoc;
22 import org.apache.commons.lang.builder.ToStringBuilder;
23
24 /**
25  * This class represents a user with username and password and a list of roles.
26  *
27  * @author Luigia Fassina @ Funambol
28  *
29  * @version $Id: Sync4jUser.java,v 1.4 2005/03/02 20:57:38 harrie Exp $
30  *
31  */

32 public class Sync4jUser implements Serializable JavaDoc {
33
34     private String JavaDoc username;
35     private String JavaDoc password;
36     private String JavaDoc email;
37     private String JavaDoc firstname;
38     private String JavaDoc lastname;
39     private String JavaDoc[] roles;
40
41     /** Creates a new instance of Sync4jUser */
42     public Sync4jUser() {
43         this(null, null, null, null, null, null);
44     }
45
46     public Sync4jUser(String JavaDoc username ,
47                       String JavaDoc password ,
48                       String JavaDoc email ,
49                       String JavaDoc firstname,
50                       String JavaDoc lastname ,
51                       String JavaDoc[] roles) {
52         this.username = username;
53         this.password = password;
54         this.email = email;
55         this.firstname = firstname;
56         this.lastname = lastname;
57         this.roles = roles;
58     }
59
60     /**
61      * Getter for property username.
62      * @return Value of property username.
63      */

64     public String JavaDoc getUsername() {
65         return username;
66     }
67
68     /**
69      * Setter for property username.
70      * @param username New value of property username.
71      */

72     public void setUsername(String JavaDoc username) {
73         this.username = username;
74     }
75
76     /**
77      * Getter for property password.
78      * @return Value of property password.
79      */

80     public String JavaDoc getPassword() {
81         return password;
82     }
83
84     /**
85      * Setter for property password.
86      * @param password New value of property password.
87      */

88     public void setPassword(String JavaDoc password) {
89         this.password = password;
90     }
91
92     /**
93      * Getter for property email.
94      * @return Value of property email.
95      */

96     public String JavaDoc getEmail() {
97         return email;
98     }
99
100     /**
101      * Setter for property email.
102      * @param email New value of property email.
103      */

104     public void setEmail(String JavaDoc email) {
105         this.email = email;
106     }
107
108     /**
109      * Getter for property firstname.
110      * @return Value of property firstname.
111      */

112     public String JavaDoc getFirstname() {
113         return firstname;
114     }
115
116     /**
117      * Setter for property firstname.
118      * @param firstname New value of property firstname.
119      */

120     public void setFirstname(String JavaDoc firstname) {
121         this.firstname = firstname;
122     }
123
124     /**
125      * Getter for property lastname.
126      * @return Value of property lastname.
127      */

128     public String JavaDoc getLastname() {
129         return lastname;
130     }
131
132     /**
133      * Setter for property lastname.
134      * @param lastname New value of property lastname.
135      */

136     public void setLastname(String JavaDoc lastname) {
137         this.lastname = lastname;
138     }
139
140     /**
141      * Getter for property roles.
142      * @return Value of property roles.
143      */

144     public String JavaDoc[] getRoles() {
145         return roles;
146     }
147     
148     /**
149      * Has the user the given role?
150      *
151      * @param role the role to check
152      *
153      * @return <i>true</i> if the user has the role <i>role</i> or <i>false</i> otherwise.
154      */

155     public boolean hasRole(final String JavaDoc role) {
156         for (int i=0; (roles != null) && (i<roles.length); ++i) {
157             if (roles[i].equals(role)) {
158                 return true;
159             }
160         }
161         
162         return false;
163     }
164
165     /**
166      * Setter for property roles.
167      * @param roles New value of property roles.
168      */

169     public void setRoles(String JavaDoc[] roles) {
170         this.roles = roles;
171     }
172
173     public String JavaDoc toString() {
174         ToStringBuilder sb = new ToStringBuilder(this);
175
176         sb.append("username:", username);
177         sb.append("email:", email);
178         sb.append("firstname:", firstname);
179         sb.append("lastname:", lastname);
180
181         return sb.toString();
182     }
183
184 }
185
Popular Tags