1 23 24 package com.sun.enterprise.tools.guiframework.event.handlers; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.ViewBeanManager; 28 import com.iplanet.jato.view.DisplayField; 29 import com.iplanet.jato.view.ContainerView; 30 import com.iplanet.jato.view.View; 31 import com.iplanet.jato.view.ViewBean; 32 import com.iplanet.jato.view.ViewBeanBase; 33 34 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 35 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 36 import com.sun.enterprise.tools.guiframework.view.DescriptorViewManager; 37 38 import java.util.Iterator ; 39 import java.util.List ; 40 import java.util.Map ; 41 42 43 47 public class SessionHandlers { 48 49 59 public void getPageSessionValue(RequestContext reqCtx, HandlerContext handlerCtx) { 60 String name = (String )handlerCtx.getInputValue(NAME); 61 if (name == null) { 62 throw new FrameworkException("'"+NAME+ 63 "' specifying the PageSession name must be provided!"); 64 } 65 66 ViewBean vb = (ViewBean)handlerCtx.getInputValue(VIEW_BEAN); 67 if (vb == null) { 68 vb = getViewBean(reqCtx, handlerCtx); 69 } 70 71 handlerCtx.setOutputValue(VALUE, vb.getPageSessionAttribute(name)); 73 } 74 75 76 79 private ViewBean getViewBean(RequestContext reqCtx, HandlerContext handlerCtx) { 80 Object viewID = handlerCtx.getInputValue(VIEW_ID); 82 if (viewID == null) { 83 throw new IllegalArgumentException ( 84 "The parameter map did not contain "+VIEW_ID+"!"); 85 } 86 87 ViewBeanManager vm = reqCtx.getViewBeanManager(); 89 ViewBean vb = null; 90 String topName = (viewID instanceof List ) ? 91 ((List )viewID).get(0).toString() : viewID.toString(); 92 try { 93 vb = vm.getViewBean(topName); 94 } catch (ClassCastException ex) { 95 vb = (ViewBean)((DescriptorViewManager)vm).getView(null, topName); 96 } catch (ClassNotFoundException ex) { 97 throw new RuntimeException (ex); 98 } 99 if (vb == null) { 100 throw new RuntimeException ( 101 "Unable to obtain the view for mapping!"); 102 } 103 104 return vb; 106 } 107 108 109 123 public void setPageSessionValue(RequestContext reqCtx, HandlerContext handlerCtx) { 124 String name = (String )handlerCtx.getInputValue(NAME); 125 if (name == null) { 126 throw new FrameworkException("'"+NAME+ 127 "' specifying the PageSession name must be provided!"); 128 } 129 130 ViewBean vb = (ViewBean)handlerCtx.getInputValue(VIEW_BEAN); 131 if (vb == null) { 132 vb = getViewBean(reqCtx, handlerCtx); 133 } 134 135 Object value = handlerCtx.getInputValue(VALUE); 136 vb.setPageSessionAttribute(name, (java.io.Serializable )value); 137 } 138 139 140 149 public void getSessionValue(RequestContext reqCtx, HandlerContext handlerCtx) { 150 Object key = handlerCtx.getInputValue(KEY); 151 if (key == null) { 152 throw new IllegalArgumentException ( 153 "The parameter map did not contain a key!"); 154 } 155 156 handlerCtx.setOutputValue(VALUE, 158 reqCtx.getRequest().getSession().getAttribute(key.toString())); 159 } 160 161 162 169 public void setSessionValue(RequestContext reqCtx, HandlerContext handlerCtx) { 170 Object value = handlerCtx.getInputValue(VALUE); 171 Object key = handlerCtx.getInputValue(KEY); 172 if (key == null) { 173 throw new IllegalArgumentException ( 174 "The parameter map did not contain a key!"); 175 } 176 reqCtx.getRequest().getSession().setAttribute(key.toString(), value); 177 } 178 179 180 183 public static final String VIEW_BEAN = "viewBean"; 184 185 188 public static final String NAME = "name"; 189 190 193 public static final String VIEW_ID = "viewID"; 194 195 198 public static final String KEY = "key"; 199 200 203 public static final String VALUE = "value"; 204 } 205 | Popular Tags |