Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » CorbaRSS Feeds

Develop a CORBA based application for addition of two complex numbers and displaying the result on client side

Posted By: Milind Mishra     Category: Java     Views: 3390

Develop a CORBA based application for addition of two complex numbers and displaying the result on client side.

Code for Develop a CORBA based application for addition of two complex numbers and displaying the result on client side in Java

// ComplexNumber.idl

module Ex3Module
{
    interface ComplexNumber
    {
        void setFirstNumber(inlonglong real , inlonglong imaginary) ;
        void setSecondNumber(inlonglong real , inlonglong imaginary) ;
        void doSum() ;
        longlong getReal() ;
        longlong getImaginary() ;
    } ;
} ;


// ComplexNumberImpl.java

import Ex3Module.ComplexNumberPOA ;

class ComplexNumberImpl extends ComplexNumberPOA
{
    long FirstReal , FirstImaginary ;
    long SecondReal , SecondImaginary ;
    long SumReal , SumImaginary ;

    publicvoid setFirstNumber(long real , long imaginary)
    {
        FirstReal = real ;
        FirstImaginary = imaginary ;
    }

    publicvoid setSecondNumber(long real , long imaginary)
    {
        SecondReal = real ;
        SecondImaginary = imaginary ;
    }    

    publicvoid doSum()
    {
        SumReal = FirstReal + SecondReal ;
        SumImaginary = FirstImaginary + SecondImaginary ;
    }

    publiclong getReal()
    {
        return SumReal ;
    }
    
    publiclong getImaginary()
    {
        return SumImaginary ;
    }
}


// ComplexNumberClient.java

import Ex3Module.* ;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;

class ComplexNumberClient
{
    publicstaticvoid main(String [] args)    
    {
        ComplexNumber cNumber = null ;

        try
        {
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);

            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);    
            
            String name = "ComplexNumber" ;

            cNumber = ComplexNumberHelper.narrow(ncRef.resolve_str(name));

            cNumber.setFirstNumber(9 , 4) ;
            cNumber.setSecondNumber(8 , 2) ;
            cNumber.doSum() ;

            System.out.println("The sum of two complexnumber is : " + cNumber.getReal() + " + " + cNumber.getImaginary() + "i") ;

                    
        }
        catch(Exception e)
        {
            e.printStackTrace() ;
        }
    }
}


// ComplexNumberServer.java

import Ex3Module.ComplexNumber ;
import org.omg.CosNaming.* ;
import org.omg.CosNaming.NamingContextPackage.* ;
import org.omg.PortableServer.* ;

class ComplexNumberServer
{
    publicstaticvoid main(String [] args)
    {
        try
        {
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args , null) ;
            
            POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

            rootPOA.the_POAManager().activate();

            ComplexNumberImpl cNumber = new ComplexNumberImpl() ;

            org.omg.CORBA.Object ref = rootPOA.servant_to_reference(cNumber) ;
            
            System.out.println("Step1");
            ComplexNumber h_ref = Ex3Module.ComplexNumberHelper.narrow(ref);

            System.out.println("Step2");
            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

            System.out.println("Step3");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            System.out.println("Step4");
            String name = "ComplexNumber";

            NameComponent path[] = ncRef.to_name(name);
            ncRef.rebind(path,h_ref);

            System.out.println("ComplexNumber Server reading and waiting....");
            orb.run();

        }
        catch(Exception e)        
        {
            e.printStackTrace() ;
        }
    }
}
  
Share: 



Milind Mishra
Milind Mishra author of Develop a CORBA based application for addition of two complex numbers and displaying the result on client side is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!