1 23 24 package com.sun.enterprise.tools.guiframework.view.descriptors; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.RequestManager; 28 import com.iplanet.jato.RequestParticipant; 29 import com.iplanet.jato.view.ContainerView; 30 import com.iplanet.jato.view.ContainerViewBase; 31 import com.iplanet.jato.view.View; 32 import com.iplanet.jato.view.ViewBean; 33 import com.iplanet.jato.view.event.DisplayEvent; 34 35 import java.io.InputStream ; 36 import java.lang.reflect.Constructor ; 37 import java.lang.reflect.InvocationTargetException ; 38 import java.lang.reflect.Method ; 39 import java.util.*; 40 41 import com.sun.enterprise.tools.guiframework.FrameworkDescriptor; 42 import com.sun.enterprise.tools.guiframework.event.descriptors.EventDescriptor; 43 import com.sun.enterprise.tools.guiframework.exception.FrameworkError; 44 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 45 import com.sun.enterprise.tools.guiframework.util.LogUtil; 46 import com.sun.enterprise.tools.guiframework.util.Util; 47 import com.sun.enterprise.tools.guiframework.view.ChildNullException; 48 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 49 import com.sun.enterprise.tools.guiframework.view.DescriptorViewManager; 50 51 52 55 public class ViewDescriptor implements FrameworkDescriptor { 56 57 62 public ViewDescriptor(String name) { 63 setName(name); 64 addChildDescriptors(); 65 } 66 67 68 73 public String getName() { 74 return _name; 75 } 76 77 78 83 public void setName(String name) { 84 if (name == null) { 85 throw new IllegalArgumentException ("'name' cannot be null!"); 86 } 87 _name = name; 88 } 89 90 91 94 public String getDescription() { 95 return _description; 96 } 97 98 99 102 public void setDescription(String desc) { 103 _description = desc; 104 } 105 106 107 124 public View getInstance(RequestContext ctx, ContainerView container, String name) { 125 throw new FrameworkException("Descriptor type for '"+name+ 126 "' is ViewDescriptor, this is not valid.", this, container); 127 } 128 129 130 155 public View getView(RequestContext ctx) { 156 Stack descStack = new Stack(); 157 158 ViewDescriptor topDesc = this; 160 while (topDesc.getParent() != null) { 161 descStack.push(topDesc.getName()); 162 topDesc = topDesc.getParent(); 163 } 164 165 View view = ((DescriptorViewManager)ctx.getViewBeanManager()). 171 getView(null, topDesc.getName(), topDesc); 172 173 while (!descStack.empty()) { 175 view = ((ContainerView)view).getChild((String )descStack.pop()); 176 } 177 178 return view; 180 } 181 182 183 186 public void registerChildren(ContainerViewBase instance) { 187 Iterator it = getChildDescriptors().iterator(); 189 ViewDescriptor desc = null; 190 View child = null; 191 192 if (LogUtil.isLoggable(LogUtil.FINER) && it.hasNext()) { 194 LogUtil.log(LogUtil.FINER, "trace.registerChildren", getName()); 195 } 196 197 while (it.hasNext()) { 198 desc = (ViewDescriptor)it.next(); 199 try { 204 if (LogUtil.isLoggable(LogUtil.FINEST) && it.hasNext()) { 206 LogUtil.log(LogUtil.FINEST, "trace.registerChild", 207 instance.getName()+"."+desc.getName()); 208 } 209 210 child = instance.getChild(desc.getName()); 211 instance.registerChild(desc.getName(), child.getClass()); 212 if (child instanceof DescriptorContainerView) { 213 continue; 217 } else if (child instanceof ContainerViewBase) { 218 desc.registerChildren((ContainerViewBase)child); 219 } else if (desc instanceof FakeContainerDescriptor) { 220 desc.registerChildren(instance); 224 } 225 } catch (ChildNullException ex) { 226 } catch (Exception ex) { 229 throw new FrameworkError( 230 ex, desc, (child == null) ? instance : child); 231 } 232 } 233 } 234 235 236 241 public String getDisplayURL() { 242 return _displayURL; 243 } 244 245 246 251 public void setDisplayURL(String url) { 252 _displayURL = url; 253 } 254 255 256 265 public EventDescriptor getEventDescriptor(String type) { 266 return (EventDescriptor)_eventDescriptors.get(type); 267 } 268 269 270 277 public void setEventDescriptor(EventDescriptor desc) { 278 _eventDescriptors.put(desc.getType(), desc); 279 } 280 281 282 287 public void addChildDescriptor(ViewDescriptor fieldDesc) { 288 fieldDesc.setParent(this); 289 _childDescriptors.add(fieldDesc); 290 _childDescriptorMap = null; 291 } 292 293 294 300 public List getChildDescriptors() { 301 return _childDescriptors; 302 } 303 304 305 311 public void setChildDescriptors(List fields) { 312 _childDescriptors = fields; 313 _childDescriptorMap = null; 314 } 315 316 317 327 public ViewDescriptor getChildDescriptor(String name) { 328 if (_childDescriptorMap == null) { 329 Iterator it = getChildDescriptors().iterator(); 331 ViewDescriptor desc = null; 332 Map newMap = new HashMap(); 333 while (it.hasNext()) { 334 desc = (ViewDescriptor)it.next(); 335 newMap.put(desc.getName(), desc); 336 } 337 if (_childDescriptorMap == null) { 338 _childDescriptorMap = newMap; 339 } 340 } 341 ViewDescriptor child = (ViewDescriptor )_childDescriptorMap.get(name); 342 if (child == null) { 343 int pos = name.indexOf('.'); 345 if (pos != -1) { 346 child = getChildDescriptor(name.substring(0, pos)); 348 if (child != null) { 349 return child.getChildDescriptor(name.substring(pos+1)); 351 } 352 } 353 } 354 return child; 355 } 356 357 358 363 public ViewDescriptor getParent() { 364 return _parent; 365 } 366 367 368 373 public void setParent(ViewDescriptor viewDesc) { 374 _parent = viewDesc; 375 } 376 377 378 386 public void setParameters(Map parameters) { 387 if (parameters == null) { 388 throw new IllegalArgumentException ( 389 "The parameter map cannot be null!"); 390 } 391 _parameters = parameters; 392 } 393 394 public Set getParameterKeys() { 395 return _parameters.keySet(); 396 } 397 398 403 public Map getParameters() { 404 Map newMap = new HashMap(_parameters.size()); 405 Iterator it = _parameters.keySet().iterator(); 406 Object key; 407 Object value; 408 while (it.hasNext()) { 410 key = it.next(); 411 value = Util.replaceVariablesWithAttributes( 412 _parameters.get(key), this); 413 newMap.put(key, value); 414 } 415 return newMap; 416 } 417 418 419 425 public void addParameter(String name, Object value) { 426 if (name == null) { 427 throw new IllegalArgumentException ("'name' cannot be null!"); 428 } 429 _parameters.put(name, value); 430 } 431 432 433 441 public Object getParameter(String name) { 442 return Util.replaceVariablesWithAttributes(_parameters.get(name), this); 443 } 444 445 446 452 public String getModelClassName() { 453 String clsName = (String )getParameter(MODEL_CLASS_NAME); 454 if (clsName == null) { 455 clsName = DEFAULT_MODEL; 456 } 457 return clsName; 458 } 459 460 461 469 public String getDefaultModelInstanceName() { 470 return getName(); 471 } 472 473 474 485 public String getModelInstanceName() { 486 String instName = (String )getParameter(MODEL_INSTANCE_NAME); 487 if (instName == null) { 488 instName = getDefaultModelInstanceName(); 489 } 490 return instName; 491 } 492 493 494 502 public boolean shouldGetModelFromSession() { 503 return new Boolean (""+getParameter(GET_MODEL_FROM_SESSION)).booleanValue(); 504 } 505 506 507 515 public boolean shouldPutModelToSession() { 516 return new Boolean (""+getParameter(PUT_MODEL_TO_SESSION)).booleanValue(); 517 } 518 519 520 527 public String getResourceBundle() { 528 String bundle = (String )getParameter(RESOURCE_BUNDLE); 529 530 for (ViewDescriptor vd = getParent(); 532 ((bundle == null) && (vd != null)); vd = vd.getParent()) { 533 bundle = (String )vd.getParameter(RESOURCE_BUNDLE); 534 } 535 536 return bundle; 538 } 539 540 541 547 public String getXMLFileName() { 548 return (String )getParameter(XML_FILE); 549 } 550 551 552 557 public InputStream getXMLFileAsStream() { 558 String fileName = getXMLFileName(); 559 if ((fileName == null) || (fileName.equals(""))) { 560 throw new FrameworkException( 561 "Parameter '"+XML_FILE+"' is missing for '"+ 562 this.getClass().getName()+":"+getName()+"'."); 563 } 564 try { 565 InputStream inStream = getClass().getClassLoader().getResourceAsStream(fileName); 567 if (inStream == null) { 568 inStream = RequestManager.getRequestContext().getServletContext(). 570 getResourceAsStream(fileName); 571 if (inStream == null) { 572 throw new FrameworkException("InputStream (null) for '"+fileName+"'."); 573 } 574 } 575 return inStream; 576 } catch (Exception ex) { 577 throw new FrameworkException("Unable to open '"+fileName+"' for '"+ 578 this.getClass().getName()+":"+getName()+"'.", ex); 579 } 580 } 581 582 583 586 public String toString() { 587 return getName(); 588 } 589 590 591 603 protected void addChildDescriptors() { 604 } 605 606 607 612 public static final String MODEL_CLASS_NAME = "modelClassName"; 613 614 617 public static final String DEFAULT_MODEL = 618 "com.iplanet.jato.model.DefaultModel"; 619 620 625 public static final String MODEL_INSTANCE_NAME = "modelInstanceName"; 626 627 632 public static final String GET_MODEL_FROM_SESSION = "modelFromSession"; 633 634 639 public static final String PUT_MODEL_TO_SESSION = "modelToSession"; 640 641 642 645 public static final String XML_FILE = "xmlFile"; 646 647 651 public static final String RESOURCE_BUNDLE = "resourceBundle"; 652 653 654 private Map _eventDescriptors = new HashMap(); 655 private List _childDescriptors = new ArrayList(); 656 private Map _childDescriptorMap = null; 657 private Map _parameters = new HashMap(); 658 private String _name = ""; 659 private String _description = ""; 660 private String _displayURL = null; 661 private ViewDescriptor _parent = null; 662 } 663 | Popular Tags |