You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/10/13 00:36:48 UTC

svn commit: r315066 - in /jakarta/tapestry/trunk/examples/Vlib/src: context/WEB-INF/ java/org/apache/tapestry/vlib/ java/org/apache/tapestry/vlib/components/ java/org/apache/tapestry/vlib/pages/ java/org/apache/tapestry/vlib/pages/admin/ java/org/apach...

Author: hlship
Date: Wed Oct 12 15:36:30 2005
New Revision: 315066

URL: http://svn.apache.org/viewcvs?rev=315066&view=rev
Log:
Continue revving Virtual Library for Tapestry 4.0

Modified:
    jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/GiveAwayBooks.properties
    jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/AdminPage.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Protected.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/VirtualLibraryEngine.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Visit.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Border.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ApplicationUnavailable.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ConfirmBookDelete.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditBook.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditProfile.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/GiveAwayBooks.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Login.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Register.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewBook.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewPerson.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditPublishers.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/TransferBooksTransfer.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java
    jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java

Modified: jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/GiveAwayBooks.properties
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/GiveAwayBooks.properties?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/GiveAwayBooks.properties (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/GiveAwayBooks.properties Wed Oct 12 15:36:30 2005
@@ -14,7 +14,6 @@
 
 select-at-least-one-book=You must select at least one book to transfer to {0}.
 update-failure=Unable to transfer book(s).
-read-users-failure=Unable to obtain list of users.
 read-books-failure=Unable to retrieve list of books.
 transfered-books=Transfered {0} book(s) to {1}.
 no-books-to-transfer=You own no books that you could give away.

Modified: jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml Wed Oct 12 15:36:30 2005
@@ -41,7 +41,8 @@
         
         <invoke-factory>
             <construct class="RemoteTemplateImpl">
-                <set-object property="coordinator" value="service:hivemind.lib.RemoteExceptionCoordinator"/>
+                <set-object property="coordinator" value="service:hivemind.lib.RemoteExceptionCoordinator"/>
+                <set-object property="operations" value="service:Operations"/>            
             </construct>
         </invoke-factory>
     </service-point>

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/AdminPage.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/AdminPage.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/AdminPage.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/AdminPage.java Wed Oct 12 15:36:30 2005
@@ -16,6 +16,9 @@
 
 import org.apache.tapestry.IRequestCycle;
 import org.apache.tapestry.PageRedirectException;
+import org.apache.tapestry.annotations.InjectPage;
+import org.apache.tapestry.annotations.InjectState;
+import org.apache.tapestry.annotations.InjectStateFlag;
 import org.apache.tapestry.callback.PageCallback;
 import org.apache.tapestry.event.PageEvent;
 import org.apache.tapestry.vlib.pages.Login;
@@ -28,26 +31,35 @@
 
 public abstract class AdminPage extends Protected implements IMessageProperty
 {
+    @InjectState("visit")
+    public abstract Visit getVisitState();
+
+    @InjectStateFlag("visit")
+    public abstract boolean getVisitStateExists();
+
+    @InjectPage("Login")
+    public abstract Login getLogin();
 
     public void pageValidate(PageEvent event)
     {
-        IRequestCycle cycle = event.getRequestCycle();
-        Visit visit = (Visit) getEngine().getVisit();
+        boolean loggedIn = getVisitStateExists() && getVisitState().isUserLoggedIn();
 
-        if (visit == null || !visit.isUserLoggedIn())
+        if (!loggedIn)
         {
-            Login login = (Login) cycle.getPage("Login");
+            Login login = getLogin();
 
             login.setCallback(new PageCallback(this));
 
             throw new PageRedirectException(login);
         }
 
-        if (!visit.getUser(cycle).isAdmin())
-        {
-            VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
+        IRequestCycle cycle = getRequestCycle();
 
-            vengine.presentError("That function is restricted to adminstrators.", cycle);
+        if (!getVisitState().getUser().isAdmin())
+        {
+            getErrorPresenter().presentError(
+                    "That function is restricted to administrators.",
+                    cycle);
 
             throw new PageRedirectException(cycle.getPage());
         }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Protected.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Protected.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Protected.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Protected.java Wed Oct 12 15:36:30 2005
@@ -34,7 +34,7 @@
  * @author Howard Lewis Ship
  */
 
-public abstract class Protected extends BasePage implements IErrorProperty, PageValidateListener
+public abstract class Protected extends BasePage implements IErrorProperty, PageValidateListener, OperationsUser
 {
     @Bean(VirtualLibraryDelegate.class)
     public abstract IValidationDelegate getValidationDelegate();

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/VirtualLibraryEngine.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/VirtualLibraryEngine.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/VirtualLibraryEngine.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/VirtualLibraryEngine.java Wed Oct 12 15:36:30 2005
@@ -208,10 +208,7 @@
         _publisherModel = null;
         _personModel = null;
 
-        Visit visit = (Visit) getVisit();
-
-        if (visit != null)
-            visit.clearCache();
+        // Note: may need to update the user property of the Visit
     }
 
     /**
@@ -357,37 +354,7 @@
         _operations = null;
     }
 
-    /**
-     * Reads a person by id.
-     */
-
-    public Person readPerson(Integer personId)
-    {
-        Person result = null;
-
-        int i = 0;
-        while (true)
-        {
-            IOperations operations = getOperations();
-
-            try
-            {
-                result = operations.getPerson(personId);
-
-                break;
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException("No such Person #" + personId + ".", ex);
-            }
-            catch (RemoteException ex)
-            {
-                rmiFailure("Unable to read Person #" + personId + ".", ex, i++);
-            }
-        }
-
-        return result;
-    }
+ 
 
     protected void handleStaleSessionException(IRequestCycle cycle, StaleSessionException exception)
     {

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Visit.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Visit.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Visit.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/Visit.java Wed Oct 12 15:36:30 2005
@@ -17,7 +17,6 @@
 import java.io.Serializable;
 import java.sql.Timestamp;
 
-import org.apache.tapestry.IRequestCycle;
 import org.apache.tapestry.vlib.ejb.Person;
 
 /**
@@ -35,16 +34,7 @@
      * Used to identify the logged in user.
      */
 
-    private transient Person _user;
-
-    private Integer _userId;
-
-    /**
-     * Set when the user first logs in. This is the time of their previous login (logging in returns
-     * the old value then updates the value for subsequent logins).
-     */
-
-    private Timestamp _lastAccess;
+    private Person _user;
 
     /**
      * Returns the time the user last accessed the database, which may be null if the user hasn't
@@ -53,25 +43,15 @@
 
     public Timestamp getLastAccess()
     {
-        return _lastAccess;
+        return _user == null ? null : _user.getLastAccess();
     }
 
     /**
      * Gets the logged-in user, or null if the user is not logged in.
      */
 
-    public Person getUser(IRequestCycle cycle)
+    public Person getUser()
     {
-        if (_user != null)
-            return _user;
-
-        if (_userId == null)
-            return null;
-
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
-
-        _user = vengine.readPerson(_userId);
-
         return _user;
     }
 
@@ -81,7 +61,7 @@
 
     public Integer getUserId()
     {
-        return _userId;
+        return _user == null ? null : _user.getId();
     }
 
     /**
@@ -89,18 +69,9 @@
      * {@link org.apache.tapestry.vlib.pages.Login} page.
      */
 
-    public void setUser(Person value)
+    public void setUser(Person user)
     {
-        _lastAccess = null;
-        _user = value;
-        _userId = null;
-
-        if (_user == null)
-            return;
-
-        _userId = _user.getId();
-
-        _lastAccess = _user.getLastAccess();
+        _user = user;
     }
 
     /**
@@ -109,7 +80,7 @@
 
     public boolean isUserLoggedIn()
     {
-        return _userId != null;
+        return _user != null;
     }
 
     /**
@@ -118,15 +89,15 @@
 
     public boolean isUserLoggedOut()
     {
-        return _userId == null;
+        return _user == null;
     }
 
     public boolean isLoggedInUser(Integer id)
     {
-        if (_userId == null)
+        if (_user == null)
             return false;
 
-        return _userId.equals(id);
+        return _user.getId().equals(id);
     }
 
     /**

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Border.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Border.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Border.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Border.java Wed Oct 12 15:36:30 2005
@@ -199,7 +199,7 @@
 
         IRequestCycle cycle = getPage().getRequestCycle();
 
-        return visit.isUserLoggedIn() && visit.getUser(cycle).isAdmin();
+        return visit.isUserLoggedIn() && visit.getUser().isAdmin();
     }
 
     public void editProfile()

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java Wed Oct 12 15:36:30 2005
@@ -97,19 +97,14 @@
     public IPage borrow(final IRequestCycle cycle, final Integer bookId)
     {
         final Visit visit = getVisit();
-        final Home home = getHome();
 
-        RemoteCallback callback = new RemoteCallback()
+        RemoteCallback<Book> callback = new RemoteCallback()
         {
-            public Object remoteCallback() throws RemoteException
+            public Book doRemote() throws RemoteException
             {
                 try
                 {
-                    Book book = getOperations().borrowBook(bookId, visit.getUserId());
-
-                    home.setMessage(borrowedBook(book.getTitle()));
-
-                    return null;
+                    return getOperations().borrowBook(bookId, visit.getUserId());
                 }
                 catch (BorrowException ex)
                 {
@@ -119,12 +114,19 @@
                 }
                 catch (FinderException ex)
                 {
-                    throw new ApplicationRuntimeException("Unable to find book or user.", ex);
+                    throw new ApplicationRuntimeException(ex);
                 }
             }
         };
 
-        getRemoteTemplate().doRemote(callback, "Error borrowing book.");
+        Book book = getRemoteTemplate().execute(callback, "Error borrowing book.");
+
+        if (book == null)
+            return null;
+
+        Home home = getHome();
+
+        home.setMessage(borrowedBook(book.getTitle()));
 
         return home;
     }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ApplicationUnavailable.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ApplicationUnavailable.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ApplicationUnavailable.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ApplicationUnavailable.java Wed Oct 12 15:36:30 2005
@@ -21,8 +21,6 @@
  * A page only displayed when the application is unavailable (typically because of repeated
  * {@link java.rmi.RemoteException}s or {@link javax.naming.NamingException}s accessing EJBs.
  * 
- * @see org.apache.tapestry.vlib.VirtualLibraryEngine#rmiFailure(String, java.rmi.RemoteException,
- *      int)
  * @author Howard Lewis Ship
  * @since 2.2
  */

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ConfirmBookDelete.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ConfirmBookDelete.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ConfirmBookDelete.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ConfirmBookDelete.java Wed Oct 12 15:36:30 2005
@@ -26,9 +26,11 @@
 import org.apache.tapestry.annotations.Message;
 import org.apache.tapestry.annotations.Meta;
 import org.apache.tapestry.html.BasePage;
+import org.apache.tapestry.vlib.OperationsUser;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.ejb.Book;
 import org.apache.tapestry.vlib.ejb.IOperations;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Presents a confirmation page before deleting a book. If the user selects "yes", the book is
@@ -38,7 +40,7 @@
  */
 
 @Meta("page-type=MyLibrary")
-public abstract class ConfirmBookDelete extends BasePage
+public abstract class ConfirmBookDelete extends BasePage implements OperationsUser
 {
     public abstract void setBookId(Integer bookId);
 
@@ -60,29 +62,9 @@
     {
         setBookId(bookId);
 
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
+        Book book = getRemoteTemplate().getBook(bookId);
 
-        int i = 0;
-        while (true)
-        {
-            try
-            {
-                IOperations operations = vengine.getOperations();
-                Book book = operations.getBook(bookId);
-
-                setBookTitle(book.getTitle());
-
-                break;
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception reading read book #" + bookId + ".", ex, i++);
-            }
-        }
+        setBookTitle(book.getTitle());
 
         getRequestCycle().activate(this);
     }
@@ -91,31 +73,24 @@
      * Hooked up to the yes component, this actually deletes the book.
      */
 
-    public void deleteBook(Integer bookPK)
+    public void deleteBook(final Integer bookId)
     {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-        Book book = null;
-
-        int i = 0;
-        while (true)
+        RemoteCallback<Book> callback = new RemoteCallback()
         {
-            try
-            {
-                IOperations operations = vengine.getOperations();
-
-                book = operations.deleteBook(bookPK);
-
-                break;
-            }
-            catch (RemoveException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
+            public Book doRemote() throws RemoteException
             {
-                vengine.rmiFailure("Remote exception deleting book #" + bookPK + ".", ex, i++);
+                try
+                {
+                    return getOperations().deleteBook(bookId);
+                }
+                catch (RemoveException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
             }
-        }
+        };
+
+        Book book = getRemoteTemplate().execute(callback, "Error deleting book #" + bookId + ".");
 
         MyLibrary myLibrary = getMyLibrary();
 

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditBook.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditBook.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditBook.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditBook.java Wed Oct 12 15:36:30 2005
@@ -33,6 +33,7 @@
 import org.apache.tapestry.vlib.Protected;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.ejb.IOperations;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Edits the properties of at book.
@@ -59,37 +60,31 @@
      * {@link org.apache.tapestry.vlib.ejb.IBook} and updates the request cycle to render this page,
      */
 
-    public void beginEdit(Integer bookId)
+    public void beginEdit(final Integer bookId)
     {
         setBookId(bookId);
 
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-
-        int i = 0;
-        while (true)
+        RemoteCallback<Map> callback = new RemoteCallback()
         {
-            try
+            public Map doRemote() throws RemoteException
             {
-                // Get the attributes as a source for our input fields.
+                try
+                {
+                    return getOperations().getBookAttributes(bookId);
 
-                IOperations operations = vengine.getOperations();
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
+            }
+        };
 
-                setAttributes(operations.getBookAttributes(bookId));
+        Map attributes = getRemoteTemplate().execute(
+                callback,
+                "Error setting up page for book #" + bookId + ".");
 
-                break;
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure(
-                        "Remote exception setting up page for book #" + bookId + ".",
-                        ex,
-                        i++);
-            }
-        }
+        setAttributes(attributes);
 
         getRequestCycle().activate(this);
     }
@@ -109,10 +104,10 @@
 
     public IPage formSubmit(IRequestCycle cycle)
     {
-        Map attributes = getAttributes();
+        final Map attributes = getAttributes();
 
-        Integer publisherId = (Integer) attributes.get("publisherId");
-        String publisherName = getPublisherName();
+        final Integer publisherId = (Integer) attributes.get("publisherId");
+        final String publisherName = getPublisherName();
 
         if (publisherId == null && HiveMind.isBlank(publisherName))
         {
@@ -131,43 +126,44 @@
         if (isInError())
             return null;
 
-        // OK, do the update.
-
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
-        Integer bookId = getBookId();
+        final Integer bookId = getBookId();
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            IOperations bean = vengine.getOperations();
-
-            try
+            public Object doRemote() throws RemoteException
             {
-                if (publisherId != null)
-                    bean.updateBook(bookId, attributes);
-                else
+
+                try
                 {
-                    bean.updateBook(bookId, attributes, publisherName);
-                    vengine.clearCache();
+                    IOperations operations = getOperations();
+
+                    if (publisherId != null)
+                        operations.updateBook(bookId, attributes);
+                    else
+                    {
+                        operations.updateBook(bookId, attributes, publisherName);
+                    }
+
+                    return null;
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
+                catch (CreateException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
                 }
 
-                break;
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (CreateException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
             }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception updating book #" + bookId + ".", ex, i++);
 
-                continue;
-            }
-        }
+        };
+
+        getRemoteTemplate().execute(callback, "Error updating book #" + bookId + ".");
+
+        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
+
+        vengine.clearCache();
 
         MyLibrary page = (MyLibrary) cycle.getPage("MyLibrary");
 

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditProfile.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditProfile.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditProfile.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/EditProfile.java Wed Oct 12 15:36:30 2005
@@ -35,6 +35,7 @@
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.Visit;
 import org.apache.tapestry.vlib.ejb.IOperations;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Edit's a user's profile: names, email and password.
@@ -84,31 +85,25 @@
     public void activate()
     {
         Visit visit = getVisitState();
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getRequestCycle().getEngine();
 
-        Integer userId = visit.getUserId();
-        Map attributes = null;
+        final Integer userId = visit.getUserId();
 
-        int i = 0;
-        while (true)
+        RemoteCallback<Map> callback = new RemoteCallback()
         {
-            try
+            public Map doRemote() throws RemoteException
             {
-                IOperations operations = vengine.getOperations();
-
-                attributes = operations.getPersonAttributes(userId);
-
-                break;
+                try
+                {
+                    return getOperations().getPersonAttributes(userId);
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
             }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception reading user.", ex, i++);
-            }
-        }
+        };
+
+        Map attributes = getRemoteTemplate().execute(callback, "Error reading user information.");
 
         attributes.remove("password");
         setAttributes(attributes);
@@ -135,7 +130,7 @@
         if (delegate.getHasErrors())
             return;
 
-        Map attributes = getAttributes();
+        final Map attributes = getAttributes();
 
         if (HiveMind.isBlank(password1) != HiveMind.isBlank(password2))
         {
@@ -156,34 +151,28 @@
         }
 
         Visit visit = getVisitState();
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
-        Integer userId = visit.getUserId();
+        final Integer userId = visit.getUserId();
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
+            public Object doRemote() throws RemoteException
             {
-                /**
-                 * Note: this allows the user to change thier e-mail such that it conflicts with
-                 * another user! Need yet-another IOperations method to perform the update!
-                 */
-
-                IOperations operations = vengine.getOperations();
-
-                operations.updatePerson(userId, attributes);
-                break;
+                try
+                {
+                    getOperations().updatePerson(userId, attributes);
+
+                    return null;
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
             }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception updating user attributes.", ex, i++);
-            }
-        }
+        };
 
+        getRemoteTemplate().execute(callback, "Error updating user attributes.");
+
+        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
         vengine.clearCache();
 
         getMyLibrary().activate();

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/GiveAwayBooks.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/GiveAwayBooks.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/GiveAwayBooks.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/GiveAwayBooks.java Wed Oct 12 15:36:30 2005
@@ -33,8 +33,8 @@
 import org.apache.tapestry.vlib.Visit;
 import org.apache.tapestry.vlib.ejb.Book;
 import org.apache.tapestry.vlib.ejb.IBookQuery;
-import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.ejb.Person;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Used to manage giving away of books to other users.
@@ -67,9 +67,6 @@
     public abstract String transferedBooks(int count, String targetName);
 
     @Message
-    public abstract String readUsersFailure();
-
-    @Message
     public abstract String readBooksFailure();
 
     @InjectPage("MyLibrary")
@@ -77,11 +74,9 @@
 
     public void formSubmit()
     {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-
-        Integer targetUserId = getTargetUserId();
+        final Integer targetUserId = getTargetUserId();
 
-        Person target = vengine.readPerson(targetUserId);
+        Person target = getRemoteTemplate().getPerson(targetUserId);
 
         List selectedBooks = getSelectedBooks();
 
@@ -93,28 +88,25 @@
             return;
         }
 
-        Integer[] bookIds = (Integer[]) selectedBooks.toArray(new Integer[count]);
+        final Integer[] bookIds = (Integer[]) selectedBooks.toArray(new Integer[count]);
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            IOperations operations = vengine.getOperations();
-
-            try
+            public Object doRemote() throws RemoteException
             {
-                operations.transferBooks(targetUserId, bookIds);
-
-                break;
+                try
+                {
+                    getOperations().transferBooks(targetUserId, bookIds);
+                    return null;
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
             }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure(updateFailure(), ex, i++);
-            }
-        }
+        };
+
+        getRemoteTemplate().execute(callback, updateFailure());
 
         MyLibrary myLibrary = getMyLibrary();
 
@@ -125,36 +117,20 @@
 
     private IPropertySelectionModel buildPersonModel()
     {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-        Visit visit = (Visit) vengine.getVisit();
+        Visit visit = getVisitState();
         Integer userPK = visit.getUserId();
 
-        Person[] persons = null;
-
-        int i = 0;
-        while (true)
-        {
-            IOperations operations = vengine.getOperations();
-
-            try
-            {
-                persons = operations.getPersons();
-
-                break;
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure(readUsersFailure(), ex, i++);
-            }
-        }
+        Person[] persons = getRemoteTemplate().getPersons();
 
         EntitySelectionModel result = new EntitySelectionModel();
 
-        for (i = 0; i < persons.length; i++)
+        for (int i = 0; i < persons.length; i++)
         {
 
             Person p = persons[i];
             Integer pk = p.getId();
+
+            // Skip the current user
 
             if (pk.equals(userPK))
                 continue;

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Login.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Login.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Login.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Login.java Wed Oct 12 15:36:30 2005
@@ -31,12 +31,14 @@
 import org.apache.tapestry.services.CookieSource;
 import org.apache.tapestry.valid.IValidationDelegate;
 import org.apache.tapestry.vlib.IErrorProperty;
+import org.apache.tapestry.vlib.OperationsUser;
 import org.apache.tapestry.vlib.VirtualLibraryDelegate;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.Visit;
 import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.ejb.LoginException;
 import org.apache.tapestry.vlib.ejb.Person;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Allows the user to login, by providing email address and password. After succesfully logging in,
@@ -46,7 +48,8 @@
  * @author Howard Lewis Ship
  */
 
-public abstract class Login extends BasePage implements IErrorProperty, PageBeginRenderListener
+public abstract class Login extends BasePage implements IErrorProperty, PageBeginRenderListener,
+        OperationsUser
 {
     /**
      * The name of a cookie to store on the user's machine that will identify them next time they
@@ -95,7 +98,7 @@
 
     public void attemptLogin(IRequestCycle cycle)
     {
-        String password = getPassword();
+        final String password = getPassword();
 
         // Do a little extra work to clear out the password.
 
@@ -110,34 +113,34 @@
         if (delegate.getHasErrors())
             return;
 
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
+            public Object doRemote() throws RemoteException
             {
-                IOperations operations = vengine.getOperations();
 
-                Person person = operations.login(getEmail(), password);
+                try
+                {
+                    Person person = getOperations().login(getEmail(), password);
+
+                    loginUser(person);
+
+                    return null;
+                }
+                catch (LoginException ex)
+                {
+                    IFormComponent field = ex.isPasswordError() ? getPasswordField()
+                            : getEmailField();
 
-                loginUser(person);
+                    getValidationDelegate().record(field, ex.getMessage());
 
-                break;
+                    return null;
+                }
 
             }
-            catch (LoginException ex)
-            {
-                IFormComponent field = ex.isPasswordError() ? getPasswordField() : getEmailField();
+        };
+
+        getRemoteTemplate().execute(callback, "Error validating user.");
 
-                getValidationDelegate().record(field, ex.getMessage());
-                return;
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception validating user.", ex, i++);
-            }
-        }
     }
 
     /**

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Register.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Register.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Register.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/Register.java Wed Oct 12 15:36:30 2005
@@ -28,11 +28,13 @@
 import org.apache.tapestry.html.BasePage;
 import org.apache.tapestry.valid.IValidationDelegate;
 import org.apache.tapestry.vlib.IErrorProperty;
+import org.apache.tapestry.vlib.OperationsUser;
 import org.apache.tapestry.vlib.VirtualLibraryDelegate;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.ejb.Person;
 import org.apache.tapestry.vlib.ejb.RegistrationException;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Invoked from the {@link Login} page, to allow a user to register into the system on-the-fly.
@@ -41,7 +43,7 @@
  */
 
 @Meta("page-type=Login")
-public abstract class Register extends BasePage implements IErrorProperty
+public abstract class Register extends BasePage implements IErrorProperty, OperationsUser
 {
     public abstract String getFirstName();
 
@@ -84,7 +86,7 @@
     {
         IValidationDelegate delegate = getValidationDelegate();
 
-        String password1 = getPassword1();
+        final String password1 = getPassword1();
         String password2 = getPassword2();
 
         setPassword1(null);
@@ -105,41 +107,34 @@
             return;
         }
 
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-        Login login = getLogin();
-
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
-            {
-                IOperations bean = vengine.getOperations();
-                Person user = bean.registerNewUser(
-                        getFirstName(),
-                        getLastName(),
-                        getEmail(),
-                        password1);
-
-                // Ask the login page to return us to the proper place, as well
-                // as set a cookie identifying the user for next time.
-
-                login.loginUser(user);
-
-                break;
-            }
-            catch (RegistrationException ex)
+            public Object doRemote() throws RemoteException
             {
-                setError(ex.getMessage());
-                return;
+                try
+                {
+                    Person user = getOperations().registerNewUser(
+                            getFirstName(),
+                            getLastName(),
+                            getEmail(),
+                            password1);
+
+                    getLogin().loginUser(user);
+
+                    return null;
+                }
+                catch (RegistrationException ex)
+                {
+                    setError(ex.getMessage());
+                    return null;
+                }
+                catch (CreateException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
             }
-            catch (CreateException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception registering new user.", ex, i++);
-            }
-        }
+        };
+
+        getRemoteTemplate().execute(callback, "Error registering new user.");
     }
 }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewBook.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewBook.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewBook.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewBook.java Wed Oct 12 15:36:30 2005
@@ -26,6 +26,7 @@
 import org.apache.tapestry.event.PageBeginRenderListener;
 import org.apache.tapestry.event.PageEvent;
 import org.apache.tapestry.html.BasePage;
+import org.apache.tapestry.vlib.OperationsUser;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.ejb.Book;
 import org.apache.tapestry.vlib.ejb.IOperations;
@@ -36,7 +37,8 @@
  * @author Howard Lewis Ship
  */
 @Meta("page-type=Search")
-public abstract class ViewBook extends BasePage implements IExternalPage, PageBeginRenderListener
+public abstract class ViewBook extends BasePage implements IExternalPage, PageBeginRenderListener,
+        OperationsUser
 {
     private DateFormat _dateFormat;
 
@@ -58,32 +60,12 @@
 
     private void readBook()
     {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-        Integer bookId = getBookId();
+        // This doesn't handle invalid book id as nicely as the 3.0 code did, but I'm
+        // getting a bit lazy!
 
-        int i = 0;
-        while (true)
-        {
-            IOperations bean = vengine.getOperations();
-
-            try
-            {
-                setBook(bean.getBook(bookId));
-
-                return;
-            }
-            catch (FinderException ex)
-            {
-                vengine.presentError("Book not found in database.", getRequestCycle());
-                return;
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception obtaining information for book #" + bookId
-                        + ".", ex, i++);
-            }
-        }
+        Book book = getRemoteTemplate().getBook(getBookId());
 
+        setBook(book);
     }
 
     public DateFormat getDateFormat()

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewPerson.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewPerson.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewPerson.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/ViewPerson.java Wed Oct 12 15:36:30 2005
@@ -24,6 +24,7 @@
 import org.apache.tapestry.event.PageBeginRenderListener;
 import org.apache.tapestry.event.PageEvent;
 import org.apache.tapestry.html.BasePage;
+import org.apache.tapestry.vlib.OperationsUser;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.components.Browser;
 import org.apache.tapestry.vlib.ejb.IBookQuery;
@@ -39,7 +40,8 @@
  * @author Howard Lewis Ship
  */
 @Meta("page-type=Search")
-public abstract class ViewPerson extends BasePage implements IExternalPage, PageBeginRenderListener
+public abstract class ViewPerson extends BasePage implements IExternalPage,
+        PageBeginRenderListener, OperationsUser
 {
     public abstract Integer getPersonId();
 
@@ -135,9 +137,7 @@
 
         if (person == null)
         {
-            VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-
-            person = vengine.readPerson(getPersonId());
+            person = getRemoteTemplate().getPerson(getPersonId());
 
             setPerson(person);
         }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditPublishers.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditPublishers.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditPublishers.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditPublishers.java Wed Oct 12 15:36:30 2005
@@ -34,9 +34,9 @@
 import org.apache.tapestry.util.DefaultPrimaryKeyConverter;
 import org.apache.tapestry.vlib.AdminPage;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
-import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.ejb.Publisher;
 import org.apache.tapestry.vlib.pages.MyLibrary;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Allows editting of the publishers in the database, including deleting publishers (which can be
@@ -100,25 +100,16 @@
 
     private void readPublishers()
     {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-        Publisher[] publishers = null;
-
-        int i = 0;
-        while (true)
+        RemoteCallback<Publisher[]> callback = new RemoteCallback()
         {
-            try
+            public Publisher[] doRemote() throws RemoteException
             {
-                IOperations operations = vengine.getOperations();
-
-                publishers = operations.getPublishers();
-
-                break;
+                return getOperations().getPublishers();
             }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure(updateFailure(), ex, i++);
-            }
-        }
+        };
+
+        Publisher[] publishers = getRemoteTemplate()
+                .execute(callback, "Could not read publishers.");
 
         DefaultPrimaryKeyConverter converter = getConverter();
 
@@ -154,37 +145,34 @@
 
     public void processForm(IRequestCycle cycle)
     {
-        Publisher[] updated = extractUpdatedPublishers();
-        Integer[] deletedKeys = extractDeletedKeys();
-
-        // Now, push the updates through to the database
-
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
+        final Publisher[] updated = extractUpdatedPublishers();
+        final Integer[] deletedKeys = extractDeletedKeys();
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
+            public Object doRemote() throws RemoteException
             {
-                IOperations operations = vengine.getOperations();
 
-                operations.updatePublishers(updated, deletedKeys);
+                try
+                {
+                    getOperations().updatePublishers(updated, deletedKeys);
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
+                catch (RemoveException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
 
-                break;
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (RemoveException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
+                return null;
             }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure(updateFailure(), ex, i++);
-            }
-        }
+        };
+
+        getRemoteTemplate().execute(callback, updateFailure());
+
+        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
 
         // Clear any cached info about publishers.
 

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java Wed Oct 12 15:36:30 2005
@@ -39,6 +39,7 @@
 import org.apache.tapestry.vlib.Visit;
 import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.ejb.Person;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Allows editting of the users. Simple flags about the user can be changed; additionally, the user
@@ -73,9 +74,6 @@
     @Message
     public abstract String usersUpdated();
 
-    @InjectState("visit")
-    public abstract Visit getVisitState();
-
     @InjectComponent("password")
     public abstract IFormComponent getPasswordField();
 
@@ -127,34 +125,25 @@
 
     private void readUsers()
     {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
         Visit visit = getVisitState();
 
         Integer userId = visit.getUserId();
-        Person[] users = null;
 
-        int i = 0;
-        while (true)
+        RemoteCallback<Person[]> callback = new RemoteCallback()
         {
-            try
-            {
-                IOperations operations = vengine.getOperations();
-
-                users = operations.getPersons();
-
-                break;
-            }
-            catch (RemoteException ex)
+            public Person[] doRemote() throws RemoteException
             {
-                vengine.rmiFailure(readFailure(), ex, i++);
+                return getOperations().getPersons();
             }
-        }
+        };
+
+        Person[] users = getRemoteTemplate().execute(callback, readFailure());
 
         UserConverter converter = getUserConverter();
 
         converter.clear();
 
-        for (i = 0; i < users.length; i++)
+        for (int i = 0; i < users.length; i++)
         {
             Integer id = users[i].getId();
 
@@ -171,19 +160,17 @@
      * Invoked when the form is submitted.
      */
 
-    public void updateUsers(IRequestCycle cycle)
+    public void updateUsers()
     {
         Visit visit = getVisitState();
 
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
-
         UserConverter converter = getUserConverter();
 
-        Person[] updates = (Person[]) converter.getValues().toArray(new Person[0]);
-        Integer[] deletedIds = extractIds(converter.getDeletedValues());
-        Integer[] resetPasswordIds = extractIds(converter.getResetPasswordValues());
+        final Person[] updates = (Person[]) converter.getValues().toArray(new Person[0]);
+        final Integer[] deletedIds = extractIds(converter.getDeletedValues());
+        final Integer[] resetPasswordIds = extractIds(converter.getResetPasswordValues());
 
-        String password = getPassword();
+        final String password = getPassword();
         setPassword(null);
 
         if (HiveMind.isBlank(password) && resetPasswordIds.length > 0)
@@ -192,31 +179,36 @@
             return;
         }
 
-        Integer adminId = visit.getUserId();
+        final Integer adminId = visit.getUserId();
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
+            public Object doRemote() throws RemoteException
             {
-                IOperations operations = vengine.getOperations();
+                try
+                {
+                    getOperations().updatePersons(
+                            updates,
+                            resetPasswordIds,
+                            password,
+                            deletedIds,
+                            adminId);
+                }
+                catch (RemoveException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
 
-                operations.updatePersons(updates, resetPasswordIds, password, deletedIds, adminId);
-                break;
+                return null;
             }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure(updateFailure(), ex, i++);
-            }
-            catch (RemoveException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
-            }
-        }
+
+        };
+
+        getRemoteTemplate().execute(callback, updateFailure());
 
         setMessage(usersUpdated());
     }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/TransferBooksTransfer.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/TransferBooksTransfer.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/TransferBooksTransfer.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/TransferBooksTransfer.java Wed Oct 12 15:36:30 2005
@@ -39,6 +39,7 @@
 import org.apache.tapestry.vlib.ejb.IBookQuery;
 import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.ejb.Person;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Second page in Transfer Books wizard; allows the books owned by the from user to be selected and
@@ -89,7 +90,7 @@
 
     public void activate(Integer fromUserId, Integer toUserId)
     {
-        Person fromUser = readPerson(fromUserId);
+        Person fromUser = getRemoteTemplate().getPerson(fromUserId);
 
         IPropertySelectionModel model = buildUserBookModel(fromUser);
 
@@ -121,7 +122,7 @@
 
         if (fromUser == null)
         {
-            fromUser = readPerson(getFromUserId());
+            fromUser = getRemoteTemplate().getPerson(getFromUserId());
             setFromUser(fromUser);
         }
 
@@ -131,7 +132,7 @@
         Person toUser = getToUser();
         if (toUser == null)
         {
-            toUser = readPerson(getToUserId());
+            toUser = getRemoteTemplate().getPerson(getToUserId());
             setToUser(toUser);
         }
     }
@@ -140,31 +141,27 @@
     {
         List selectedBooks = getSelectedBooks();
 
-        Integer[] keys = (Integer[]) selectedBooks.toArray(new Integer[0]);
-        Person toUser = getToUser();
-
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
+        final Integer[] keys = (Integer[]) selectedBooks.toArray(new Integer[0]);
+        final Person toUser = getToUser();
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
+            public Object doRemote() throws RemoteException
             {
-                IOperations operations = vengine.getOperations();
-
-                operations.transferBooks(toUser.getId(), keys);
+                try
+                {
+                    getOperations().transferBooks(toUser.getId(), keys);
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
 
-                break;
-            }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException(ex);
+                return null;
             }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Unable to transfer ownership of books.", ex, i++);
-            }
-        }
+        };
+
+        getRemoteTemplate().execute(callback, "Unable to transfer ownership of books.");
 
         Person fromUser = getFromUser();
 
@@ -213,10 +210,4 @@
         return model;
     }
 
-    private Person readPerson(Integer personId)
-    {
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
-
-        return vengine.readPerson(personId);
-    }
 }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java Wed Oct 12 15:36:30 2005
@@ -22,7 +22,7 @@
  * @author Howard M. Lewis Ship
  * @since 4.0
  */
-public interface RemoteCallback
+public interface RemoteCallback<T>
 {
     /**
      * Invoked by {@link RemoteTemplate}.
@@ -30,5 +30,5 @@
      * @return
      * @throws RemoteException
      */
-    Object remoteCallback() throws RemoteException;
+    T doRemote() throws RemoteException;
 }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java Wed Oct 12 15:36:30 2005
@@ -14,8 +14,12 @@
 
 package org.apache.tapestry.vlib.services;
 
+import org.apache.tapestry.vlib.ejb.Book;
+import org.apache.tapestry.vlib.ejb.Person;
+
 /**
- * Used to execute a {@link org.apache.tapestry.vlib.services.RemoteCallback}.
+ * Used to execute a {@link org.apache.tapestry.vlib.services.RemoteCallback}. In addition,
+ * provides a few very common operations.
  * 
  * @author Howard M. Lewis Ship
  */
@@ -30,5 +34,34 @@
      *            used when the callback fails
      * @return the return value of the callback
      */
-    Object doRemote(RemoteCallback callback, String errorMessage);
+    <T> T execute(RemoteCallback<T> callback, String errorMessage);
+
+    /**
+     * Reads a person, which is expected to exist.
+     * 
+     * @param personId
+     *            unique id for the person
+     * @return the Person
+     * @throws org.apache.hivemind.ApplicationRuntimeException
+     *             if the person does not exist, or if there are any other errors
+     */
+    Person getPerson(Integer personId);
+
+    /**
+     * Returns all persons, sorted by last name, then by first name.
+     */
+
+    Person[] getPersons();
+
+    /**
+     * Reads a book, which must exist.
+     * 
+     * @param bookId
+     *            unique id for the book
+     * @return the book
+     * @throws org.apache.hivemind.ApplicationRuntimeException
+     *             if the book does not exist, or if there are any other errors
+     */
+
+    Book getBook(Integer bookId);
 }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java Wed Oct 12 15:36:30 2005
@@ -16,8 +16,13 @@
 
 import java.rmi.RemoteException;
 
+import javax.ejb.FinderException;
+
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.lib.RemoteExceptionCoordinator;
+import org.apache.tapestry.vlib.ejb.Book;
+import org.apache.tapestry.vlib.ejb.IOperations;
+import org.apache.tapestry.vlib.ejb.Person;
 
 /**
  * Handles remote exceptions and retries.
@@ -31,7 +36,9 @@
 
     private RemoteExceptionCoordinator _coordinator;
 
-    public Object doRemote(RemoteCallback callback, String errorMessage)
+    private IOperations _operations;
+
+    public <T> T execute(RemoteCallback<T> callback, String errorMessage)
     {
         int attempt = 1;
 
@@ -39,7 +46,7 @@
         {
             try
             {
-                return callback.remoteCallback();
+                return callback.doRemote();
             }
             catch (RemoteException ex)
             {
@@ -54,8 +61,66 @@
         }
     }
 
+    public Person getPerson(final Integer personId)
+    {
+        RemoteCallback<Person> callback = new RemoteCallback()
+        {
+            public Person doRemote() throws RemoteException
+            {
+                try
+                {
+                    return _operations.getPerson(personId);
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
+            }
+        };
+
+        return execute(callback, "Unable to read Person #" + personId + ".");
+    }
+
+    public Person[] getPersons()
+    {
+        RemoteCallback<Person[]> callback = new RemoteCallback()
+        {
+            public Person[] doRemote() throws RemoteException
+            {
+                return _operations.getPersons();
+            }
+        };
+
+        return execute(callback, "Error reading application users.");
+    }
+
+    public Book getBook(final Integer bookId)
+    {
+        RemoteCallback<Book> callback = new RemoteCallback()
+        {
+            public Book doRemote() throws RemoteException
+            {
+                try
+                {
+                    return _operations.getBook(bookId);
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException(ex);
+                }
+            }
+        };
+
+        return execute(callback, "Unable to read Book #" + bookId + ".");
+    }
+
     public void setCoordinator(RemoteExceptionCoordinator coordinator)
     {
         _coordinator = coordinator;
+    }
+
+    public void setOperations(IOperations operations)
+    {
+        _operations = operations;
     }
 }

Modified: jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java?rev=315066&r1=315065&r2=315066&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java Wed Oct 12 15:36:30 2005
@@ -19,6 +19,9 @@
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.lib.RemoteExceptionCoordinator;
 import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.vlib.ejb.Book;
+import org.apache.tapestry.vlib.ejb.IOperations;
+import org.apache.tapestry.vlib.ejb.Person;
 
 /**
  * Tests for {@link org.apache.tapestry.vlib.services.RemoteTemplateImpl}.
@@ -33,30 +36,29 @@
         RemoteTemplate rt = new RemoteTemplateImpl();
         RemoteCallback callback = new RemoteCallback()
         {
-            public Object remoteCallback() throws RemoteException
+            public Object doRemote() throws RemoteException
             {
                 return "flintstone";
             }
         };
 
-        Object actual = rt.doRemote(callback, "my error message");
+        Object actual = rt.execute(callback, "my error message");
 
         assertEquals("flintstone", actual);
     }
 
     public void testSuccessAfterRetry() throws Exception
     {
-        RemoteCallback callback = (RemoteCallback) newMock(RemoteCallback.class);
-        RemoteExceptionCoordinator coordinator = (RemoteExceptionCoordinator) newMock(RemoteExceptionCoordinator.class);
+        RemoteCallback callback = newCallback();
+        RemoteExceptionCoordinator coordinator = newCoordinator();
 
         Throwable t = new RemoteException();
 
-        callback.remoteCallback();
-        setThrowable(callback, t);
+        trainDoRemote(callback, t);
 
         coordinator.fireRemoteExceptionDidOccur(callback, t);
 
-        callback.remoteCallback();
+        callback.doRemote();
         setReturnValue(callback, "rubble");
 
         replayControls();
@@ -65,26 +67,24 @@
 
         rt.setCoordinator(coordinator);
 
-        assertEquals("rubble", rt.doRemote(callback, "my error message"));
+        assertEquals("rubble", rt.execute(callback, "my error message"));
 
         verifyControls();
     }
 
     public void testFailure() throws Exception
     {
-        RemoteCallback callback = (RemoteCallback) newMock(RemoteCallback.class);
-        RemoteExceptionCoordinator coordinator = (RemoteExceptionCoordinator) newMock(RemoteExceptionCoordinator.class);
+        RemoteCallback callback = newCallback();
+        RemoteExceptionCoordinator coordinator = newCoordinator();
 
         Throwable t1 = new RemoteException();
         Throwable t2 = new RemoteException();
 
-        callback.remoteCallback();
-        setThrowable(callback, t1);
+        trainDoRemote(callback, t1);
 
         coordinator.fireRemoteExceptionDidOccur(callback, t1);
 
-        callback.remoteCallback();
-        setThrowable(callback, t2);
+        trainDoRemote(callback, t2);
 
         coordinator.fireRemoteExceptionDidOccur(callback, t2);
 
@@ -96,7 +96,7 @@
 
         try
         {
-            rt.doRemote(callback, "error message");
+            rt.execute(callback, "error message");
             unreachable();
         }
         catch (ApplicationRuntimeException ex)
@@ -107,4 +107,84 @@
 
         verifyControls();
     }
+
+    public void testGetPerson() throws Exception
+    {
+        Integer personId = new Integer(33);
+
+        IOperations operations = newOperations();
+        Person person = new Person(new Object[Person.N_COLUMNS]);
+
+        operations.getPerson(personId);
+        setReturnValue(operations, person);
+
+        replayControls();
+
+        RemoteTemplateImpl template = new RemoteTemplateImpl();
+        template.setOperations(operations);
+
+        assertSame(person, template.getPerson(personId));
+
+        verifyControls();
+    }
+
+    public void testGetPersons() throws Exception
+    {
+        IOperations operations = newOperations();
+        Person[] persons = new Person[0];
+
+        operations.getPersons();
+        setReturnValue(operations, persons);
+
+        replayControls();
+
+        RemoteTemplateImpl template = new RemoteTemplateImpl();
+        template.setOperations(operations);
+
+        assertSame(persons, template.getPersons());
+
+        verifyControls();
+    }
+
+    public void testGetBook() throws Exception
+    {
+        Integer bookId = new Integer(33);
+
+        IOperations operations = newOperations();
+        Book book = new Book(new Object[Book.N_COLUMNS]);
+
+        operations.getBook(bookId);
+        setReturnValue(operations, book);
+
+        replayControls();
+
+        RemoteTemplateImpl template = new RemoteTemplateImpl();
+        template.setOperations(operations);
+
+        assertSame(book, template.getBook(bookId));
+
+        verifyControls();
+    }
+
+    private IOperations newOperations()
+    {
+        return (IOperations) newMock(IOperations.class);
+    }
+
+    private void trainDoRemote(RemoteCallback callback, Throwable t) throws RemoteException
+    {
+        callback.doRemote();
+        setThrowable(callback, t);
+    }
+
+    private RemoteExceptionCoordinator newCoordinator()
+    {
+        return (RemoteExceptionCoordinator) newMock(RemoteExceptionCoordinator.class);
+    }
+
+    private RemoteCallback newCallback()
+    {
+        return (RemoteCallback) newMock(RemoteCallback.class);
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org