001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.engine;
016
017 import java.io.IOException;
018 import java.util.HashMap;
019 import java.util.Map;
020
021 import org.apache.tapestry.IRequestCycle;
022 import org.apache.tapestry.Tapestry;
023 import org.apache.tapestry.services.LinkFactory;
024 import org.apache.tapestry.services.ResponseRenderer;
025 import org.apache.tapestry.services.ServiceConstants;
026
027 /**
028 * An implementation of the home service that renders the Home page. This is the
029 * most likely candidate for overriding ... for example, to select the page to
030 * render based on known information about the user (stored as a cookie).
031 *
032 * @author Howard Lewis Ship
033 * @since 1.0.9
034 */
035
036 public class HomeService implements IEngineService
037 {
038
039 /** @since 4.0 */
040 private ResponseRenderer _responseRenderer;
041
042 /** @since 4.0 */
043
044 private LinkFactory _linkFactory;
045
046 /** @since 4.0 */
047
048 private String _pageName;
049
050 public ILink getLink(boolean post, Object parameter)
051 {
052 if (parameter != null)
053 throw new IllegalArgumentException(EngineMessages
054 .serviceNoParameter(this));
055
056 Map parameters = new HashMap();
057
058 parameters.put(ServiceConstants.SERVICE, getName());
059
060 return _linkFactory.constructLink(this, post, parameters, true);
061 }
062
063 public void service(IRequestCycle cycle)
064 throws IOException
065 {
066 cycle.activate(_pageName);
067
068 _responseRenderer.renderResponse(cycle);
069 }
070
071 public String getName()
072 {
073 return Tapestry.HOME_SERVICE;
074 }
075
076 /** @since 4.0 */
077 public void setResponseRenderer(ResponseRenderer responseRenderer)
078 {
079 _responseRenderer = responseRenderer;
080 }
081
082 /** @since 4.0 */
083 public void setLinkFactory(LinkFactory linkFactory)
084 {
085 _linkFactory = linkFactory;
086 }
087
088 /** @since 4.0 */
089 public void setPageName(String pageName)
090 {
091 _pageName = pageName;
092 }
093
094 /** @since 4.0 */
095 public String getPageName()
096 {
097 return _pageName;
098 }
099 }