Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » CorbaRSS Feeds

Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

Posted By: Waldemar Fischer     Category: Java     Views: 1807

Write a CORBA enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet.

Code for Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet in Java

----------------------------------------------------------------------------------
                    IDL
----------------------------------------------------------------------------------
module HelloApp
{
    interface Hello
    {
        string sayHello(instring str);
        oneway void shutdown();
    };
};

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

import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

import java.util.Properties;

class HelloImpl extends HelloPOA 
{
    private ORB orb;

    publicvoid setORB(ORB orb_val) 
    {
        orb = orb_val; 
    }    
          public String sayHello(String str)
          {
                   String upr_str=str.toUpperCase();
                   return ("\nHELLO"+upr_str);
          }    
          publicvoid shutdown() 
          {
                  orb.shutdown(false);
          }
}


publicclass HelloServer 
{
           publicstaticvoid main(String args[]) 
           {
                try
                { 
                      ORB orb = ORB.init(args, null);
 
                      POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
                      rootpoa.the_POAManager().activate();  

                      HelloImpl helloImpl = new HelloImpl();
                      helloImpl.setORB(orb); 

                      org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl);
                      Hello href = HelloHelper.narrow(ref);  
      
                     org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
                     NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
  
                     String name = "Hello";
                     NameComponent path[] = ncRef.to_name( name );
                     ncRef.rebind(path, href);

                     System.out.println("HelloServer ready and waiting ...");

                     orb.run();
               }     
               catch (Exception e) 
               {
                     System.err.println("ERROR: " + e);
                     e.printStackTrace(System.out);
               }      
               System.out.println("HelloServer Exiting ...");    
         }
}

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

import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.awt.Graphics;

publicclass HelloApplet extends java.applet.Applet
{
          publicvoid init() 
          { 
                 try
                 {
                       ORB orb = ORB.init(this, null);
      
                       org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
                       NamingContext ncRef = NamingContextHelper.narrow(objRef);

                       NameComponent nc = new NameComponent("Hello", "");
                       NameComponent path[] = {nc};
                       Hello helloRef = HelloHelper.narrow(ncRef.resolve(path));
      
                       message = helloRef.sayHello("glsict");    
                  }
                  catch(Exception e)
                 {
                       System.out.println("HelloApplet exception: " + e);
                       e.printStackTrace(System.out);
                 }  
           }

           String message = "";
 
           publicvoid paint(Graphics g)
           {
                  g.drawString(message, 25, 50);
           }
}

-------------------------------------------------------------------------------------------------
                    Applet (HTML File)
-------------------------------------------------------------------------------------------------

<HTML><HEAD>
<TITLE>Java IDL Getting Started: Running Hello Name Applet</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1 ALIGN=CENTER>Running the Hello Name Applet</H1>
<HR><P>If all goes well, the applet appears below:<P>
<APPLET CODE=HelloApplet.class       WIDTH=500        HEIGHT=300>
<PARAM name="org.omg.CORBA.ORBInitialHost"value=localhost>
<PARAM name="org.omg.CORBA.ORBInitialPort"value=1050>
</APPLET>
</BODY>
</HTML>
  
Share: 



Waldemar Fischer
Waldemar Fischer author of Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet is from Frankfurt, Germany.
 
View All Articles

 
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!