1 16 package org.apache.myfaces.xdoclet; 17 18 import java.util.Properties ; 19 20 import xdoclet.XDocletException; 21 import xdoclet.XDocletTagSupport; 22 import xjavadoc.XField; 23 24 33 public class WapFacesTagHandler extends XDocletTagSupport { 34 private int iter = 0; 35 36 public String componentFamily() throws XDocletException { 37 return (getTagValue(FOR_CLASS, "wapfaces.tag", "componentFamily", null, null, false, false)); 38 } 39 40 public String rendererType() throws XDocletException { 41 return (getTagValue(FOR_CLASS, "wapfaces.tag", "rendererType", null, null, false, false)); 42 } 43 44 public String tagName() throws XDocletException { 45 return (getTagValue(FOR_CLASS, "wapfaces.tag", "tagName", null, null, false, false)); 46 } 47 48 public String tagBaseClass() throws XDocletException { 49 return (getTagValue(FOR_CLASS, "wapfaces.tag", "tagBaseClass", null, null, false, false)); 50 } 51 52 public String bodyContent() throws XDocletException { 53 return (getTagValue(FOR_CLASS, "wapfaces.tag", "bodyContent", null, null, false, false)); 54 } 55 56 private String attributeName(){ 57 XField field = getCurrentField(); 58 return(field.getName()); 59 } 60 61 private String attributeType(){ 62 XField field = getCurrentField(); 63 return(field.getType().getQualifiedName()); 64 } 65 66 69 public String attributeInitValue() throws XDocletException { 70 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "initValue", null, null, false, false); 71 72 if (value == null) return(attributeNullValue()); 73 return (value); 74 } 75 76 77 public String attributeNullValue() throws XDocletException { 78 String type = attributeType(); 79 if (type == null) throw new XDocletException("Missing(or wrong) attribute 'type' in property declaration."); 80 if (type.equals("boolean")) return("false"); 81 if (type.equals("byte")) return("0"); 82 if (type.equals("short")) return("0"); 83 if (type.equals("int")) return("0"); 84 if (type.equals("long")) return("0"); 85 if (type.equals("float")) return("0.0"); 86 if (type.equals("double")) return("0.0"); 87 if (type.equals("char")) return("\u0000"); 88 return("null"); 89 } 90 91 public void ifIsAttributePrimitive(String template) throws XDocletException { 92 if (isAttributePrimitive()) 93 generate(template); 94 } 95 96 public void ifIsNotAttributePrimitive(String template) throws XDocletException { 97 if (!isAttributePrimitive()) 98 generate(template); 99 } 100 101 102 private boolean isAttributePrimitive() throws XDocletException { 103 String type = attributeType(); 104 if (type == null) throw new XDocletException("Missing(or wrong) attribute 'type' in property declaration."); 105 if (type.equals("boolean") || type.equals("byte") || type.equals("short") || 106 type.equals("int") || type.equals("long") || type.equals("float") || 107 type.equals("double") || type.equals("char")) 108 return (true); 109 110 return(false); 111 } 112 113 114 public String classForType() throws XDocletException { 115 117 String type = attributeType(); 118 try { 119 if (isAttributePrimitive()){ 120 if (type != null && type.equals("int")) return("Integer"); 122 else 123 return (firstLetterToUpperCase(type)); 124 } 125 return (type); 126 127 } catch (Exception ex){ 128 throw new XDocletException(ex.getMessage()); 129 } 130 } 131 132 public String isAttributeRequired() throws XDocletException { 133 return(String.valueOf(attributeRequired())); 134 } 135 136 public void ifIsAttributeRequired(String template) throws XDocletException { 137 if (attributeRequired()) 138 generate(template); 139 } 140 141 private boolean attributeRequired() throws XDocletException { 142 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "required", null, "false", false, false); 143 144 try { 145 return (stringToBoolean(value)); 146 } catch (NumberFormatException ex) { 147 return(false); 148 } 149 } 150 151 public String isRtExprValue() throws XDocletException { 152 return(String.valueOf(rtExprValue())); 153 } 154 155 private boolean rtExprValue() throws XDocletException { 156 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "rtexprvalue", null, "false", false, false); 157 158 try { 159 return (stringToBoolean(value)); 160 } catch (NumberFormatException ex) { 161 return(false); 162 } 163 } 164 165 public void ifIsAttributeValueBinding(String template) throws XDocletException { 166 if (isAttributeValueBinding()) 167 generate(template); 168 } 169 170 public void ifIsNotAttributeValueBinding(String template) throws XDocletException { 171 if (!isAttributeValueBinding()) 172 generate(template); 173 } 174 175 private boolean isAttributeValueBinding() throws XDocletException { 176 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "valueBinding", null, "false", false, false); 177 178 try { 179 return (stringToBoolean(value)); 180 } catch (NumberFormatException ex) { 181 return(false); 182 } 183 } 184 185 public void ifIsNotAttributeAbstract(String template) throws XDocletException { 186 if (!isAttributeAbstract()) generate(template); 188 } 189 190 private boolean isAttributeAbstract() throws XDocletException { 191 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "abstract", null, "false", false, false); 192 193 try { 194 return (stringToBoolean(value)); 195 } catch (NumberFormatException ex) { 196 return(false); 197 } 198 } 199 200 public void ifIsNotAttributeInherit(String template) throws XDocletException { 201 if (!isAttributeInherid()) generate(template); 203 } 204 205 private boolean isAttributeInherid() throws XDocletException { 206 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "inherit", null, "false", false, false); 207 208 try { 209 return (stringToBoolean(value)); 210 } catch (NumberFormatException ex) { 211 return(false); 212 } 213 } 214 215 public void ifIsAttributeReplaced(String template) throws XDocletException{ 216 if (isAttributeReplaced()) 217 generate(template); 218 } 219 220 public void ifIsNotAttributeReplaced(String template) throws XDocletException{ 221 if (!isAttributeReplaced()) generate(template); 223 } 224 225 private boolean isAttributeReplaced() throws XDocletException { 226 boolean isEmpty = getReplacedAttributeName() == null || "".endsWith(getReplacedAttributeName()); 227 228 return(!isEmpty); 229 } 230 231 public String getReplacedAttributeName() throws XDocletException { 232 String value = getTagValue(FOR_FIELD, "wapfaces.attribute", "replaceWith", null, null, false, false); 233 234 return(value); 235 } 236 237 public String getterMethodName() throws XDocletException { 238 String name = attributeName(); 239 240 try { 241 return (getterPrefix() + firstLetterToUpperCase(name)); 242 } catch (Exception ex){ 243 throw new XDocletException(ex.getMessage()); 244 } 245 } 246 247 248 public String firstLetterToUpperCaseAttributeName() throws XDocletException { 249 String name = attributeName(); 250 251 try { 252 return (firstLetterToUpperCase(name)); 253 } catch (Exception ex){ 254 throw new XDocletException(ex.getMessage()); 255 } 256 } 257 258 public String setterMethodName() throws XDocletException { 259 String name = attributeName(); 260 try { 261 return ("set" + firstLetterToUpperCase(name)); 262 } catch (Exception ex){ 263 throw new XDocletException(ex.getMessage()); 264 } 265 } 266 267 public void iterateValue() { 268 iter = iter + 1; 269 } 270 271 public String iteratorValue() { 272 return (String.valueOf(iter)); 273 } 274 275 public void setIterator(Properties prop) throws XDocletException { 276 String value = prop.getProperty("value"); 277 try { 278 iter = Integer.parseInt(value); 279 } catch (NumberFormatException ex) { 280 throw new XDocletException("You have to set property 'value' in method setIterator. 'Value' is a integer number."); 281 } 282 } 283 284 private String getterPrefix(){ 285 if ("boolean".equals(attributeType())) 286 return("is"); 287 return("get"); 288 } 289 290 private String firstLetterToUpperCase(String str) throws Exception { 291 if (str != null && str.length() > 0){ 292 str = str.substring(0, 1).toUpperCase() + str.substring(1); 293 return (str); 294 } 295 else throw new Exception ("Attribut name error. Name must have at least one character."); 296 } 297 298 private boolean stringToBoolean(String str){ 299 Boolean bool = Boolean.valueOf(str); 300 return(bool.booleanValue()); 301 } 302 } 303 | Popular Tags |