001    package hirondelle.web4jtools.codegenerator.dao;
002    
003    import hirondelle.web4j.model.AppException;
004    import hirondelle.web4j.action.ActionImpl;
005    import hirondelle.web4j.request.RequestParser;
006    import hirondelle.web4j.action.ResponsePage;
007    import hirondelle.web4jtools.codegenerator.codes.UiStyle;
008    import hirondelle.web4jtools.codegenerator.feature.Feature;
009    import hirondelle.web4jtools.codegenerator.feature.FeatureAction;
010    import hirondelle.web4jtools.util.TemplatedPage;
011    
012    /**
013    * Generate the source code for the Data Access Object, and serve as plain text.
014    * 
015    * <P>Uses the {@link hirondelle.web4jtools.codegenerator.feature.Feature} and 
016    * List of {@link hirondelle.web4jtools.codegenerator.field.Field} objects placed in session scope.
017    */
018    public final class DaoAction extends ActionImpl {
019    
020      public DaoAction(RequestParser aRequestParser) {
021        super(LIST_AND_EDIT, aRequestParser);  
022      }
023      
024      @Override public ResponsePage execute() throws AppException {
025        UiStyle uiStyle = getUiStyle();
026        if ( UiStyle.ListAndEdit == uiStyle ) {
027          //use default forward
028        }
029        else if ( UiStyle.ShowAndApply == uiStyle ) {
030          setResponsePage(SHOW_AND_APPLY);
031        }
032        else {
033          throw new AssertionError("Unexpected value for UiStyle : " + uiStyle);
034        }
035        
036        return getResponsePage();
037      }
038    
039      // PRIVATE //
040      private static final ResponsePage LIST_AND_EDIT = TemplatedPage.getPlain("DAO", "listAndEdit.jsp", DaoAction.class);
041      private static final ResponsePage SHOW_AND_APPLY = TemplatedPage.getPlain("DAO", "showAndApply.jsp", DaoAction.class);
042    
043      private UiStyle getUiStyle() {
044        Feature feature = (Feature) getFromSession(FeatureAction.FEATURE_KEY);
045        return feature.getUiStyle();
046      }
047    }