To develop an Enterprise Java Bean for Library operations
#1

Aim : To develop an Enterprise Java Bean for Library operations
Algorthm :
1. Create five programs – Book, Bookbome, Bookbean, Bookexception, and Bookclient
2. In the Bookhome class just invoke the create() method with appropriate arguments
3. In the Book class, just define the prototytpes of addbook(), removebook() and getcontents() methods
4. In the Bookbean class provide the implementation for the various methods
5. In the Bookexception class provide the implementation for BookException
6. In the Bookclient class get the customer name and the various books he wants, also perform the other operations accordingly
Program
Book- Remote interface

Code:
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
public interface Book extends EJBObject
{
public void addBook(String title) throws RemoteException;
public void removeBook(String title) throws RemoteException,BookException;
public Vector getContents() throws RemoteException;
}

Book-Home interface

import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface BookHome extends EJBHome
{
public Book create(String person) throws RemoteException,CreateException;
public Book create(String person,String id) throws RemoteException,CreateException;
}

Book Bean class
import java.util.*;
import javax.ejb.*;
public class BookEJB implements SessionBean
{
String CustomerName;
String customerId;
Vector contents;
public void ejbCreate(String person) throws CreateException
{
if(person==null)
throw new CreateException("\nNull person not allowed");
else
CustomerName= person;
System.out.println("\nCustomer name: "+person);
customerId = "0";
contents = new Vector();
}
public void ejbCreate(String person,String id) throws CreateException
{
if(person==null)
throw new CreateException("\nNull person not allowed");
else
CustomerName= person;
System.out.println("\nCustomer name: "+person);
customerId = "0";
contents = new Vector();
}
public void addBook(String title)
{
contents.addElement(title);
}
public void removeBook(String title) throws BookException
{
boolean result = contents.removeElement(title);
if(result==false)
throw new BookException(title+"  Book is not in cart");
}
public Vector getContents()
{
return contents;
}
public BookEJB() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}
public void setSessionContext(SessionContext ctx) {}
}

Book-Exception

public class BookException extends Exception
{
public BookException() {}
public BookException(String msg)
{
super(msg);
}
}

Book-Client
Code:
import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import java.io.*;
import java.util.*;
public class BookClient
{
public static void main(String arg[])
{
Enumeration enum;
Vector bookList;
Book shoppingCart;
try
{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
p.put(Context.SECURITY_PRINCIPAL,"mca");
p.put(Context.SECURITY_CREDENTIALS,"mcastudent");
InitialContext ict = new InitialContext(p);
System.out.println("Context sucessful");
Object t = ict.lookup("BookEJB2");
System.out.println("Lookup successful");
BookHome home = (BookHome)PortableRemoteObject.narrow(t,BookHome.class);
shoppingCart = home.create("Siva","123");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nEnter customer name ");
String cust = br.readLine();
System.out.println("\nEnter the bookname U want: ");
String book1 = br.readLine();
shoppingCart.addBook(book1);
System.out.println("\nEnter the bookname U want: ");
String book2 = br.readLine();
shoppingCart.addBook(book2);
System.out.println("\nEnter the bookname U want: ");
String book3 = br.readLine();
shoppingCart.addBook(book3);
System.out.println("\nCustomer name is :"+cust);
System.out.println("Selected books are listed below");
bookList  = new Vector();
bookList = shoppingCart.getContents();
enum = bookList.elements();
while(enum.hasMoreElements())
{
String title = (String)enum.nextElement();
System.out.println(title);
}
System.out.println("\nDo U want to remove any book from cart");
String ch = br.readLine();
if(ch.equals("y"))
{
try
{
System.out.println("Enter the book name");
String remBook = br.readLine();
shoppingCart.removeBook(remBook);
System.out.println("\nBook has been removed from the cart");
System.out.println("Customer nmae: "+cust);
System.out.println("Slected books are listed below");
bookList = shoppingCart.getContents();
enum = bookList.elements();
while(enum.hasMoreElements())
{
String title1 = (String)enum.nextElement();
System.out.println(title1);
}
System.out.println("Thanks for dealing with us");
}
catch(Exception ex)
{
System.out.println("caught a BookException " +ex.getMessage());
}
}
else
System.out.println("thanks for dealing with us");
shoppingCart.remove();
}
catch(Exception ex)
{
System.out.println("Caught a Book Exception");
ex.printStackTrace();
}
}
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: how to develop student management sysytem in java, create session bean client for oracle jdeveloper, android jelly bean report, runner bean soup, create a java bean to draw various graphical shapes and display it using or withoutusing bdk, android 5 0 jelly bean seminar pdf, bean soup,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Simple Key Events Java source code smart paper boy 3 3,582 07-02-2017, 03:41 PM
Last Post: NARESHLAFOOT
  Window Events Java source code smart paper boy 1 3,659 02-03-2012, 10:48 AM
Last Post: seminar paper
  Inter net banking java source code smart paper boy 3 5,925 01-03-2012, 11:24 AM
Last Post: seminar paper
  UDP server java source code smart paper boy 1 3,800 05-01-2012, 05:50 PM
Last Post: jeslinapeter
  UDP client Java source code smart paper boy 2 3,659 12-12-2011, 09:56 AM
Last Post: seminar addict
  Text Demo Java source code smart paper boy 0 2,069 30-08-2011, 12:44 PM
Last Post: smart paper boy
  Text Area Demo Java source code smart paper boy 0 2,072 30-08-2011, 12:44 PM
Last Post: smart paper boy
  Servlet Database Java source code smart paper boy 0 2,450 30-08-2011, 12:42 PM
Last Post: smart paper boy
  server test Java source code smart paper boy 0 2,256 30-08-2011, 12:42 PM
Last Post: smart paper boy
  Ser To App java source code smart paper boy 0 1,670 30-08-2011, 12:39 PM
Last Post: smart paper boy

Forum Jump: