KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Map JavaDoc;
18
19 import org.apache.hivemind.util.Defense;
20 import org.apache.tapestry.util.QueryParameterMap;
21
22 /**
23  * Implementation of {@link org.apache.tapestry.engine.ServiceEncoding}, which adds the ability to
24  * determine when the encoding has been modified.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class ServiceEncodingImpl implements ServiceEncoding
30 {
31     private String JavaDoc _servletPath;
32
33     /**
34      * Map of query parameter values; key is string name, value is either a string, an array of
35      * strings, or null. Could have done this with subclassing rather than delegation.
36      */

37
38     private final QueryParameterMap _parameters;
39
40     private boolean _modified;
41
42     public boolean isModified()
43     {
44         return _modified;
45     }
46
47     public void resetModified()
48     {
49         _modified = false;
50     }
51
52     /**
53      * Creates a new instance with a new map of parameters.
54      */

55
56     public ServiceEncodingImpl(String JavaDoc servletPath)
57     {
58         this(servletPath, new QueryParameterMap());
59     }
60
61     public ServiceEncodingImpl(String JavaDoc servletPath, Map JavaDoc parametersMap)
62     {
63         this(servletPath, new QueryParameterMap(parametersMap));
64     }
65
66     public ServiceEncodingImpl(String JavaDoc servletPath, QueryParameterMap parameters)
67     {
68         Defense.notNull(servletPath, "servletPath");
69         Defense.notNull(parameters, "parameters");
70
71         _servletPath = servletPath;
72
73         _parameters = parameters;
74     }
75
76     public String JavaDoc getParameterValue(String JavaDoc name)
77     {
78         return _parameters.getParameterValue(name);
79     }
80
81     public String JavaDoc[] getParameterValues(String JavaDoc name)
82     {
83         return _parameters.getParameterValues(name);
84     }
85
86     public void setServletPath(String JavaDoc servletPath)
87     {
88         Defense.notNull(servletPath, "servletPath");
89
90         _servletPath = servletPath;
91         _modified = true;
92     }
93
94     public void setParameterValue(String JavaDoc name, String JavaDoc value)
95     {
96         _parameters.setParameterValue(name, value);
97
98         _modified = true;
99     }
100
101     public void setParameterValues(String JavaDoc name, String JavaDoc[] values)
102     {
103         _parameters.setParameterValues(name, values);
104
105         _modified = true;
106     }
107
108     public String JavaDoc getServletPath()
109     {
110         return _servletPath;
111     }
112
113     public String JavaDoc[] getParameterNames()
114     {
115         return _parameters.getParameterNames();
116     }
117
118 }
Popular Tags