1 21 22 package com.sun.enterprise.tools.guiframework.event.descriptors; 23 24 import com.iplanet.jato.RequestContext; 25 26 import com.sun.enterprise.tools.guiframework.FrameworkDescriptor; 27 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 28 import com.sun.enterprise.tools.guiframework.util.PermissionChecker; 29 import com.sun.enterprise.tools.guiframework.util.Util; 30 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 31 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 32 33 import java.lang.reflect.Method ; 34 import java.util.ArrayList ; 35 import java.util.HashMap ; 36 import java.util.List ; 37 import java.util.Map ; 38 39 40 45 public class HandlerDescriptor implements FrameworkDescriptor { 46 47 52 public HandlerDescriptor(String name) { 53 setName(name); 54 } 55 56 57 60 public String getName() { 61 return _name; 62 } 63 64 65 68 protected void setName(String name) { 69 if (name == null) { 70 throw new FrameworkException("Handler name cannot be null!"); 71 } 72 _name = name; 73 } 74 75 76 79 public String getDescription() { 80 return _description; 81 } 82 83 84 87 public void setDescription(String desc) { 88 _description = desc; 89 } 90 91 92 97 public FrameworkDescriptor getParent() { 99 throw new FrameworkException( 100 "Get parent is not implemented for HandlerDescriptors!"); 101 } 102 103 104 117 118 119 133 public void setHandlerMethod(String cls, String methodName) { 134 if ((cls == null) || (methodName == null)) { 135 throw new IllegalArgumentException ( 136 "Class name and method name must be non-null!"); 137 } 138 139 _cls = cls; 141 _methodName = methodName; 142 } 143 144 private void setMethod() { 145 if ((_cls == null) || (_methodName == null)) { 146 return; 147 } 148 149 Class clzz = null; 151 try { 152 clzz = Class.forName(_cls); 153 } catch (ClassNotFoundException ex) { 154 throw new RuntimeException ("Class '"+_cls+"' not found!", ex); 155 } 156 157 Method method = null; 159 try { 160 method = clzz.getMethod(_methodName, EVENT_ARGS); 161 } catch (NoSuchMethodException ex) { 162 throw new RuntimeException ("Method '"+_methodName+"' not found!", ex); 163 } 164 165 _method = method; 167 } 168 169 public void setHandlerMethod(Method method) { 170 _method = method; 171 _cls = method.getDeclaringClass().getName(); 172 _methodName = method.getName(); 173 } 174 175 176 public Method getHandlerMethod() { 177 if (_method == null) { 178 setMethod(); 179 } 180 return _method; 181 } 182 183 184 190 public void addInputDescriptor(IODescriptor desc) { 191 _inputDescriptors.put(desc.getName(), desc); 192 } 193 194 195 200 public void setInputDescriptors(Map inputDescriptors) { 201 if (inputDescriptors == null) { 202 throw new IllegalArgumentException ( 203 "inputDescriptors cannot be null!"); 204 } 205 _inputDescriptors = inputDescriptors; 206 } 207 208 209 214 public Map getInputDescriptors() { 215 return _inputDescriptors; 216 } 217 218 219 222 public IODescriptor getInputDescriptor(String name) { 223 return (IODescriptor)_inputDescriptors.get(name); 224 } 225 226 227 233 public void addOutputDescriptor(IODescriptor desc) { 234 _outputDescriptors.put(desc.getName(), desc); 235 } 236 237 238 243 public void setOutputDescriptors(Map outputDescriptors) { 244 if (outputDescriptors == null) { 245 throw new IllegalArgumentException ( 246 "outputDescriptors cannot be null!"); 247 } 248 _outputDescriptors = outputDescriptors; 249 } 250 251 252 257 public Map getOutputDescriptors() { 258 return _outputDescriptors; 259 } 260 261 262 265 public IODescriptor getOutputDescriptor(String name) { 266 return (IODescriptor)_outputDescriptors.get(name); 267 } 268 269 270 276 public void addChildHandlerDescriptor(UseHandlerDescriptor desc) { 277 _childHandlers.add(desc); 278 } 279 280 281 286 public void setChildHandlerDescriptors(List childHandlers) { 287 if (childHandlers == null) { 288 throw new IllegalArgumentException ( 289 "childHandlers cannot be null!"); 290 } 291 _childHandlers = childHandlers; 292 } 293 294 295 300 public List getChildHandlerDescriptors() { 301 return _childHandlers; 302 } 303 304 305 308 public String getIfCheck() { 309 return _ifCheck; 310 } 311 312 313 316 public void setIfCheck(String ifCheck) { 317 _ifCheck = ifCheck; 318 } 319 320 321 333 public boolean hasPermission(ViewDescriptor vd) { 334 String ifCheck = getIfCheck(); 336 if ((ifCheck == null) || (ifCheck.trim().length() == 0)) { 337 return true; 339 } 340 341 return new PermissionChecker(ifCheck, vd).hasPermission(); 343 } 344 345 346 public static final Class [] EVENT_ARGS = new Class [] {RequestContext.class, HandlerContext.class}; 347 348 private String _name = null; 351 private String _description = null; 352 private String _cls = null; 353 private String _methodName = null; 354 private transient Method _method = null; 355 private String _ifCheck = null; 356 private Map _inputDescriptors = new HashMap (5); 357 private Map _outputDescriptors = new HashMap (5); 358 private List _childHandlers = new ArrayList (5); 359 } 360 | Popular Tags |