1 package org.jbpm.calendar; 2 3 import java.io.Serializable ; 4 import java.text.DateFormat ; 5 import java.text.SimpleDateFormat ; 6 import java.util.ArrayList ; 7 import java.util.Calendar ; 8 import java.util.Date ; 9 import java.util.List ; 10 import java.util.Properties ; 11 import java.util.StringTokenizer ; 12 13 16 public class Day implements Serializable { 17 18 private static final long serialVersionUID = 1L; 19 20 DayPart[] dayParts = null; 21 BusinessCalendar businessCalendar = null; 22 23 public static Day[] parseWeekDays(Properties calendarProperties, BusinessCalendar businessCalendar) { 24 DateFormat dateFormat = new SimpleDateFormat (calendarProperties.getProperty("hour.format")); 25 Day[] weekDays = new Day[8]; 26 weekDays[Calendar.MONDAY] = new Day( calendarProperties.getProperty("weekday.monday"), dateFormat, businessCalendar ); 27 weekDays[Calendar.TUESDAY] = new Day( calendarProperties.getProperty("weekday.thuesday"), dateFormat, businessCalendar ); 28 weekDays[Calendar.WEDNESDAY] = new Day( calendarProperties.getProperty("weekday.wednesday"), dateFormat, businessCalendar ); 29 weekDays[Calendar.THURSDAY] = new Day( calendarProperties.getProperty("weekday.thursday"), dateFormat, businessCalendar ); 30 weekDays[Calendar.FRIDAY] = new Day( calendarProperties.getProperty("weekday.friday"), dateFormat, businessCalendar ); 31 weekDays[Calendar.SATURDAY] = new Day( calendarProperties.getProperty("weekday.saturday"), dateFormat, businessCalendar ); 32 weekDays[Calendar.SUNDAY] = new Day( calendarProperties.getProperty("weekday.sunday"), dateFormat, businessCalendar ); 33 return weekDays; 34 } 35 36 public Day(String dayPartsText, DateFormat dateFormat, BusinessCalendar businessCalendar) { 37 this.businessCalendar = businessCalendar; 38 39 List dayPartsList = new ArrayList (); 40 StringTokenizer tokenizer = new StringTokenizer (dayPartsText, "&"); 41 while (tokenizer.hasMoreTokens()) { 42 String dayPartText = tokenizer.nextToken().trim(); 43 dayPartsList.add(new DayPart(dayPartText, dateFormat, this, dayPartsList.size())); 44 } 45 46 dayParts = (DayPart[]) dayPartsList.toArray(new DayPart[dayPartsList.size()]); 47 } 48 49 public void findNextDayPartStart(int dayPartIndex, Date date, Object [] result) { 50 if (dayPartIndex < dayParts.length) { 52 if (dayParts[dayPartIndex].isStartAfter(date)) { 53 result[0] = dayParts[dayPartIndex].getStartTime(date); 54 result[1] = dayParts[dayPartIndex]; 55 } else { 56 findNextDayPartStart(dayPartIndex+1, date, result); 57 } 58 } else { 59 date = businessCalendar.findStartOfNextDay(date); 61 Day nextDay = businessCalendar.findDay(date); 62 nextDay.findNextDayPartStart(0, date, result); 63 } 64 } 65 } 66 | Popular Tags |