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.ResourceVersionActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  /**
24   * Form object used for manipulating ResourceVersions into Join application web layer.
25   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26   * @version $Revision: 1.1 $
27   *
28   * @struts.form name="resourceVersionForm"
29   */
30  public class ResourceVersionForm extends JoinForm{
31  
32     // Attributes ---------------------------------------------------------------
33  
34     /** This resource version name (should be unique) */
35     private String name;
36     /** This resource version description */
37     private String description;
38  
39     /** The key of this resource type */
40     private String resourceTypeKey;
41  
42  
43     // Constructors -------------------------------------------------------------
44  
45     /** Creates a new instance of ResourceVersionForm. */
46     public ResourceVersionForm(){
47     }
48  
49  
50     // Public -------------------------------------------------------------------
51  
52     /** @return This resource version name */
53     public String getName(){
54        return name;
55     }
56     /** @param name Thi sresource version name */
57     public void setName(String name){
58        this.name = name;
59     }
60     /** @return This resouce version description */
61     public String getDescription(){
62        return description;
63     }
64     /** @param description This resource version description */
65     public void setDescription(String description){
66        this.description = description;
67     }
68  
69     /** @return he key of this resource type */
70     public String getResourceTypeKey(){
71        return resourceTypeKey;
72     }
73     /** @param typeKey he key of this resource type */
74     public void setResourceTypeKey(String typeKey){
75        this.resourceTypeKey = typeKey;
76     }
77  
78  
79     // Implementation of JoinForm -----------------------------------------------
80  
81     /**
82      * Validation of the form attributes.
83      * @param operation String representing the operation to invoke on Action
84      * @param mapping Mapping between forwards name and path for this action
85      * @param request The servlet container request wrapper
86      */
87     public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
88        // Check attributes depending on operation.
89        if (ResourceVersionActions.LOAD_OP.equals(operation)){
90           // Check if identifier is missing.
91           validateEntityObjectId();
92        }
93        else if (ResourceVersionActions.SAVE_OP.equals(operation)){
94           // Check if name is missing.
95           if (name == null || name.length() == 0)
96              addActionError("errors.required", getGuiMessageResources().getMessage("label.resourceversion.name"));
97           // Check if description is missing.
98           if (description == null || description.length() == 0)
99              addActionError("errors.required", getGuiMessageResources().getMessage("label.resourceversion.description"));
100          // Check if resource type key is missing.
101          if (resourceTypeKey == null || resourceTypeKey.length() == 0)
102             addActionError("errors.required", getGuiMessageResources().getMessage("label.resource.resourcetype"));
103       }
104    }
105 }