1 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 ; 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 33 public class GenForwardModel 34 extends ForwardModel 35 implements JpfLanguageConstants 36 { 37 public GenForwardModel( GenStrutsApp parent, AnnotationInstance annotation, ClassDeclaration jclass, 38 String 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 DeclaredType outputFormType = CompilerUtils.getDeclaredType( annotation, OUTPUT_FORM_BEAN_TYPE_ATTR, true ); 52 String 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; assert field != null; assert field.getType() instanceof DeclaredType : field.getType().getClass().getName(); outputFormType = ( DeclaredType ) field.getType(); 60 } 61 setOutputFormBeanMember( outputFormMember ); 62 setOutputFormBeanType( outputFormType != null ? CompilerUtils.getLoadableName( outputFormType ) : null ); 63 64 String returnAction = CompilerUtils.getString( annotation, RETURN_ACTION_ATTR, true ); 68 String navigateTo = CompilerUtils.getEnumFieldName( annotation, NAVIGATE_TO_ATTR, true ); 69 String tilesDefinition = CompilerUtils.getString( annotation, TILES_DEFINITION_ATTR, true ); 70 String path = CompilerUtils.getString( annotation, PATH_ATTR, true ); 71 String action = CompilerUtils.getString( annotation, ACTION_ATTR, true ); 72 73 if ( action != null ) 74 { 75 assert path == null; 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 ); } 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 ); } 111 else if ( tilesDefinition != null ) 112 { 113 assert path == null; 114 setPath( tilesDefinition ); } 116 else 117 { 118 assert path != null; 120 boolean contextRelative = true; 125 if ( ! path.startsWith( "/" ) ) 126 { 127 contextRelative = false; 128 129 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 ); } 145 } 146 147 static void addForwards( AnnotationInstance annotation, ForwardContainer container, ClassDeclaration jclass, 148 GenStrutsApp strutsApp, String commentSuffix ) 149 { 150 List forwards = CompilerUtils.getAnnotationArray( annotation, FORWARDS_ATTR, true ); 151 addForwards( forwards, container, jclass, strutsApp, commentSuffix ); 152 } 153 154 static void addForwards( Collection forwards, ForwardContainer container, 155 ClassDeclaration jclass, GenStrutsApp strutsApp, String commentSuffix ) 156 { 157 if ( forwards != null ) 158 { 159 for ( Iterator 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 actionOutputs = 170 CompilerUtils.getAnnotationArray( annotation, ACTION_OUTPUTS_ATTR, true ); 171 172 if ( actionOutputs != null ) 173 { 174 for ( Iterator 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 |