KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > HomeService


1 // Copyright 2004, 2005 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.engine;
16
17 import java.io.IOException JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.Tapestry;
23 import org.apache.tapestry.services.LinkFactory;
24 import org.apache.tapestry.services.ResponseRenderer;
25 import org.apache.tapestry.services.ServiceConstants;
26
27 /**
28  * An implementation of the home service that renders the Home page. This is the most likely
29  * candidate for overriding ... for example, to select the page to render based on known information
30  * about the user (stored as a cookie).
31  *
32  * @author Howard Lewis Ship
33  * @since 1.0.9
34  */

35
36 public class HomeService implements IEngineService
37 {
38     /** @since 4.0 */
39     private ResponseRenderer _responseRenderer;
40
41     /** @since 4.0 */
42
43     private LinkFactory _linkFactory;
44
45     /** @since 4.0 */
46
47     private String JavaDoc _pageName;
48
49     public ILink getLink(IRequestCycle cycle, Object JavaDoc parameter)
50     {
51         if (parameter != null)
52             throw new IllegalArgumentException JavaDoc(EngineMessages.serviceNoParameter(this));
53
54         Map JavaDoc parameters = new HashMap JavaDoc();
55
56         parameters.put(ServiceConstants.SERVICE, Tapestry.HOME_SERVICE);
57
58         return _linkFactory.constructLink(cycle, parameters, true);
59     }
60
61     public void service(IRequestCycle cycle) throws IOException JavaDoc
62     {
63         cycle.activate(_pageName);
64
65         _responseRenderer.renderResponse(cycle);
66     }
67
68     public String JavaDoc getName()
69     {
70         return Tapestry.HOME_SERVICE;
71     }
72
73     /** @since 4.0 */
74     public void setResponseRenderer(ResponseRenderer responseRenderer)
75     {
76         _responseRenderer = responseRenderer;
77     }
78
79     /** @since 4.0 */
80     public void setLinkFactory(LinkFactory linkFactory)
81     {
82         _linkFactory = linkFactory;
83     }
84
85     /** @since 4.0 */
86     public void setPageName(String JavaDoc pageName)
87     {
88         _pageName = pageName;
89     }
90
91     /** @since 4.0 */
92     public String JavaDoc getPageName()
93     {
94         return _pageName;
95     }
96 }
Popular Tags