View Javadoc

1   /**
2    * Copyright 2005-2007 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.ParameterValueActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  import java.util.Map;
25  import java.util.HashMap;
26  /**
27   * Form object to manage parameters values into Join application. 
28   * @author <a href="mailto:jerome.evrard@gmail.com">Jerome Evrard</a>
29   * @version $Revision: 1.3 $
30   * 
31   * @struts.form name="parameterValueForm"
32   */
33  public class ParameterValueForm extends JoinForm{
34  
35     // Attributes ---------------------------------------------------------------
36  
37     /** Edited parameter value */
38     private String value;
39     /** Edited parameter name */
40     private String parameterName;
41  
42  
43     /** Edited environment name */
44     private String editedEnvironment;
45     /** Edited target name */
46     private String editedTarget;
47  
48     /** Viewed environment name */
49     private String viewedEnvironment;
50     /** Viewed target name */
51     private String viewedTarget;
52     /** Render parameters values */
53     private boolean render;
54  
55     /**
56      * The map of values in form to copy. Keys are the id of value,
57      * values are boolean telling if value is selected to copy.
58      */
59     private Map copiedValue = new HashMap();
60  
61  
62     // Public -------------------------------------------------------------------
63  
64     /** @return Returns the value. */
65     public String getValue(){
66        return value;
67     }
68     /** @param value The value to set. */
69     public void setValue(String value){
70        this.value = value;
71     }
72     /** @return Returns the parameter. */
73     public String getParameterName(){
74        return parameterName;
75     }
76     /** @param parameterName The parameter to set. */
77     public void setParameterName(String parameterName){
78        this.parameterName = parameterName;
79     }
80  
81     /** @return Returns the editedEnvironment. */
82     public String getEditedEnvironment(){
83        return editedEnvironment;
84     }
85     /** @param editedEnvironment The editedEnvironment to set. */
86     public void setEditedEnvironment(String editedEnvironment){
87        this.editedEnvironment = editedEnvironment;
88     }
89     /** @return Returns the editedTarget. */
90     public String getEditedTarget(){
91        return editedTarget;
92     }
93     /** @param editedTarget The editedTarget to set. */
94     public void setEditedTarget(String editedTarget){
95        this.editedTarget = editedTarget;
96     }
97  
98     /** @return Returns the viewedEnvironment. */
99     public String getViewedEnvironment(){
100       return viewedEnvironment;
101    }
102    /** @param viewedEnvironment The viewedEnvironment to set. */
103    public void setViewedEnvironment(String viewedEnvironment){
104       this.viewedEnvironment = viewedEnvironment;
105    }
106    /** @return Returns the viewedTarget. */
107    public String getViewedTarget(){
108       return viewedTarget;
109    }
110    /** @param viewedTarget The viewedTarget to set. */
111    public void setViewedTarget(String viewedTarget){
112       this.viewedTarget = viewedTarget;
113    }
114    /** @return Returns the render. */
115    public boolean isRender(){
116       return render;
117    }
118    /** @param render The render to set. */
119    public void setRender(boolean render){
120       this.render = render;
121    }
122 
123    /** @return Get the map of values to copy. */
124    public Map getCopiedValuesMap(){
125       return copiedValue;
126    }
127    /**
128     * Set if a value is selected for copy.
129     * @param key The value id.
130     * @param value "on" if value is selected
131     */
132    public void setCopiedValue(String key, Object value){
133       copiedValue.put(key, value);
134    }
135    /**
136     * Get "on" if the value is selected for copy.
137     * @param key The value id.
138     * @return "on" if values is selcted, else null.
139     */
140    public Object getCopiedValue(String key){
141       return copiedValue.get(key);
142    }
143 
144    
145    // Override of JoinForm -----------------------------------------------------
146    
147    /**
148     * Validation of the form attributes.
149     * @param operation String representing the operation to invoke on Action
150     * @param mapping Mapping between forwards name and path for this action
151     * @param request The servlet container request wrapper
152     */
153    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request) {
154       // Validate attributes depending on operation.
155       if (ParameterValueActions.LOAD_OP.equals(operation) || ParameterValueActions.DELETE_OP.equals(operation)){
156          // Check and see if idenitifier is missing.
157          validateEntityObjectId();
158       }
159       else if (ParameterValueActions.SAVE_OP.equals(operation)){
160          // Check and see if edited target is missing.
161          if (editedTarget == null || editedTarget.length() == 0)
162             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.target"));
163          // Check and see if edited environment is missing.
164          if (editedEnvironment == null || editedEnvironment.length() == 0)
165             addActionError("errors.required", getGuiMessageResources().getMessage("label.physicalenv"));
166          // Check and see if value is missing.
167          if (value == null || value.length() == 0)
168             addActionError("errors.required", getGuiMessageResources().getMessage("label.parametervalue"));
169          // Check and see if parameter name is missing.
170          if (parameterName == null || parameterName.length() == 0)
171             addActionError("errors.required", getGuiMessageResources().getMessage("label.parameter"));
172       }
173       else if (ParameterValueActions.SHOW_VALUES_OP.equals(operation)){
174          // Check and see if viewed target is missing.
175          if (viewedTarget == null || viewedTarget.length() == 0)
176             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.target"));
177          // Check and see if viewed environment is missing.
178          if (viewedEnvironment == null || viewedEnvironment.length() == 0)
179             addActionError("errors.required", getGuiMessageResources().getMessage("label.physicalenv"));
180       }
181       else if (ParameterValueActions.PASTE_VALUES_OP.equals(operation)){
182          // Check and see if edited target is missing.
183          if (editedTarget == null || editedTarget.length() == 0)
184             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.target"));
185          // Check and see if edited environment is missing.
186          if (editedEnvironment == null || editedEnvironment.length() == 0)
187             addActionError("errors.required", getGuiMessageResources().getMessage("label.physicalenv"));
188       }
189    }
190 }