01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.example;
21:
22: import de.schlund.pfixcore.example.iwrapper.Counter;
23: import de.schlund.pfixcore.generator.IHandler;
24: import de.schlund.pfixcore.generator.IWrapper;
25: import de.schlund.pfixcore.workflow.Context;
26: import de.schlund.util.statuscodes.StatusCodeLib;
27:
28: /**
29: * CounterHandler.java
30: *
31: *
32: * Created: Wed Nov 21 18:44:20 2001
33: *
34: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
35: *
36: *
37: */
38:
39: public class CounterHandler implements IHandler {
40: // private final static Logger LOG = Logger.getLogger(CounterHandler.class);
41:
42: public void handleSubmittedData(Context context, IWrapper wrapper)
43: throws Exception {
44: Counter counter = (Counter) wrapper;
45: ContextCounter cc = SampleRes.getContextCounter(context);
46:
47: Boolean showcounter = counter.getShowCounter();
48: Integer count = counter.getAdd();
49:
50: if (showcounter != null) {
51: cc.setShowCounter(showcounter);
52: }
53:
54: if (cc.getShowCounter().booleanValue() && count != null) {
55: cc.addToCounter(count.intValue());
56: }
57:
58: // demo of pageMessage feature
59: int c = cc.getCounter();
60: if (c > 9) {
61: context
62: .addPageMessage(
63: StatusCodeLib.PFIXCORE_EXAMPLE_COUNTER_WARN_GREATER_9,
64: new String[] { "" + c }, "error");
65: context.prohibitContinue();
66: } else if (c > 5) {
67: context
68: .addPageMessage(
69: StatusCodeLib.PFIXCORE_EXAMPLE_COUNTER_WARN_GREATER_5,
70: new String[] { "" + c }, "warn");
71: } else if (c > 3) {
72: context
73: .addPageMessage(
74: StatusCodeLib.PFIXCORE_EXAMPLE_COUNTER_INFO_GREATER_3,
75: new String[] { "" + c }, "info");
76: }
77:
78: }
79:
80: public void retrieveCurrentStatus(Context context, IWrapper wrapper)
81: throws Exception {
82: // We do nothing here. There are no formelements that need prefilling.
83: }
84:
85: public boolean needsData(Context context) {
86: return false;
87: }
88:
89: public boolean isActive(Context context) {
90: return true;
91: }
92:
93: public boolean prerequisitesMet(Context context) {
94: return true;
95: }
96:
97: }// CounterHandler
|