1 15 package org.apache.tapestry.vlib.pages; 16 17 import java.rmi.RemoteException ; 18 19 import org.apache.tapestry.IExternalPage; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.event.PageEvent; 22 import org.apache.tapestry.event.PageRenderListener; 23 import org.apache.tapestry.html.BasePage; 24 import org.apache.tapestry.vlib.VirtualLibraryEngine; 25 import org.apache.tapestry.vlib.components.Browser; 26 import org.apache.tapestry.vlib.ejb.IBookQuery; 27 import org.apache.tapestry.vlib.ejb.Person; 28 import org.apache.tapestry.vlib.ejb.SortColumn; 29 import org.apache.tapestry.vlib.ejb.SortOrdering; 30 31 40 41 public abstract class ViewPerson extends BasePage implements IExternalPage, PageRenderListener 42 { 43 public abstract Integer getPersonId(); 44 45 public abstract void setPersonId(Integer personId); 46 47 public abstract void setPerson(Person value); 48 49 public abstract Person getPerson(); 50 51 public abstract IBookQuery getQuery(); 52 53 public abstract void setQuery(IBookQuery value); 54 55 public abstract SortColumn getSortColumn(); 56 57 public abstract boolean isDescending(); 58 59 private Browser _browser; 60 61 public void finishLoad() 62 { 63 _browser = (Browser) getComponent("browser"); 64 } 65 66 71 72 public void activateExternalPage(Object [] parameters, IRequestCycle cycle) 73 { 74 Integer personId = (Integer ) parameters[0]; 75 76 setPersonId(personId); 77 78 80 int count = runQuery(); 81 82 _browser.initializeForResultCount(count); 83 } 84 85 public void requery(IRequestCycle cycle) 86 { 87 int count = runQuery(); 88 89 if (_browser.getResultCount() != count) 90 _browser.setResultCount(count); 91 } 92 93 private int runQuery() 94 { 95 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 96 Integer personId = getPersonId(); 97 98 SortOrdering ordering = new SortOrdering(getSortColumn(), isDescending()); 99 100 int i = 0; 101 while (true) 102 { 103 IBookQuery query = getQuery(); 104 105 if (query == null) 106 { 107 query = vengine.createNewQuery(); 108 109 setQuery(query); 110 } 111 112 try 113 { 114 return query.ownerQuery(personId, ordering); 115 } 116 catch (RemoteException ex) 117 { 118 vengine.rmiFailure("Remote exception for owner query.", ex, i++); 119 120 setQuery(null); 121 } 122 } 123 124 } 125 126 public void pageBeginRender(PageEvent event) 127 { 128 Person person = getPerson(); 129 130 if (person == null) 131 { 132 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 133 134 person = vengine.readPerson(getPersonId()); 135 136 setPerson(person); 137 } 138 } 139 140 } | Popular Tags |