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

Quick Search    Search Deep

Source code: com/clra/web/MemberView.java


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: MemberView.java,v $
5    * $Date: 2003/03/13 04:51:50 $
6    * $Revision: 1.11 $
7    */
8   
9   package com.clra.web;
10  
11  import com.clra.member.Address;
12  import com.clra.member.MemberException;
13  import com.clra.member.MemberSnapshot;
14  import com.clra.member.MemberName;
15  import com.clra.member.Telephone;
16  import com.clra.util.DBConfiguration;
17  import com.clra.util.INamed;
18  import com.clra.util.ValidationException;
19  import java.io.Serializable;
20  import java.util.Date;
21  import java.util.Map;
22  import java.util.Calendar;
23  import java.text.*;
24  
25  /**
26   * Read-only information about a member. This is a thin wrapper around
27   * MemberSnapshot. The class exists so that some logic can be pulled
28   * out of the memberlist.jsp screen.
29   *
30   * @version $Id: MemberView.java,v 1.11 2003/03/13 04:51:50 rphall Exp $
31   * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
32   */
33  public class MemberView implements INamed, Comparable, Serializable {
34  
35    private MemberNameFormat memberNameFormat = MemberNameFormat.FIRSTLAST;
36    private MemberSnapshot snapshot = null;
37  
38    /** Produces an invalid MemberView. Used only during deserialization */
39    public MemberView() {}
40  
41    public MemberView( MemberSnapshot snapshot ) {
42      if ( snapshot == null ) {
43        throw new IllegalArgumentException( "null snapshot" );
44      }
45      this.snapshot = snapshot;
46    }
47  
48    /** Returns the format used by <tt>getName()</tt> */
49    public MemberNameFormat getMemberNameFormat() {
50      return this.memberNameFormat;
51    }
52  
53    /** Sets the format used by <tt>getName()</tt> */
54    public void setMemberNameFormat( MemberNameFormat memberNameFormat ) {
55      if ( memberNameFormat == null ) {
56        throw new IllegalArgumentException( "null member-name format" );
57      }
58      this.memberNameFormat = memberNameFormat;
59    }
60  
61    /**
62     * Returns a String presentation of a member's name, formatted
63     * according to <tt>getMemberNameFormat()</tt>.
64     */
65    public String getName() {
66      return this.getMemberNameFormat().format(this.snapshot.getMemberName());
67    }
68  
69    public Integer getId() {
70      return this.snapshot.getId();
71    }
72  
73    public String getAccountName() {
74      return this.snapshot.getAccountName();
75    }
76  
77    public String getAccountPassword() {
78      return this.snapshot.getAccountPassword();
79    }
80  
81    public String getAccountTypeStr() {
82      return this.snapshot.getAccountType().toString();
83    }
84  
85    public MemberName getMemberName() {
86      return this.snapshot.getMemberName();
87    }
88  
89    public boolean hasEmail() {
90      return this.snapshot.getEmail() != null;
91    }
92  
93    public String getEmail() {
94      return hasEmail() ? this.snapshot.getEmail().toString() : "" ;
95    }
96  
97    public Map getTelephoneNumbers() {
98      return this.snapshot.getTelephoneNumbers();
99    }
100 
101   public String getEveningPhoneStr() {
102     Map phones = getTelephoneNumbers();
103     Telephone phone = (Telephone) phones.get( Telephone.EVENING );
104     String retVal = "";
105     return phoneToString(phone);
106   }
107 
108   public String getDayPhoneStr() {
109     Map phones = getTelephoneNumbers();
110     Telephone phone = (Telephone) phones.get( Telephone.DAY );
111     return phoneToString(phone);
112   }
113 
114   public String getOtherPhoneStr() {
115     Map phones = getTelephoneNumbers();
116     Telephone phone = (Telephone) phones.get( Telephone.OTHER );
117     return phoneToString(phone);
118   }
119 
120   private static String phoneToString( Telephone phone ) {
121     String retVal = "";
122     if ( phone != null ) {
123       StringBuffer sb = new StringBuffer(25);
124       sb.append( phone.getAreaCode() );
125       sb.append( "&nbsp;" );
126       sb.append( phone.getExchange() );
127       sb.append( "-" );
128       sb.append( phone.getLocal() );
129       if ( phone.getExtension() != null
130         && phone.getExtension().trim().length() > 0 ) {
131         sb.append( " " );
132         sb.append( "<em>x</em>&nbsp;" );
133         sb.append( phone.getExtension().trim() );
134       }
135       retVal = new String( sb );
136     }
137     return retVal;
138   }
139 
140   public Address getAddress() {
141     return this.snapshot.getAddress();
142   }
143 
144   public Date getAccountYear() {
145     return this.snapshot.getAccountDate();
146   }
147 
148   public int getAccountYear4() {
149     return 1900 + this.snapshot.getAccountDate().getYear();
150   }
151 
152   public boolean hasKnownBirthDate() {
153     return this.snapshot.getBirthDate() != null;
154   }
155 
156   public Date getBirthDate() {
157     return this.snapshot.getBirthDate();
158   }
159 
160   public boolean hasNoRoles() {
161     return this.snapshot.getMemberRoles().length == 0;
162   }
163 
164   public boolean hasRole(String role) {
165     return this.snapshot.hasRole(role);
166   }
167 
168   /** Two members are equal iff their id's are equal. */
169   public boolean equals( Object o ) {
170 
171     boolean retVal = false;
172     if ( o instanceof MemberView ) {
173       retVal = this.snapshot.equals( ((MemberView) o).snapshot );
174     }
175 
176     return retVal;
177   } // equals(Object)
178 
179   /** Member objects are hashed by id's */
180   public int hashCode() {
181     return this.snapshot.hashCode();
182   }
183 
184   /**
185    * Defines a natural ordering for members by lastname, firstname, middlename
186    * and suffix.<p>
187    *
188    * Note: this class has a natural ordering that is inconsistent with equals.
189    * Equality is defined by member id's, not by member names.
190    *
191    * @param o A member object.
192    * @exception ClassCastException if o is not a member object.
193    */
194   public int compareTo( Object o ) throws ClassCastException {
195     // Precondition
196     if ( !(o instanceof MemberView) ) {
197       throw new ClassCastException( "not a member object" );
198     }
199 
200     MemberView other = (MemberView) o;
201     int retVal = this.snapshot.compareTo( other.snapshot );
202 
203     return retVal;
204   } // compareTo(Object)
205 
206 } // MemberView
207 
208 /*
209  * $Log: MemberView.java,v $
210  * Revision 1.11  2003/03/13 04:51:50  rphall
211  * Simplified phone format
212  *
213  * Revision 1.10  2003/02/26 03:38:46  rphall
214  * Added copyright and GPL license
215  *
216  * Revision 1.9  2003/02/22 20:47:57  rphall
217  * Added various (hokey) getXxxPhoneStr()
218  *
219  * Revision 1.8  2003/02/21 19:21:01  rphall
220  * Fixed bug in getEmail()
221  *
222  * Revision 1.7  2003/02/20 16:32:30  rphall
223  * Add hasNoRoles() method
224  *
225  * Revision 1.6  2003/02/20 04:53:24  rphall
226  * Removed gratuitous use of CLRA acronym
227  *
228  * Revision 1.5  2003/02/16 00:49:51  rphall
229  * Removed obsolete comments
230  *
231  * Revision 1.4  2002/05/31 14:06:04  jmstone
232  * Additions for handling dates
233  *
234  * Revision 1.3  2002/03/15 13:19:08  timguinther
235  * update to display (or not) rowing admin link based on member role
236  *
237  * Revision 1.2  2002/02/18 18:06:33  rphall
238  * Ran dos2unix to remove ^M (carriage return) from end of lines
239  *
240  * Revision 1.1.1.1  2002/01/03 21:57:28  rphall
241  * Initial load, 5th try, Jan-03-2002 4:57 PM
242  *
243  * Revision 1.4  2002/01/01 03:40:33  rphall
244  * Moved getName() from MemberName to MemberView
245  *
246  * Revision 1.3  2001/12/31 14:32:58  rphall
247  * Renamed 'member.Name' to 'member.MemberName'
248  *
249  * Revision 1.2  2001/12/12 04:10:19  rphall
250  * Fixed build problems
251  *
252  * Revision 1.1  2001/12/11 23:46:33  rphall
253  * Moved from rowing/member package to web package
254  *
255  * Revision 1.4  2001/11/28 11:55:15  rphall
256  * Made Serializable
257  *
258  * Revision 1.3  2001/11/18 17:04:06  rphall
259  * Import of DBConfiguration and ValidationException
260  *
261  * Revision 1.2  2001/11/10 19:09:04  rphall
262  * Fixed compareTo(String)
263  *
264  * Revision 1.1  2001/11/10 16:17:34  rphall
265  * First compilable version
266  *
267  */
268