Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/clra/member/MemberRole.java


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: MemberRole.java,v $
5    * $Date: 2003/03/01 00:45:14 $
6    * $Revision: 1.8 $
7    */
8   
9   package com.clra.member;
10  
11  import java.io.Serializable;
12  
13  /**
14   * Encapsulates information about the role of a member within the club.
15   * A member's roles determine his or her access rights. For example, a
16   * treasurer or a member-manager may update the account information of other
17   * members, but they can not create or edit rowing sessions. Conversely,
18   * a captain or a coach may create and edit rowing sessions, but they can
19   * not update the account information of other members. If a member has no
20   * roles, the member has no access rights to the website.
21   * @version $Revision: 1.8 $ $Date: 2003/03/01 00:45:14 $
22   * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
23   */
24  public class MemberRole implements Serializable {
25  
26    /** The default group for member roles */
27    public final static String ROLEGROUP_ROLES = "Roles"; // case set by JAAS
28  
29    /** Designates the  default role for active members */
30    public final static String ROLE_MEMBER = "MEMBER";
31  
32    /** Designates a member who can assign boatings */
33    public final static String ROLE_COACH = "COACH";
34  
35    /** Designates a member who is in charge of club operations */
36    public final static String ROLE_CAPTAIN = "CAPTAIN";
37  
38    /** Designates a member who takes attendance */
39    public final static String ROLE_SESSIONMGR = "SESSIONMGR";
40  
41    /** Designates a member who is in charge of invoicing */
42    public final static String ROLE_TREASURER = "TREASURER";
43  
44    /** Designates a member who assigns roles to other members */
45    public final static String ROLE_MEMBERMGR = "MEMBERMGR";
46  
47    /** The default role for members */
48    public final static MemberRole MEMBER =
49        new MemberRole( ROLE_MEMBER, ROLEGROUP_ROLES );
50  
51    /** The role of a member who can assign boatings */
52    public final static MemberRole COACH =
53        new MemberRole( ROLE_COACH, ROLEGROUP_ROLES );
54  
55    /** The role of a member who is in charge of club operations */
56    public final static MemberRole CAPTAIN =
57        new MemberRole( ROLE_CAPTAIN, ROLEGROUP_ROLES );
58  
59    /** The role of a member who takes attendance */
60    public final static MemberRole SESSIONMGR =
61        new MemberRole( ROLE_SESSIONMGR, ROLEGROUP_ROLES );
62  
63    /** The role of a member who is in charge of invoicing */
64    public final static MemberRole TREASURER =
65        new MemberRole( ROLE_TREASURER, ROLEGROUP_ROLES );
66  
67    /** The role of a member who assigns roles to other members */
68    public final static MemberRole MEMBERMGR =
69        new MemberRole( ROLE_MEMBERMGR, ROLEGROUP_ROLES );
70  
71    public final static String[] ALLOWED_ROLES() {
72      return new String[] {
73        ROLE_MEMBER,
74        ROLE_COACH,
75        ROLE_CAPTAIN,
76        ROLE_SESSIONMGR,
77        ROLE_TREASURER,
78        ROLE_MEMBERMGR
79      };
80    }
81  
82    public final static String[] ALLOWED_ROLEGROUPS() {
83      return new String[] {
84        ROLEGROUP_ROLES
85      };
86    }
87  
88    /** The role of the Member */
89    private final String role;
90  
91    /** The JAAS-related group of the role */
92    private final String roleGroup;
93  
94    /** Creates a role in the default role group */
95    public MemberRole( String role ) {
96      this( role, ROLEGROUP_ROLES );
97    }
98  
99    /** Creates a role in the specified role group */
100   public MemberRole( String role, String roleGroup ) {
101     // Preconditions
102     if ( role == null ) {
103       throw new IllegalArgumentException( "null role" );
104     }
105     if ( roleGroup == null ) {
106       throw new IllegalArgumentException( "null role group" );
107     }
108     role = role.trim().toUpperCase();
109 
110     // Must be case-sensitive comparison for roleGroup
111     roleGroup = roleGroup.trim();
112 
113     boolean isOK = false;
114     String[] ALLOWED = ALLOWED_ROLES();
115     for ( int i=0; i<ALLOWED.length; i++ ) {
116       if ( ALLOWED[i].equals(role) ) {
117         isOK = true;
118         break;
119       }
120     }
121     if ( !isOK ) {
122       throw new IllegalArgumentException( "invalid role == " + role );
123     }
124 
125     isOK = false;
126     ALLOWED = ALLOWED_ROLEGROUPS();
127     for ( int i=0; i<ALLOWED.length; i++ ) {
128       // Must be case-sensitive comparison
129       if ( ALLOWED[i].equals(roleGroup) ) {
130         isOK = true;
131         break;
132       }
133     }
134     if ( !isOK ) {
135       throw new IllegalArgumentException( "invalid roleGroup == " + roleGroup );
136     }
137 
138     this.role = role;
139     this.roleGroup = roleGroup;
140 
141   } // ctor(String,String)
142 
143   public String getRole() {
144     return this.role;
145   }
146 
147   public String getRoleGroup() {
148     return this.roleGroup;
149   }
150 
151   public String toString() {
152     return this.role;
153   }
154 
155   /** For now, string comparison assume the default group */
156   public boolean equals( Object o ) {
157     boolean retVal;
158     if ( o == null ) {
159       retVal = false;
160     }
161     else if ( o instanceof MemberRole ) {
162       MemberRole that = (MemberRole) o;
163       retVal = this.role.equalsIgnoreCase( that.role );
164       retVal = retVal && this.roleGroup.equalsIgnoreCase( that.roleGroup );
165     }
166     else {
167       retVal = false;
168     }
169 
170     return retVal;
171   } // equals(Object)
172 
173   public int hashCode() {
174     int retVal = this.role.trim().toUpperCase().hashCode();
175     retVal += this.roleGroup.trim().toUpperCase().hashCode();
176     return retVal;
177   }
178 
179 } // MemberRole
180 
181 /*
182  * $Log: MemberRole.java,v $
183  * Revision 1.8  2003/03/01 00:45:14  rphall
184  * Removed no-param default constructor
185  *
186  * Revision 1.7  2003/02/28 14:05:50  rphall
187  * Added default constructor so that class could be used as a Java bean
188  *
189  * Revision 1.6  2003/02/26 03:38:45  rphall
190  * Added copyright and GPL license
191  *
192  * Revision 1.5  2003/02/21 05:01:17  rphall
193  * Made RoleGroup case-sensitive
194  *
195  * Revision 1.4  2003/02/19 22:26:39  rphall
196  * Removed gratuitous use of CLRA acronym
197  *
198  * Revision 1.3  2003/02/16 00:43:57  rphall
199  * Fixed bug in constructor
200  *
201  * Revision 1.2  2003/02/15 04:31:42  rphall
202  * Changes connected to major revision of MemberBean
203  *
204  */
205