1 23 24 29 30 package com.sun.enterprise.tools.admingui.handlers; 31 32 import java.util.ArrayList ; 33 import java.util.Properties ; 34 import java.util.Enumeration ; 35 36 import com.iplanet.jato.RequestContext; 37 import com.iplanet.jato.RequestContextImpl; 38 import com.iplanet.jato.RequestManager; 39 import com.iplanet.jato.ViewBeanManager; 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.ViewBase; 47 import com.iplanet.jato.view.ViewBean; 48 import com.iplanet.jato.view.DisplayField; 49 import com.iplanet.jato.model.ModelControlException; 50 import com.iplanet.jato.view.event.ChildContentDisplayEvent; 51 import com.iplanet.jato.util.NonSyncStringBuffer; 52 53 import javax.management.MBeanException ; 54 import javax.management.ObjectName ; 55 import javax.management.AttributeList ; 56 import javax.management.Attribute ; 57 58 import javax.servlet.ServletRequest ; 59 60 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 61 import com.sun.enterprise.tools.guiframework.model.ModelManager; 62 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 63 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 64 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager; 65 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 66 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 67 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 68 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent; 69 70 import com.sun.web.ui.model.CCActionTableModelInterface; 71 import com.sun.web.ui.view.html.CCButton; 72 import com.sun.web.ui.taglib.pagetitle.CCPageTitleTag; 73 import com.sun.web.ui.taglib.html.CCTextFieldTag; 74 75 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 76 import com.sun.enterprise.tools.admingui.util.Util; 77 78 import com.sun.enterprise.tools.admingui.ConfigProperties; 79 80 81 public class SystemPropsHandlers { 82 83 static public String extractToken(String token) { 84 if (token == null) 85 return null; 86 int j = token.indexOf("${"); 87 if (j >= 0) { 88 int i = token.indexOf('}'); 89 if (i < 0) i = token.length(); 90 return token.substring(j+2,i); 91 } 92 return token; 93 } 94 95 static public String resolveToken(String token) { 96 String [] tokenTypes = new String []{"java.lang.String", "java.lang.String"}; 97 Object [] tokensParams = new Object []{"${"+token+"}", "server"}; 98 String value = (String ) MBeanUtil.invoke( 99 "com.sun.appserv:type=domain,category=config", "resolveTokens", 100 tokensParams, tokenTypes); 101 return value; 102 } 103 104 static public String resolveAndReplaceToken(String tokenString) { 105 String token = null; 106 if (tokenString != null && tokenString.indexOf("${") >= 0) 107 token = extractToken(tokenString); 108 if (token == null) 109 return tokenString; 110 return tokenString.replaceAll("\\$\\{"+token+"\\}", resolveToken(token)); 111 } 112 113 public void isConfigProperty(RequestContext ctx, HandlerContext handlerCtx) { 114 String property = (String )handlerCtx.getInputValue("property"); 115 boolean result = false; 116 if (property != null) 119 result = property.indexOf("com.sun.aas") >= 0; 120 handlerCtx.setOutputValue("result", (result)?("true"):("false")); 121 } 122 123 public void loadConfigPropertyHelp(RequestContext ctx, HandlerContext handlerCtx) { 124 CCActionTableModelInterface model = (CCActionTableModelInterface) 125 handlerCtx.getInputValue(MODEL); 126 ((DefaultModel)model).clear(); 127 String paramName = (String )handlerCtx.getInputValue("paramName"); 128 129 if (paramName == null) { 130 return; 131 } 132 String baseName = "com.sun.enterprise.tools.admingui.resources.AsEnv"; 133 String description = Util.getMessage(baseName, paramName, null); 134 model.appendRow(); 135 model.setValue("propertyName", paramName); 136 model.setValue("description", description); 137 } 138 139 public void loadTokenEditTable(RequestContext ctx, HandlerContext handlerCtx) { 140 CCActionTableModelInterface model = (CCActionTableModelInterface) 141 handlerCtx.getInputValue(MODEL); 142 ((DefaultModel)model).clear(); 143 144 String configObjectName = (String )handlerCtx.getInputValue("configName"); 145 String paramName = (String )handlerCtx.getInputValue("paramName"); 146 if (paramName == null) 147 return; 148 paramName = extractToken(paramName); 150 151 ObjectName [] refs = null; 152 try { 153 refs = (ObjectName [])MBeanUtil.invoke(configObjectName, 154 "listReferencees", null, null); 155 } catch (Exception ex) { 156 model.appendRow(); 159 model.setValue("clusterName", ""); 160 model.setValue("instanceName", ""); 161 model.setValue("value", resolveToken(paramName)); 162 return; 164 } 165 loadSystemProperties(model, refs, paramName, ""); 166 } 167 168 private void loadSystemProperties(CCActionTableModelInterface model, 169 ObjectName [] refs, String paramName, String clusterName) { 170 171 if (refs == null) 172 return; 173 Object [] params = new Object []{new Boolean (true)}; 174 String [] types = new String []{"boolean"}; 175 String [] tokenTypes = new String []{"java.lang.String", "java.lang.String"}; 176 177 for (int i=0; i<refs.length; i++) { 178 ObjectName reference = refs[i]; 179 if (reference.getKeyProperty("type").equals("cluster")) { 182 ObjectName [] instances = (ObjectName []) MBeanUtil.invoke(reference, 183 "listServerInstances", null, null); 184 clusterName = reference.getKeyProperty("name"); 185 loadSystemProperties(model, instances, paramName, clusterName); 186 continue; 187 } 188 Properties props = (Properties )MBeanUtil.invoke(reference, 189 "listSystemProperties", params, types); 190 if (props == null) { 192 continue; 193 } 194 String instanceName = reference.getKeyProperty("name"); 195 String value = props.getProperty(paramName, null); 196 if (value == null) { 197 Object [] tokensParams = new Object []{"${"+paramName+"}", instanceName}; 200 value = (String ) MBeanUtil.invoke( 201 "com.sun.appserv:type=domain,category=config", "resolveTokens", 202 tokensParams, tokenTypes); 203 } 204 if (value == null) value = ""; 205 model.appendRow(); 207 model.setValue("clusterName", clusterName); 208 model.setValue("instanceName", instanceName); 209 model.setValue("value", value); 210 model.setValue("objectName", reference.toString()); } 212 } 213 214 public void saveTokenEditTable(RequestContext ctx, HandlerContext handlerCtx) 215 throws ModelControlException { 216 View view = handlerCtx.getView(); 217 DescriptorContainerView descView = (DescriptorContainerView) 218 (((ViewBase)view).getParentViewBean()); 219 ViewDescriptor vd = descView.getViewDescriptor(); 220 221 String [] deleteTypes = new String []{"java.lang.String"}; 222 String [] createTypes = new String []{"java.util.Properties"}; 223 Object [] params = null; 224 225 String tokenValue = (String ) handlerCtx.getInputValue("tokenValue"); 226 tokenValue = extractToken(tokenValue); 227 if (tokenValue == null) 228 return; 229 CCActionTableModelInterface model = 230 (CCActionTableModelInterface)handlerCtx.getInputValue(MODEL); 231 model.beforeFirst(); 232 233 while(model.next()) { 234 String objectName = (String ) model.getValue("objectName"); 235 String value = (String ) model.getValue("value"); 236 239 try { 240 params = new Object []{tokenValue}; 241 MBeanUtil.invoke(objectName, "deleteSystemProperty", params, deleteTypes); 242 } catch (Exception ex) { 243 } 245 if (value != null && value.length() > 0) { 246 Properties newProp = new Properties (); 247 newProp.setProperty(tokenValue, value); 248 params = new Object []{newProp}; 249 MBeanUtil.invoke(objectName, "createSystemProperties", params, createTypes); 250 } 251 } 252 } 253 254 public void beginTokensPageTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) { 255 CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource(); 256 String titleKey = (String ) handlerCtx.getInputValue("titleKey"); 257 String params = (String ) handlerCtx.getInputValue("params"); 258 259 if(titleKey == null || titleKey.length() == 0) { 260 titleKey = "tokens.ConfigPageTitle"; 261 } 262 263 String msg = Util.getMessage(titleKey, new Object []{params}); 264 tag.setPageTitleText(msg); 265 } 266 267 public void removeDollarSign(RequestContext ctx, HandlerContext handlerCtx) { 268 String in = (String ) handlerCtx.getInputValue("systemProp"); 269 handlerCtx.setOutputValue("result", extractToken(in)); 270 } 271 272 public void loadConfigSystemProperties(RequestContext ctx, HandlerContext handlerCtx) { 273 CCActionTableModelInterface model = (CCActionTableModelInterface) 274 handlerCtx.getInputValue(MODEL); 275 ((DefaultModel)model).clear(); 276 Properties props = (Properties ) handlerCtx.getInputValue("properties"); 277 String linkText = Util.getMessage("props.instanceValues"); 278 try { 279 Enumeration ee = props.propertyNames(); 280 while (ee.hasMoreElements()) { 281 String name = (String )ee.nextElement(); 282 model.appendRow(); 283 model.setValue(PROPERTY_NAME, name); 284 model.setValue(PROPERTY_VALUE, props.getProperty(name)); 285 model.setValue("instanceValuesHref", name); 286 model.setValue("instanceValues", linkText); 287 model.setRowSelected(false); 288 } 289 } catch (Exception ex) { 290 throw new FrameworkException("loadConfigSystemProperties: Loading error. ", ex); 291 } 292 } 293 294 public String endExtendedTextDisplay(RequestContext ctx, HandlerContext handlerCtx) { 295 ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent(); 296 String html = ev.getContent(); 297 298 if ((ev.getSource() instanceof CCTextFieldTag) == false) 299 return html; 301 if (html == null || html.length() == 0) 302 return html; 303 304 String value = Util.extractHtmlProp(html, "value"); 305 if (value == null || value.length() == 0) 306 return html; 307 value = value.trim(); 308 309 String sizeStr = Util.extractHtmlProp(html, "size"); 311 if (sizeStr != null && sizeStr.length() > 0) { 312 int currentSize = 0; 313 try { 314 currentSize = Integer.parseInt(sizeStr); 315 int size = ((value.length() + 4) / 8) * 10 ; 316 if (size > 100) size = 100; 317 if (currentSize < size) { 318 html = Util.removeHtmlProp(html, "size"); 319 html = Util.addHtmlProp(html, ("size="+size)); 320 } 322 } catch (Exception ex) { 323 } 325 } 326 327 int j = value.indexOf("${"); 328 if (j >= 0) { 329 int i = value.indexOf('}'); 330 if (i<0) i = value.length(); 331 value = value.substring(j+2,i); 332 } else { 333 return html; 334 } 335 String name = Util.extractHtmlProp(html, "name"); 336 int i = name.indexOf('.'); 337 String listPage = name; 338 if (i>0) 339 listPage = name.substring(0,i); 340 NonSyncStringBuffer href = new NonSyncStringBuffer(); 341 String editKeyValue = (String ) ctx.getRequest().getAttribute("editKeyValue"); 342 href.append("\n<a HREF=\"../admingui/tokensEdit?attrValue=") 343 .append(Util.URLencode(ctx, value)) 344 .append("&listPage=").append(listPage); 345 if (editKeyValue != null && editKeyValue.length() > 0) 346 href.append("&editKeyValue=").append(Util.URLencode(ctx, editKeyValue)); 347 if(value.startsWith("com.sun.aas")) { 348 href.append("\"> ") 350 .append(Util.getMessage("common.Description")) 351 .append("</a>"); 352 353 } 354 else { 355 href.append("\"> ") 357 .append(Util.getMessage("props.actualValues")) 358 .append("</a>"); 359 } 360 361 return html + href; 362 } 363 364 372 public static final String MODEL = "model"; 373 public static final String PROPERTY_NAME = "propertyName"; 374 public static final String PROPERTY_VALUE = "propertyValue"; 375 } 376 | Popular Tags |