Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with CORBA Client...

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with CORBA Client...

    I am trying to create a server and client where the client can contact the server to create an account and deposit and withdraw into the account. The client should be able to open more than one account.

    I have no idea how to code the the Client bit.

    // The package containing our stubs.
    import AccountApp.*;
    // HelloServer will use the naming service.
    import org.omg.CosNaming.*;
    // The package containing special exceptions thrown by the name service.
    import org.omg.CosNaming.NamingContextPackage.*;
    // All CORBA applications need these classes.
    import org.omg.CORBA.*;
    import java.util.List;
    import java.util.LinkedList;
     
     
     
    public class Server 
    {
      public static void main(String args[])
      {
        try{
     
          // Create and initialize the ORB
          ORB orb = ORB.init(args, null);
     
          // Create the servant and register it with the ORB
          AccountImpl accRef = new AccountImpl();
          orb.connect(accRef);
     
          // Get the root naming context
          org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
          NamingContext ncRef = NamingContextHelper.narrow(objRef);
     
          // Bind the object reference in naming
          // Make sure there are no spaces between ""
          NameComponent nc = new NameComponent("Account", "");
          NameComponent path[] = {nc};
          ncRef.rebind(path, accRef);
     
          // Wait for invocations from clients
          java.lang.Object sync = new java.lang.Object();
          synchronized(sync){
            sync.wait();
          }
     
        } catch(Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
          }  
      }
    }
     
    class AccountImpl extends _AccountImplBase{
    	private String accountNo;
    	private String ownersName;
    	private String pin;
    	private float balance;
            //private List<Account> accounts;
            //private int number_of_accounts;
     
    	public AccountImpl(){
    	accountNo = "0987";
            pin = "1234";
            ownersName = "John";
            balance = 0;
            //accounts = new LinkedList<Account>();
           //number_of_accounts = 0;
            }
     
    	public float getBalance(String PIN)
     	 throws WrongPIN{
     	 	 pin = PIN;
     	  if (!PIN.equals(pin))
     	    throw new WrongPIN();
     	      return balance;
     	 	}
     
           public float deposit(String PIN, float amount)
              throws WrongPIN {
              	   pin = PIN;
                if (!PIN.equals(pin))
                  throw new WrongPIN();
                     balance += amount;
                         return balance;
                }
     
           public float withdraw(String PIN, float amount)
              throws WrongPIN, InsufficientFunds {
              	   pin = PIN;
                  if (!PIN.equals(pin))
                      throw new WrongPIN();
                          if (amount > balance)
                              throw new InsufficientFunds();
                                  balance -= amount;
                                     return balance;
                 }
     
          public void create(String name, float balance, String PIN){
        //++number_of_accounts;
        // Account res = new AccountImpl( Integer.toString(number_of_accounts)
                                     //  , PIN
                                      // , name
                                      // , balance);
        //  accounts.add( res );
        }
    }

    class Client
    {
      public static void main(String args[])
      {
        try{
     
          // Create and initialize the ORB
          ORB orb = ORB.init(args, null);
     
          // Get the root naming context
          org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
          NamingContext ncRef = NamingContextHelper.narrow(objRef);
     
          // Resolve the object reference in naming
          // make sure there are no spaces between ""
          NameComponent nc = new NameComponent("Account", "");
          NameComponent path[] = {nc};
          Account accRef = AccountHelper.narrow(ncRef.resolve(path));
     
     
        } catch(Exception e) {
            System.out.println("ERROR : " + e);
            e.printStackTrace(System.out);
          }  
      }
    }
    Last edited by RiskyShenanigan; March 18th, 2011 at 11:17 AM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Help with CORBA Client...

    What are your issues exactly? You need to give us a detailed description of the problems you are facing.
    How far have you got? Does any of it work etc..

    Seeing as you are using CORBA imports, you are very limited to the people who can actually compile this.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with CORBA Client...

    The problem I am having is in the Client class, I am unsure how to implement the methods that the Client can invoke, for instance deposit, withdraw and getBalance.

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with CORBA Client...

    Basically what I want is methods to call Server objects such as deposit, withdraw, and getBalance from the Client class, I just do not know how to write them.

Similar Threads

  1. http client
    By ilearn-computer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 06:47 AM
  2. web service client
    By maverick257 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 24th, 2010, 02:59 AM
  3. IRC client
    By Brt93yoda in forum The Cafe
    Replies: 14
    Last Post: November 26th, 2010, 03:31 PM
  4. CORBA , RMI and now JSHOOTER !
    By mcgrow in forum Web Frameworks
    Replies: 0
    Last Post: August 4th, 2010, 02:30 PM
  5. [SOLVED] web client
    By 5723 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: June 10th, 2009, 04:44 PM