// project.beh Insurance Database Technology Transfer Project // for Demeter/Java // by Karen Yahle Agents { traversal printAgents (PrintingVisitor pV) { to {AgentRecord, Person, AgentCode} ; } traversal allAgents2 (T2Visitor V) { to {AgentRecord } ; } traversal allAgents4 (T4Visitor V) { to {AgentRecord, Person, AgentCode} ; } traversal allAgents3 (T3Visitor V) { to {AgentRecord } ; } traversal allAgents6 (T6Visitor V) { to {AgentRecord } ; } traversal allCodes (AVisitor V) { to {AgentRecord, AgentCode } ; } void myprint() (@ PrintingVisitor pV = new PrintingVisitor(); this.printAgents(pV); @) void doTransTwo( Insurees insurees) (@ T2Visitor tv2 = new T2Visitor( this, insurees ); this.allAgents2(tv2); @) void doTransFour(Insurees insurees, Premium queryamt) (@ T4Visitor tv4 = new T4Visitor( this, insurees, queryamt ); this.allAgents4(tv4); @) void doTransThree(Insurees insurees, PolicyType qtype) (@ T3Visitor tv3 = new T3Visitor( this, insurees, qtype ); this.allAgents3(tv3); @) void doTransSix( Insurees insurees) (@ T6Visitor tv6 = new T6Visitor( this, insurees ); this.allAgents6(tv6); @) AgentCode findAgentCode(Person agent) (@ AVisitor aV = new AVisitor(agent, new AgentCode()); this.allCodes(aV); AgentCode ret = aV.get_return_val(); return ret; @) } Insurees { traversal allInsurees (T1Visitor V) { to { InsureeRecord, Person } ; } traversal allPrint (PrintingVisitor cV) { to { PolicyRecord, PolicyType, Person }; } traversal allPolicyTypes(CheckVisitor cV) { to { PolicyRecord, PolicyType, Person }; } traversal allPremiums (SumVisitor sV) { to { PolicyRecord, Premium }; } traversal allAgents5 (T5Visitor V) { to { InsureeRecord, PolicyRecord }; } traversal allTypes(CountTVisitor V) { to {InsureeRecord, PolicyList, PolicyRecord};} traversal allPolicies(CountPVisitor V) { to {InsureeRecord, PolicyList, PolicyRecord};} void myprint() (@ PrintingVisitor pV = new PrintingVisitor(); this.allPrint(pV); @) void printAllInsurees() (@ T1Visitor tv1 = new T1Visitor(); this.allInsurees(tv1); @) void countTypes(AgentCode code) (@ CountTVisitor cV = new CountTVisitor(code, new Person(), 0); this.allTypes(cV); @) void countPolicies (AgentCode code, Person agent) (@ CountPVisitor cV = new CountPVisitor(code, agent, 0, 0, 0); this.allPolicies(cV); @) int getPremiumSum(AgentCode match) (@ int ret = 0; SumVisitor sV = new SumVisitor( match, ret); this.allPremiums(sV); ret = sV.get_return_val(); return ret; @) int getPolicyType(PolicyType match, AgentCode code) (@ int ret = 0; CheckVisitor cV = new CheckVisitor( match, code, ret); this.allPolicyTypes(cV); ret = cV.get_return_val(); return ret; @) void doTransFive(AgentCode code) (@ T5Visitor tV = new T5Visitor(code, new Person()); this.allAgents5(tV); @) } Transactions { traversal printTrans (PrintingVisitor V) { to { Transaction, Person } ; } traversal allTransProcess (doTransVisitor V) { to { Transaction } ; } void myprint() (@ PrintingVisitor pV = new PrintingVisitor(); this.printTrans(pV); @) void processTransactions(Agents agents, Insurees insurees) (@ doTransVisitor tV = new doTransVisitor(agents, insurees); this.allTransProcess(tV); @) } doTransVisitor { before Transaction1 (@ System.out.println("\nPROCESSING TRANSACTION ONE: "); host.processOne(insurees); @) before Transaction2 (@ System.out.println("\nPROCESSING TRANSACTION TWO: "); host.processTwo(agents, insurees); @) before Transaction3 (@ System.out.println("\nPROCESSING TRANSACTION THREE: "); PolicyType qtype = host.get_qtype(); host.processThree(agents, insurees, qtype); @) before Transaction4 (@ System.out.println("\nPROCESSING TRANSACTION FOUR: "); Premium queryamt = host.get_premium(); host.processFour(agents, insurees, queryamt); @) before Transaction5 (@ System.out.println("\nPROCESSING TRANSACTION FIVE: "); Person agentname = host.get_person(); AgentCode code = agents.findAgentCode(agentname); System.out.println("***Insurees who have bought insurance from : " + agentname.get_first().get_name().toString() + " " + agentname.get_last().get_name().toString() ); host.processFive( insurees, code ); @) before Transaction6 (@ System.out.println("\nPROCESSING TRANSACTION SIX: "); System.out.println("***Insurees that have bought more than one type insurance from the same agent: "); host.processSix(agents, insurees); @) } // transaction one prints the list of insurees Transaction1 { void processOne(Insurees insurees) (@ System.out.println("***Print all insurees (lastname, firstname) "); insurees.printAllInsurees(); @) } // transaction two finds all agents that have sold at least one // policy of same type to more than one insuree. Transaction2 { void processTwo(Agents agents, Insurees insurees) (@ System.out.println("***Agents that have sold same policy type to more than one insuree: "); agents.doTransTwo(insurees); @) } // transaction three finds and prints all agents that sold the type of // insurance specified in the query field of the transaction. Transaction3 { void processThree(Agents agents, Insurees insurees, PolicyType qtype) (@ System.out.println("***Print agents who have sold type of : " + qtype.get_id().toString() ); agents.doTransThree(insurees, qtype); @) } // transaction four finds and prints all agents that have sold a total // greater than the amount in the query premium filed of the transaction. Transaction4 { void processFour(Agents agents, Insurees insurees, Premium queryamt) (@ System.out.println("***Print agents with sales greater than : $" + queryamt.get_i() ); agents.doTransFour(insurees, queryamt); @) } // transaction five finds all insurees that have bought insurance from an // agent specified in the query field of the transaction. Transaction5 { void processFive(Insurees insurees, AgentCode agentcode ) (@ insurees.doTransFive(agentcode); @) } // transaction six will find and print all insurees that have bought more // than one kind of insurance from the same agent. Transaction6 { void processSix(Agents agents, Insurees insurees ) (@ agents.doTransSix(insurees); @) } T1Visitor { before Person (@ System.out.println( host.get_last().get_name().toString() + ", " + host.get_first().get_name().toString()); @) } T2Visitor { before AgentRecord (@ AgentCode code = host.get_agentcode(); Person agent = host.get_agent(); insurees.countPolicies(code, agent); @) } // parameters to this visitor are agents, insurees, queryamt. T4Visitor { before AgentRecord (@ AgentCode match = host.get_agentcode(); int sum = 0; sum = insurees.getPremiumSum(match); if ( sum > queryamt.get_i()) { System.out.println( host.get_agent().get_last().get_name().toString() + ", $" + sum ); } @) } // parameters to this visitor are agents, insurees, qtype. T3Visitor { before AgentRecord (@ int ret = 0; AgentCode code = host.get_agentcode(); ret = insurees.getPolicyType(qtype, code); if ( ret == 1) { System.out.println("agent: " + host.get_agent().get_last().get_name().toString() + ", " + host.get_agent().get_first().get_name().toString() ); } @) } T5Visitor { before InsureeRecord (@ iname = host.get_fullname(); @) before PolicyRecord (@ if (host.get_agentcode().get_i() == code.get_i() ) { System.out.print("insuree: " + iname.get_last().get_name().toString() + ", " + iname.get_first().get_name().toString() + "; "); System.out.println("agentCode: " + host.get_agentcode().get_i()); } @) } T6Visitor { before AgentRecord (@ AgentCode code = host.get_agentcode(); insurees.countTypes(code); @) } // SumVisitor has parameters of AgentCode and int SumVisitor { before PolicyRecord (@ if (code.get_i() == host.get_agentcode().get_i() ) { sum = sum + host.get_premium().get_i(); } @) return int (@ sum @) } CountTVisitor { before InsureeRecord (@ flag = 0; iname = host.get_fullname(); @) before PolicyRecord (@ if (code.get_i() == host.get_agentcode().get_i() ) { flag = flag + 1; } @) after PolicyList (@ if (flag > 1) { System.out.println("insuree: " + iname.get_last().get_name().toString() + ", " + iname.get_first().get_name().toString() ); } flag = 0; @) } CountPVisitor { before PolicyRecord (@ if (code.get_i() == host.get_agentcode().get_i() ) { PolicyType pt = host.get_policytype(); if (pt.get_id().toString().equals("accident")) aflag = aflag + 1; if (pt.get_id().toString().equals("life")) lflag = lflag + 1; if (pt.get_id().toString().equals("home")) hflag = hflag + 1; } @) after InsureeList (@ if ((aflag > 1) || (hflag >1) || (lflag > 1)) { System.out.println("agent: " + aname.get_last().get_name().toString() + ", " + aname.get_first().get_name().toString() + ", " + code.get_i() ); } aflag = 0; hflag = 0; lflag = 0; @) } // parameter of Check Visitor is PolicyType CheckVisitor { before PolicyRecord (@ if (type.get_id().equals(host.get_policytype().get_id())) { if (code.get_i() == host.get_agentcode().get_i()) ret = 1; } @) return int (@ ret @) } AVisitor { before AgentRecord (@ if (host.get_agent().get_last().get_name().equals (agent.get_last().get_name()) && (host.get_agent().get_first().get_name().equals (agent.get_first().get_name()) ) ) { code = host.get_agentcode(); // System.out.println(" Found agent code : " // + host.get_agentcode().get_i() ); } @) return AgentCode (@ code @) } // printing visitor used for debugging PrintingVisitor { before AgentList (@ System.out.println ("Printing Agent List: "); @) before AgentRecord (@ System.out.println("Agent Record: " ); @) before Person (@ System.out.println(" Person: " + host.get_first().get_name().toString() + " " + host.get_last().get_name().toString()); @) before Name (@ System.out.println(" Name : " + host.get_name().toString()); @) before AgentCode (@ System.out.println(" AgentCode: " + host.get_i()); @) after AgentRecord (@ System.out.println(" done with Agent Record."); @) before InsureeList (@ System.out.println (" Printing InsureeList: "); @) before InsureeRecord (@ System.out.println(" Insuree: "); @) after InsureeRecord (@ System.out.println(" done with Insuree "); @) before PolicyList (@ System.out.println (" Printing PolicyList: "); @) before PolicyRecord (@ System.out.print(" Policy Record: " ); @) before Premium (@ System.out.print(" premium: " + host.get_i()); @) before PolicyType (@ System.out.println ("Policy Type: " + host.get_id().toString() ); @) before Transactions (@ System.out.println (" Printing Transactions: "); @) before Transaction1 (@ System.out.println (" Transaction1: " + host.get_type().get_i() ); @) before Transaction2 (@ System.out.println (" Transaction2: " + host.get_type().get_i() ); @) before Transaction3 (@ System.out.println (" Transaction3: " + host.get_type().get_i() + " " + host.get_qtype().get_id().toString() ); @) before Transaction4 (@ System.out.println (" Transaction4: " + host.get_type().get_i() + " " + host.get_premium().get_i() ); @) before Transaction5 (@ System.out.println (" Transaction5: " + host.get_type().get_i() ); @) before Transaction6 (@ System.out.println (" Transaction6: " + host.get_type().get_i() ); @) } Main { (@ static public void main(String args[]) throws Exception { File agentfile = new File("agent.input"); if (!agentfile.canRead()) { System.out.println("agent file not readable."); System.exit(-1); } System.out.println(" Reading in Agent List: "); Agents agents = Agents.parse(new FileInputStream(agentfile)); // agents.myprint(); File insureefile = new File("insuree.input"); if (!insureefile.canRead()) { System.out.println("insuree file file not readable."); System.exit(-1); } System.out.println(" Reading in Insuree List: "); Insurees insurees = Insurees.parse(new FileInputStream(insureefile)); // insurees.myprint(); File transfile = new File("trans.input"); if (!transfile.canRead()) { System.out.println("transaction file not readable."); System.exit(-1); } Transactions transactions = Transactions.parse(new FileInputStream(transfile)); // transactions.myprint(); transactions.processTransactions(agents, insurees); } // System.out.println("DONE!"); @) }