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.EnvironmentMappingActions;
19
20 import org.apache.struts.action.ActionMapping;
21
22 import javax.servlet.http.HttpServletRequest;
23
24 import java.util.Date;
25 /**
26 * Form object used for manipulating environment mappings into Join application.
27 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28 * @version $Revision: 1.1 $
29 *
30 * @struts.form name="envMappingForm"
31 */
32 public class EnvironmentMappingForm extends JoinForm{
33
34
35
36 /** The unique key of logical environment this maping is for */
37 private String logicalEnvKey;
38 /** The unique key of physical environment this mapping is for */
39 private String physicalEnvKey;
40 /** The starting date of this environmnent mapping */
41 private Date startDate;
42 /** The end date of this environment mapping */
43 private Date endDate;
44
45
46
47
48 /** Creates a new instance of EnvironmentMappingForm */
49 public EnvironmentMappingForm(){
50 }
51
52
53
54
55 /** @return The unique key of logical environment of this mapping */
56 public String getLogicalEnvKey(){
57 return logicalEnvKey;
58 }
59 /** @param logicalEnvKey The unique key of logical environment of this mapping */
60 public void setLogicalEnvKey(String logicalEnvKey){
61 this.logicalEnvKey = logicalEnvKey;
62 }
63
64 /** @return The unique key of physical environment of this mapping */
65 public String getPhysicalEnvKey(){
66 return physicalEnvKey;
67 }
68 /** @param physicalEnvKey The unique key of physical environment of this mapping */
69 public void setPhysicalEnvKey(String physicalEnvKey){
70 this.physicalEnvKey = physicalEnvKey;
71 }
72
73 /** @return The starting date of this environmnent mapping */
74 public Date getStartDate(){
75 return startDate;
76 }
77 /** @param startDate The starting date of this environmnent mapping */
78 public void setStartDate(Date startDate){
79 this.startDate = startDate;
80 }
81
82 /** @return The end date of this environment mapping */
83 public Date getEndDate(){
84 return endDate;
85 }
86 /** @param endDate The end date of this environment mapping */
87 public void setEndDate(Date endDate){
88 this.endDate = endDate;
89 }
90
91
92
93
94 /**
95 * Validate form attributes depending on requested operation.
96 * @param operation String representing the operation to invoke on Action
97 * @param mapping Mapping between forwards name and path for this action
98 * @param request The servlet container request wrapper
99 */
100 public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
101
102 if (EnvironmentMappingActions.LOAD_OP.equals(operation) || EnvironmentMappingActions.CLOSE_OP.equals(operation)){
103
104 validateEntityObjectId();
105 }
106 else if (EnvironmentMappingActions.FORM_OP.equals(operation)){
107
108 if (logicalEnvKey == null || logicalEnvKey.length() == 0)
109 addActionError("errors.required", getGuiMessageResources().getMessage("label.envmapping.logicalenv"));
110 }
111 else if (EnvironmentMappingActions.CREATE_OP.equals(operation)){
112
113 if (logicalEnvKey == null || logicalEnvKey.length() == 0)
114 addActionError("errors.required", getGuiMessageResources().getMessage("label.envmapping.logicalenv"));
115
116 if (physicalEnvKey == null || physicalEnvKey.length() == 0)
117 addActionError("errors.required", getGuiMessageResources().getMessage("label.envmapping.physicalenv"));
118 }
119 else if (EnvironmentMappingActions.VIEW_OP.equals(operation)){
120
121 if ((logicalEnvKey == null || logicalEnvKey.length() == 0)
122 && (physicalEnvKey == null || physicalEnvKey.length() == 0)){
123
124 addActionError("errors.required", getGuiMessageResources().getMessage("label.envmapping.logicalenv"));
125 addActionError("errors.required", getGuiMessageResources().getMessage("label.envmapping.physicalenv"));
126 }
127 }
128 }
129
130
131
132
133 /**
134 * Reset form attributes.
135 * @param mapping Mapping between forwards name and path for this action
136 * @param request The servlet container request wrapper
137 */
138 public void reset(ActionMapping mapping, HttpServletRequest request){
139 super.reset(mapping, request);
140 logicalEnvKey = null;
141 physicalEnvKey = null;
142 startDate = null;
143 endDate = null;
144 }
145 }