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.ConsumerActions;
19 import org.figure8.join.core.messaging.JMSConsumerBean;
20 import org.figure8.join.core.messaging.JMSConsumerBeanParameterInfo;
21
22 import org.apache.struts.action.ActionMapping;
23
24 import javax.servlet.http.HttpServletRequest;
25
26 import java.util.Map;
27 import java.util.HashMap;
28 /**
29 * Form object used for managing and manipulating event consumers.
30 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
31 * @version $Revision: 1.1 $
32 *
33 * @struts.form name="consumerForm"
34 */
35 public class ConsumerForm extends JoinForm{
36
37
38
39 /** The name corresponding to the consumer. */
40 private String name;
41 /** The message selector expression to apply on consumer. */
42 private String selector;
43 /** The reference of destination this consumer get messages from. */
44 private String destination;
45 /** The Java class used for instanciating a JMS consumer */
46 private String consumerBeanClass;
47 /** Whether the described consumer is active or not (it may have been temporarily disabled) */
48 private boolean active = true;
49 /** Whether the described consumer bean is thread safe or not. Default is true. */
50 private boolean threadSafe = true;
51
52 /** String representation of <b>active</b> flag. */
53 private String activeStr;
54 /** String representation of <b>threadSafe</b> flag. */
55 private String threadSafeStr;
56
57 /**
58 * The map of parameters of the consumer bean instance if Configurable.
59 * Keys are the name of parmaeter, values are string representing values.
60 */
61 private Map parameters = new HashMap();
62
63
64
65
66 /** Creates a new instance of ConsumerForm. */
67 public ConsumerForm(){
68 }
69
70
71
72
73 /** @return The name corresponding to the consumer */
74 public String getName(){
75 return name;
76 }
77 /** @param name The name corresponding to the consumer */
78 public void setName(String name){
79 this.name = name;
80 }
81 /** @return The message selector expression to apply on consumer*/
82 public String getSelector(){
83 return selector;
84 }
85 /** @param selector The message selector expression to apply on consumer */
86 public void setSelector(String selector){
87 this.selector = selector;
88 }
89 /** @return The reference of destination this consumer get messages from */
90 public String getDestination(){
91 return destination;
92 }
93 /** @param destination The reference of destination this consumer get messages from */
94 public void setDestination(String destination){
95 this.destination = destination;
96 }
97 /** @return The Java class used for instanciating a JMS consumer */
98 public String getConsumerBeanClass(){
99 return consumerBeanClass;
100 }
101 /** @param consumerBeanClass The Java class used for instanciating a JMS consumer */
102 public void setConsumerBeanClass(String consumerBeanClass){
103 this.consumerBeanClass = consumerBeanClass;
104 }
105 /** @return Whether the described consumer is active or not */
106 public boolean isActive(){
107 return active;
108 }
109 /** @param active Whether the described consumer is active or not */
110 public void setActive(boolean active){
111 this.active = active;
112 this.activeStr = String.valueOf(active);
113 }
114 /** @return Whether the described consumer bean is thread safe or not */
115 public boolean isThreadSafe(){
116 return threadSafe;
117 }
118 /** @param threadSafe Whether the described consumer bean is thread safe or not */
119 public void setThreadSafe(boolean threadSafe){
120 this.threadSafe = threadSafe;
121 this.threadSafeStr = String.valueOf(threadSafe);
122 }
123
124 /** @return Flag telling if consumer is active (should be a boolean) */
125 public String getActiveStr(){
126 return activeStr;
127 }
128 /** @param activeStr Flag telling if consumer is active (must be a boolean) */
129 public void setActiveStr(String activeStr){
130 this.activeStr = activeStr;
131 }
132 /** @return Flag telling is consumer is thread safe (should be a boolean) */
133 public String getThreadSafeStr(){
134 return threadSafeStr;
135 }
136 /** @param threadSafeStr Flag telling is consumer is thread safe (must be a boolean) */
137 public void setThreadSafeStr(String threadSafeStr){
138 this.threadSafeStr = threadSafeStr;
139 }
140
141 /** @return Map of parameters associated to consumer. */
142 public Map getParameters(){
143 return parameters;
144 }
145 /**
146 * @param key Name of parameter to get value for
147 * @return string representing parameter value, null if unknown
148 */
149 public Object getMappedParameter(String key){
150 return parameters.get(key);
151 }
152 /**
153 * @param key Name of parameter to set value for
154 * @param value Value of parameters (String representation)
155 */
156 public void setMappedParameter(String key, Object value){
157 parameters.put(key, value);
158 }
159
160 /** @param parameter Existing consumer parameter to add to map ones. */
161 public void addParameter(JMSConsumerBeanParameterInfo parameter){
162 setMappedParameter(parameter.getName(), parameter.getValue());
163 }
164
165
166
167
168 /**
169 * Validation of the form attributes.
170 * @param operation String representing the operation to invoke on Action
171 * @param mapping Mapping between forwards name and path for this action
172 * @param request The servlet container request wrapper
173 */
174 public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
175
176 if (ConsumerActions.LOAD_OP.equals(operation) || ConsumerActions.DETAILS_OP.equals(operation)){
177
178 if (name == null || name.length() == 0)
179 addActionError("errors.required", getGuiMessageResources().getMessage("label.consumer.name"));
180 }
181 else if (ConsumerActions.SAVE_OP.equals(operation)){
182
183 if (name == null || name.length() == 0)
184 addActionError("errors.required", getGuiMessageResources().getMessage("label.consumer.name"));
185
186 if (destination == null || destination.length() == 0)
187 addActionError("errors.required", getGuiMessageResources().getMessage("label.consumer.destination"));
188
189 if (consumerBeanClass == null || consumerBeanClass.length() == 0)
190 addActionError("errors.required", getGuiMessageResources().getMessage("label.consumer.consumerBeanClass"));
191 else{
192 try{
193
194 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(consumerBeanClass);
195 if (!JMSConsumerBean.class.isAssignableFrom(clazz))
196 addActionError("errors.badimplementation", getGuiMessageResources().getMessage("label.consumer.consumerBeanClass"));
197 }
198 catch (ClassNotFoundException cnfe){
199 addActionError("errors.classnotfound", getGuiMessageResources().getMessage("label.consumer.consumerBeanClass"));
200 }
201 }
202
203
204 active = Boolean.valueOf(activeStr).booleanValue();
205 threadSafe = Boolean.valueOf(threadSafeStr).booleanValue();
206 }
207 else if (ConsumerActions.SAVE_PARAM_OP.equals(operation)){
208
209 }
210 }
211
212
213
214
215 /**
216 * Reset form attributes.
217 * @param mapping Mapping between forwards name and path for this action
218 * @param request The servlet container request wrapper
219 */
220 public void reset(ActionMapping mapping, HttpServletRequest request){
221 super.reset(mapping, request);
222 name = null;
223 selector = null;
224 destination = null;
225 consumerBeanClass = null;
226 active = true;
227 threadSafe = true;
228 activeStr = null;
229 threadSafeStr = null;
230 }
231 }