KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > config > ForwardConfig


1 /*
2  * $Id: ForwardConfig.java 55980 2004-10-29 15:34:55Z husted $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.struts.config;
21
22
23 import java.io.Serializable JavaDoc;
24
25
26 /**
27  * <p>A JavaBean representing the configuration information of a
28  * <code>&lt;forward&gt;</code> element from a Struts
29  * configuration file.</p>
30  *
31  * @version $Rev: 55980 $ $Date: 2004-10-29 16:34:55 +0100 (Fri, 29 Oct 2004) $
32  * @since Struts 1.1
33  */

34
35 public class ForwardConfig implements Serializable JavaDoc {
36
37
38     // ----------------------------------------------------------- Constructors
39

40
41     /**
42      * Construct a new instance with default values.
43      */

44     public ForwardConfig() {
45
46         super();
47
48     }
49
50
51     /**
52      * Construct a new instance with the specified values.
53      *
54      * @param name Name of this forward
55      * @param path Path to which control should be forwarded or redirected
56      * @param redirect Should we do a redirect?
57      */

58     public ForwardConfig(String JavaDoc name, String JavaDoc path, boolean redirect) {
59
60         super();
61         setName(name);
62         setPath(path);
63         setRedirect(redirect);
64
65     }
66
67
68     /**
69      * Construct a new instance with the specified values.
70      *
71      * @param name Name of this forward
72      * @param path Path to which control should be forwarded or redirected
73      * @param redirect Should we do a redirect?
74      * @param contextRelative Is this path context relative?
75      * @deprecated Use module rather than contextRelative
76      */

77     public ForwardConfig(String JavaDoc name, String JavaDoc path, boolean redirect,
78                          boolean contextRelative) {
79
80         super();
81         setName(name);
82         setPath(path);
83         setRedirect(redirect);
84         setContextRelative(contextRelative);
85
86     }
87
88     /**
89      * <p>Construct a new instance with the specified values.</p>
90      * @param name Name of this forward
91      * @param path Path to which control should be forwarded or redirected
92      * @param redirect Should we do a redirect?
93      * @param module Module prefix, if any
94      */

95     public ForwardConfig(String JavaDoc name, String JavaDoc path, boolean redirect,
96                          String JavaDoc module) {
97
98         super();
99         setName(name);
100         setPath(path);
101         setRedirect(redirect);
102         setModule(module);
103
104     }
105
106
107     // ----------------------------------------------------- Instance Variables
108

109
110     /**
111      * Has this component been completely configured?
112      */

113     protected boolean configured = false;
114
115
116     // ------------------------------------------------------------- Properties
117

118
119     /**
120      * Should the value of the <code>path</code> property be considered
121      * context-relative if it starts with a slash (and therefore not
122      * prefixed with the module prefix?
123      * @deprecated Use module property instead; will be removed in a release following 1.2.0.
124      */

125     protected boolean contextRelative = false;
126
127     /**
128      * @deprecated Use module property instead; will be removed in a release following 1.2.0.
129      */

130     public boolean getContextRelative() {
131         return (this.contextRelative);
132     }
133
134     /**
135      * @deprecated Use module property instead; will be removed in a release following 1.2.0.
136      */

137     public void setContextRelative(boolean contextRelative) {
138         if (configured) {
139             throw new IllegalStateException JavaDoc("Configuration is frozen");
140         }
141         this.contextRelative = contextRelative;
142     }
143
144
145     /**
146      * The unique identifier of this forward, which is used to reference it
147      * in <code>Action</code> classes.
148      */

149     protected String JavaDoc name = null;
150
151     public String JavaDoc getName() {
152         return (this.name);
153     }
154
155     public void setName(String JavaDoc name) {
156         if (configured) {
157             throw new IllegalStateException JavaDoc("Configuration is frozen");
158         }
159         this.name = name;
160     }
161
162
163     /**
164      * <p>The URL to which this <code>ForwardConfig</code> entry points,
165      * which must start with a slash ("/") character. It is
166      * interpreted according to the following rules:</p>
167      * <ul>
168      * <li>If <code>contextRelative</code> property is <code>true</code>, the
169      * path is considered to be context-relative within the current web
170      * application (even if we are in a named module). It will be
171      * prefixed by the context path to create a server-relative URL.</li>
172      * <li>If the <code>contextRelative</code> property is false, the path is
173      * considered to be the module-relative portion of the URL.
174      * It will be used as the replacement for the <code>$P</code>
175      * marker in the <code>forwardPattern</code> property defined on the
176      * {@link ControllerConfig} element for our current module.
177      * For the default <code>forwardPattern</code> value of
178      * <code>$C$M$P</code>, the resulting server-relative URL will be
179      * the concatenation of the context path, the module prefix,
180      * and the <code>path</code> from this <code>ForwardConfig</code>.</li>
181      * </ul>
182      */

183     protected String JavaDoc path = null;
184
185     public String JavaDoc getPath() {
186         return (this.path);
187     }
188
189     public void setPath(String JavaDoc path) {
190         if (configured) {
191             throw new IllegalStateException JavaDoc("Configuration is frozen");
192         }
193         this.path = path;
194     }
195
196
197     /**
198      * <p>The prefix of the module to which this <code>ForwardConfig</code> entry points,
199      * which must start with a slash ("/") character. </p>
200      * <p>Usage note: If a forward config is used in a hyperlink,
201      * and a module is specified, the path must lead to another
202      * action and not directly to a page. This is in keeping with
203      * rule that in a modular application all links must be to
204      * an action rather than a page.
205      * </p>
206      */

207     protected String JavaDoc module = null;
208
209     public String JavaDoc getModule() {
210         return (this.module);
211     }
212
213     public void setModule(String JavaDoc module) {
214         if (configured) {
215             throw new IllegalStateException JavaDoc("Configuration is frozen");
216         }
217         this.module = module;
218     }
219
220
221     /**
222      * Should a redirect be used to transfer control to the specified path?
223      */

224     protected boolean redirect = false;
225
226     public boolean getRedirect() {
227         return (this.redirect);
228     }
229
230     public void setRedirect(boolean redirect) {
231         if (configured) {
232             throw new IllegalStateException JavaDoc("Configuration is frozen");
233         }
234         this.redirect = redirect;
235     }
236
237
238     // --------------------------------------------------------- Public Methods
239

240
241     /**
242      * Freeze the configuration of this component.
243      */

244     public void freeze() {
245
246         configured = true;
247
248     }
249
250
251     /**
252      * Return a String representation of this object.
253      */

254     public String JavaDoc toString() {
255
256         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ForwardConfig[");
257         sb.append("name=");
258         sb.append(this.name);
259         sb.append(",path=");
260         sb.append(this.path);
261         sb.append(",redirect=");
262         sb.append(this.redirect);
263         sb.append(",contextRelative=");
264         sb.append(this.contextRelative);
265         sb.append(",module=");
266         sb.append(this.module);
267         sb.append("]");
268         return (sb.toString());
269
270     }
271
272
273 }
274
Popular Tags