KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > loanbroker > LenderGateway


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package loanbroker;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.servicemix.components.util.TransformComponentSupport;
23
24 import javax.jbi.messaging.MessageExchange;
25 import javax.jbi.messaging.MessagingException;
26 import javax.jbi.messaging.NormalizedMessage;
27 import javax.xml.namespace.QName JavaDoc;
28
29 public class LenderGateway extends TransformComponentSupport {
30
31     private static final Log log = LogFactory.getLog(LenderGateway.class);
32
33     protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
34         log.info("Receiving lender gateway request");
35         double amount = ((Double JavaDoc) in.getProperty(Constants.PROPERTY_AMOUNT)).doubleValue();
36         int score = ((Integer JavaDoc) in.getProperty(Constants.PROPERTY_SCORE)).intValue();
37         int hlength = ((Integer JavaDoc) in.getProperty(Constants.PROPERTY_HISTORYLENGTH)).intValue();
38         QName JavaDoc[] recipients;
39         if (amount >= 75000.0 && score >= 600 && hlength >= 8) {
40             recipients = new QName JavaDoc[] { new QName JavaDoc(Constants.LOANBROKER_NS, "bank1"),
41                                        new QName JavaDoc(Constants.LOANBROKER_NS, "bank2") };
42         } else
43         if (amount >= 10000.0 && amount < 75000.0 && score >= 400 && hlength >= 3) {
44             recipients = new QName JavaDoc[] { new QName JavaDoc(Constants.LOANBROKER_NS, "bank3"),
45                                        new QName JavaDoc(Constants.LOANBROKER_NS, "bank4") };
46         } else {
47             recipients = new QName JavaDoc[] { new QName JavaDoc(Constants.LOANBROKER_NS, "bank5") };
48         }
49         out.setProperty(Constants.PROPERTY_RECIPIENTS, recipients);
50         return true;
51     }
52
53 }
54
Popular Tags