1 23 package com.sun.enterprise.tools.jsfext.layout.descriptor; 24 25 import com.sun.enterprise.tools.jsfext.component.TemplateComponent; 26 import com.sun.enterprise.tools.jsfext.event.DecodeEvent; 27 28 import java.util.ArrayList ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Map ; 33 34 import javax.faces.context.FacesContext; 35 import javax.faces.component.UIComponent; 36 37 38 51 public class LayoutDefinition extends LayoutElementBase { 52 53 56 public LayoutDefinition(String id) { 57 super(null, id); 59 60 addComponentType(new ComponentType( 62 STATIC_TEXT_TYPE, STATIC_TEXT_FACTORY_CLASS_NAME)); 63 } 64 65 66 73 public ComponentType getComponentType(String typeID) { 74 return (ComponentType) _types.get(typeID); 75 } 76 77 78 88 public void addComponentType(ComponentType type) { 89 _types.put(type.getId(), type); 90 } 91 92 100 public void addResource(Resource res) { 101 _resources.add(res); 102 } 103 104 109 public List getResources() { 110 return _resources; 111 } 112 113 124 public static LayoutElement getChildLayoutElementById(FacesContext context, String id, LayoutElement parent, UIComponent parentComponent) { 125 128 if (parent.getId(context, parentComponent).equals(id)) { 130 return parent; 131 } 132 133 Iterator it = parent.getChildLayoutElements().iterator(); 135 LayoutElement elt = null; 136 while (it.hasNext()) { 137 elt = getChildLayoutElementById( 138 context, id, (LayoutElement) it.next(), parentComponent); 139 if (elt != null) { 140 return elt; 142 } 143 } 144 145 return null; 147 } 148 149 150 157 public Object getAttribute(String key) { 158 return _attributes.get(key); 159 } 160 161 162 171 public void setAttribute(String key, Object value) { 172 _attributes.put(key, value); 173 } 174 175 176 185 protected boolean encodeThis(FacesContext context, UIComponent component) { 186 return true; 187 } 188 189 199 public List getHandlers(String type, UIComponent comp) { 200 List handlers = null; 202 203 if ((comp != null) 208 && (!(comp.getParent() instanceof TemplateComponent))) { 209 List instHandlers = (List ) comp.getAttributes().get(type); 210 if ((instHandlers != null) && (instHandlers.size() > 0)) { 211 handlers = new ArrayList (instHandlers); 214 215 List defHandlers = getHandlers(type); 216 if (defHandlers != null) { 217 handlers.addAll(getHandlers(type)); 219 } 220 } 221 } 222 if (handlers == null) { 223 handlers = getHandlers(type); 224 } 225 226 return handlers; 227 } 228 229 236 public void decode(FacesContext context, UIComponent component) { 237 dispatchHandlers(context, DECODE, new DecodeEvent(component)); 239 } 240 241 242 246 public static final String DECODE = "decode"; 247 248 253 public static final String STATIC_TEXT_TYPE = 254 "staticText"; 255 256 259 public static final String STATIC_TEXT_FACTORY_CLASS_NAME = 260 "com.sun.enterprise.tools.jsfext.component.factory.basic.StaticTextFactory"; 261 262 267 private List _resources = new ArrayList (); 268 269 273 private Map _types = new HashMap (); 274 275 279 private Map _attributes = new HashMap (); 280 } 281 | Popular Tags |