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.ResourceMappingActions;
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 resource 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="resMappingForm"
31   */
32  public class ResourceMappingForm extends JoinForm{
33  
34     // Attributes ---------------------------------------------------------------
35  
36     /** The unique id of infrastructure resource this mapping is for */
37     private long resourceId = -1;
38     /** The unique key of physical environment this mapping is for */
39     private String environmentKey;
40     /** The starting date of this resource mapping */
41     private Date startDate;
42     /** The end date of this resource mapping */
43     private Date endDate;
44  
45     /** String representation of resourceId (should be a long) */
46     private String resourceIdStr = null;
47  
48  
49     // Constructors -------------------------------------------------------------
50  
51     /** Creates a new instance of ResourceMappingForm. */
52     public ResourceMappingForm(){
53     }
54  
55  
56     // Public -------------------------------------------------------------------
57  
58     /** @return The unique id of infrastructure resource this mapping is for */
59     public long getResourceId(){
60        return resourceId;
61     }
62     /** @param resourceId The unique id of infrastructure resource this mapping is for */
63     public void setResourceId(long resourceId){
64        this.resourceId = resourceId;
65        this.resourceIdStr = String.valueOf(resourceId);
66     }
67     /** @return The unique key of physical environment this mapping is for */
68     public String getEnvironmentKey(){
69        return environmentKey;
70     }
71     /** @param environmentKey The unique key of physical environment this mapping is for */
72     public void setEnvironmentKey(String environmentKey){
73        this.environmentKey = environmentKey;
74     }
75  
76     /** @return The starting date of this resource mapping */
77     public Date getStartDate(){
78        return startDate;
79     }
80     /** @param startDate The starting date of this resource mapping */
81     public void setStartDate(Date startDate){
82        this.startDate = startDate;
83     }
84     /** @return The end date of this resource mapping */
85     public Date getEndDate(){
86        return endDate;
87     }
88     /** @param endDate The end date of this resource mapping */
89     public void setEndDate(Date endDate){
90        this.endDate = endDate;
91     }
92  
93     /** @return String representation of resourceId (should be a long) */
94     public String getResourceIdStr(){
95        return resourceIdStr;
96     }
97     /** @param resourceIdStr String representation of resourceId (must be a long) */
98     public void setResourceIdStr(String resourceIdStr){
99        this.resourceIdStr = resourceIdStr;
100    }
101 
102 
103    // Implementation of JoinForm -----------------------------------------------
104 
105    /**
106     * Validate form attributes.
107     * @param operation String representing the operation to invoke on Action
108     * @param mapping Mapping between forwards name and path for this action
109     * @param request The servlet container request wrapper
110     */
111    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
112 
113       if (ResourceMappingActions.LOAD_OP.equals(operation) || ResourceMappingActions.CLOSE_OP.equals(operation)){
114          // Check that mapping identifier is present.
115          validateEntityObjectId();
116       }
117       else if (ResourceMappingActions.CREATE_OP.equals(operation)){
118          // Check and see if environment key is missing.
119          if (environmentKey == null || environmentKey.length() == 0)
120             addActionError("errors.required", getGuiMessageResources().getMessage("label.resmapping.environment"));
121          // Check and see if resource identifier is missing.
122          if (resourceIdStr == null || resourceIdStr.length() == 0)
123             addActionError("errors.required", getGuiMessageResources().getMessage("label.resmapping.resource"));
124          else{
125             // Check and see resource if id is a long.
126             try {resourceId = Long.valueOf(resourceIdStr).longValue();}
127             catch (Exception e){
128                addActionError("errors.range", getGuiMessageResources().getMessage("label.resmapping.resource"),
129                        "1", String.valueOf(Long.MAX_VALUE));
130             }
131          }
132       }
133    }
134 
135 
136    // Override of ActionForm ---------------------------------------------------
137 
138    /**
139     * Reset form attributes.
140     * @param mapping Mapping between forwards name and path for this action
141     * @param request The servlet container request wrapper
142     */
143    public void reset(ActionMapping mapping, HttpServletRequest request){
144       super.reset(mapping, request);
145       resourceId = -1;
146       environmentKey = null;
147       startDate = null;
148       endDate = null;
149       resourceIdStr = null;
150    }
151 }