KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRequestCycle;
20     import org.apache.tapestry.html.BasePage;
21     import org.apache.tapestry.vlib.IMessageProperty;
22     import org.apache.tapestry.vlib.VirtualLibraryEngine;
23     import org.apache.tapestry.vlib.components.Browser;
24     import org.apache.tapestry.vlib.ejb.IBookQuery;
25     import org.apache.tapestry.vlib.ejb.MasterQueryParameters;
26     import org.apache.tapestry.vlib.ejb.SortColumn;
27     import org.apache.tapestry.vlib.ejb.SortOrdering;
28
29 /**
30  * Runs queries and displays matches.
31  *
32  * @author Howard Lewis Ship
33  * @version $Id: BookMatches.java,v 1.11 2004/02/19 17:37:48 hlship Exp $
34  **/

35
36 public abstract class BookMatches extends BasePage
37 {
38     private Browser _browser;
39
40     public void finishLoad()
41     {
42         _browser = (Browser) getComponent("browser");
43     }
44
45     public abstract IBookQuery getBookQuery();
46
47     public abstract void setBookQuery(IBookQuery bookQuery);
48
49     public abstract SortColumn getSortColumn();
50
51     public abstract boolean isDescending();
52
53     public abstract MasterQueryParameters getQueryParameters();
54
55     public abstract void setQueryParameters(MasterQueryParameters queryParameters);
56
57     /**
58      * Invoked by the {@link Home} page to perform a query.
59      *
60      **/

61
62     public void performQuery(MasterQueryParameters parameters, IRequestCycle cycle)
63     {
64         setQueryParameters(parameters);
65
66         int count = executeQuery();
67
68         if (count == 0)
69         {
70             IMessageProperty page = (IMessageProperty) cycle.getPage();
71             page.setMessage(getMessage("no-matches"));
72             return;
73         }
74
75         _browser.initializeForResultCount(count);
76         cycle.activate(this);
77     }
78
79     public void requery(IRequestCycle cycle)
80     {
81         int count = executeQuery();
82
83         if (count != _browser.getResultCount())
84             _browser.initializeForResultCount(count);
85     }
86
87     private int executeQuery()
88     {
89         VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine();
90
91         MasterQueryParameters parameters = getQueryParameters();
92
93         SortOrdering ordering = new SortOrdering(getSortColumn(), isDescending());
94
95         int i = 0;
96         while (true)
97         {
98             try
99             {
100                 IBookQuery query = getBookQuery();
101
102                 if (query == null)
103                 {
104                     query = vengine.createNewQuery();
105                     setBookQuery(query);
106                 }
107                 
108                 return query.masterQuery(parameters, ordering);
109             }
110             catch (RemoteException JavaDoc ex)
111             {
112                 vengine.rmiFailure("Remote exception processing query.", ex, i++);
113                 
114                 setBookQuery(null);
115             }
116
117         }
118     }
119
120 }
Popular Tags