01: /*
02: * $Id: ParamComboImpl.java,v 1.4 2007/03/12 10:46:14 agoubard Exp $
03: */
04: package com.mycompany.allinone.api;
05:
06: import java.util.Calendar;
07: import org.xins.common.types.standard.Date;
08:
09: /**
10: * Implementation of the <code>ParamCombo</code> function.
11: *
12: * @version $Revision: 1.4 $ $Date: 2007/03/12 10:46:14 $
13: * @author John Doe (<a href="mailto:john.doe@mycompany.com">john.doe@mycompany.com</a>)
14: */
15: public class ParamComboImpl extends ParamCombo {
16:
17: /**
18: * Constructs a new <code>ParamComboImpl</code> instance.
19: *
20: * @param api
21: * the API to which this function belongs, guaranteed to be not
22: * <code>null</code>.
23: */
24: public ParamComboImpl(APIImpl api) {
25: super (api);
26: }
27:
28: public final Result call(Request request) throws Throwable {
29: int age;
30: if (request.isSetAge()) {
31: age = request.getAge().intValue();
32:
33: SuccessfulResult result = new SuccessfulResult();
34: Calendar calendar = Calendar.getInstance();
35: result.setRegistrationYear(calendar.get(Calendar.YEAR)
36: - age + 1);
37: result.setRegistrationMonth(calendar.get(Calendar.MONTH));
38: return result;
39: } else {
40: int year;
41: int month;
42: int day;
43: if (request.isSetBirthDate()) {
44: year = request.getBirthDate().getYear();
45: month = request.getBirthDate().getMonthOfYear();
46: day = request.getBirthDate().getDayOfMonth();
47: } else {
48: year = request.getBirthYear().intValue();
49: month = request.getBirthMonth().intValue();
50: day = request.getBirthDay().intValue();
51: }
52:
53: // Create an invalid response
54: // This is only for demonstration purpose as no API should normally
55: // return an invalid response.
56: if (year > 2005) {
57: return new SuccessfulResult();
58: }
59:
60: SuccessfulResult result = new SuccessfulResult();
61: result.setRegistrationDate(new Date.Value(year + 1, month,
62: 1));
63: return result;
64: }
65: }
66: }
|