KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > vlib > pages > ConfirmBookDelete


1 // Copyright 2004 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.vlib.pages;
16
17 import java.rmi.RemoteException JavaDoc;
18
19 import javax.ejb.FinderException JavaDoc;
20 import javax.ejb.RemoveException JavaDoc;
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 /**
30  * Presents a confirmation page before deleting a book. If the user
31  * selects "yes", the book is deleted; otherwise the user is returned
32  * to the {@link MyLibrary} page.
33  *
34  * @author Howard Lewis Ship
35  * @version $Id: ConfirmBookDelete.java,v 1.11 2004/04/30 15:17:21 hlship Exp $
36  *
37  **/

38
39 public abstract class ConfirmBookDelete extends BasePage
40 {
41     public abstract void setBookId(Integer JavaDoc bookId);
42
43     public abstract void setBookTitle(String JavaDoc title);
44
45     /**
46      * Invoked (by {@link MyLibrary}) to select a book to be
47      * deleted. This method sets the temporary page properties
48      * (bookPrimaryKey and bookTitle) and invoked {@link IRequestCycle#setPage(IPage)}.
49      *
50      **/

51
52     public void selectBook(Integer JavaDoc 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 JavaDoc ex)
71             {
72                 throw new ApplicationRuntimeException(ex);
73             }
74             catch (RemoteException JavaDoc ex)
75             {
76                 vengine.rmiFailure("Remote exception reading read book #" + bookId + ".", ex, i++);
77             }
78         }
79
80         cycle.activate(this);
81     }
82
83     /**
84      * Hooked up to the yes component, this actually deletes the book.
85      *
86      **/

87
88     public void deleteBook(IRequestCycle cycle)
89     {
90         Object JavaDoc[] parameters = cycle.getServiceParameters();
91         Integer JavaDoc bookPK = (Integer JavaDoc) 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 JavaDoc ex)
108             {
109                 throw new ApplicationRuntimeException(ex);
110             }
111             catch (RemoteException JavaDoc 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