01: /*
02: * $Id: LogdocImpl.java,v 1.9 2007/09/18 11:27:13 agoubard Exp $
03: */
04: package com.mycompany.allinone.api;
05:
06: import java.util.Date;
07:
08: /**
09: * Implementation of the <code>Logdoc</code> function.
10: *
11: * @version $Revision: 1.9 $ $Date: 2007/09/18 11:27:13 $
12: * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
13: */
14: public class LogdocImpl extends Logdoc {
15:
16: /**
17: * Constructs a new <code>LogdocImpl</code> instance.
18: *
19: * @param api
20: * the API to which this function belongs, guaranteed to be not
21: * <code>null</code>.
22: */
23: public LogdocImpl(APIImpl api) {
24: super (api);
25: }
26:
27: public final Result call(Request request) throws Throwable {
28: String input = request.getInputText();
29: int firstSpacePos = input.indexOf(' ');
30: try {
31: int number = -1;
32: if (firstSpacePos != -1) {
33: number = Integer.parseInt(input.substring(0,
34: firstSpacePos));
35: } else {
36: number = Integer.parseInt(input);
37: }
38: Log.log_10000(input, number);
39: boolean odd = number % 2 == 0;
40: boolean thousands = number > 1000;
41: long squareNumber = (long) (number * number);
42: Log.log_10002(odd, new Boolean(thousands), squareNumber,
43: new Date(), getClass().getName());
44: } catch (NumberFormatException nfe) {
45: Log.log_10001(nfe);
46: return new InvalidNumberResult();
47: }
48: return new SuccessfulResult();
49: }
50: }
|