1 23 24 package com.sun.enterprise.tools.guiframework.view; 25 26 import com.iplanet.jato.RequestManager; 27 import com.iplanet.jato.view.View; 28 import com.iplanet.jato.view.ViewBean; 29 import com.iplanet.jato.util.TypeConverter; 30 31 import com.sun.enterprise.tools.guiframework.event.descriptors.HandlerDescriptor; 32 import com.sun.enterprise.tools.guiframework.event.descriptors.IODescriptor; 33 import com.sun.enterprise.tools.guiframework.event.descriptors.UseHandlerDescriptor; 34 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 35 import com.sun.enterprise.tools.guiframework.util.Util; 36 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 37 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 38 39 import java.io.Serializable ; 40 import java.util.EventObject ; 41 42 43 46 public class HandlerContextImpl implements HandlerContext { 47 48 51 protected HandlerContextImpl(UseHandlerDescriptor useHandler, HandlerDescriptor handler, View view, ViewDescriptor vd, EventObject event) { 52 _eventObject = event; 53 _useHandlerDesc = useHandler; 54 _handlerDesc = handler; 55 _view = view; 56 _viewDesc = vd; 57 } 58 59 60 63 public View getView() { 64 return _view; 65 } 66 67 68 72 public ViewDescriptor getViewDescriptor() { 73 return _viewDesc; 74 103 } 104 105 106 109 public EventObject getEvent() { 110 return _eventObject; 111 } 112 113 114 121 public UseHandlerDescriptor getUseHandlerDescriptor() { 122 return _useHandlerDesc; 123 } 124 125 126 132 public HandlerDescriptor getHandlerDescriptor() { 133 return _handlerDesc; 134 } 135 136 137 143 public Object getInputValue(String name) { 144 IODescriptor inDesc = getHandlerDescriptor().getInputDescriptor(name); 146 if (inDesc == null) { 147 throw new FrameworkException("Attempted to get input value '"+name+ 148 "', however, this is not a declared input parameter in "+ 149 "function '"+getHandlerDescriptor().getName()+"'! Check your"+ 150 " handler and/or the XML (near ViewDescriptor '"+ 151 getViewDescriptor().getName()+"').", getViewDescriptor(), 152 getView()); 153 } 154 155 Object value = getUseHandlerDescriptor().getInputValue(name); 157 if (value == null) { 158 value = inDesc.getDefault(); 159 } 160 value = Util.replaceVariablesWithAttributes(value, getViewDescriptor()); 161 162 value = TypeConverter.asType(inDesc.getType(), value); 164 165 return value; 166 } 167 168 169 179 public void setOutputValue(String name, Object value) { 180 HandlerDescriptor handler = getHandlerDescriptor(); 182 IODescriptor outDesc = handler.getOutputDescriptor(name); 183 if (outDesc == null) { 184 throw new FrameworkException("Attempted to set output value '"+name+ 185 "' from handler '"+handler.getName()+"', however, this is not "+ 186 "a declared output parameter! Check your handler and/or the "+ 187 "XML.", getViewDescriptor(), getView()); 188 } 189 190 value = TypeConverter.asType(outDesc.getType(), value); 192 193 String targetKey; 195 String targetType; 196 String outputParams[] = getUseHandlerDescriptor().getOutputMapping(name); 197 if (outputParams == null) { 198 targetKey = handler.getName()+OUTPUT_VALUE_SEPARATOR+name; 199 targetType = ATTRIBUTE_TYPE; 200 } else { 201 targetKey = outputParams[0]; 202 if (targetKey == null) { 203 targetKey = handler.getName()+OUTPUT_VALUE_SEPARATOR+name; 204 } 205 targetType = outputParams[1]; 206 if (targetType == null) { 207 targetType = ATTRIBUTE_TYPE; 208 } 209 } 210 if (targetType.equalsIgnoreCase(ATTRIBUTE_TYPE)) { 211 RequestManager.getRequestContext().getRequest(). 212 setAttribute(targetKey, value); 213 } else if (targetType.equalsIgnoreCase(SESSION_TYPE)) { 214 RequestManager.getRequestContext().getRequest().getSession(). 215 setAttribute(targetKey, value); 216 } else if (targetType.equalsIgnoreCase(PAGE_SESSION_TYPE)) { 217 ViewBean vb = Util.getParentViewBean(getView()); 218 vb.setPageSessionAttribute(targetKey, (Serializable )value); 219 } else { 220 throw new FrameworkException("Invalid target type '"+targetKey+ 221 "' used for assigning output from function '"+ 222 handler.getName()+"'.", getViewDescriptor(), getView()); 223 } 224 } 225 226 227 230 public Object getOutputValue(String name) { 231 HandlerDescriptor handler = getHandlerDescriptor(); 233 IODescriptor outDesc = handler.getOutputDescriptor(name); 234 if (outDesc == null) { 235 throw new FrameworkException("Attempted to get output value '"+name+ 236 "' from handler '"+handler.getName()+"', however, this is not "+ 237 "a declared output parameter! Check your handler and/or the "+ 238 "XML.", getViewDescriptor(), getView()); 239 } 240 241 String targetKey; 243 String targetType; 244 String outputParams[] = 245 getUseHandlerDescriptor().getOutputMapping(name); 246 if (outputParams == null) { 247 targetKey = handler.getName()+OUTPUT_VALUE_SEPARATOR+name; 248 targetType = ATTRIBUTE_TYPE; 249 } else { 250 targetKey = outputParams[0]; 251 if (targetKey == null) { 252 targetKey = handler.getName()+OUTPUT_VALUE_SEPARATOR+name; 253 } 254 targetType = outputParams[1]; 255 if (targetType == null) { 256 targetType = ATTRIBUTE_TYPE; 257 } 258 } 259 260 Object value; 262 if (targetType.equalsIgnoreCase(ATTRIBUTE_TYPE)) { 263 value = RequestManager.getRequestContext().getRequest(). 264 getAttribute(targetKey); 265 } else if (targetType.equalsIgnoreCase(SESSION_TYPE)) { 266 value = RequestManager.getRequestContext().getRequest(). 267 getSession().getAttribute(targetKey); 268 } else if (targetType.equalsIgnoreCase(PAGE_SESSION_TYPE)) { 269 ViewBean vb = Util.getParentViewBean(getView()); 270 value = vb.getPageSessionAttribute(targetKey); 271 } else { 272 throw new FrameworkException("Invalid target type '"+targetKey+ 273 "' used for assigning output from function '"+ 274 handler.getName()+"'.", getViewDescriptor(), getView()); 275 } 276 return value; 277 } 278 279 280 public static final String OUTPUT_VALUE_SEPARATOR = "."; 281 public static final String ATTRIBUTE_TYPE = "attribute"; 282 public static final String SESSION_TYPE = "session"; 283 public static final String PAGE_SESSION_TYPE = "pageSession"; 284 285 286 private EventObject _eventObject = null; 287 private HandlerDescriptor _handlerDesc = null; 288 private UseHandlerDescriptor _useHandlerDesc = null; 289 private View _view = null; 290 private ViewDescriptor _viewDesc = null; 291 } 292 | Popular Tags |