View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.control.form;
16  
17  import org.figure8.join.control.JoinForm;
18  import org.figure8.join.control.action.StepActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  /**
24   * Form object used for manipulating Steps into Join application.
25   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26   * @version $Revision: 1.1 $
27   *
28   * @struts.form name="stepForm"
29   */
30  public class StepForm extends JoinForm{
31  
32     // Attributes ---------------------------------------------------------------
33  
34     /** The label of current step */
35     private String label;
36     /** The position of current step into integration cycle */
37     private int position = -1;
38  
39     /** String representation of <b>position</b> */
40     private String positionStr;
41  
42  
43     // Constructors -------------------------------------------------------------
44  
45     /** Creates a new instance of StepForm */
46     public StepForm(){
47     }
48  
49  
50     // Public -------------------------------------------------------------------
51  
52     /** @return Label of current step */
53     public String getLabel(){
54        return label;
55     }
56     /** @param label Label of current step */
57     public void setLabel(String label){
58        this.label = label;
59     }
60     /** @return Position of current step into the integration cycle */
61     public int getPosition(){
62        return position;
63     }
64     /** @param position Position of current step into integration cycle */
65     public void setPosition(int position){
66        this.position = position;
67        this.positionStr = String.valueOf(position);
68     }
69  
70     /** @return Position of current step into the integration cycle (should be an integer) */
71     public String getPositionStr(){
72        return positionStr;
73     }
74     /** @param position Position of current step into integration cycle (must be an integer) */
75     public void setPositionStr(String position){
76        this.positionStr = position;
77     }
78  
79  
80     // Implementation of JoinForm -----------------------------------------------
81  
82     /**
83      * Validation of the form attributes.
84      * @param operation String representing the operation to invoke on Action
85      * @param mapping Mapping between forwards name and path for this action
86      * @param request The servlet container request wrapper
87      */
88     public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
89  
90        if (StepActions.LOAD_OP.equals(operation)){
91           // Check and see if id is missing.
92           validateEntityObjectId();
93        }
94        else if (StepActions.SAVE_OP.equals(operation)){
95           // Check and see if label is missing.
96           if (label == null || label.length() == 0)
97              addActionError("errors.required", getGuiMessageResources().getMessage("label.step.label"));
98           // Check and see if position is missing.
99           if (positionStr == null || positionStr.length() == 0)
100             addActionError("errors.required", getGuiMessageResources().getMessage("label.step.position"));
101          else{
102             // Check and see if position is an integer.
103             try {position = Integer.valueOf(positionStr).intValue();}
104             catch (Exception e){
105                addActionError("errors.integer", getGuiMessageResources().getMessage("label.step.position"));
106             }
107             // Check and see if position is an integer > -1.
108             if (position < 0)
109                addActionError("errors.range", getGuiMessageResources().getMessage("label.step.position"), "0", String.valueOf(Integer.MAX_VALUE));
110          }
111       }
112    }
113 
114 
115    // Override of ActionForm ---------------------------------------------------
116 
117    /**
118     * Reset form attributes.
119     * @param mapping Mapping between forwards name and path for this action
120     * @param request The servlet container request wrapper
121     */
122    public void reset(ActionMapping mapping, HttpServletRequest request){
123       super.reset(mapping, request);
124       label = null;
125       position = -1;
126       positionStr = null;
127    }
128 }