1 23 24 29 30 package com.sun.enterprise.tools.admingui.handlers; 31 32 import com.iplanet.jato.ModelManager; 33 import com.iplanet.jato.RequestContext; 34 import com.iplanet.jato.RequestContextImpl; 35 import com.iplanet.jato.RequestManager; 36 import com.iplanet.jato.model.DefaultModel; 37 import com.iplanet.jato.model.Model; 38 import com.iplanet.jato.model.ModelControlException; 39 import com.iplanet.jato.view.View; 40 import com.iplanet.jato.view.ViewBean; 41 42 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 43 import com.sun.enterprise.tools.admingui.util.Util; 44 45 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 46 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 47 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 48 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 49 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager; 50 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 51 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 52 53 import com.sun.web.ui.model.CCActionTableModel; 54 import com.sun.web.ui.model.CCActionTableModelInterface; 55 import com.sun.web.ui.model.CCPropertySheetModelInterface; 56 57 import java.util.ArrayList ; 58 import java.util.EventObject ; 59 import java.util.List ; 60 61 import javax.management.MBeanException ; 62 import javax.management.ObjectName ; 63 import javax.management.AttributeList ; 64 import javax.management.Attribute ; 65 import javax.servlet.ServletRequest ; 66 import javax.servlet.http.HttpServletRequest ; 67 import javax.servlet.http.HttpSession ; 68 69 70 73 public class WizardHandlers { 74 75 78 public void create(RequestContext ctx, HandlerContext handlerCtx) { 79 DescriptorContainerView descView = (DescriptorContainerView)ctx.getRequest().getAttribute("wizardView"); 80 ArrayList displayNames = (ArrayList )ctx.getRequest().getAttribute("displayNames"); 81 ArrayList modelNames = (ArrayList )ctx.getRequest().getAttribute("modelNames"); 82 String objectName = (String )ctx.getRequest().getAttribute("objectName"); 83 String methodName = (String )ctx.getRequest().getAttribute("methodName"); 84 AttributeList attrList = new AttributeList (); 85 86 for (int i = 0; i < displayNames.size(); i++) { 87 Attribute attr = new Attribute ((String )modelNames.get(i), 88 (String )descView.getDisplayFieldValue(((String )(displayNames.get(i))))); 89 attrList.add(attr); 90 } 91 92 Object params[] = {attrList}; 93 String types[] = {"javax.management.AttributeList"}; 94 try { 95 Object obj = MBeanUtil.invoke(objectName, methodName, params, types); 96 ObjectName objName = (ObjectName )obj; 97 if (Util.isLoggableFINEST()) { 98 Util.logFINEST("In create object name is: "+objName.toString()); 99 } 100 ctx.getRequest().setAttribute(PROPS_OBJECT_NAME, objName.toString()); 101 } catch (Exception ex) { 102 throw new FrameworkException( 103 ex, descView.getViewDescriptor(), handlerCtx.getView()); 104 } 105 } 106 107 108 111 public void saveProperties(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException { 112 DescriptorContainerView descView = (DescriptorContainerView)ctx.getRequest().getAttribute("wizardView"); 113 114 CCActionTableModelInterface model = 115 (CCActionTableModelInterface)ctx.getRequest().getAttribute("wizardTableModel"); 116 String objectName = (String )ctx.getRequest().getAttribute(PROPS_OBJECT_NAME); 117 if (Util.isLoggableFINEST()) { 118 Util.logFINEST("In save object name is: "+objectName); 119 } 120 model.setRowSelectionType("multiple"); 121 model.beforeFirst(); 122 AttributeList attrs = new AttributeList (); 123 String [] type = new String []{"javax.management.Attribute"}; 124 try { 125 while(model.next()) { 126 String name = (String ) model.getValue(PROPERTY_NAME); 127 String value = (String ) model.getValue(PROPERTY_VALUE); 128 if (name != null && (!name.trim().equals(""))) { 129 Object params[] = {new Attribute (name, value)}; 130 MBeanUtil.invoke(objectName, "setProperty", params, type); 131 } 132 } 133 } catch (Exception ex) { 134 throw new FrameworkException( 135 ex, descView.getViewDescriptor(), handlerCtx.getView()); 136 } 137 } 138 139 140 143 public void isTableLoaded(RequestContext ctx, HandlerContext handlerCtx) { 144 boolean tL = false; 145 if (ctx.getRequest().getAttribute(TABLE_LOAD) != null){ 146 tL = new Boolean (""+ctx.getRequest().getAttribute(TABLE_LOAD)).booleanValue(); 147 } 148 149 if(tL) { 150 ctx.getRequest().setAttribute(TABLE_LOAD, "true"); 151 } else { 152 ctx.getRequest().setAttribute(TABLE_LOAD, "false"); 153 } 154 155 } 156 157 158 161 public void addProperty(RequestContext ctx, HandlerContext handlerCtx) { 162 ServletRequest req = ctx.getRequest(); 163 164 DescriptorContainerView descView = (DescriptorContainerView)req.getAttribute("property.child"); 165 166 if (descView == null) { 167 throw new FrameworkException( 168 "addPropertyTest: 'child' attributes were null!", null, handlerCtx.getView()); 169 } 170 171 CCActionTableModelInterface model = (CCActionTableModelInterface)req.getAttribute(PROP_MODEL); 172 if (Util.isLoggableFINEST()) { 173 Util.logFINEST("**MODEL IS: "+model); 174 } 175 176 try { 178 if ((model != null) && (model instanceof DefaultModel)) { 179 model.last(); 180 181 if (Util.isLoggableFINEST()) { 182 StringBuffer buf = new StringBuffer (); 184 buf.append("MODEL IS NOT NULL:\n"); 185 buf.append("**Number of rows: "+model.getNumRows()+"***"); 186 buf.append("**Last row index: "+((CCActionTableModel)model).getLastRowIndex()+"***"); 187 Util.logFINEST(buf.toString()); 188 } 189 190 model.appendRow(); 191 ((CCActionTableModel)model).sort(); 192 model.setValue(PROPERTY_NAME, ""); 193 model.setValue(PROPERTY_VALUE, ""); 194 if (Util.isLoggableFINEST()) { 195 Util.logFINEST("***Number of rows: "+model.getNumRows()+"***"); 196 } 197 model.beforeFirst(); 198 } else { 199 if (Util.isLoggableFINEST()) { 200 Util.logFINEST("MODEL IS NULL"); 201 } 202 } 203 } catch (Exception ex) { 204 throw new FrameworkException( 205 ex, descView.getViewDescriptor(), handlerCtx.getView()); 206 } 207 descView.forwardTo(ctx); 208 } 209 210 211 214 public void deleteProperties(RequestContext ctx, HandlerContext handlerCtx) { 215 ServletRequest req = ctx.getRequest(); 217 DescriptorContainerView descView = (DescriptorContainerView)req.getAttribute("property.child"); 218 219 CCActionTableModelInterface model = (CCActionTableModelInterface)req.getAttribute(PROP_MODEL); 220 if (Util.isLoggableFINEST()) { 221 Util.logFINEST("Model name is: "+model); 222 } 223 model.setRowSelectionType("multiple"); 224 225 try { 226 model.beforeFirst(); 227 AttributeList attrs = new AttributeList (); 228 229 while(model.next()) { 230 if (!model.isRowSelected()) { 231 String name = (String ) model.getValue(PROPERTY_NAME); 232 String value = (String )model.getValue(PROPERTY_VALUE); 233 if (Util.isLoggableFINEST()) { 234 Util.logFINEST("Property '"+name+"' with value '"+value+"' not selected."); 235 } 236 237 if (name != null && (! name.trim().equals(""))) { 238 attrs.add(new Attribute (name, value)); 239 } 240 } 241 } 242 ((DefaultModel)model).clear(); 243 if (attrs != null) { 244 for (int props=0; props<attrs.size(); props++) { 245 Attribute attr = (Attribute )attrs.get(props); 246 Object attrValue = attr.getValue(); 247 String attrName = attr.getName(); 248 model.appendRow(); 249 ((CCActionTableModel)model).sort(); 250 model.setValue(PROPERTY_NAME, attr.getName()); 251 model.setValue(PROPERTY_VALUE, attr.getValue()); 252 model.setRowSelected(false); 253 } 254 } 255 } catch (Exception ex) { 256 throw new FrameworkException( 257 ex, descView.getViewDescriptor(), handlerCtx.getView()); 258 } 259 } 260 261 262 270 public void clearModels(RequestContext ctx, HandlerContext handlerCtx) { 271 HttpServletRequest req = ctx.getRequest(); 273 Object obj = req.getAttribute(MODEL_NAMES); 274 if (obj == null) { 275 throw new FrameworkException( 276 "You must specifiy '"+MODEL_NAMES+"' to remove from Session."); 277 } 278 if (obj instanceof String ) { 279 ArrayList list = new ArrayList (); 280 list.add(obj); 281 obj = list; 282 } 283 if (!(obj instanceof List )) { 284 throw new FrameworkException( 285 "'"+MODEL_NAMES+"' must be a java.util.List!"); 286 } 287 String names[] = 288 (String [])((List )obj).toArray(new String [((List )obj).size()]); 289 290 HttpSession session = req.getSession(); 292 ModelManager modelMgr = ctx.getModelManager(); 293 Model model = null; 294 for (int count=0; count<names.length; count++) { 295 obj = session.getAttribute(names[count]); 296 if (obj != null) { 297 model = (Model)obj; 298 if (model instanceof DefaultModel) { 299 ((DefaultModel)model).clear(); 302 } 303 modelMgr.removeFromSession(model); 304 } 305 } 306 } 307 308 309 312 public static final String MODEL_NAMES = "clearModels.modelNames"; 313 public static final String PROPERTY_NAME = "propertyName"; 314 public static final String PROPERTY_VALUE = "propertyValue"; 315 public static final String PROPS_OBJECT_NAME = "resourceName"; 316 public static final String TABLE_LOAD = "wizard.loadTable"; 317 public static final String PROP_MODEL = "property.model"; 318 public static final String PROP_CHILD = "property.child"; 319 } 320 | Popular Tags |