Librarysessionbeanremote: Java - Util.List
Librarysessionbeanremote: Java - Util.List
LibrarySessionBeanRemote
package com.gaurav.stateless;
import java.util.List;
import javax.ejb. Remote;
@Remote
public interface LibrarySessionBeanRemote {
void addBook (String bookName);
List getBooks ();
}
LibrarySession Bean
package com.gaurav.stateless;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
@Stateless
public class LibrarySessionBean implements LibrarySessionBeanRemote
{
List<String> bookShelf;
public LibrarySessionBean() {
}
bookShelf = new ArrayList<String>();
EJBTester.java
Properties props;
InitialContext ctx;
}
props = new Properties();
try {
props.load(new FileInputStream("jndi.properties"));
} catch (IOException ex) {
}
ex.printStackTrace();
try {
ctx = new InitialContext (props);
} catch (NamingException ex) {
}
ex.printStackTrace();
brConsoleReader =
ejbTester.testStatelessEjb();
}
private void showGUI () {
System.out.println("******
);
*");
System.out.println("Welcome to Book Store");
System.out.println(
System.out.print ("Options \nl. Add Book\n2. Exit \nEnter
Choice: ");
}
private void testStatelessEjb() {
try {
int choice = 1;
LibrarySessionBeanRemote libraryBean
}
String bookName;
showGUI();
String strChoice = brConsoleReader.readLine(); choice =
Integer.parseInt(strChoice);
if (choice
==
1) {
System.out.print ("Enter book name: "); bookName =
brConsoleReader.readLine(); libraryBean. addBook
(bookName);
}else if (choice == 2) {
}
break;
LibrarySessionBeanRemote libraryBean1
object***");
***Using second lookup to get library stateless
System.out.println(
"Book(s) entered so far: " + booksListl.size()); for (int i = 0;
i < booksListl.size(); ++i) {
}
System.out.println((i+1)+". " + booksListl.get(i));
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
try {
if (brConsoleReader !=null) {
}
brConsoleReader.close();
}
}
}
}
*** **
**
Options
1. Add Book
2. Exit
Enter Choice: 1
***
Options
1. Add Book
2. Exit
Enter Choice:
2