@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
EX NO :6 DATE : 27-8-2014 
STOCK APPLICATION USING CORBA 
NAME : M.F.JERINCE RAJA ROLLNO : 12LMC004 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
STOCK.IDL 
********* 
module stck_market 
{ 
interface stock 
{ 
const unsigned short SIZE = 20; 
typedef string name[SIZE]; 
typedef short id[6]; 
typedef short amount[10]; 
typedef long shares[SIZE]; 
typedef string addr[SIZE]; 
long buyshare(in long amt,in long share); 
long sellshare(in long amt,in long share); 
}; 
}; 
STOCKIMPL 
********** 
import stck_market.*; 
import org.omg.CORBA.*; 
class stckimpl extends stockPOA 
{ 
private ORB orb; 
public stckimpl(ORB orb) 
{ 
this.orb = orb; 
} 
public int buyshare(int amt,int share) 
{ 
return(amt*share); 
} 
public int sellshare(int amt,int share) 
{ 
return(amt*share); 
} 
} 
SERVER 
****** 
import stck_market.*; 
import org.omg.CORBA.*; 
import org.omg.CosNaming.*; 
import org.omg.PortableServer.*; 
import org.omg.PortableServer.POA; 
import org.omg.CosNaming.NamingContextPackage.*; 
public class server 
{ 
public static void main(String args[])
{ 
try 
{ 
ORB orb = ORB.init(args, null); 
stckimpl imp_obj = new stckimpl(orb); 
POA rootpoa = 
POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 
rootpoa.the_POAManager().activate(); 
org.omg.CORBA.Object ref = 
rootpoa.servant_to_reference(imp_obj); 
stock href = stockHelper.narrow(ref); 
org.omg.CORBA.Object objRef = 
orb.resolve_initial_references("NameService"); 
NamingContextExt ncRef = 
NamingContextExtHelper.narrow(objRef); 
String name = "stock"; 
NameComponent path[] = ncRef.to_name( name ); 
ncRef.rebind(path, href); 
System.out.println(" Server ready... "); 
orb.run(); 
} 
catch (Exception e) 
{ 
System.err.println("ERROR: " + e); 
e.printStackTrace(System.out); 
} 
System.out.println("Server Exiting ...."); 
} 
} 
CLIENT 
******* 
import stck_market.*; 
import org.omg.CORBA.*; 
import org.omg.CosNaming.*; 
import org.omg.CosNaming.NamingContextPackage.*; 
import java.io.*; 
public class client 
{ 
public static void main(String args[]) 
{ 
try 
{ 
int cmid = 0, csid = 0, repeat = 1,n; 
int comp_id[] = new int[6]; 
String comp_name[] = new String[stck_market.stock.SIZE]; 
int shr[] = new int[stck_market.stock.SIZE]; 
int shr_pri[] = new int[stck_market.stock.SIZE]; 
String comp_addr[] = new String[stck_market.stock.SIZE]; 
int amt[] = new int[stck_market.stock.SIZE];
int cust_id[] = new int[6]; 
String cust_name[] = new String[stck_market.stock.SIZE]; 
int cust_shr[] = new int[stck_market.stock.SIZE]; 
String cust_addr[] = new String[stck_market.stock.SIZE]; 
int cust_amt[] = new int[stck_market.stock.SIZE]; 
int ctshr_pri[] = new int[stck_market.stock.SIZE]; 
BufferedReader br = new BufferedReader(new 
InputStreamReader(System.in)); 
ORB orb = ORB.init(args, null); 
org.omg.CORBA.Object objRef = 
orb.resolve_initial_references("NameService"); 
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); 
String name = "stock"; 
stock obj = stockHelper.narrow(ncRef.resolve_str(name)); 
System.out.println("Handle obtained on server object: "+obj); 
System.out.println(" CORBA APPLICATION FOR STOCK MARKET "); 
System.out.println(" ~~~~~ ~~~~~~~~~~~ ~~~ ~~~~~ ~~~~~~ "); 
System.out.println(" Enter the number of company & customer to be 
registered : "); 
n = Integer.parseInt(br.readLine()); 
for(int i=0;i<n;i++) 
{ 
System.out.println("tt Company Registration "); 
System.out.println(" Enter the company ID : "); 
comp_id[i] = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the company name : "); 
comp_name[i] = br.readLine(); 
System.out.println(" Enter the company address : "); 
comp_addr[i] = br.readLine(); 
System.out.println(" Enter the company shares : "); 
shr[i] = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the unit prize of shares : "); 
shr_pri[i] = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the total amount of shares owned : 
"); 
amt[i] = Integer.parseInt(br.readLine()); 
System.out.println("tt Customer Registration "); 
System.out.println(" Enter the customer ID : "); 
cust_id[i] = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the customer name : "); 
cust_name[i] = br.readLine(); 
System.out.println(" Enter the customer address : "); 
cust_addr[i] = br.readLine(); 
System.out.println(" Enter the number of shares owned : "); 
cust_shr[i] = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the unit prize of shares : "); 
ctshr_pri[i] = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the total amount of shares owned : 
"); 
cust_amt[i] = Integer.parseInt(br.readLine()); 
} 
do 
{ 
System.out.println(" 1 - > BUY SHARES 2 - > SELL SHARES 3 - > LIST 
THE DETAILS "); 
System.out.println(" Enter the choice : "); 
int ch = Integer.parseInt(br.readLine()); 
switch(ch) 
{ 
case 1: 
System.out.println("t BUY SHARES "); 
System.out.println(" Enter the company ID : "); 
cmid = Integer.parseInt(br.readLine());
System.out.println(" Enter the customer ID : "); 
csid = Integer.parseInt(br.readLine()); 
for(int i=0;i<n;i++) 
{ 
if(cmid==comp_id[i] && csid==cust_id[i]) 
{ 
System.out.println(" Enter the number of shares to buy : "); 
int share = Integer.parseInt(br.readLine()); 
int unit_price = shr_pri[i]; 
int cur_amt = obj.buyshare(unit_price,share); 
System.out.println(" Shares bought : "+share); 
System.out.println(" Total amount : "+cur_amt); 
shr[i] = shr[i] - share; 
amt[i] = amt[i] - cur_amt; 
cust_shr[i] = cust_shr[i] + share; 
cust_amt[i] = cust_amt[i] + cur_amt; 
break; 
}} 
break; 
case 2: 
System.out.println("t SELL SHARES "); 
System.out.println(" Enter the company ID : "); 
cmid = Integer.parseInt(br.readLine()); 
System.out.println(" Enter the customer ID : "); 
csid = Integer.parseInt(br.readLine()); 
for(int i=0;i<n;i++) 
{ 
if(cmid==comp_id[i] && csid==cust_id[i]) 
{ 
System.out.println(" Enter the number of shares to sell : "); 
int share = Integer.parseInt(br.readLine()); 
int unit_price = ctshr_pri[i]; 
int cur_amt = obj.sellshare(unit_price,share); 
System.out.println(" Shares sold : "+share); 
System.out.println(" Total amount : "+cur_amt); 
shr[i] = shr[i] + share; 
amt[i] = amt[i] + cur_amt; 
cust_shr[i] = cust_shr[i] - share; 
cust_amt[i] = cust_amt[i] - cur_amt; 
break; 
} 
} 
break; 
case 3: 
for(int i=0;i<n;i++) 
{ 
System.out.println("ttt Company Details "); 
System.out.println("t Company ID : "+comp_id[i]); 
System.out.println("t Company name : "+comp_name[i]); 
System.out.println("t Company Shares : "+shr[i]); 
System.out.println("t Total Amount of Shares Owned : "+amt[i]); 
System.out.println("ttt Customer Details "); 
System.out.println("t Customer ID : "+cust_id[i]); 
System.out.println("t Customer Name : "+cust_name[i]); 
System.out.println("t Total Number of Shares Owned : "+cust_shr[i]); 
System.out.println("t Total Amount of Shares Owned : "+cust_amt[i]);
} 
break; 
} 
System.out.println(" Press 1 to continue... "); 
repeat = Integer.parseInt(br.readLine()); 
}while(repeat==1); 
} 
catch (Exception e1) 
{ 
System.out.println("ERROR : " + e1) ; 
e1.printStackTrace(System.out); 
} 
} 
} 
OUTPUT 
****** 
Z:st>idlj -fall stock.idl 
Z:st>javac *.java 
Note: .stck_marketstockPOA.java uses unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details. 
Z:st>javac *.java stck_market/*.java 
Note: stck_marketstockPOA.java uses unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details. 
Z:st>orbd -ORBInitialPort 2500 
Z:st>java server -ORBInitialPort 2500 
Server ready... 
CORBA APPLICATION FOR STOCK MARKET 
~~~~~ ~~~~~~~~~~~ ~~~ ~~~~~ ~~~~~~ 
Enter the number of company & customer to be registered : 
1 
Company Registration 
Enter the company ID : 
1234 
Enter the company name : 
cicso 
Enter the company address : 
northstreet 
Enter the company shares : 
100 
Enter the unit priCe of shares : 
50 
Enter the total amount of shares owned : 
80 
Customer Registration 
Enter the customer ID : 
101 
Enter the customer name : 
RAJA 
Enter the customer address : 
M.G,.R nagar 
Enter the number of shares owned : 
40 
Enter the unit prize of shares :
40 
Enter the total amount of shares owned : 
10 
1 - > BUY SHARES 2 - > SELL SHARES 3 - > LIST THE DETAILS 
Enter the choice : 
1 
BUY SHARES 
Enter the company ID : 
1234 
Enter the customer ID : 
101 
Enter the number of shares to buy : 
15 
Shares bought : 15 
Total amount : 750 
Press 1 to continue...
40 
Enter the total amount of shares owned : 
10 
1 - > BUY SHARES 2 - > SELL SHARES 3 - > LIST THE DETAILS 
Enter the choice : 
1 
BUY SHARES 
Enter the company ID : 
1234 
Enter the customer ID : 
101 
Enter the number of shares to buy : 
15 
Shares bought : 15 
Total amount : 750 
Press 1 to continue...

STOCK APPLICATION USING CORBA

  • 1.
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ EX NO:6 DATE : 27-8-2014 STOCK APPLICATION USING CORBA NAME : M.F.JERINCE RAJA ROLLNO : 12LMC004 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ STOCK.IDL ********* module stck_market { interface stock { const unsigned short SIZE = 20; typedef string name[SIZE]; typedef short id[6]; typedef short amount[10]; typedef long shares[SIZE]; typedef string addr[SIZE]; long buyshare(in long amt,in long share); long sellshare(in long amt,in long share); }; }; STOCKIMPL ********** import stck_market.*; import org.omg.CORBA.*; class stckimpl extends stockPOA { private ORB orb; public stckimpl(ORB orb) { this.orb = orb; } public int buyshare(int amt,int share) { return(amt*share); } public int sellshare(int amt,int share) { return(amt*share); } } SERVER ****** import stck_market.*; import org.omg.CORBA.*; import org.omg.CosNaming.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; import org.omg.CosNaming.NamingContextPackage.*; public class server { public static void main(String args[])
  • 2.
    { try { ORB orb = ORB.init(args, null); stckimpl imp_obj = new stckimpl(orb); POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); org.omg.CORBA.Object ref = rootpoa.servant_to_reference(imp_obj); stock href = stockHelper.narrow(ref); org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); String name = "stock"; NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, href); System.out.println(" Server ready... "); orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } System.out.println("Server Exiting ...."); } } CLIENT ******* import stck_market.*; import org.omg.CORBA.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import java.io.*; public class client { public static void main(String args[]) { try { int cmid = 0, csid = 0, repeat = 1,n; int comp_id[] = new int[6]; String comp_name[] = new String[stck_market.stock.SIZE]; int shr[] = new int[stck_market.stock.SIZE]; int shr_pri[] = new int[stck_market.stock.SIZE]; String comp_addr[] = new String[stck_market.stock.SIZE]; int amt[] = new int[stck_market.stock.SIZE];
  • 3.
    int cust_id[] =new int[6]; String cust_name[] = new String[stck_market.stock.SIZE]; int cust_shr[] = new int[stck_market.stock.SIZE]; String cust_addr[] = new String[stck_market.stock.SIZE]; int cust_amt[] = new int[stck_market.stock.SIZE]; int ctshr_pri[] = new int[stck_market.stock.SIZE]; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ORB orb = ORB.init(args, null); org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); String name = "stock"; stock obj = stockHelper.narrow(ncRef.resolve_str(name)); System.out.println("Handle obtained on server object: "+obj); System.out.println(" CORBA APPLICATION FOR STOCK MARKET "); System.out.println(" ~~~~~ ~~~~~~~~~~~ ~~~ ~~~~~ ~~~~~~ "); System.out.println(" Enter the number of company & customer to be registered : "); n = Integer.parseInt(br.readLine()); for(int i=0;i<n;i++) { System.out.println("tt Company Registration "); System.out.println(" Enter the company ID : "); comp_id[i] = Integer.parseInt(br.readLine()); System.out.println(" Enter the company name : "); comp_name[i] = br.readLine(); System.out.println(" Enter the company address : "); comp_addr[i] = br.readLine(); System.out.println(" Enter the company shares : "); shr[i] = Integer.parseInt(br.readLine()); System.out.println(" Enter the unit prize of shares : "); shr_pri[i] = Integer.parseInt(br.readLine()); System.out.println(" Enter the total amount of shares owned : "); amt[i] = Integer.parseInt(br.readLine()); System.out.println("tt Customer Registration "); System.out.println(" Enter the customer ID : "); cust_id[i] = Integer.parseInt(br.readLine()); System.out.println(" Enter the customer name : "); cust_name[i] = br.readLine(); System.out.println(" Enter the customer address : "); cust_addr[i] = br.readLine(); System.out.println(" Enter the number of shares owned : "); cust_shr[i] = Integer.parseInt(br.readLine()); System.out.println(" Enter the unit prize of shares : "); ctshr_pri[i] = Integer.parseInt(br.readLine()); System.out.println(" Enter the total amount of shares owned : "); cust_amt[i] = Integer.parseInt(br.readLine()); } do { System.out.println(" 1 - > BUY SHARES 2 - > SELL SHARES 3 - > LIST THE DETAILS "); System.out.println(" Enter the choice : "); int ch = Integer.parseInt(br.readLine()); switch(ch) { case 1: System.out.println("t BUY SHARES "); System.out.println(" Enter the company ID : "); cmid = Integer.parseInt(br.readLine());
  • 4.
    System.out.println(" Enter thecustomer ID : "); csid = Integer.parseInt(br.readLine()); for(int i=0;i<n;i++) { if(cmid==comp_id[i] && csid==cust_id[i]) { System.out.println(" Enter the number of shares to buy : "); int share = Integer.parseInt(br.readLine()); int unit_price = shr_pri[i]; int cur_amt = obj.buyshare(unit_price,share); System.out.println(" Shares bought : "+share); System.out.println(" Total amount : "+cur_amt); shr[i] = shr[i] - share; amt[i] = amt[i] - cur_amt; cust_shr[i] = cust_shr[i] + share; cust_amt[i] = cust_amt[i] + cur_amt; break; }} break; case 2: System.out.println("t SELL SHARES "); System.out.println(" Enter the company ID : "); cmid = Integer.parseInt(br.readLine()); System.out.println(" Enter the customer ID : "); csid = Integer.parseInt(br.readLine()); for(int i=0;i<n;i++) { if(cmid==comp_id[i] && csid==cust_id[i]) { System.out.println(" Enter the number of shares to sell : "); int share = Integer.parseInt(br.readLine()); int unit_price = ctshr_pri[i]; int cur_amt = obj.sellshare(unit_price,share); System.out.println(" Shares sold : "+share); System.out.println(" Total amount : "+cur_amt); shr[i] = shr[i] + share; amt[i] = amt[i] + cur_amt; cust_shr[i] = cust_shr[i] - share; cust_amt[i] = cust_amt[i] - cur_amt; break; } } break; case 3: for(int i=0;i<n;i++) { System.out.println("ttt Company Details "); System.out.println("t Company ID : "+comp_id[i]); System.out.println("t Company name : "+comp_name[i]); System.out.println("t Company Shares : "+shr[i]); System.out.println("t Total Amount of Shares Owned : "+amt[i]); System.out.println("ttt Customer Details "); System.out.println("t Customer ID : "+cust_id[i]); System.out.println("t Customer Name : "+cust_name[i]); System.out.println("t Total Number of Shares Owned : "+cust_shr[i]); System.out.println("t Total Amount of Shares Owned : "+cust_amt[i]);
  • 5.
    } break; } System.out.println(" Press 1 to continue... "); repeat = Integer.parseInt(br.readLine()); }while(repeat==1); } catch (Exception e1) { System.out.println("ERROR : " + e1) ; e1.printStackTrace(System.out); } } } OUTPUT ****** Z:st>idlj -fall stock.idl Z:st>javac *.java Note: .stck_marketstockPOA.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Z:st>javac *.java stck_market/*.java Note: stck_marketstockPOA.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Z:st>orbd -ORBInitialPort 2500 Z:st>java server -ORBInitialPort 2500 Server ready... CORBA APPLICATION FOR STOCK MARKET ~~~~~ ~~~~~~~~~~~ ~~~ ~~~~~ ~~~~~~ Enter the number of company & customer to be registered : 1 Company Registration Enter the company ID : 1234 Enter the company name : cicso Enter the company address : northstreet Enter the company shares : 100 Enter the unit priCe of shares : 50 Enter the total amount of shares owned : 80 Customer Registration Enter the customer ID : 101 Enter the customer name : RAJA Enter the customer address : M.G,.R nagar Enter the number of shares owned : 40 Enter the unit prize of shares :
  • 6.
    40 Enter thetotal amount of shares owned : 10 1 - > BUY SHARES 2 - > SELL SHARES 3 - > LIST THE DETAILS Enter the choice : 1 BUY SHARES Enter the company ID : 1234 Enter the customer ID : 101 Enter the number of shares to buy : 15 Shares bought : 15 Total amount : 750 Press 1 to continue...
  • 7.
    40 Enter thetotal amount of shares owned : 10 1 - > BUY SHARES 2 - > SELL SHARES 3 - > LIST THE DETAILS Enter the choice : 1 BUY SHARES Enter the company ID : 1234 Enter the customer ID : 101 Enter the number of shares to buy : 15 Shares bought : 15 Total amount : 750 Press 1 to continue...