01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
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: */package loanbroker;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.apache.servicemix.components.util.TransformComponentSupport;
22:
23: import javax.jbi.messaging.MessageExchange;
24: import javax.jbi.messaging.MessagingException;
25: import javax.jbi.messaging.NormalizedMessage;
26: import javax.xml.namespace.QName;
27:
28: public class LenderGateway extends TransformComponentSupport {
29:
30: private static final Log log = LogFactory
31: .getLog(LenderGateway.class);
32:
33: protected boolean transform(MessageExchange exchange,
34: NormalizedMessage in, NormalizedMessage out)
35: throws MessagingException {
36: log.info("Receiving lender gateway request");
37: double amount = ((Double) in
38: .getProperty(Constants.PROPERTY_AMOUNT)).doubleValue();
39: int score = ((Integer) in.getProperty(Constants.PROPERTY_SCORE))
40: .intValue();
41: int hlength = ((Integer) in
42: .getProperty(Constants.PROPERTY_HISTORYLENGTH))
43: .intValue();
44: QName[] recipients;
45: if (amount >= 75000.0 && score >= 600 && hlength >= 8) {
46: recipients = new QName[] {
47: new QName(Constants.LOANBROKER_NS, "bank1"),
48: new QName(Constants.LOANBROKER_NS, "bank2") };
49: } else if (amount >= 10000.0 && amount < 75000.0
50: && score >= 400 && hlength >= 3) {
51: recipients = new QName[] {
52: new QName(Constants.LOANBROKER_NS, "bank3"),
53: new QName(Constants.LOANBROKER_NS, "bank4") };
54: } else {
55: recipients = new QName[] { new QName(
56: Constants.LOANBROKER_NS, "bank5") };
57: }
58: out.setProperty(Constants.PROPERTY_RECIPIENTS, recipients);
59: return true;
60: }
61:
62: }
|