KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > model > ForwardModel


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

18 package org.apache.beehive.netui.compiler.model;
19
20 import java.util.List JavaDoc;
21 import java.util.ArrayList JavaDoc;
22
23 import org.apache.beehive.netui.compiler.model.schema.struts11.ForwardDocument.Forward;
24 import org.apache.beehive.netui.compiler.model.schema.struts11.SetPropertyDocument.SetProperty;
25 import org.apache.beehive.netui.compiler.JpfLanguageConstants;
26
27 /**
28  * Represents an action forward in a Struts application.
29  */

30 public class ForwardModel
31         extends StrutsElementSupport
32         implements JpfLanguageConstants
33 {
34     private static final String JavaDoc JPF_ACTION_FWD_CLASSNAME = PAGEFLOW_PACKAGE + ".config.PageFlowActionForward";
35     
36     private boolean _isNestedReturn = false;
37     private boolean _contextRelative = false;
38     private String JavaDoc _name; // required to be set
39
private String JavaDoc _path; // required to be set
40
private boolean _redirect = false;
41     private boolean _externalRedirect = false;
42     private boolean _returnToPage = false;
43     private boolean _returnToAction = false;
44     private String JavaDoc _outputFormBeanType;
45     private String JavaDoc _outputFormBeanMember;
46     private boolean _hasExplicitRedirectValue = false;
47     private List JavaDoc _actionOutputs = null;
48     private boolean _restoreQueryString = false;
49     
50
51     protected ForwardModel( StrutsApp parent )
52     {
53         super( parent );
54     }
55     
56     public ForwardModel( String JavaDoc name, String JavaDoc path, StrutsApp parent )
57     {
58         super( parent );
59         _name = name;
60         _path = path;
61     }
62
63     public void writeToXMLBean( Forward xb )
64     {
65         assert _name != null;
66
67         xb.setName( _name );
68         
69         if ( xb.getPath() == null )
70         {
71             xb.setPath( _path == null ? "" : _path );
72         }
73         
74         if ( xb.getContextRelative() == null && _contextRelative )
75         {
76             xb.setContextRelative( Forward.ContextRelative.TRUE );
77         }
78         
79         if ( xb.getRedirect() == null && _redirect )
80         {
81             xb.setRedirect( Forward.Redirect.TRUE );
82         }
83         
84         //
85
// "externalRedirect" is set using set-property, to indicate that the redirect
86
// is to another app.
87
//
88
if ( _externalRedirect ) addSetProperty( xb, "externalRedirect", "true" );
89         
90         //
91
// "returnToPage" is set using set-property, which requires us to override the
92
// ActionForward class.
93
//
94
if ( _returnToPage ) addSetProperty( xb, "returnToPage", "true" );
95
96         //
97
// "returnToAction" is set using set-property, which requires us to override the
98
// ActionForward class.
99
//
100
if ( _returnToAction ) addSetProperty( xb, "returnToAction", "true" );
101
102         if ( _hasExplicitRedirectValue ) addSetProperty( xb, "hasExplicitRedirectValue", "true" );
103
104         if ( _restoreQueryString ) addSetProperty( xb, "restoreQueryString", "true" );
105         
106         if ( _actionOutputs != null && _actionOutputs.size() > 0 )
107         {
108             if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FWD_CLASSNAME );
109
110             int n = _actionOutputs.size();
111             SetProperty countProp = xb.addNewSetProperty();
112             countProp.setProperty( "actionOutputCount" );
113             countProp.setValue( Integer.toString( n ) );
114             
115             for ( int i = 0; i < n; ++i )
116             {
117                 ActionOutputModel pi = ( ActionOutputModel ) _actionOutputs.get( i );
118                 SetProperty prop = xb.addNewSetProperty();
119                 prop.setProperty( "actionOutput" + i );
120                 prop.setValue( pi.getType() + '|' + pi.getNullable() + '|' + pi.getName() );
121             }
122         }
123         
124         //
125
// "nestedReturn" is set using set-property, which requires us to override the
126
// ActionForward class.
127
//
128
if ( _isNestedReturn ) addSetProperty( xb, "nestedReturn", "true" );
129         if ( _outputFormBeanType != null ) addSetProperty( xb, "returnFormType", _outputFormBeanType );
130         if ( _outputFormBeanMember != null ) addSetProperty( xb, "returnFormMember", _outputFormBeanMember );
131         
132         addComment( xb );
133     }
134
135     public boolean isReturnToPage()
136     {
137         return _returnToPage;
138     }
139
140     public void setReturnToPage( boolean returnToPage )
141     {
142         _returnToPage = returnToPage;
143     }
144
145     public boolean isReturnToAction()
146     {
147         return _returnToAction;
148     }
149
150     public void setReturnToAction( boolean returnToAction )
151     {
152         _returnToAction = returnToAction;
153     }
154
155     public void setIsNestedReturn( boolean nestedReturn )
156     {
157         _isNestedReturn = nestedReturn;
158     }
159
160     public String JavaDoc getOutputFormBeanType()
161     {
162         return _outputFormBeanType;
163     }
164
165     public void setOutputFormBeanType( String JavaDoc outputFormBeanType )
166     {
167         _outputFormBeanType = outputFormBeanType;
168     }
169
170     public String JavaDoc getOutputFormBeanMember()
171     {
172         return _outputFormBeanMember;
173     }
174
175     public void setOutputFormBeanMember( String JavaDoc outputFormBeanMember )
176     {
177         _outputFormBeanMember = outputFormBeanMember;
178     }
179
180     public boolean getContextRelative()
181     {
182         return _contextRelative;
183     }
184
185     public void setContextRelative( boolean contextRelative )
186     {
187         _contextRelative = contextRelative;
188     }
189
190     public String JavaDoc getName()
191     {
192         return _name;
193     }
194
195     public void setName( String JavaDoc name )
196     {
197         _name = name;
198     }
199
200     public String JavaDoc getPath()
201     {
202         return _path;
203     }
204
205     public void setPath( String JavaDoc path )
206     {
207         _path = path;
208     }
209
210     public boolean isRedirect()
211     {
212         return _redirect;
213     }
214
215     public void setRedirect( boolean redirect )
216     {
217         _redirect = redirect;
218         _hasExplicitRedirectValue = redirect;
219     }
220
221     public boolean isExternalRedirect()
222     {
223         return _externalRedirect;
224     }
225
226     public void setExternalRedirect( boolean externalRedirect )
227     {
228         _externalRedirect = externalRedirect;
229         if ( externalRedirect ) setRedirect( externalRedirect );
230     }
231
232     public boolean isRestoreQueryString()
233     {
234         return _restoreQueryString;
235     }
236
237     public void setRestoreQueryString( boolean restore )
238     {
239         _restoreQueryString = restore;
240     }
241
242     /**
243      * @deprecated
244      * @see #forwardsToPage
245      */

246     public final boolean isPageForward()
247     {
248         return forwardsToPage();
249     }
250
251     public boolean forwardsToPage()
252     {
253         return ! _path.endsWith( ".do" ) && ! _path.endsWith( ".jpf" ); // NOI18N
254
}
255
256     public boolean forwardsToAction()
257     {
258         return _path.endsWith( ".do" ); // NOI18N
259
}
260
261     public final boolean forwardsToPageFlow()
262     {
263         return _path.endsWith( ".jpf" ); // NOI18N
264
}
265
266     public String JavaDoc getPageName()
267     {
268         assert forwardsToPage() : "getPageName() called for non-page " + _path; // NOI18N
269

270         int slash = _path.lastIndexOf( '/' ); // NOI18N
271
return slash != -1 ? _path.substring( slash + 1 ) : _path;
272     }
273
274     public String JavaDoc getActionName()
275     {
276         assert forwardsToAction() : "getActionName() called for non-action" + _path; // NOI18N
277

278         int index = _path.indexOf( ".do" ); // NOI18N
279
assert index != -1;
280         return _path.substring( 0, index );
281     }
282
283     public void addActionOutput( ActionOutputModel actionOutput )
284     {
285         if ( _actionOutputs == null ) _actionOutputs = new ArrayList JavaDoc();
286         _actionOutputs.add( actionOutput );
287     }
288     
289     public boolean isNestedReturn()
290     {
291         return _isNestedReturn;
292     }
293     
294     private static void addSetProperty( Forward xb, String JavaDoc propertyName, String JavaDoc propertyValue )
295     {
296         SetProperty prop = xb.addNewSetProperty();
297         prop.setProperty( propertyName );
298         prop.setValue( propertyValue );
299         if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FWD_CLASSNAME );
300     }
301 }
302
Popular Tags