1 14 15 package com.sun.facelets.tag.jsf; 16 17 import java.util.logging.Level ; 18 import java.util.logging.Logger ; 19 20 import javax.faces.component.UIComponent; 21 import javax.faces.component.UIComponentBase; 22 23 import com.sun.facelets.FaceletContext; 24 import com.sun.facelets.el.LegacyValueBinding; 25 import com.sun.facelets.tag.TagAttribute; 26 import com.sun.facelets.tag.Metadata; 27 import com.sun.facelets.tag.MetaRule; 28 import com.sun.facelets.tag.MetadataTarget; 29 import com.sun.facelets.util.FacesAPI; 30 31 36 final class ComponentRule extends MetaRule { 37 38 final class LiteralAttributeMetadata extends Metadata { 39 40 private final String name; 41 private final String value; 42 43 public LiteralAttributeMetadata(String name, String value) { 44 this.value = value; 45 this.name = name; 46 } 47 48 public void applyMetadata(FaceletContext ctx, Object instance) { 49 ((UIComponent) instance).getAttributes().put(this.name, this.value); 50 } 51 } 52 53 final static class ValueExpressionMetadata extends Metadata { 54 55 private final String name; 56 57 private final TagAttribute attr; 58 59 private final Class type; 60 61 public ValueExpressionMetadata(String name, Class type, 62 TagAttribute attr) { 63 this.name = name; 64 this.attr = attr; 65 this.type = type; 66 } 67 68 public void applyMetadata(FaceletContext ctx, Object instance) { 69 ((UIComponent) instance).setValueExpression(this.name, this.attr 70 .getValueExpression(ctx, this.type)); 71 } 72 73 } 74 75 final static class ValueBindingMetadata extends Metadata { 76 77 private final String name; 78 79 private final TagAttribute attr; 80 81 private final Class type; 82 83 public ValueBindingMetadata(String name, Class type, TagAttribute attr) { 84 this.name = name; 85 this.attr = attr; 86 this.type = type; 87 } 88 89 public void applyMetadata(FaceletContext ctx, Object instance) { 90 ((UIComponent) instance).setValueBinding(this.name, 91 new LegacyValueBinding(this.attr.getValueExpression(ctx, 92 this.type))); 93 } 94 95 } 96 97 private final static Logger log = Logger 98 .getLogger("facelets.tag.component"); 99 100 public final static ComponentRule Instance = new ComponentRule(); 101 102 public ComponentRule() { 103 super(); 104 } 105 106 public Metadata applyRule(String name, TagAttribute attribute, 107 MetadataTarget meta) { 108 if (meta.isTargetInstanceOf(UIComponent.class)) { 109 110 if (!attribute.isLiteral()) { 112 Class type = meta.getPropertyType(name); 113 if (type == null) { 114 type = Object .class; 115 } 116 if (FacesAPI.getComponentVersion(meta.getTargetClass()) >= 12) { 117 return new ValueExpressionMetadata(name, type, attribute); 118 } else { 119 return new ValueBindingMetadata(name, type, attribute); 120 } 121 } else if (meta.getWriteMethod(name) == null) { 122 123 warnAttr(attribute, meta.getTargetClass(), name); 125 126 return new LiteralAttributeMetadata(name, attribute.getValue()); 127 } 128 } 129 return null; 130 } 131 132 private static void warnAttr(TagAttribute attr, Class type, String n) { 133 if (log.isLoggable(Level.WARNING)) { 134 log.warning(attr + " Property '" + n + "' is not on type: " 135 + type.getName()); 136 } 137 } 138 139 } 140 | Popular Tags |