KickJava   Java API By Example, From Geeks To Geeks.

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


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.JpfLanguageConstants;
21 import org.apache.beehive.netui.compiler.CompilerUtils;
22 import org.apache.beehive.netui.compiler.model.ForwardModel;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
24 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.FieldDeclaration;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
27 import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance;
28
29 import java.util.List JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32
33 public class GenSimpleActionModel
34         extends GenActionModel
35         implements JpfLanguageConstants
36 {
37     public GenSimpleActionModel( AnnotationInstance annotation, GenStrutsApp parentApp, ClassDeclaration jclass )
38     {
39         super( CompilerUtils.getString( annotation, NAME_ATTR, true ), annotation, parentApp, jclass );
40         
41         setSimpleAction( true );
42         addForwards( annotation, parentApp, jclass );
43         
44         String JavaDoc formMember = getFormMember();
45         if ( formMember != null )
46         {
47             FieldDeclaration field = CompilerUtils.findField( jclass, formMember );
48             assert field != null; // checker should prevent this
49
setFormBeanName( addFormBean( field.getType(), parentApp ) );
50         }
51         else
52         {
53             setReadonly( true ); // can't modify member state; mark as read-only
54

55             TypeInstance formBeanType = CompilerUtils.getTypeInstance( annotation, USE_FORM_BEAN_TYPE_ATTR, true );
56             
57             if ( formBeanType != null )
58             {
59                 setFormBeanName( addFormBean( formBeanType, parentApp ) );
60             }
61         }
62     }
63
64     protected String JavaDoc getFormBean( Declaration sourceElement, GenStrutsApp parentApp )
65     {
66         return null;
67     }
68
69     protected void getForwards( AnnotationInstance annotation, ClassDeclaration jclass, GenStrutsApp parentApp )
70     {
71     }
72
73     private void addForwards( AnnotationInstance annotation, GenStrutsApp parentApp, ClassDeclaration jclass )
74     {
75         //
76
// First add the default forward -- the one that is parsed from the simple action annotation itself.
77
// But, if the "forwardRef" attribute was given, simply use the one referenced.
78
//
79
String JavaDoc forwardRef = CompilerUtils.getString( annotation, FORWARD_REF_ATTR, true );
80         
81         if ( forwardRef == null )
82         {
83             forwardRef = DEFAULT_SIMPLE_ACTION_FORWARD_NAME;
84             ForwardModel fwd = new SimpleActionForward( forwardRef, parentApp, annotation, jclass );
85             
86             if ( fwd.getPath() != null || fwd.isReturnToAction() || fwd.isReturnToPage() || fwd.isNestedReturn() )
87             {
88                 addForward( fwd );
89             }
90         }
91         
92         setDefaultForwardName( forwardRef );
93         
94         List JavaDoc conditionalFwdAnnotations =
95                 CompilerUtils.getAnnotationArray( annotation, CONDITIONAL_FORWARDS_ATTR, true );
96         
97         if ( conditionalFwdAnnotations != null )
98         {
99             int anonCount = 0;
100             
101             for ( Iterator JavaDoc ii = conditionalFwdAnnotations.iterator(); ii.hasNext(); )
102             {
103                 AnnotationInstance conditionalFwdAnnotation = ( AnnotationInstance ) ii.next();
104                 ForwardModel conditionalFwd = new SimpleActionForward( parentApp, conditionalFwdAnnotation, jclass );
105                 String JavaDoc expression = CompilerUtils.getString( conditionalFwdAnnotation, CONDITION_ATTR, true );
106                 assert expression != null;
107                 
108                 if ( conditionalFwd.getName() == null ) conditionalFwd.setName( "_anon" + ++anonCount );
109                 addForward( conditionalFwd );
110                 addConditionalForward( expression, conditionalFwd.getName() );
111             }
112         }
113     }
114     
115     private static class SimpleActionForward extends GenForwardModel
116     {
117         public SimpleActionForward( GenStrutsApp parent, AnnotationInstance annotation, ClassDeclaration jclass )
118         {
119             super( parent, annotation, jclass, null );
120         }
121         
122         public SimpleActionForward( String JavaDoc name, GenStrutsApp parent, AnnotationInstance annotation, ClassDeclaration jclass )
123         {
124             super( parent, annotation, jclass, null );
125             setName( name );
126         }
127
128         protected void addActionOutputs( AnnotationInstance annotation, ClassDeclaration jclass )
129         {
130             // do nothing -- there are no action outputs on simple actions
131
}
132     }
133 }
134
135
Popular Tags