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.LogicalEnvironmentActions;
19  import org.apache.struts.action.ActionMapping;
20  
21  import javax.servlet.http.HttpServletRequest;
22  /**
23   * This is a Struts form for managing and manipulating LogicalEnvironment into Join.
24   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
25   * @version $Revision: 1.1 $
26   *
27   * @struts.form name="logicalEnvForm"
28   */
29  public class LogicalEnvironmentForm extends JoinForm{
30  
31     // Attributes ---------------------------------------------------------------
32  
33     /** The key of current logical environment. */
34     private String key;
35     /** The label of current logical environment. */
36     private String label;
37     /** The description of current logical environment. */
38     private String description;
39     /** The identifier of logical environment manager. */
40     private String managerId;
41     /** The flag telling if logical environment is active or not; */
42     private boolean active = true;
43     /** The name of release this environment is attached to */
44     private String releaseName;
45     /** The unique id of step this environment is dedicated to */
46     private long stepId = -1;
47  
48     /** String representation of the <b>active</b> flag. */
49     private String activeStr;
50     /** String representation of the <b>stepId</b> long. */
51     private String stepIdStr;
52  
53  
54     // Constructors -------------------------------------------------------------
55  
56     /** Creates a new LogicalEnvironmentForm. */
57     public LogicalEnvironmentForm(){
58     }
59  
60  
61     // Public -------------------------------------------------------------------
62  
63     /** @return The business key of current logical environment */
64     public String getKey(){
65        return key;
66     }
67     /** @param key The business key of current logical environment */
68     public void setKey(String key){
69        this.key = key;
70     }
71     /** @return The label of current logical environment */
72     public String getLabel(){
73        return label;
74     }
75     /** @param label The label of logical environment represented by form */
76     public void setLabel(String label){
77        this.label = label;
78     }
79     /** @return The description of the currently loaded logical environment */
80     public String getDescription(){
81        return description;
82     }
83     /** @param description The description of the current logical environment */
84     public void setDescription(String description){
85        this.description = description;
86     }
87     /** @return The identifier of user managing the logical environment */
88     public String getManagerId(){
89        return managerId;
90     }
91     /** @param managerId The identifier of manager for logical environment */
92     public void setManagerId(String managerId){
93        this.managerId = managerId;
94     }
95     /** @return true if the logical environment is active. */
96     public boolean isActive(){
97        return active;
98     }
99     /** @param active The flag telling if environment is active */
100    public void setActive(boolean active){
101       this.active = active;
102       this.activeStr = String.valueOf(active);
103    }
104    /** @return The name of the release this environment is attached to */
105    public String getReleaseName(){
106       return releaseName;
107    }
108    /** @param releaseName The name of release this environment is attached to */
109    public void setReleaseName(String releaseName){
110       this.releaseName = releaseName;
111    }
112    /** @return The unique id of step this environment is dedicated to */
113    public long getStepId(){
114       return stepId;
115    }
116    /** @param stepId The unique id of step this environment is dedicated to */
117    public void setStepId(long stepId){
118       this.stepId = stepId;
119       this.stepIdStr = String.valueOf(stepId);
120    }
121 
122    /** @return Flag telling if current environment is active or not */
123    public String getActiveStr(){
124       return activeStr;
125    }
126    /** @param activeStr Flag telling if current environment is active or not */
127    public void setActiveStr(String activeStr){
128       this.activeStr = activeStr;
129    }
130    /** @return String representation of the <b>stepId</b> long */
131    public String getStepIdStr(){
132       return stepIdStr;
133    }
134    /** @param stepIdStr String representation of the <b>stepId</b> long. */
135    public void setStepIdStr(String stepIdStr){
136       this.stepIdStr = stepIdStr;
137    }
138 
139 
140    // Implementation of JoinForm -----------------------------------------------
141 
142    /**
143     * Validate form attributes depending on operation.
144     * @param operation String representing the operation to invoke on Action
145     * @param mapping Mapping between forwards name and path for this action
146     * @param request The servlet container request wrapper
147     */
148    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
149 
150       if (LogicalEnvironmentActions.LOAD_OP.equals(operation)){
151          // Check and see if key is missing.
152          if (key == null || key.length() == 0)
153             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.key"));
154       }
155       else if (LogicalEnvironmentActions.SAVE_OP.equals(operation)){
156          // Check and see if key is missing.
157          if (key == null || key.length() == 0)
158             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.key"));
159          // Check and see if label is missing.
160          if (label == null || label.length() == 0)
161             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.label"));
162          // Check and see if description is missing.
163          if (description == null || description.length() == 0)
164             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.description"));
165          // Check and see if managerId is missing.
166          if (managerId == null || managerId.length() == 0)
167             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.managerId"));
168          // Check and see if release is missing.
169          if (releaseName == null || releaseName.length() == 0)
170             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.release"));
171          // Check and see if step is missing.
172          if (stepIdStr == null || stepIdStr.length() == 0)
173             addActionError("errors.required", getGuiMessageResources().getMessage("label.logicalenv.step"));
174          else{
175             // Check and see if step is a long.
176             try {stepId = Long.valueOf(stepIdStr).longValue();}
177             catch (Exception e){
178                addActionError("errors.integer", getGuiMessageResources().getMessage("label.logicalenv.step"));
179             }
180          }
181 
182          // Parse the active flag.
183          active = Boolean.valueOf(activeStr).booleanValue();
184       }
185    }
186 
187 
188    // Override of ActionForm ---------------------------------------------------
189 
190    /**
191     * Reset form attributes.
192     * @param mapping Mapping between forwards name and path for this action
193     * @param request The servlet container request wrapper
194     */
195    public void reset(ActionMapping mapping, HttpServletRequest request){
196       super.reset(mapping, request);
197       key = null;
198       label = null;
199       description = null;
200       managerId = null;
201       stepId = -1;
202       releaseName = null;
203       activeStr = null;
204    }
205 }