View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.custom.schedule.model;
21  
22  import java.io.Serializable;
23  
24  import java.util.Calendar;
25  import java.util.Date;
26  import java.util.TimeZone;
27  
28  import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
29  
30  
31  /**
32   * <p>
33   * A default implementation of a Schedule entry
34   * </p>
35   *
36   * @author Jurgen Lust (latest modification by $Author: werpu $)
37   * @version $Revision: 371736 $
38   */
39  public class DefaultScheduleEntry
40      implements Serializable, ScheduleEntry
41  {
42      //~ Instance fields --------------------------------------------------------
43  
44      /**
45       * serial id for serialisation versioning
46       */
47      private static final long serialVersionUID = 1L;
48      private Date endTime;
49      private Date startTime;
50      private String description;
51      private String id;
52      private String subtitle;
53      private String title;
54      private boolean allDay;
55      private TimeZone timeZone;
56  
57      //~ Methods ----------------------------------------------------------------
58  
59      /**
60       * @return the current timezone
61       */
62      public TimeZone getTimeZone ()
63      {
64        return this.timeZone;
65      }
66  
67      /**
68       * Set current timezone
69       * @param timeZone the timezone
70       */
71      public void setTimeZone (TimeZone timeZone)
72      {
73        this.timeZone = timeZone;
74      }
75  
76      /**
77       * @param description The description to set.
78       */
79      public void setDescription(String description)
80      {
81          this.description = description;
82      }
83  
84      /**
85       * @return Returns the description.
86       */
87      public String getDescription()
88      {
89          return description;
90      }
91  
92      /**
93       * @param endTime The endTime to set.
94       */
95      public void setEndTime(Date endTime)
96      {
97          this.endTime = endTime;
98      }
99  
100     /**
101      * @return Returns the endTime.
102      */
103     public Date getEndTime()
104     {
105       if (endTime == null) endTime = new Date();
106       if (isAllDay()) {
107         Date truncated = ScheduleUtil.truncate(endTime, getTimeZone());
108         Calendar cal = ScheduleUtil.getCalendarInstance(truncated, getTimeZone());
109         cal.add(Calendar.MILLISECOND, -1);
110         truncated = cal.getTime();
111         if (!truncated.equals(endTime)) {
112           cal.add(Calendar.DATE, 1);
113         }
114         return cal.getTime();
115       }
116         return endTime;
117     }
118 
119     /**
120      * @param id The id to set.
121      */
122     public void setId(String id)
123     {
124         this.id = id;
125     }
126 
127     /**
128      * @return Returns the id.
129      */
130     public String getId()
131     {
132         return id;
133     }
134 
135     /**
136      * @param startTime The startTime to set.
137      */
138     public void setStartTime(Date startTime)
139     {
140         this.startTime = startTime;
141     }
142 
143     /**
144      * @return Returns the startTime. If the allDay property is true, the startTime is truncated to 00:00.
145      */
146     public Date getStartTime()
147     {
148       if (startTime == null) startTime = new Date();
149       if (isAllDay()) {
150         return ScheduleUtil.truncate(startTime, getTimeZone());
151       } else {
152             return startTime;
153       }
154     }
155 
156     /**
157      * @param subtitle The subtitle to set.
158      */
159     public void setSubtitle(String subtitle)
160     {
161         this.subtitle = subtitle;
162     }
163 
164     /**
165      * @return Returns the subtitle.
166      */
167     public String getSubtitle()
168     {
169         return subtitle;
170     }
171 
172     /**
173      * @param title The title to set.
174      */
175     public void setTitle(String title)
176     {
177         this.title = title;
178     }
179 
180     /**
181      * @return Returns the title.
182      */
183     public String getTitle()
184     {
185         return title;
186     }
187     
188     /**
189      * @return Returns true if the entry last all day.
190      */
191     public boolean isAllDay()
192     {
193         return allDay;
194     }
195 
196     /**
197      * @param allDay does the entry last all day?
198      */
199     public void setAllDay(boolean allDay) {
200         this.allDay = allDay;
201     }
202     
203 }
204 //The End