01: /*
02: * $Id: AttributeComboImpl.java,v 1.3 2007/03/12 10:46:13 agoubard Exp $
03: */
04: package com.mycompany.allinone.api;
05:
06: import com.mycompany.allinone.api.AttributeCombo.Request.Person;
07: import java.util.Calendar;
08: import java.util.Iterator;
09: import org.xins.common.types.standard.Date;
10:
11: /**
12: * Implementation of the <code>AttributeCombo</code> function.
13: *
14: * <p>Description: A function to test the attribute-combo.
15: *
16: * @version $Revision: 1.3 $ $Date: 2007/03/12 10:46:13 $
17: * @author John Doe (<a href="mailto:john.doe@mycompany.com">john.doe@mycompany.com</a>)
18: */
19: public final class AttributeComboImpl extends AttributeCombo {
20:
21: /**
22: * Constructs a new <code>AttributeComboImpl</code> instance.
23: *
24: * @param api
25: * the API to which this function belongs, guaranteed to be not
26: * <code>null</code>.
27: */
28: public AttributeComboImpl(APIImpl api) {
29: super (api);
30: }
31:
32: /**
33: * Calls this function. If the function fails, it may throw any kind of
34: * exception. All exceptions will be handled by the caller.
35: *
36: * @param request
37: * the request, never <code>null</code>.
38: *
39: * @return
40: * the result of the function call, should never be <code>null</code>.
41: *
42: * @throws Throwable
43: * if anything went wrong.
44: */
45: public Result call(Request request) throws Throwable {
46: Calendar calendar = Calendar.getInstance();
47: SuccessfulResult result = new SuccessfulResult();
48: Iterator itPersons = request.listPerson().iterator();
49: while (itPersons.hasNext()) {
50: Person nextPerson = (Person) itPersons.next();
51: Registration registration = new Registration();
52: if (nextPerson.isSetAge()) {
53: int age = nextPerson.getAge().intValue();
54: registration.setRegistrationYear(calendar
55: .get(Calendar.YEAR)
56: - age + 1);
57: registration.setRegistrationMonth(calendar
58: .get(Calendar.MONTH));
59: } else {
60: int year;
61: int month;
62: int day;
63: if (nextPerson.isSetBirthDate()) {
64: year = nextPerson.getBirthDate().getYear();
65: month = nextPerson.getBirthDate().getMonthOfYear();
66: day = nextPerson.getBirthDate().getDayOfMonth();
67: } else {
68: year = nextPerson.getBirthYear().intValue();
69: month = nextPerson.getBirthMonth().intValue();
70: day = nextPerson.getBirthDay().intValue();
71: }
72:
73: // Create an invalid response for year above 2006
74: // This is only for demonstration purpose as no API should normally
75: // return an invalid response.
76: if (year <= 2006) {
77: registration.setRegistrationDate(new Date.Value(
78: year + 1, month, 1));
79: }
80: }
81: result.addRegistration(registration);
82: }
83: return result;
84: }
85: }
|