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.ScriptLogActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  /**
24   * Form object used for managing and manipulating script log info wrappers.
25   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26   * @version $Revision: 1.1 $
27   *
28   * @struts.form name="scriptLogForm"
29   */
30  public class ScriptLogForm extends JoinForm{
31  
32     // Attributes ---------------------------------------------------------------
33  
34     /** The unique identifier of entity referenced by this log */
35     private long entityId;
36     /** The class of entity referenced by this log */
37     private String entityClass;
38     /** The name of executed script */
39     private String scriptName;
40     /** The category of executed script */
41     private String scriptCategory;
42  
43     /** String representation ot the unique identifier of entity referenced */
44     private String entityIdStr = null;
45  
46  
47     // Constructors -------------------------------------------------------------
48  
49     /** Creates a new instance of JoinForm */
50     public ScriptLogForm(){
51     }
52  
53  
54     // Public -------------------------------------------------------------------
55  
56     /** @return The referenced entity unique identifier */
57     public long getEntityId(){
58        return entityId;
59     }
60     /** @param entityId The referenced entity unique identifier */
61     public void setEntityId(long entityId){
62        this.entityId = entityId;
63        this.entityIdStr = String.valueOf(entityId);
64     }
65  
66     /** @return The referenced entity class */
67     public String getEntityClass(){
68        return entityClass;
69     }
70     /** @param entityClass The referenced entity class */
71     public void setEntityClass(String entityClass){
72        this.entityClass = entityClass;
73     }
74  
75     /** @return The name of executed script */
76     public String getScriptName(){
77        return scriptName;
78     }
79     /** @param scriptName The name of executed script */
80     public void setScriptName(String scriptName){
81        this.scriptName = scriptName;
82     }
83     /** @return The category of executed script */
84     public String getScriptCategory(){
85        return scriptCategory;
86     }
87     /** @param scriptCategory The category of executed script */
88     public void setScriptCategory(String scriptCategory){
89        this.scriptCategory = scriptCategory;
90     }
91  
92     /** @param entityIdStr String representation of entity identifier (must be a long) */
93     public void setEntityIdStr(String entityIdStr){
94        this.entityIdStr = entityIdStr;
95     }
96  
97  
98     // Implementation of JoinForm -----------------------------------------------
99  
100    /**
101     * Validate form attributes.
102     * @param operation String representing the operation to invoke on Action
103     * @param mapping Mapping between forwards name and path for this action
104     * @param request The servlet container request wrapper
105     */
106    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
107 
108       if (ScriptLogActions.SCRIPT_OP.equals(operation)){
109          // Check and see if script name is missing.
110          if (scriptName == null || scriptName.length() == 0)
111             addActionError("errors.required", getGuiMessageResources().getMessage("label.scriptinfo.name"));
112          // Check and see if script category is missing.
113          if (scriptCategory == null || scriptCategory.length() == 0)
114             addActionError("errors.required", getGuiMessageResources().getMessage("label.scriptinfo.category"));
115       }
116       else if (ScriptLogActions.ENTITY_OP.equals(operation)){
117          // Check and see if entity classe is misssing.
118          if (entityClass == null || entityClass.length() == 0)
119             addActionError("errors.required", getGuiMessageResources().getMessage("label.scriptinfo.entityClass"));
120          // Check and see if entity identifier is missing.
121          if (entityIdStr == null || entityIdStr.length() == 0)
122             addActionError("errors.required", getGuiMessageResources().getMessage("label.scriptinfo.entityId"));
123          else{
124             try {entityId = Long.parseLong(entityIdStr);}
125             catch (Exception e){
126                addActionError("errors.long", getGuiMessageResources().getMessage("label.scriptinfo.entityId"));
127             }
128          }
129       }
130    }
131 
132 
133    // Override of ActionForm ---------------------------------------------------
134 
135    /**
136     * Reset form attributes.
137     * @param mapping Mapping between forwards name and path for this action
138     * @param request The servlet container request wrapper
139     */
140    public void reset(ActionMapping mapping, HttpServletRequest request){
141       super.reset(mapping, request);
142       scriptName = null;
143       scriptCategory = null;
144       entityId = -1;
145       entityClass = null;
146       entityIdStr = null;
147    }
148 }
149