1 15 package org.apache.tapestry.vlib.pages; 16 17 import java.rmi.RemoteException ; 18 19 import javax.ejb.FinderException ; 20 import javax.ejb.RemoveException ; 21 22 import org.apache.hivemind.ApplicationRuntimeException; 23 import org.apache.tapestry.IRequestCycle; 24 import org.apache.tapestry.html.BasePage; 25 import org.apache.tapestry.vlib.VirtualLibraryEngine; 26 import org.apache.tapestry.vlib.ejb.Book; 27 import org.apache.tapestry.vlib.ejb.IOperations; 28 29 38 39 public abstract class ConfirmBookDelete extends BasePage 40 { 41 public abstract void setBookId(Integer bookId); 42 43 public abstract void setBookTitle(String title); 44 45 51 52 public void selectBook(Integer bookId, IRequestCycle cycle) 53 { 54 setBookId(bookId); 55 56 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 57 58 int i = 0; 59 while (true) 60 { 61 try 62 { 63 IOperations operations = vengine.getOperations(); 64 Book book = operations.getBook(bookId); 65 66 setBookTitle(book.getTitle()); 67 68 break; 69 } 70 catch (FinderException ex) 71 { 72 throw new ApplicationRuntimeException(ex); 73 } 74 catch (RemoteException ex) 75 { 76 vengine.rmiFailure("Remote exception reading read book #" + bookId + ".", ex, i++); 77 } 78 } 79 80 cycle.activate(this); 81 } 82 83 87 88 public void deleteBook(IRequestCycle cycle) 89 { 90 Object [] parameters = cycle.getServiceParameters(); 91 Integer bookPK = (Integer ) parameters[0]; 92 93 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 94 Book book = null; 95 96 int i = 0; 97 while (true) 98 { 99 try 100 { 101 IOperations operations = vengine.getOperations(); 102 103 book = operations.deleteBook(bookPK); 104 105 break; 106 } 107 catch (RemoveException ex) 108 { 109 throw new ApplicationRuntimeException(ex); 110 } 111 catch (RemoteException ex) 112 { 113 vengine.rmiFailure("Remote exception deleting book #" + bookPK + ".", ex, i++); 114 } 115 } 116 117 MyLibrary myLibrary = (MyLibrary) cycle.getPage("MyLibrary"); 118 119 myLibrary.setMessage(format("book-deleted", book.getTitle())); 120 121 myLibrary.activate(cycle); 122 } 123 } | Popular Tags |