1 23 24 package com.sun.enterprise.tools.guiframework.event.handlers; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.model.Model; 28 import com.iplanet.jato.model.DefaultModel; 29 30 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 31 import com.sun.enterprise.tools.guiframework.model.ModelManager; 32 33 import java.util.Map ; 34 35 36 39 public class ModelHandlers { 40 41 47 public void getModel(RequestContext reqCtx, HandlerContext handlerCtx) { 48 Object classname = handlerCtx.getInputValue(MODEL_CLASS); 50 if (classname == null) { 51 throw new IllegalArgumentException ( 52 "The parameter map did not contain a parameter named '"+ 53 MODEL_CLASS+"'!"); 54 } 55 Object instanceName = handlerCtx.getInputValue(INSTANCE_NAME); 56 if (instanceName == null) { 57 throw new IllegalArgumentException ( 58 "The parameter map did not contain a parameter named '"+ 59 INSTANCE_NAME+"'!"); 60 } 61 62 boolean fromSession = false; 64 boolean toSession = false; 65 Boolean boolValue = (Boolean )handlerCtx.getInputValue(FROM_SESSION); 66 if (boolValue != null) { 67 fromSession = boolValue.booleanValue(); 68 } 69 boolValue = (Boolean )handlerCtx.getInputValue(TO_SESSION); 70 if (boolValue != null) { 71 toSession = boolValue.booleanValue(); 72 } 73 74 if (!(classname instanceof Class )) { 76 try { 77 classname = Class.forName(classname.toString()); 78 } catch (ClassNotFoundException ex) { 79 throw new RuntimeException (ex); 80 } 81 } 82 83 handlerCtx.setOutputValue(VALUE, 85 reqCtx.getModelManager().getModel( 86 (Class )classname, 87 instanceName.toString(), 88 fromSession, toSession)); 89 } 90 91 92 98 public void registerModel(RequestContext reqCtx, HandlerContext handlerCtx) { 99 Object instanceName = handlerCtx.getInputValue(INSTANCE_NAME); 101 if (instanceName == null) { 102 throw new IllegalArgumentException ( 103 "The parameter map did not contain a parameter named '"+ 104 INSTANCE_NAME+"'!"); 105 } 106 107 Model model = (Model)handlerCtx.getInputValue(MODEL); 109 ModelManager modelManager = (ModelManager)reqCtx.getModelManager(); 110 modelManager.registerModel(instanceName.toString(), model); 111 } 112 113 114 120 public void getModelValue(RequestContext reqCtx, HandlerContext handlerCtx) { 121 Object key = handlerCtx.getInputValue(MODEL_KEY); 123 if (key == null) { 124 throw new IllegalArgumentException ( 125 "The parameter map did not contain a parameter named '"+ 126 MODEL_KEY+"'!"); 127 } 128 129 Model model = (Model)handlerCtx.getInputValue(MODEL); 131 if (model == null) { 132 getModel(reqCtx, handlerCtx); 134 model = (Model)handlerCtx.getOutputValue(VALUE); 135 } 136 137 handlerCtx.setOutputValue(VALUE, model.getValue(key.toString())); 139 } 140 141 public void dumpModelValues(RequestContext reqCtx, HandlerContext handlerCtx) { 142 Model model = (Model)handlerCtx.getInputValue(MODEL); 143 if (model == null) { 144 getModel(reqCtx, handlerCtx); 145 model = (Model)handlerCtx.getOutputValue(VALUE); 146 } 147 if (model != null) 148 ((DefaultModel)model).dumpValues(System.out); 149 } 150 151 157 public void setModelValue(RequestContext reqCtx, HandlerContext handlerCtx) { 158 Object key = handlerCtx.getInputValue(MODEL_KEY); 160 if (key == null) { 161 throw new IllegalArgumentException ( 162 "The parameter map did not contain a parameter named '"+ 163 MODEL_KEY+"'!"); 164 } 165 166 Object value = handlerCtx.getInputValue(VALUE); 168 Model model = (Model)handlerCtx.getInputValue(MODEL); 169 if (model != null) { 170 model.setValue(key.toString(), value); 172 return; 173 } 174 175 getModel(reqCtx, handlerCtx); 177 model = (Model)handlerCtx.getOutputValue(VALUE); 178 model.setValue(key.toString(), value); 179 } 180 181 182 185 public static final String VALUE = "value"; 186 187 190 public static final String FROM_SESSION = "modelFromSession"; 191 192 195 public static final String TO_SESSION = "modelToSession"; 196 197 200 public static final String MODEL_CLASS = "modelClass"; 201 202 205 public static final String INSTANCE_NAME = "instanceName"; 206 207 210 public static final String MODEL_KEY = "key"; 211 212 215 public static final String MODEL = "model"; 216 } 217 | Popular Tags |