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 org.apache.hivemind.util.Defense;
018    import org.apache.tapestry.util.QueryParameterMap;
019    
020    /**
021     * Implementation of {@link org.apache.tapestry.engine.ServiceEncoding}, which adds the ability to
022     * determine when the encoding has been modified.
023     * 
024     * @author Howard M. Lewis Ship
025     * @since 4.0
026     */
027    public class ServiceEncodingImpl implements ServiceEncoding
028    {
029        protected String _servletPath;
030    
031        protected String _pathInfo;
032    
033        /**
034         * Map of query parameter values; key is string name, value is either a string, an array of
035         * strings, or null. Could have done this with subclassing rather than delegation.
036         */
037    
038        protected final QueryParameterMap _parameters;
039    
040        protected boolean _modified;
041    
042        /**
043         * Creates a new instance with a new map of parameters.
044         */
045    
046        public ServiceEncodingImpl(String servletPath)
047        {
048            this(servletPath, null, new QueryParameterMap());
049        }
050    
051        public ServiceEncodingImpl(String servletPath, QueryParameterMap parametersMap)
052        {
053            this(servletPath, null, parametersMap);
054        }
055    
056        public ServiceEncodingImpl(String servletPath, String pathInfo, QueryParameterMap parameters)
057        {
058            Defense.notNull(servletPath, "servletPath");
059            Defense.notNull(parameters, "parameters");
060    
061            _servletPath = servletPath;
062            _pathInfo = pathInfo;
063            _parameters = parameters;
064        }
065        
066        public boolean isModified()
067        {
068            return _modified;
069        }
070    
071        public void resetModified()
072        {
073            _modified = false;
074        }
075    
076        public String getParameterValue(String name)
077        {
078            return _parameters.getParameterValue(name);
079        }
080    
081        public String[] getParameterValues(String name)
082        {
083            return _parameters.getParameterValues(name);
084        }
085    
086        public void setServletPath(String servletPath)
087        {
088            Defense.notNull(servletPath, "servletPath");
089    
090            _servletPath = servletPath;
091            _modified = true;
092        }
093    
094        public void setParameterValue(String name, String value)
095        {
096            _parameters.setParameterValue(name, value);
097    
098            _modified = true;
099        }
100    
101        public void setParameterValues(String name, String[] values)
102        {
103            _parameters.setParameterValues(name, values);
104    
105            _modified = true;
106        }
107    
108        public String getServletPath()
109        {
110            return _servletPath;
111        }
112    
113        public String[] getParameterNames()
114        {
115            return _parameters.getParameterNames();
116        }
117    
118        public String getPathInfo()
119        {
120            return _pathInfo;
121        }
122        
123        public void setPathInfo(String pathInfo) 
124        {
125            _pathInfo = pathInfo;
126        }
127    }