/*
 * The contents of this file are subject to the JOnAS Public License Version 
 * 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License on the JOnAS web site.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 * See the License for the specific terms governing rights and limitations under 
 * the License.
 *
 * The Original Code is JOnAS application server code released July 1999.
 *
 * The Initial Developer of the Original Code is Bull S.A.
 * The Original Code and portions created by Bull S.A. are
 *    Copyright (C) 1999 Bull S.A. All Rights Reserved.
 *
 * Contributor(s): ______________________________________.
 *
 * --------------------------------------------------------------------------
 * $Id: ClientAccount.java,v 1.4 2000/03/06 14:37:24 durieuph Exp $
 * --------------------------------------------------------------------------
 */


   package Category;

   import java.io.BufferedReader; 
   import java.io.FileInputStream;
   import java.io.InputStreamReader; 
   import java.io.IOException;
   import java.rmi.RemoteException;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Properties;
   import javax.ejb.FinderException;
   import javax.ejb.RemoveException;
   import javax.transaction.UserTransaction;
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import javax.rmi.PortableRemoteObject;
   import Category.Category;
   import Category.CategoryHome;

/**
 * Sample for entity beans.
 * Usage: 
 * 
 */
   public class CategoryClient {
   
      private static UserTransaction utx = null;
   
      private static void CategoryList(CategoryHome h) {
         Enumeration alist;
         Category acc;
         try {
            utx.begin();	// faster if made inside a Tx
            alist = h.findAllCategory();
            while (alist.hasMoreElements()) {
               acc = (Category) alist.nextElement();
               System.out.println(acc.GetNcat()+" "+acc.GetCat());
            }
            utx.commit();
         } 
            catch (Exception e) {
               System.err.println("Exception getting account list: " + e);
               System.exit(2);
            }
      }
   
      public static void main(String[] args) {
      
      // 1st arg. is the bean home (AccountImplHome or AccountExplHome)
         String beanName = "categoryHome";
      
      // get JNDI initial context
         Context initialContext = null;
         try {
            initialContext = new InitialContext();
         } 
            catch (Exception e) {
               System.err.println("Cannot get initial context for JNDI: " + e);
               System.exit(2);
            }
      
      // We want to start transactions from client: get UserTransaction
         System.out.println("Getting a UserTransaction object from JNDI");
         try {
            utx = (UserTransaction)
               PortableRemoteObject.narrow(initialContext.lookup("javax.transaction.UserTransaction"),
                                 UserTransaction.class);
         } 
            catch (Exception e) {
               System.err.println("Cannot lookup UserTransaction: "+e);
               System.exit(2);
            }
      
      // Connecting to Home thru JNDI
         System.out.println("Connecting to the categoryHome");
         CategoryHome home = null;
         try {
            home = (CategoryHome)PortableRemoteObject.narrow(
                                 initialContext.lookup(beanName),
                                 CategoryHome.class);
         } 
            catch (Exception e) {
               System.err.println("Cannot lookup "+beanName+": " +e);
               System.exit(2);
            }
      
      // List existing Accounts
         System.out.println("Getting the list of existing categories in database");
         CategoryList(home);
      
      
      
      
      
      
      
      
      
      
      
      // Exit program
         System.out.println("Client terminated");
      }
   
   }


