The following code shows an example of using a LoanAnalyzer CORBA object. This simplified object determines whether an applicant is approved for a loan based on the information that is supplied.
The LoanAnalyzer CORBA interface has one method, which takes the following two in arguments:
- An Account struct that identifies the applicant's account. It includes a Person struct that represents the account holder, and the applicant's age and income.
- A CreditCards sequence, which corresponds to the set of credit cards the user currently has. The credit card type is represented by a member of the CardType enumerator. (This example assumes the applicant has no more than one of any type of card.)
The object returns a Boolean value indicating whether the application is accepted or rejected.
The CFML does the following:
- Initializes the values of the ColdFusion variables that are used in the object method. In a more complete example, the information would come from a form, query, or both.
The code for the Person and Account structs is straightforward. The cards variable, which represents the applicant's credit cards, is more complex. The interface IDL uses a sequence of enumerators to represent the cards. ColdFusion represents an IDL sequence as an array, and an enumerator as 0-indexed number indicating the position of the selected item among the items in the enumerator type definition.
In this case, the applicant has a Master Card, a Visa card, and a Diners card. Because Master Card (MC) is the first entry in the enumerator type definition, it is represented in ColdFusion by the number 0. Visa is the third entry, so it is represented by 2. Diners is the fifth entry, so it is represented by 4. These numbers must be put in an array to represent the sequence, resulting in a three-element, one-dimensional array containing 0, 2, and 4.
- Instantiates the CORBA object.
- Calls the approve method of the CORBA object and gets the result in the return variable, ret.
- Displays the value of the ret variable, Yes or No.
IDL
|
struct Person
{
long pid;
string name;
string middle;
string last_name;
}
struct Account
{
Person person;
short age;
double income;
}
double loanAmountl
enum cardType {AMEX, VISA, MC, DISCOVER, DINERS};
typedef sequence<cardType> CreditCards;
interface LoanAnalyzer
{
boolean approve( in Account, in CreditCards);
}
|
CFML
|
<!--- Declare a "person" struct ---->
<cfset p = StructNew()>
<cfif IsStruct(p)>
<cfset p.pid = 1003232>
<cfset p.name = "Eduardo">
<cfset p.middle = "R">
<cfset p.last_name = "Doe">
</cfif>
<!---- Declare an "Account" struct --->
<cfset a = StructNew()>
<cfif IsStruct(a)>
<cfset a.person = p>
<cfset a.age = 34>
<cfset a.income = 150120.50>
</cfif>
<!----- Declare a "CreditCards" sequence --->
<cfset cards = ArrayNew(1)>
<cfset cards[1] = 0> <!--- corresponds to Amex --->
<cfset cards[2] = 2> <!--- corresponds to MC --->
<cfset cards[3] = 4> <!--- corresponds to Diners --->
<!---- Creating a CORBA handle using the Naming Service---->
<cfset handle = CreateObject("CORBA", "FirstBostonBank/MA/Loans",
"NameService") >
<cfset ret=handle.approve(a, cards)>
<cfoutput>Account approval: #ret#</cfoutput>
|