1 23 24 package com.sun.enterprise.tools.guiframework.view; 25 26 import com.iplanet.jato.RequestCompletionListener; 27 import com.iplanet.jato.RequestContext; 28 import com.iplanet.jato.ViewBeanManager; 29 import com.iplanet.jato.view.ContainerView; 30 import com.iplanet.jato.view.View; 31 import com.iplanet.jato.view.ViewBean; 32 33 import java.util.HashMap ; 34 import java.util.Map ; 35 36 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 37 import com.sun.enterprise.tools.guiframework.util.LogUtil; 38 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 39 40 41 public class DescriptorViewManager extends ViewBeanManager { 42 43 53 public DescriptorViewManager(RequestContext context, String basePackage) { 54 super(context, basePackage); 55 _reqCtx = context; } 57 58 59 75 public ViewBean getViewBean(String name) throws ClassNotFoundException { 76 ViewBean vb = (ViewBean)getView(null, name); 78 79 if (vb == null) { 81 try { 83 _useClassName = true; 84 if(name != null && name.endsWith("ViewBean")) { 85 int beginIndex = name.lastIndexOf('.') + 1; 87 int endIndex = name.length() - VB_LEN; 88 name = name.substring(beginIndex, endIndex); 89 } 90 vb = super.getLocalViewBean(name); 91 } catch (ClassNotFoundException ex) { 92 throw new FrameworkException("Unable to locate ViewBean: "+name, ex); 93 } finally { 94 _useClassName = false; 95 } 96 97 registerInstance(vb); 99 } 100 101 return vb; 103 } 104 105 106 121 public ViewBean getViewBeanByClassName(String className) throws ClassNotFoundException { 122 if (_useClassName) { 123 return super.getViewBean(className); 127 } 128 129 return getViewBean(className); 131 } 132 133 134 148 public View getView(View parent, String name) { 149 if (name == null) { 150 throw new IllegalArgumentException ("Name cannot be null!"); 151 } 152 153 View view = (View)_instances.get(name); 155 if (view != null) { 156 return view; 157 } 158 159 ViewDescriptorManager mgr = ViewDescriptorManager.getInstance(); 161 162 165 ViewDescriptor desc = mgr.getViewDescriptor(name); 167 168 if (desc == null) { 170 if (LogUtil.isLoggable(LogUtil.FINE)) { 171 LogUtil.log(LogUtil.FINE, "framework.getViewDescriptor", name); 172 } 173 174 return null; 176 } 177 178 if (LogUtil.isLoggable(LogUtil.FINER)) { 180 LogUtil.log(LogUtil.FINER, "trace.gotViewDescriptor", name); 181 } 182 183 return getView(parent, name, desc); 184 } 185 186 187 201 public View getView(View parent, String name, ViewDescriptor desc) { 202 View view = (View)_instances.get(name); 204 if (view != null) { 205 return view; 206 } 207 208 if (desc == null) { 210 throw new IllegalArgumentException ("ViewDescriptor was null!!"); 211 } 212 213 DescriptorViewHelper.beforeCreate(_reqCtx, 219 ((parent instanceof DescriptorContainerView) ? 220 (DescriptorContainerView)parent : null), desc); 221 222 view = desc.getInstance(_reqCtx, (ContainerView)parent, name); 224 225 registerInstance(view); 227 228 if (LogUtil.isLoggable(LogUtil.FINER)) { 230 LogUtil.log(LogUtil.FINER, "trace.createdView", 231 new Object [] {name, view}); 232 } 233 234 DescriptorViewHelper.afterCreate(_reqCtx, view, desc); 239 240 return view; 242 } 243 244 245 255 public ViewBean getLocalViewBean(String name) throws ClassNotFoundException { 256 return getViewBean(name); 257 } 258 259 260 270 public ViewBean getViewBean(Class cls) { 271 if (_useClassName) { 272 _useClassName = false; 273 return super.getViewBean(cls); 274 } 275 throw new FrameworkException("This method is unsupported!"); 276 } 277 278 279 290 public void registerInstance(ViewBean bean) { 291 registerInstance((View)bean); 292 } 293 294 295 301 public void registerInstance(View view) { 302 if (!_instances.containsKey(view.getName())) { 303 _instances.put(view.getName(), view); 304 if (view instanceof RequestCompletionListener) { 305 _reqCtx.addRequestCompletionListener((RequestCompletionListener)view); 306 } 307 } 308 } 309 310 311 protected RequestContext _reqCtx; 312 protected boolean _useClassName = false; 313 314 public static final int VB_LEN = "ViewBean".length(); 315 private Map _instances = new HashMap (); 316 } 317 | Popular Tags |