1 22 package org.objectweb.petals.demo.mortgage.evalrate.sdk; 23 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import org.objectweb.petals.component.common.HandlingException; 28 import org.objectweb.petals.tools.jbicommon.util.StringHelper; 29 30 35 public class EvalRateImpl implements EvalRate { 36 37 private Logger logger; 38 39 public EvalRateImpl(Logger logger) { 40 super(); 41 this.logger = logger; 42 } 43 44 public String evaluate(String profile) throws HandlingException { 45 46 String msg = ""; 47 String 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 String 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 if ("Yes".equalsIgnoreCase(realProfile)) { 66 response = "5"; 67 } 68 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 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 response = "<response>" + response + "</response>"; 89 } 90 return response; 91 } 92 93 } 94 | Popular Tags |