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.TShirt;
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: * TShirtHandler.java
30: *
31: *
32: * Created: Thu Oct 18 18:53:20 2001
33: *
34: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
35: *
36: *
37: */
38:
39: public class TShirtHandler implements IHandler {
40: public void handleSubmittedData(Context context, IWrapper wrapper)
41: throws Exception {
42: TShirt tshirt = (TShirt) wrapper;
43: ContextTShirt ct = SampleRes.getContextTShirt(context);
44: Integer color = tshirt.getColor();
45: String size = tshirt.getSize();
46: Integer[] feature = tshirt.getFeature();
47:
48: if (size.equals("L") && color.equals(new Integer(2))) {
49: // The combination size "L" and color No. "2" is considered invalid (maybe out of stock)
50: tshirt
51: .addSCodeSize(
52: StatusCodeLib.PFIXCORE_EXAMPLE_TSHIRT_SIZECOLOR_OUTOF_STOCK,
53: new String[] { "L", "2" }, "note");
54: return;
55: }
56:
57: // Everything was ok, store it.
58: ct.setSize(size);
59: ct.setColor(color);
60: if (feature != null) {
61: ct.setFeature(feature);
62: } else {
63: ct.setFeature(new Integer[] { new Integer(-1) });
64: // This is needed so we produce some output at all on retrieveCurrentStatus when
65: // the user decided to NOT check any checkbox in the UI (this makes defaults work)
66: }
67:
68: }
69:
70: public void retrieveCurrentStatus(Context context, IWrapper wrapper)
71: throws Exception {
72: TShirt tshirt = (TShirt) wrapper;
73: ContextTShirt ct = SampleRes.getContextTShirt(context);
74:
75: if (!ct.needsData()) {
76: tshirt.setColor(ct.getColor());
77: tshirt.setSize(ct.getSize());
78: tshirt.setFeature(ct.getFeature());
79: }
80: }
81:
82: public boolean needsData(Context context) throws Exception {
83: ContextTShirt ct = SampleRes.getContextTShirt(context);
84: return ct.needsData();
85: }
86:
87: public boolean prerequisitesMet(Context context) throws Exception {
88: return true;
89: }
90:
91: public boolean isActive(Context context) throws Exception {
92: return true;
93: }
94:
95: }// TShirtHandler
|