Source code: com/clra/web/SessionView.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: SessionView.java,v $
5 * $Date: 2003/02/26 03:38:46 $
6 * $Revision: 1.3 $
7 */
8
9 package com.clra.web;
10
11 import com.clra.rowing.DefaultRowingSessionComparator;
12 import com.clra.rowing.RowingSessionLevel;
13 import com.clra.rowing.RowingSessionSnapshot;
14 import com.clra.rowing.RowingSessionState;
15 import com.clra.rowing.RowingSessionType;
16 import java.rmi.RemoteException;
17 import java.util.Date;
18 import java.text.SimpleDateFormat;
19 import java.io.Serializable;
20 import org.apache.log4j.Category;
21
22 /**
23 * Read-only information about a session. A thin-wrapper around
24 * RowingSessionSnapshot, with some String properties useful
25 * in JSP's.
26 *
27 * @version $Id: SessionView.java,v 1.3 2003/02/26 03:38:46 rphall Exp $
28 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
29 */
30 public class SessionView implements Comparable, Serializable {
31
32 private final static String base = SessionView.class.getName();
33 private final static Category theLog = Category.getInstance( base );
34
35 private RowingSessionSnapshot data;
36
37 private String dateFormatSpec = "EEEE MM/dd/yyyy 'at' hh:mm am";
38
39 /**
40 * Constructs an invalid instance. Use this constructor only for JSP beans
41 * and immediately set valid values via setValuesFromRowingSession(..).
42 */
43 public SessionView() {
44 this.data = null;
45 }
46
47 public SessionView( RowingSessionSnapshot rss ) {
48 setData( rss );
49 }
50
51 /** Deprecated */
52 public void setData( RowingSessionSnapshot rss ) {
53 if ( rss == null ) {
54 throw new IllegalArgumentException( "null rowing snapshot" );
55 }
56 this.data = rss;
57 }
58
59 public RowingSessionSnapshot getData() {
60 return this.data;
61 }
62
63 public Integer getId() {
64 return this.getData().getId();
65 }
66
67 public Date getDate() {
68 return this.getData().getDate();
69 }
70
71 /**
72 * Specifies how the date should be formatted as a string.
73 * The SimpleDateFormat class spells out how formats are specified.
74 * @see java.text.SimpleDateFormat
75 */
76 public void setDateFormatSpec( String spec ) {
77 if ( spec == null || spec.trim().length() == 0 ) {
78 throw new IllegalArgumentException( "invalid spec == '" + spec + "'");
79 }
80 this.dateFormatSpec = spec;
81 }
82
83 /**
84 * Returns the specification for the rowing date is formatted as a string.
85 * The SimpleDateFormat class spells out how formats are specified.
86 * @see java.text.SimpleDateFormat
87 */
88 public String getDateFormatSpec() {
89 if ( this.dateFormatSpec== null
90 || this.dateFormatSpec.trim().length() == 0) {
91 String msg = "invalid spec == '" + this.dateFormatSpec + "'";
92 throw new IllegalStateException( msg );
93 }
94 return this.dateFormatSpec;
95 }
96
97 /** Returns the date as a formatted string, using the current format */
98 public String getDateAsString() {
99 SimpleDateFormat sdf = new SimpleDateFormat( this.getDateFormatSpec() );
100 String retVal = sdf.format( this.getDate() );
101 return retVal;
102 }
103
104 public String getLevel() {
105 return this.getData().getLevel().getName();
106 }
107
108 public String getType() {
109 return this.getData().getType().getName();
110 }
111
112 public String getState() {
113 return this.getData().getState().getName();
114 }
115
116 /** Two sessions are equal iff they their natural comparator returns equal */
117 public boolean equals( Object o ) {
118
119 boolean retVal = false;
120 if ( o instanceof SessionView ) {
121 retVal = this.compareTo( o ) == 0;
122 }
123
124 return retVal;
125 } // equals(Object)
126
127 /** Session objects are hashed by id's */
128 public int hashCode() {
129 return this.getData().hashCode();
130 }
131
132 /**
133 * Orders views by the natural comparator for rowing sessions.
134 *
135 * @param o A session object.
136 * @exception ClassCastException if o is not a session object.
137 */
138 public int compareTo( Object o ) throws ClassCastException {
139
140 if ( !(o instanceof SessionView) ) {
141 throw new ClassCastException( "not a session object" );
142 }
143 int retVal = DefaultRowingSessionComparator.staticCompare(
144 this.getData(), ((SessionView)o).getData() );
145
146 return retVal;
147 } // compareTo(Object)
148
149 } // SessionView
150
151 /*
152 * $Log: SessionView.java,v $
153 * Revision 1.3 2003/02/26 03:38:46 rphall
154 * Added copyright and GPL license
155 *
156 * Revision 1.2 2002/02/18 18:07:20 rphall
157 * Ran dos2unix to remove ^M (carriage return) from end of lines
158 *
159 * Revision 1.1.1.1 2002/01/03 21:57:28 rphall
160 * Initial load, 5th try, Jan-03-2002 4:57 PM
161 *
162 * Revision 1.8 2001/12/15 02:28:17 rphall
163 * Added date formatting
164 *
165 * Revision 1.7 2001/12/13 21:25:13 rphall
166 * Remove EJB-based ctor's; check snapshot isn't null on setData
167 *
168 * Revision 1.6 2001/12/13 01:30:21 rphall
169 * Enrollment business and web objects
170 *
171 * Revision 1.5 2001/12/07 01:07:24 rphall
172 * Checkpt: before debugging slow perf
173 *
174 * Revision 1.4 2001/12/06 21:26:48 rphall
175 * Checkpt
176 *
177 * Revision 1.3 2001/12/06 04:56:47 rphall
178 * Cleaned up constructors & properties
179 *
180 * Revision 1.2 2001/11/28 12:09:26 rphall
181 * Made Serializable
182 *
183 * Revision 1.1 2001/11/23 19:40:02 rphall
184 * Major revision
185 *
186 * Revision 1.2 2001/11/18 17:07:08 rphall
187 * Checkpt before major revision of rowing package
188 *
189 */
190