KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > genmodel > GenForwardModel


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.genmodel;
19
20 import org.apache.beehive.netui.compiler.model.ForwardModel;
21 import org.apache.beehive.netui.compiler.model.ForwardContainer;
22 import org.apache.beehive.netui.compiler.CompilerUtils;
23 import org.apache.beehive.netui.compiler.JpfLanguageConstants;
24 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.FieldDeclaration;
27 import org.apache.beehive.netui.compiler.typesystem.type.DeclaredType;
28
29 import java.util.List JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 public class GenForwardModel
34         extends ForwardModel
35         implements JpfLanguageConstants
36 {
37     public GenForwardModel( GenStrutsApp parent, AnnotationInstance annotation, ClassDeclaration jclass,
38                             String JavaDoc commentSuffix )
39     {
40         super( parent );
41         
42         setName( CompilerUtils.getString( annotation, NAME_ATTR, true ) );
43         setRedirect( CompilerUtils.getBoolean( annotation, REDIRECT_ATTR, false ).booleanValue() );
44         if ( CompilerUtils.getBoolean( annotation, EXTERNAL_REDIRECT_ATTR, false ).booleanValue() ) {
45             setExternalRedirect( true );
46         }
47         
48         //
49
// outputFormBean/outputFormBeanType
50
//
51
DeclaredType outputFormType = CompilerUtils.getDeclaredType( annotation, OUTPUT_FORM_BEAN_TYPE_ATTR, true );
52         String JavaDoc outputFormMember = CompilerUtils.getString( annotation, OUTPUT_FORM_BEAN_ATTR, true );
53         if ( outputFormMember != null )
54         {
55             FieldDeclaration field = CompilerUtils.getClassField( jclass, outputFormMember, null );
56             assert outputFormType == null; // checker should catch this
57
assert field != null; // checker should catch this
58
assert field.getType() instanceof DeclaredType : field.getType().getClass().getName(); // checker enforces
59
outputFormType = ( DeclaredType ) field.getType();
60         }
61         setOutputFormBeanMember( outputFormMember );
62         setOutputFormBeanType( outputFormType != null ? CompilerUtils.getLoadableName( outputFormType ) : null );
63         
64         //
65
// path, tilesDefinition, navigateTo, returnAction (mutually exclusive)
66
//
67
String JavaDoc returnAction = CompilerUtils.getString( annotation, RETURN_ACTION_ATTR, true );
68         String JavaDoc navigateTo = CompilerUtils.getEnumFieldName( annotation, NAVIGATE_TO_ATTR, true );
69         String JavaDoc tilesDefinition = CompilerUtils.getString( annotation, TILES_DEFINITION_ATTR, true );
70         String JavaDoc path = CompilerUtils.getString( annotation, PATH_ATTR, true );
71         String JavaDoc action = CompilerUtils.getString( annotation, ACTION_ATTR, true );
72         
73         if ( action != null )
74         {
75             assert path == null; // checker should enforce this
76
path = action + ACTION_EXTENSION_DOT;
77         }
78         
79         if ( returnAction != null )
80         {
81             assert navigateTo == null;
82             assert tilesDefinition == null;
83             assert path == null;
84             setIsNestedReturn( true );
85             setPath( returnAction ); // set the returnAction as the path -- the runtime expects it there
86
}
87         else if ( navigateTo != null )
88         {
89             assert tilesDefinition == null;
90             assert path == null;
91             
92             if ( navigateTo.equals( NAVIGATE_TO_PAGE_LEGACY_STR )
93                  || navigateTo.equals( NAVIGATE_TO_CURRENT_PAGE_STR )
94                  || navigateTo.equals( NAVIGATE_TO_PREVIOUS_PAGE_STR ) )
95             {
96                 setReturnToPage( true );
97             }
98             else if ( navigateTo.equals( NAVIGATE_TO_PREVIOUS_ACTION_STR ) )
99             {
100                 setReturnToAction( true );
101             }
102             else
103             {
104                 assert false : "unknown value for navigateTo: \"" + navigateTo + '"';
105             }
106
107             boolean restore = CompilerUtils.getBoolean( annotation, RESTORE_QUERY_STRING_ATTR, false ).booleanValue();
108             setRestoreQueryString( restore );
109             setPath( navigateTo ); // set the actual navigateTo value as the path -- the runtime expects it there
110
}
111         else if ( tilesDefinition != null )
112         {
113             assert path == null;
114             setPath( tilesDefinition ); // set the tilesDefinition as the path -- the runtime expects it there
115
}
116         else
117         {
118             assert path != null; // checker should enforce this
119

120             //
121
// Translate our relative-path convention (normal) to the Struts convention, which adds a '/'
122
// to any module-relative path.
123
//
124
boolean contextRelative = true;
125             if ( ! path.startsWith( "/" ) )
126             {
127                 contextRelative = false;
128                 
129                 //
130
// If it's an absolute URL, then the path shouldn't have a slash inserted in front of it.
131
//
132
if ( ! CompilerUtils.isAbsoluteURL( path ) ) path = '/' + path;
133             }
134             
135             setPath( path );
136             setContextRelative( contextRelative );
137         }
138
139         addActionOutputs( annotation, jclass );
140         
141         if ( commentSuffix != null )
142         {
143             setComment( "forward \"" + getName() + '"' + commentSuffix ); // @TODO I18N the comment
144
}
145     }
146     
147     static void addForwards( AnnotationInstance annotation, ForwardContainer container, ClassDeclaration jclass,
148                              GenStrutsApp strutsApp, String JavaDoc commentSuffix )
149     {
150         List JavaDoc forwards = CompilerUtils.getAnnotationArray( annotation, FORWARDS_ATTR, true );
151         addForwards( forwards, container, jclass, strutsApp, commentSuffix );
152     }
153     
154     static void addForwards( Collection JavaDoc forwards, ForwardContainer container,
155                              ClassDeclaration jclass, GenStrutsApp strutsApp, String JavaDoc commentSuffix )
156     {
157         if ( forwards != null )
158         {
159             for ( Iterator JavaDoc ii = forwards.iterator(); ii.hasNext(); )
160             {
161                 AnnotationInstance ann = ( AnnotationInstance ) ii.next();
162                 container.addForward( new GenForwardModel( strutsApp, ann, jclass, commentSuffix ) );
163             }
164         }
165     }
166         
167     protected void addActionOutputs( AnnotationInstance annotation, ClassDeclaration jclass )
168     {
169         List JavaDoc actionOutputs =
170                 CompilerUtils.getAnnotationArray( annotation, ACTION_OUTPUTS_ATTR, true );
171         
172         if ( actionOutputs != null )
173         {
174             for ( Iterator JavaDoc ii = actionOutputs.iterator(); ii.hasNext(); )
175             {
176                 AnnotationInstance ann = ( AnnotationInstance ) ii.next();
177                 addActionOutput( new GenActionOutputModel( ann, jclass ) );
178             }
179         }
180     }
181 }
182
Popular Tags