1 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 ; 30 import java.util.Iterator ; 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 formMember = getFormMember(); 45 if ( formMember != null ) 46 { 47 FieldDeclaration field = CompilerUtils.findField( jclass, formMember ); 48 assert field != null; setFormBeanName( addFormBean( field.getType(), parentApp ) ); 50 } 51 else 52 { 53 setReadonly( true ); 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 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 String 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 conditionalFwdAnnotations = 95 CompilerUtils.getAnnotationArray( annotation, CONDITIONAL_FORWARDS_ATTR, true ); 96 97 if ( conditionalFwdAnnotations != null ) 98 { 99 int anonCount = 0; 100 101 for ( Iterator ii = conditionalFwdAnnotations.iterator(); ii.hasNext(); ) 102 { 103 AnnotationInstance conditionalFwdAnnotation = ( AnnotationInstance ) ii.next(); 104 ForwardModel conditionalFwd = new SimpleActionForward( parentApp, conditionalFwdAnnotation, jclass ); 105 String 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 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 } 132 } 133 } 134 135 | Popular Tags |