KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > engine > scheduling > hibernate > PersistentReportJobCalendarTrigger


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.engine.scheduling.hibernate;
22
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.SortedSet JavaDoc;
26 import java.util.TreeSet JavaDoc;
27
28 import com.jaspersoft.jasperserver.api.JSExceptionWrapper;
29 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJobCalendarTrigger;
30 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJobTrigger;
31
32 /**
33  * @author Lucian Chirita (lucianc@users.sourceforge.net)
34  * @version $Id: PersistentReportJobCalendarTrigger.java 3550 2006-06-06 18:47:26Z lucian $
35  */

36 public class PersistentReportJobCalendarTrigger extends PersistentReportJobTrigger {
37     
38     private static final String JavaDoc ENUM_SEPARATOR = ",";
39     private static final String JavaDoc ENUM_SEPARATOR_REGEX = ",";
40     
41     private String JavaDoc minutes;
42     private String JavaDoc hours;
43     private byte daysType;
44     private String JavaDoc weekDays;
45     private String JavaDoc monthDays;
46     private String JavaDoc months;
47     
48     public PersistentReportJobCalendarTrigger() {
49     }
50
51     public String JavaDoc getHours() {
52         return hours;
53     }
54
55     public void setHours(String JavaDoc hours) {
56         this.hours = hours;
57     }
58
59     public String JavaDoc getMinutes() {
60         return minutes;
61     }
62
63     public void setMinutes(String JavaDoc minutes) {
64         this.minutes = minutes;
65     }
66
67     public void copyFrom(ReportJobTrigger trigger) {
68         super.copyFrom(trigger);
69         
70         ReportJobCalendarTrigger calendarTrigger = (ReportJobCalendarTrigger) trigger;
71         setMinutes(calendarTrigger.getMinutes());
72         setHours(calendarTrigger.getHours());
73         setDaysType(calendarTrigger.getDaysType());
74         setWeekDays(toEnumerationString(calendarTrigger.getWeekDays()));
75         setMonthDays(calendarTrigger.getMonthDays());
76         setMonths(toEnumerationString(calendarTrigger.getMonths()));
77     }
78
79     public ReportJobTrigger toClient() {
80         ReportJobCalendarTrigger trigger = new ReportJobCalendarTrigger();
81         super.copyTo(trigger);
82         trigger.setMinutes(getMinutes());
83         trigger.setHours(getHours());
84         trigger.setDaysType(getDaysType());
85         trigger.setWeekDays(parseEnumerationString(getWeekDays()));
86         trigger.setMonthDays(getMonthDays());
87         trigger.setMonths(parseEnumerationString(getMonths()));
88         return trigger;
89     }
90
91     public boolean supports(Class JavaDoc triggerClass) {
92         return ReportJobCalendarTrigger.class.isAssignableFrom(triggerClass);
93     }
94
95     public byte getDaysType() {
96         return daysType;
97     }
98
99     public void setDaysType(byte daysType) {
100         this.daysType = daysType;
101     }
102
103     public String JavaDoc getMonthDays() {
104         return monthDays;
105     }
106
107     public void setMonthDays(String JavaDoc monthDays) {
108         this.monthDays = monthDays;
109     }
110
111     public String JavaDoc getMonths() {
112         return months;
113     }
114
115     public void setMonths(String JavaDoc months) {
116         this.months = months;
117     }
118
119     public String JavaDoc getWeekDays() {
120         return weekDays;
121     }
122
123     public void setWeekDays(String JavaDoc weekDays) {
124         this.weekDays = weekDays;
125     }
126
127     protected String JavaDoc toEnumerationString(Set JavaDoc vals) {
128         if (vals == null || vals.isEmpty()) {
129             return null;
130         }
131         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
132         SortedSet JavaDoc sorted = new TreeSet JavaDoc(vals);
133         for (Iterator JavaDoc it = sorted.iterator(); it.hasNext();) {
134             Byte JavaDoc val = (Byte JavaDoc) it.next();
135             str.append(val.byteValue());
136             str.append(ENUM_SEPARATOR);
137         }
138         return str.substring(0, str.length() - 1);
139     }
140
141     protected SortedSet JavaDoc parseEnumerationString(String JavaDoc str) {
142         if (str == null || str.length() == 0) {
143             return null;
144         }
145         SortedSet JavaDoc valsSet = new TreeSet JavaDoc();
146         String JavaDoc[] vals = str.split(ENUM_SEPARATOR_REGEX);
147         for (int i = 0; i < vals.length; i++) {
148             String JavaDoc strVal = vals[i];
149             try {
150                 Byte JavaDoc val = Byte.valueOf(strVal);
151                 valsSet.add(val);
152             } catch (NumberFormatException JavaDoc e) {
153                 throw new JSExceptionWrapper(e);
154             }
155         }
156         return valsSet;
157     }
158
159 }
160
Popular Tags