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.MachineActions;
19
20 import org.apache.struts.action.ActionMapping;
21
22 import javax.servlet.http.HttpServletRequest;
23 /**
24 * Form object used for manipulating physical Machines into Join application.
25 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26 * @version $Revision: 1.1 $
27 *
28 * @struts.form name="machineForm"
29 */
30 public class MachineForm extends JoinForm{
31
32
33
34 /** This machine full network name */
35 private String name;
36 /** This machine IP address */
37 private String ipAddress;
38 /** This machine Operating System info */
39 private String osInfo;
40 /** This machine CPU info */
41 private String cpuInfo;
42 /** This machine RAM amount */
43 private int ramAmount = -1;
44 /** This machine ROM amount */
45 private int romAmount = -1;
46
47 /** String representation of <b>ramAmount</b> */
48 private String ramAmountStr = null;
49 /** String representation of <b>romAmount</b> */
50 private String romAmountStr = null;
51
52
53
54
55 /** Creates a new instance of MachineForm. */
56 public MachineForm(){
57 }
58
59
60
61
62 /** @return The machine full network name */
63 public String getName(){
64 return name;
65 }
66 /** @param name This machine full network name */
67 public void setName(String name){
68 this.name = name;
69 }
70 /** @return The current machine IP address */
71 public String getIpAddress(){
72 return ipAddress;
73 }
74 /** @param ipAddress The machine IP address */
75 public void setIpAddress(String ipAddress){
76 this.ipAddress = ipAddress;
77 }
78 /** @return The current machine operating system infos */
79 public String getOsInfo(){
80 return osInfo;
81 }
82 /** @param osInfo The machine operation system infos */
83 public void setOsInfo(String osInfo){
84 this.osInfo = osInfo;
85 }
86 /** @return The current machine CPU infos */
87 public String getCpuInfo(){
88 return cpuInfo;
89 }
90 /** @param cpuInfo The machine CPU infos */
91 public void setCpuInfo(String cpuInfo){
92 this.cpuInfo = cpuInfo;
93 }
94 /** @return The amount of RAM on current machine */
95 public int getRamAmount(){
96 return ramAmount;
97 }
98 /** @param ramAmount The amount of RAM on machine */
99 public void setRamAmount(int ramAmount){
100 this.ramAmount = ramAmount;
101 }
102 /** @return The amount of ROM on current machine */
103 public int getRomAmount(){
104 return romAmount;
105 }
106 /** @param romAmount The amount of ROM on machine */
107 public void setRomAmount(int romAmount){
108 this.romAmount = romAmount;
109 }
110
111 /** @return The amount of RAM on current machine (should be an integer) */
112 public String getRamAmountStr(){
113 return ramAmountStr;
114 }
115 /** @param ramAmountStr The amount of RAM on machine (should be an integer) */
116 public void setRamAmountStr(String ramAmountStr){
117 this.ramAmountStr = ramAmountStr;
118 }
119 /** @return The amount of ROM on current machine (should be an integer) */
120 public String getRomAmountStr(){
121 return romAmountStr;
122 }
123 /** @param romAmountStr The amount of ROM on machine (should be an integer) */
124 public void setRomAmountStr(String romAmountStr){
125 this.romAmountStr = romAmountStr;
126 }
127
128
129
130
131 /**
132 * Validation of the form attributes.
133 * @param operation String representing the operation to invoke on Action
134 * @param mapping Mapping between forwards name and path for this action
135 * @param request The servlet container request wrapper
136 */
137 public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
138
139 if (MachineActions.LOAD_OP.equals(operation) || MachineActions.DETAILS_OP.equals(operation)){
140
141 validateEntityObjectId();
142 }
143 else if (MachineActions.SAVE_OP.equals(operation)){
144
145 if (name == null || name.length() == 0)
146 addActionError("errors.required", getGuiMessageResources().getMessage("label.machine.name"));
147
148 if (ipAddress == null || ipAddress.length() == 0)
149 addActionError("errors.required", getGuiMessageResources().getMessage("label.machine.ipaddress"));
150
151 if (ramAmountStr != null && ramAmountStr.length() > 0){
152 try {ramAmount = Integer.valueOf(ramAmountStr).intValue();}
153 catch (Exception e){
154 addActionError("errors.integer", getGuiMessageResources().getMessage("label.machine.ramamount"));
155 }
156 }
157
158 if (romAmountStr != null && romAmountStr.length() > 0){
159 try {romAmount = Integer.valueOf(romAmountStr).intValue();}
160 catch (Exception e){
161 addActionError("errors.integer", getGuiMessageResources().getMessage("label.machine.romamount"));
162 }
163 }
164 }
165 }
166
167
168
169
170 /**
171 * Reset form attributes.
172 * @param mapping Mapping between forwards name and path for this action
173 * @param request The servlet container request wrapper
174 */
175 public void reset(ActionMapping mapping, HttpServletRequest request){
176 super.reset(mapping, request);
177 }
178 }