1 23 24 28 29 package com.sun.enterprise.tools.admingui.handlers; 30 31 import java.util.ArrayList ; 32 import java.util.EventObject ; 33 import java.util.StringTokenizer ; 34 import java.util.Properties ; 35 import java.util.Enumeration ; 36 37 import com.iplanet.jato.RequestContext; 38 import com.iplanet.jato.RequestContextImpl; 39 import com.iplanet.jato.RequestManager; 40 import com.iplanet.jato.model.DefaultModel; 41 import com.iplanet.jato.model.Model; 42 import com.iplanet.jato.util.RootCauseException; 43 import com.iplanet.jato.view.ContainerView; 44 import com.iplanet.jato.view.ContainerViewBase; 45 import com.iplanet.jato.view.View; 46 import com.iplanet.jato.view.DisplayFieldImpl; 47 import com.iplanet.jato.view.ViewBase; 48 import com.iplanet.jato.view.ViewBean; 49 import com.iplanet.jato.view.html.SelectableGroup; 50 import com.iplanet.jato.view.html.OptionList; 51 52 import javax.management.MBeanException ; 53 import javax.management.ObjectName ; 54 import javax.management.AttributeList ; 55 import javax.management.Attribute ; 56 import javax.servlet.ServletRequest ; 57 58 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 59 import com.sun.enterprise.tools.guiframework.model.ModelManager; 60 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 61 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 62 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 63 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 64 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 65 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 66 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent; 67 68 import com.sun.web.ui.model.CCActionTableModelInterface; 69 import com.sun.web.ui.model.CCPropertySheetModelInterface; 70 import com.sun.web.ui.model.CCActionTableModel; 71 72 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 73 import com.sun.enterprise.tools.admingui.util.Util; 74 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode; 75 import com.sun.enterprise.tools.admingui.tree.IndexTreeModelImpl; 76 import com.sun.enterprise.tools.admingui.tree.IndexTreeModel; 77 78 79 82 public class ConnectorHandlers { 83 84 public static final String PROP_MODEL = "property.model"; 85 public static final String PROP_CHILD = "property.child"; 86 public static final String PROPERTY_NAME = "propertyName"; 87 public static final String PROPERTY_VALUE = "propertyValue"; 88 89 90 93 public void populateDropdown(RequestContext ctx, HandlerContext handlerCtx) { 94 View view = handlerCtx.getView(); 95 SelectableGroup dropDownChild = (SelectableGroup) view; 97 DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent(); 99 100 ViewDescriptor vd = parent.getViewDescriptor(); 102 ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName()); 103 105 String methodName = (String )ctx.getRequest().getAttribute("dropDownMethodName"); 106 String objectName = (String )ctx.getRequest().getAttribute("dropDownObjectName"); 107 String attr = (String )ctx.getRequest().getAttribute("dropDownAttributeName"); 108 if (attr == null) { 109 throw new FrameworkException("attribute is null", cvd, view); 110 } 111 ctx.getRequest().setAttribute("rarName", attr); 112 Object [] params = new Object []{attr}; 113 114 if (objectName == null || methodName == null) { 115 throw new FrameworkException("objectName or methodName is null", 116 cvd, view); 117 } 118 119 dropDownChild.setLabelForNoneSelected(" "); 121 String [] type = new String []{"java.lang.String"}; 122 try { 123 Object keys = (Object ) MBeanUtil.invoke(objectName, methodName, params, type); 124 String [] choices = (String [])keys; 125 127 OptionList dropDownMenuOptions = new OptionList(choices,choices); dropDownChild.setOptions(dropDownMenuOptions); 129 } catch (Exception ex) { 130 throw new FrameworkException(ex, cvd, view); 131 } 132 } 133 134 135 138 public void populatePropsTableModel(RequestContext ctx, HandlerContext handlerCtx) { 139 View view = handlerCtx.getView(); 140 if (!(handlerCtx.getEvent() instanceof BeforeCreateEvent)) { 141 ViewDescriptor desc = (view instanceof DescriptorContainerView) ? 142 ((DescriptorContainerView)view).getViewDescriptor() : 143 (ViewDescriptor)null; 144 throw new FrameworkException("This handler is for 'beforeCreate'" + 145 " handlers only!", desc, view); 146 } 147 ViewDescriptor desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 148 try { 149 if (desc instanceof CCActionTableDescriptor) { 150 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 151 loadProperties(ccDesc.getModel(), ctx); 152 } 153 } catch (Exception ex) { 154 throw new FrameworkException(ex, desc, view); 155 } 156 } 157 158 161 public void populateAdminPropsTableModel(RequestContext ctx, HandlerContext handlerCtx) { 162 View view = handlerCtx.getView(); 163 if (!(handlerCtx.getEvent() instanceof BeforeCreateEvent)) { 164 ViewDescriptor desc = (view instanceof DescriptorContainerView) ? 165 ((DescriptorContainerView)view).getViewDescriptor() : 166 (ViewDescriptor)null; 167 throw new FrameworkException("This handler is for 'beforeCreate'" + 168 " handlers only!", desc, view); 169 } 170 ViewDescriptor desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 171 try { 172 if (desc instanceof CCActionTableDescriptor) { 173 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 174 adminLoadProperties(ccDesc.getModel(), ctx); 175 } 176 } catch (Exception ex) { 177 throw new FrameworkException(ex, desc, view); 178 } 179 } 180 181 182 183 private void loadProperties(CCActionTableModelInterface model, RequestContext ctx) { 184 ServletRequest req = ctx.getRequest(); 185 String methodName = (String )req.getAttribute("dropDownMethodName"); 186 String objectName = (String )req.getAttribute("dropDownObjectName"); 187 String attr = (String )req.getAttribute("rarName"); 188 String cd = (String )req.getAttribute("connectionDefinition"); 189 if (attr == null) { 192 throw new FrameworkException("attribute is null"); 193 } 194 if (cd == null) { 195 throw new FrameworkException("connection definition is null"); 196 } 197 198 AttributeList attrList = new AttributeList (); 199 attrList.add(new Attribute ("resource-adapter-name", attr)); 200 attrList.add(new Attribute ("connection-definition-name", cd)); 201 Object [] params = new Object []{attrList}; 202 203 if (objectName == null || methodName == null) { 204 throw new FrameworkException("objectName or methodName is null", null, null); 205 } 206 String [] type = new String []{"javax.management.AttributeList"}; 207 208 Object keys = (Object )MBeanUtil.invoke(objectName, methodName, params, type); 209 Properties props = (Properties )keys; 210 211 if (props == null) { 212 return; } 214 215 try { 216 Enumeration enums = props.propertyNames(); 217 while(enums.hasMoreElements()){ 218 model.appendRow(); 219 String name = (String )enums.nextElement(); 220 String value = props.getProperty(name); 221 model.setValue(PROPERTY_NAME, name); 222 model.setValue(PROPERTY_VALUE, value); 223 } 224 } catch (Exception ex) { 225 throw new FrameworkException(ex); 226 } 227 } 228 229 230 private void adminLoadProperties(CCActionTableModelInterface model, RequestContext ctx) { 231 ServletRequest req = ctx.getRequest(); 232 String methodName = (String )req.getAttribute("dropDownMethodName"); 233 String objectName = (String )req.getAttribute("dropDownObjectName"); 234 String attr = (String )req.getAttribute("JndiName"); 235 String ra = (String )req.getAttribute("connectorModule"); 236 if (attr == null) { 237 throw new FrameworkException("attribute is null"); 238 } 239 if (ra == null) { 240 throw new FrameworkException("connector Module is null"); 241 } 242 243 AttributeList attrList = new AttributeList (); 244 attrList.add(new Attribute ("resource-adapter-name", ra)); 245 attrList.add(new Attribute ("admin_object_interface", attr)); 246 Object [] params = new Object []{attrList}; 247 248 if (objectName == null || methodName == null) { 249 throw new FrameworkException("objectName or methodName is null", null, null); 250 } 251 String [] type = new String []{"javax.management.AttributeList"}; 252 253 Object keys = (Object ) MBeanUtil.invoke(objectName, methodName, params, type); 254 Properties props = (Properties )keys; 255 256 if (props == null) { 257 return; } 259 260 try { 261 Enumeration enums = props.propertyNames(); 262 while(enums.hasMoreElements()){ 263 model.appendRow(); 264 String name = (String )enums.nextElement(); 265 String value = props.getProperty(name); 266 model.setValue(PROPERTY_NAME, name); 267 model.setValue(PROPERTY_VALUE, value); 268 } 269 } catch (Exception ex) { 270 throw new FrameworkException(ex); 271 } 272 } 273 } 274 | Popular Tags |