1 23 package com.sun.enterprise.tools.jsfext.event.handlers; 24 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Modifier ; 27 import java.util.ArrayList ; 28 import java.util.HashMap ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 33 52 public class HandlerDefinition implements java.io.Serializable { 53 54 57 public HandlerDefinition(String id) { 58 _id = id; 59 } 60 61 64 public String getId() { 65 return _id; 66 } 67 68 71 public String getDescription() { 72 return _description; 73 } 74 75 78 public void setDescription(String desc) { 79 _description = desc; 80 } 81 82 94 public void setHandlerMethod(String cls, String methodName) { 95 if ((cls == null) || (methodName == null)) { 96 throw new IllegalArgumentException ( 97 "Class name and method name must be non-null!"); 98 } 99 _methodClass = cls; 100 _methodName = methodName; 101 } 102 103 106 public void setHandlerMethod(Method method) { 107 if (method != null) { 108 _methodName = method.getName(); 109 _methodClass = method.getDeclaringClass().getName(); 110 } else { 111 _methodName = null; 112 _methodClass = null; 113 } 114 _method = method; 115 } 116 117 120 public boolean isStatic() { 121 if (_static == null) { 122 _static = Boolean.valueOf( 123 Modifier.isStatic(getHandlerMethod().getModifiers())); 124 } 125 return _static.booleanValue(); 126 } 127 128 131 public Method getHandlerMethod() { 132 if (_method != null) { 133 return _method; 135 } 136 137 if ((_methodClass != null) && (_methodName != null)) { 139 Class clzz = null; 141 try { 142 clzz = Class.forName(_methodClass); 143 } catch (ClassNotFoundException ex) { 144 throw new RuntimeException ("'" 145 + _methodClass + "' not found!", ex); 146 } 147 148 Method method = null; 150 try { 151 method = clzz.getMethod(_methodName, EVENT_ARGS); 152 } catch (NoSuchMethodException ex) { 153 throw new RuntimeException ( 154 "Method '" + _methodName + "' not found!", ex); 155 } 156 157 _method = method; 159 } 160 161 return _method; 163 } 164 165 171 public void addInputDef(IODescriptor desc) { 172 _inputDefs.put(desc.getName(), desc); 173 } 174 175 180 public void setInputDefs(Map inputDefs) { 181 if (inputDefs == null) { 182 throw new IllegalArgumentException ( 183 "inputDefs cannot be null!"); 184 } 185 _inputDefs = inputDefs; 186 } 187 188 193 public Map getInputDefs() { 194 return _inputDefs; 195 } 196 197 200 public IODescriptor getInputDef(String name) { 201 return (IODescriptor) _inputDefs.get(name); 202 } 203 204 210 public void addOutputDef(IODescriptor desc) { 211 _outputDefs.put(desc.getName(), desc); 212 } 213 214 219 public void setOutputDefs(Map outputDefs) { 220 if (outputDefs == null) { 221 throw new IllegalArgumentException ( 222 "outputDefs cannot be null!"); 223 } 224 _outputDefs = outputDefs; 225 } 226 227 232 public Map getOutputDefs() { 233 return _outputDefs; 234 } 235 236 239 public IODescriptor getOutputDef(String name) { 240 return (IODescriptor) _outputDefs.get(name); 241 } 242 243 249 public void addChildHandler(Handler desc) { 250 _childHandlers.add(desc); 251 } 252 253 258 public void setChildHandlers(List childHandlers) { 259 if (childHandlers == null) { 260 throw new IllegalArgumentException ( 261 "childHandlers cannot be null!"); 262 } 263 _childHandlers = childHandlers; 264 } 265 266 271 public List getChildHandlers() { 272 return _childHandlers; 273 } 274 275 276 public static final Class [] EVENT_ARGS = new Class [] {HandlerContext.class}; 277 278 private String _id = null; 279 private String _description = null; 280 private String _methodClass = null; 281 private String _methodName = null; 282 private transient Method _method = null; 283 private Map _inputDefs = new HashMap (5); 284 private Map _outputDefs = new HashMap (5); 285 private List _childHandlers = new ArrayList (5); 286 private transient Boolean _static = null; 287 288 private static final long serialVersionUID = 0xA8B7C6D5E4F30211L; 289 } 290 | Popular Tags |