1 23 package com.sun.enterprise.tools.jsfext.component; 24 25 import com.sun.enterprise.tools.jsfext.layout.LayoutDefinitionManager; 26 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutComponent; 27 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutDefinition; 28 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutElement; 29 30 import java.io.IOException ; 31 32 import javax.faces.component.UIComponent; 33 import javax.faces.component.UIComponentBase; 34 import javax.faces.context.FacesContext; 35 36 37 50 public abstract class TemplateComponentBase extends UIComponentBase implements TemplateComponent { 51 52 62 public UIComponent getChild(FacesContext context, String id) { 63 if ((id == null) || (id.trim().equals(""))) { 64 return null; 66 } 67 68 UIComponent childComponent = ComponentUtil.findChild(this, id, id); 72 if (childComponent != null) { 73 return childComponent; 74 } 75 76 LayoutDefinition ld = getLayoutDefinition(context); 79 if (ld == null) { 80 return null; 82 } 83 84 LayoutElement elt = 86 LayoutDefinition.getChildLayoutElementById(context, id, ld, this); 87 88 return getChild(context, (LayoutComponent) elt); 90 } 91 92 93 102 public UIComponent getChild(FacesContext context, LayoutComponent descriptor) { 103 UIComponent childComponent = null; 104 105 if (descriptor == null) { 107 throw new IllegalArgumentException ("The LayoutComponent is null!"); 108 } 109 110 String id = descriptor.getId(context, this); 112 if ((id != null) && !(id.trim().equals(""))) { 113 childComponent = ComponentUtil.findChild(this, id, id); 115 if (childComponent != null) { 116 return childComponent; 117 } 118 } 119 120 123 descriptor.beforeCreate(context, this); 125 126 childComponent = 128 ComponentUtil.createChildComponent(context, descriptor, this); 129 130 descriptor.afterCreate(context, childComponent); 132 133 return childComponent; 135 } 136 137 144 public LayoutDefinition getLayoutDefinition(FacesContext context) { 145 if (_layoutDefinition != null) { 147 return _layoutDefinition; 148 } 149 150 String key = getLayoutDefinitionKey(); 152 if (key == null) { 153 throw new NullPointerException ("LayoutDefinition key is null!"); 154 } 155 156 LayoutDefinitionManager ldm = 158 LayoutDefinitionManager.getManager(context); 159 160 try { 162 _layoutDefinition = ldm.getLayoutDefinition(key); 163 } catch (IOException ex) { 164 throw new IllegalArgumentException ( 165 "A LayoutDefinition was not provided for '" + key 166 + "'! This is required.", ex); 167 } 168 169 return _layoutDefinition; 171 } 172 173 182 public Object saveState(FacesContext context) { 183 Object [] values = new Object [2]; 184 values[0] = super.saveState(context); 185 values[1] = _ldmKey; 186 return values; 187 } 188 189 197 public void restoreState(FacesContext context, Object state) { 198 Object [] values = (Object []) state; 199 super.restoreState(context, values[0]); 200 _ldmKey = (java.lang.String ) values[1]; 201 } 202 203 208 public String getLayoutDefinitionKey() { 209 return _ldmKey; 210 } 211 212 213 218 public void setLayoutDefinitionKey(String key) { 219 _ldmKey = key; 220 } 221 222 227 private String _ldmKey = null; 228 229 230 234 private transient LayoutDefinition _layoutDefinition = null; 235 } 236 | Popular Tags |