KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > demo > mortgage > evalrate > sdk > EvalRateImpl


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id$
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.demo.mortgage.evalrate.sdk;
23
24 import java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 import org.objectweb.petals.component.common.HandlingException;
28 import org.objectweb.petals.tools.jbicommon.util.StringHelper;
29
30 /**
31  *
32  * @author ofabre
33  *
34  */

35 public class EvalRateImpl implements EvalRate {
36
37     private Logger JavaDoc logger;
38
39     public EvalRateImpl(Logger JavaDoc logger) {
40         super();
41         this.logger = logger;
42     }
43
44     public String JavaDoc evaluate(String JavaDoc profile) throws HandlingException {
45
46         String JavaDoc msg = "";
47         String JavaDoc response = "";
48
49         if (StringHelper.isNullOrEmpty(profile)) {
50             msg = "You must specify the profil of the mortgage subscriber";
51             logger.log(Level.SEVERE, msg);
52             throw new HandlingException(msg);
53         }
54
55         // Get the string content from the xml content
56
String JavaDoc realProfile = profile
57                 .substring(profile.indexOf("<profile>") + 9, profile
58                         .indexOf("</profile>"));
59
60         logger
61                 .info("Eval Rate Module called to evaluate mortgage rate based on the following profile : "
62                         + realProfile);
63         // Only "yes" profile is allowed for a simple Mortgage
64
// Rate evaluation (first Mortgage process)
65
if ("Yes".equalsIgnoreCase(realProfile)) {
66             response = "5";
67         }
68         // For a Detailed Mortgage Rate evaluation, three different
69
// profiles are allowed : Good, Medium and Risky
70
else if ("Good".equalsIgnoreCase(realProfile)) {
71             response = "4";
72         } else if ("Medium".equalsIgnoreCase(realProfile)) {
73             response = "5";
74         } else if ("Risky".equalsIgnoreCase(realProfile)) {
75             response = "6";
76         }
77
78         // Other profile are not allowed
79
if ("".equals(response)) {
80             msg = "Given mortgage profile isn't allowed: " + realProfile;
81             logger.log(Level.SEVERE, "The EvalRate answers a fault: "
82                     + response);
83             throw new HandlingException(msg);
84         } else {
85             logger.log(Level.INFO, "The EvalRate answer : " + response);
86
87             // Create xml content from string content
88
response = "<response>" + response + "</response>";
89         }
90         return response;
91     }
92
93 }
94
Popular Tags