From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/mortgage/CreditCheck.java | 29 ++++++++ .../src/main/java/mortgage/CreditCheckImpl.java | 32 +++++++++ .../mortgage/src/main/java/mortgage/Customer.java | 75 +++++++++++++++++++++ .../src/main/java/mortgage/InterestRateQuote.java | 23 +++++++ .../main/java/mortgage/InterestRateQuoteImpl.java | 31 +++++++++ .../src/main/java/mortgage/LoanApproval.java | 27 ++++++++ .../src/main/java/mortgage/LoanApprovalImpl.java | 78 ++++++++++++++++++++++ .../src/main/java/mortgage/MortgageCalculator.java | 29 ++++++++ .../main/java/mortgage/MortgageCalculatorImpl.java | 37 ++++++++++ .../src/main/java/mortgage/MortgageClient.java | 43 ++++++++++++ .../src/main/java/mortgage/RiskAssessment.java | 27 ++++++++ .../src/main/java/mortgage/RiskAssessmentImpl.java | 37 ++++++++++ 12 files changed, 468 insertions(+) create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheck.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheckImpl.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/Customer.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuote.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuoteImpl.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApproval.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApprovalImpl.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculator.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculatorImpl.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageClient.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessment.java create mode 100644 sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessmentImpl.java (limited to 'sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage') diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheck.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheck.java new file mode 100644 index 0000000000..c5787b7819 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheck.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.annotations.Remotable; + +/** + * CreditCheck interface + */ +@Remotable +public interface CreditCheck { + int getCreditScore(String ssn); +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheckImpl.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheckImpl.java new file mode 100644 index 0000000000..86fe88b417 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/CreditCheckImpl.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.annotations.Service; + +/** + * A pojo implementation of the CreditCheck service + */ +@Service(CreditCheck.class) +public class CreditCheckImpl implements CreditCheck { + + public int getCreditScore(String ssn) { + return (int) (700 + (Math.random() - 0.5) * 100); + } +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/Customer.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/Customer.java new file mode 100644 index 0000000000..a8b23c6019 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/Customer.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mortgage; + +/** + * A simple Customer object + */ +public class Customer { + private String ssn; + private String firstName; + private String lastName; + private double monthlyIncome; + private String state; + + public double getMonthlyIncome() { + return monthlyIncome; + } + + public void setMonthlyIncome(double monthlyIncome) { + this.monthlyIncome = monthlyIncome; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getSsn() { + return ssn; + } + + public void setSsn(String ssn) { + this.ssn = ssn; + } + + public String toString() { + return firstName + " " + lastName + "[" + ssn + "]"; + } +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuote.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuote.java new file mode 100644 index 0000000000..b5bafeb204 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuote.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +public interface InterestRateQuote { + public float getRate(String state, double loanAmount, int termInYears); +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuoteImpl.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuoteImpl.java new file mode 100644 index 0000000000..93054a2491 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/InterestRateQuoteImpl.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.annotations.Service; + +@Service(InterestRateQuote.class) +public class InterestRateQuoteImpl implements InterestRateQuote { + public float getRate(String state, double loanAmount, int termInYears) { + if (termInYears == 5) + return 5.5f; + else + return 6.5f; + } +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApproval.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApproval.java new file mode 100644 index 0000000000..dcdad18496 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApproval.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mortgage; + +/** + * Loan Approval interface + */ +public interface LoanApproval { + public boolean approve(Customer customer, double loanAmount, int years); +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApprovalImpl.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApprovalImpl.java new file mode 100644 index 0000000000..12212b61f0 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/LoanApprovalImpl.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +/** + * An implementation of the LoanApproval service. + */ +@Scope("MODULE") +@Service(LoanApproval.class) +public class LoanApprovalImpl implements LoanApproval { + + private CreditCheck creditCheck; + private RiskAssessment riskAssessment; + private MortgageCalculator mortgageCalculator; + private InterestRateQuote interestRateQuote; + + private int minimumCreditScore = 650; + + @Property(name = "minimumCreditScore") + public void setMinimumCreditScore(int minimumCreditScore) { + this.minimumCreditScore = minimumCreditScore; + } + + @Reference + public void setCreditCheck(CreditCheck creditCheck) { + this.creditCheck = creditCheck; + } + + @Reference + public void setInterestRateQuote(InterestRateQuote interestRateQuote) { + this.interestRateQuote = interestRateQuote; + } + + @Reference + public void setMortgageCalculator(MortgageCalculator mortgageCalculator) { + this.mortgageCalculator = mortgageCalculator; + } + + @Reference + public void setRiskAssessment(RiskAssessment riskAssessment) { + this.riskAssessment = riskAssessment; + } + + /** + * @see mortgage.LoanApproval#approve(mortgage.Customer, double, int) + */ + public boolean approve(Customer customer, double loanAmount, int years) { + int score = creditCheck.getCreditScore(customer.getSsn()); + if (score < minimumCreditScore) { + return false; + } + float rate = interestRateQuote.getRate(customer.getState(), loanAmount, years); + double monthlyPayment = mortgageCalculator.getMonthlyPayment(loanAmount, years, rate); + double ratio = monthlyPayment/customer.getMonthlyIncome(); + return riskAssessment.assess(score, ratio); + } +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculator.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculator.java new file mode 100644 index 0000000000..cacd8694de --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculator.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.annotations.Remotable; + +/** + * The Mortgage Calculator service interface. + */ +@Remotable +public interface MortgageCalculator { + public double getMonthlyPayment(double principal, int years, float interestRate); +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculatorImpl.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculatorImpl.java new file mode 100644 index 0000000000..c89830ca84 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageCalculatorImpl.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.annotations.Service; + +/** + * An implementation of the Calculator service. + */ +@Service(MortgageCalculator.class) +public class MortgageCalculatorImpl implements MortgageCalculator { + + public double getMonthlyPayment(double principal, int years, float interestRate) { + double monthlyRate = interestRate / 12.0 / 100.0; + double p = Math.pow(1 + monthlyRate, years * 12); + double q = p / (p - 1); + double monthlyPayment = principal * monthlyRate * q; + return monthlyPayment; + } + +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageClient.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageClient.java new file mode 100644 index 0000000000..d548f638c0 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/MortgageClient.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mortgage; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +/** + * This client program to invoke the Mortgage LoanApproval service + */ +public class MortgageClient { + public static void main(String[] args) throws Exception { + + CompositeContext context = CurrentCompositeContext.getContext(); + LoanApproval loanApplication = context.locateService(LoanApproval.class, "LoanApprovalComponent"); + + Customer customer = new Customer(); + customer.setSsn("111-22-3333"); + customer.setFirstName("John"); + customer.setLastName("Smith"); + customer.setMonthlyIncome(5000.0d); + customer.setState("CA"); + + boolean result = loanApplication.approve(customer, 200000d, 30); + System.out.println((result ? "Approved: " : "Rejected: ") + customer); + } +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessment.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessment.java new file mode 100644 index 0000000000..23c9589e85 --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessment.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mortgage; + +/** + * Risk Assessment interface + */ +public interface RiskAssessment { + public boolean assess(int creditScore, double ratio); +} diff --git a/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessmentImpl.java b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessmentImpl.java new file mode 100644 index 0000000000..8144ef2a7d --- /dev/null +++ b/sandbox/rfeng/samples.M2/mortgage/src/main/java/mortgage/RiskAssessmentImpl.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mortgage; + +import org.osoa.sca.annotations.Service; + +/** + * A pojo implementation of RiskAssessment service + */ +@Service(RiskAssessment.class) +public class RiskAssessmentImpl implements RiskAssessment { + public boolean assess(int creditScore, double ratio) { + if (creditScore >= 750) + return ratio < 0.35; + else if (creditScore >= 700) + return ratio < 0.30; + else + return ratio < 0.25; + } +} -- cgit v1.2.3