View Javadoc

1   /***
2    * User.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2003 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.permissioning;
27  
28  import java.util.HashSet;
29  import java.util.Hashtable;
30  
31  import org.jcreme.enumerations.Enumeration;
32  
33  /***
34   * This defines the users of a system. Each user is assigned business roles.
35   * These roles will define what actions can be carried on.
36   * 
37   * @author $Author: dbregeon $
38   * @version $Revision: 1.1 $
39   */
40  public class User extends Enumeration {
41      protected static final Hashtable fromName = new Hashtable();
42  
43      protected String fullName = null;
44  
45      protected HashSet roles = new HashSet();
46  
47      protected User(String name) {
48          super(name);
49      }
50  
51      public void setFullName(String s) {
52          this.fullName = s;
53      }
54  
55      public String getFullName() {
56          return this.fullName;
57      }
58  
59      public void addRole(Role r) {
60          if (r != null) {
61              this.roles.add(r);
62          }
63      }
64  
65      public void removeRole(Role r) {
66          if (r != null) {
67              this.roles.remove(r);
68          }
69      }
70  
71      public Role[] getRoles() {
72          return (Role[]) this.roles.toArray(new Role[0]);
73      }
74  
75      public boolean hasRole(Role r) {
76          return (r != null) && (this.roles.contains(r));
77      }
78  
79      /***
80       * @see org.jcreme.enumerations.Enumeration#getFromName()
81       */
82      protected Hashtable getFromName() {
83          return fromName;
84      }
85  
86      public static User[] getUsers() {
87          return (User[]) fromName.values().toArray(new User[0]);
88      }
89  
90      public static Enumeration[] getValues() {
91          return (Enumeration[]) fromName.values().toArray(new Enumeration[0]);
92      }
93  
94  }