1 23 package com.sun.enterprise.tools.jsfext.component.factory; 24 25 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutComponent; 26 import com.sun.enterprise.tools.jsfext.util.LogUtil; 27 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import javax.faces.component.UIComponent; 32 import javax.faces.context.FacesContext; 33 import javax.faces.el.ValueBinding; 34 import javax.faces.webapp.UIComponentTag; 35 36 37 43 public abstract class ComponentFactoryBase implements ComponentFactory { 44 45 60 protected void setOptions(FacesContext context, LayoutComponent desc, UIComponent comp) { 61 String compId = (String ) desc.getId(context, comp.getParent()); 65 if ((compId != null) && (!compId.equals(""))) { 66 comp.setId(compId); 67 } 68 69 Map attributes = comp.getAttributes(); 71 Iterator it = desc.getOptions().keySet().iterator(); 73 Object value = null; 74 String strVal = null; 75 String key = null; 76 while (it.hasNext()) { 77 key = (String ) it.next(); 79 value = desc.getEvaluatedOption(context, key, comp); 80 81 strVal = "" + value; 83 if (UIComponentTag.isValueReference(strVal)) { 84 ValueBinding vb = 85 context.getApplication().createValueBinding(strVal); 86 comp.setValueBinding((String ) key, vb); 87 } else { 88 try { 90 attributes.put(key, value); 91 } catch (NullPointerException ex) { 92 attributes.remove(key); 94 } 95 } 96 } 97 98 storeInstanceHandlers(desc, comp); 100 } 101 102 123 protected void storeInstanceHandlers(LayoutComponent desc, UIComponent comp) { 124 if (!desc.isNested()) { 125 return; 128 } 129 130 Iterator it = desc.getHandlersByTypeMap().keySet().iterator(); 132 if (it.hasNext()) { 133 String eventType = null; 134 Map compAttrs = comp.getAttributes(); 135 while (it.hasNext()) { 136 eventType = (String ) it.next(); 139 if (eventType.equals(LayoutComponent.BEFORE_CREATE)) { 140 continue; 142 } else if (eventType.equals(LayoutComponent.AFTER_CREATE)) { 143 continue; 145 } 146 compAttrs.put(eventType, desc.getHandlers(eventType)); 147 } 148 } 149 } 150 151 162 protected void addChild(FacesContext context, LayoutComponent descriptor, UIComponent parent, UIComponent child) { 163 if (descriptor.isFacetChild()) { 164 String name = (String ) descriptor.getEvaluatedOption( 165 context, LayoutComponent.FACET_NAME, child); 166 if (name != null) { 167 parent.getFacets().put(name, child); 168 } else { 169 if (LogUtil.configEnabled()) { 171 LogUtil.config("Warning: no facet name was supplied for '" 172 + descriptor.getId(context, child) + "'!"); 173 } 174 175 child.setParent(parent); 177 } 178 } else { 179 parent.getChildren().add(child); 181 } 182 } 183 } 184 | Popular Tags |