Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » CorbaRSS Feeds

Develop a CORBA application that takes a string from client and returns whether it is palindrome

Posted By: Grace Campbell     Category: Java     Views: 3110

Develop a CORBA application that takes a string from client and returns whether it is palindrome.

Code for Develop a CORBA application that takes a string from client and returns whether it is palindrome in Java

----------------------------------------------------------------------------------
                    IDL
----------------------------------------------------------------------------------
module MyString
{
   interface StringOp
   {
    string revstr(instring strMyString);
    oneway void shutdown();
   };
};

-------------------------------------------------------------------------------------------------
                    Server
-------------------------------------------------------------------------------------------------

import MyString.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.util.Properties;

class stringImpl extends StringOpPOA
{
    private ORB orb;
    publicvoid setORB(ORB orb_val)
    {
        orb = orb_val;
    }
    public String revstr(String strMyString)
    {
        String strMyString1;
        StringBuffer temp = new StringBuffer(strMyString);
        temp.reverse();
        strMyString1 = temp.toString();
        if((strMyString.equals(strMyString1)) == true)
        {
            return("Palindrom");
        }
        else
        {
            return("NotPalindrom");
        }
    }
    publicvoid shutdown()
    {
        orb.shutdown(false);
    }
}

class calcServer
{
    publicstaticvoid main(String args[])
    {
        try
        {
            ORB orb = ORB.init(args,null);
            
            POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPoa"));

            rootpoa.the_POAManager().activate();

            stringImpl objString = new stringImpl();

            objString.setORB(orb);
            
            org.omg.CORBA.Object ref = rootpoa.servant_to_reference(objString);
            StringOp href = StringOpHelper.narrow(ref);
            
            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            
            NameComponent path[] = ncRef.to_name("calc");
            ncRef.rebind(path,href);
            
            System.out.println("Server ready");
            
            orb.run();
        }
        catch(Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

-------------------------------------------------------------------------------------------------
                    Client
-------------------------------------------------------------------------------------------------

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

class calcClient
{
    static StringOp stringImpl;
    publicstaticvoid connect(ORB objOrb, org.omg.CORBA.Object objRef,NamingContextExt ncRef)
    {
        try
        {
            
            objRef = objOrb.resolve_initial_references("NameService");
            ncRef = NamingContextExtHelper.narrow(objRef);
            stringImpl = StringOpHelper.narrow(ncRef.resolve_str("calc"));
        }
        catch(Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }
        
    }
    publicstaticvoid main(String args[])
    {
        ORB objOrb=ORB.init(args, null);;
        org.omg.CORBA.Object objRef=null;
        NamingContextExt ncRef=null;
        connect(objOrb,objRef,ncRef);
        String s1 = "Vidyadhar",s2;
        s2 = stringImpl.revstr(s1);
        System.out.println("Original String is :==> " + s1);
        System.out.println("Ans is :==> " + s2);

        String s3 = "nayan",s4;
        s4 = stringImpl.revstr(s3);
        System.out.println("original String is :==> " + s3);
        System.out.println("Ans is :==> " + s4);

    }
}

-------------------------------------------------------------------------------------------------
                    Output
-------------------------------------------------------------------------------------------------

Original String is :==> Vidyadhar
Ans is :==> NotPalindrom

Original String is :==> nayan
Ans is :==> Palindrom
  
Share: 



Grace Campbell
Grace Campbell author of Develop a CORBA application that takes a string from client and returns whether it is palindrome is from Toronto, Canada.
 
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!