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    
019    import org.apache.tapestry.IRequestCycle;
020    
021    /**
022     * A service, provided by the {@link org.apache.tapestry.IEngine}, for its pages and/or components.
023     * Services are responsible for constructing {@link EngineServiceLink}s (an encoding of URLs) to
024     * represent dynamic application behavior, and for parsing those URLs when a subsequent request
025     * involves them.
026     * 
027     * @see org.apache.tapestry.IEngine#getService(String)
028     * @author Howard Lewis Ship
029     */
030    
031    public interface IEngineService
032    {
033        /**
034         * Builds a URL for a service. This is performed during the rendering phase of one request cycle
035         * and bulds URLs that will invoke activity in a subsequent request cycle.
036         * <p>
037         * <b>This method changed incompatibly between release 3.0 and release 4.0. </b>
038         * </p>
039         * 
040         * @param cycle
041         *            Defines the request cycle being processed.
042         * @param post
043         *            if true, then the link will be used for a post (not a get, i.e., for a HTML form);
044         *            this may affect what information is encoded into the link
045         * @param parameter
046         *            An object that provide any additional information needed by the service. Each
047         *            service implementation will expect that an object of the proper type be passed in.
048         *            In some cases, a simple String will do; in others, a specific object (possibly
049         *            implementing an interface) will be required.
050         * @return The URL for the service. The URL will have to be encoded via
051         *         {@link javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String)}.
052         */
053    
054        public ILink getLink(IRequestCycle cycle, boolean post, Object parameter);
055    
056        /**
057         * Perform the service, interpreting the URL (from the
058         * {@link javax.servlet.http.HttpServletRequest}) responding appropriately, and rendering a
059         * result page.
060         * 
061         * @param cycle
062         *            the incoming request
063         * @see org.apache.tapestry.IEngine#service(org.apache.tapestry.request.RequestContext)
064         */
065    
066        public void service(IRequestCycle cycle) throws IOException;
067    
068        /**
069         * Returns the name of the service.
070         * 
071         * @since 1.0.1
072         */
073    
074        public String getName();
075    }