KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 /**
32  * Displays the book inventory list for a single {@link org.apache.tapestry.vlib.ejb.IPerson}, showing
33  * what books are owned by the person, who has them borrowed, etc. If the
34  * user is logged in, then books can be borrowed from this page as well.
35  *
36  * @author Howard Lewis Ship
37  * @version $Id: ViewPerson.java,v 1.12 2004/02/19 17:37:48 hlship Exp $
38  *
39  **/

40
41 public abstract class ViewPerson extends BasePage implements IExternalPage, PageRenderListener
42 {
43     public abstract Integer JavaDoc getPersonId();
44
45     public abstract void setPersonId(Integer JavaDoc 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     /**
67      * Invoked by the external service to being viewing the
68      * identified person.
69      *
70      **/

71
72     public void activateExternalPage(Object JavaDoc[] parameters, IRequestCycle cycle)
73     {
74         Integer JavaDoc personId = (Integer JavaDoc) parameters[0];
75
76         setPersonId(personId);
77
78         // Force the query to be re-run when the person changes.
79

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 JavaDoc 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 JavaDoc 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