1 5 package xdoclet.tagshandler; 6 7 import java.util.Collection ; 8 9 import java.util.Iterator ; 10 import java.util.Properties ; 11 import java.util.SortedSet ; 12 import java.util.TreeSet ; 13 14 import org.apache.commons.logging.Log; 15 16 import xjavadoc.XClass; 17 import xjavadoc.XConstructor; 18 19 import xdoclet.XDocletException; 20 import xdoclet.util.DocletUtil; 21 import xdoclet.util.LogUtil; 22 23 29 public class ConstructorTagsHandler extends AbstractProgramElementTagsHandler 30 { 31 32 50 public void setCurrentConstructor(String template, Properties attributes) throws XDocletException 51 { 52 String constructorName = attributes.getProperty("name"); 53 String parametersStr = attributes.getProperty("parameters"); 54 String delimiter = attributes.getProperty("delimiter"); 55 56 String [] parameters = null; 57 58 if (parametersStr != null) { 59 if (delimiter == null) { 60 delimiter = PARAMETER_DELIMITER; 61 } 62 63 parameters = DocletUtil.tokenizeDelimitedToArray(parametersStr, delimiter); 64 } 65 66 XConstructor oldConstructor = getCurrentConstructor(); 67 68 if (hasConstructor(getCurrentClass(), constructorName, parameters, true)) { 69 generate(template); 70 } 71 72 setCurrentConstructor(oldConstructor); 73 } 74 75 88 public String constructorComment(Properties attributes) throws XDocletException 89 { 90 return memberComment(attributes, FOR_CONSTRUCTOR); 91 } 92 93 108 public String exceptionList(Properties attributes) throws XDocletException 109 { 110 return exceptionList(attributes, FOR_CONSTRUCTOR); 111 } 112 113 126 public void forAllClassConstructors(String template, Properties attributes) throws XDocletException 127 { 128 String typeName = attributes.getProperty("type"); 129 int extent = TypeTagsHandler.extractExtentType(attributes.getProperty("extent")); 130 131 SortedSet constructors = new TreeSet (); 132 133 for (Iterator i = getAllClasses().iterator(); i.hasNext(); ) { 134 XClass clazz = (XClass) i.next(); 135 136 if (typeName == null || TypeTagsHandler.isOfType(clazz, typeName, extent)) { 137 Collection classConstructors = clazz.getConstructors(); 138 139 constructors.addAll(classConstructors); 140 141 } 142 } 143 144 Iterator constructorIterator = constructors.iterator(); 145 146 while (constructorIterator.hasNext()) { 147 XConstructor current = (XConstructor) constructorIterator.next(); 148 149 setCurrentClass(current.getContainingClass()); 150 setCurrentConstructor(current); 151 152 generate(template); 153 } 154 } 155 156 168 public void forAllConstructors(String template, Properties attributes) throws XDocletException 169 { 170 forAllMembers(template, attributes, FOR_CONSTRUCTOR); 171 } 172 173 187 public void ifDoesntHaveConstructorTag(String template, Properties attributes) throws XDocletException 188 { 189 if (!hasTag(attributes, FOR_CONSTRUCTOR)) { 190 generate(template); 191 } 192 else { 193 String error = attributes.getProperty("error"); 194 195 if (error != null) { 196 getEngine().print(error); 197 } 198 } 199 } 200 201 215 public void ifHasConstructorTag(String template, Properties attributes) throws XDocletException 216 { 217 if (hasTag(attributes, FOR_CONSTRUCTOR)) { 218 generate(template); 219 } 220 else { 221 String error = attributes.getProperty("error"); 222 223 if (error != null) { 224 getEngine().print(error); 225 } 226 } 227 } 228 229 237 public void executeAndRestoreConstructor(String template, Properties attributes) throws XDocletException 238 { 239 XConstructor constructor = getCurrentConstructor(); 240 241 generate(template); 242 setCurrentConstructor(constructor); 243 } 244 245 258 public void ifConstructorTagValueEquals(String template, Properties attributes) throws XDocletException 259 { 260 if (isTagValueEqual(attributes, FOR_CONSTRUCTOR)) { 261 generate(template); 262 } 263 } 264 265 278 public void ifConstructorTagValueNotEquals(String template, Properties attributes) throws XDocletException 279 { 280 if (!isTagValueEqual(attributes, FOR_CONSTRUCTOR)) { 281 generate(template); 282 } 283 } 284 285 303 public String constructorTagValue(Properties attributes) throws XDocletException 304 { 305 return getExpandedDelimitedTagValue(attributes, FOR_CONSTRUCTOR); 306 } 307 308 317 public void forAllConstructorTags(String template, Properties attributes) throws XDocletException 318 { 319 forAllMemberTags(template, attributes, FOR_CONSTRUCTOR, XDocletTagshandlerMessages.ONLY_CALL_CONSTRUCTOR_NOT_NULL, new String []{"forAllConstructorTags"}); 320 } 321 322 334 public void forAllConstructorTagTokens(String template, Properties attributes) throws XDocletException 335 { 336 forAllMemberTagTokens(template, attributes, FOR_CONSTRUCTOR); 337 } 338 339 346 public String firstSentenceDescriptionOfCurrentConstructor() throws XDocletException 347 { 348 return firstSentenceDescriptionOfCurrentMember(getCurrentConstructor()); 349 } 350 351 357 public String modifiers() throws XDocletException 358 { 359 return modifiers(FOR_CONSTRUCTOR); 360 } 361 362 370 public String constructorName(Properties attributes) throws XDocletException 371 { 372 if (attributes != null) { 373 String value = (String ) attributes.get("value"); 374 375 if (value != null) { 376 String m = getCurrentConstructor().getName().substring(Integer.parseInt(value)); 377 char firstU = m.charAt(0); 379 char firstL = Character.toLowerCase(firstU); 380 381 return firstL + m.substring(1); 382 } 383 } 384 return getCurrentConstructor() != null ? getCurrentConstructor().getName() : ""; 385 } 386 387 393 public String currentConstructorName() throws XDocletException 394 { 395 return getCurrentConstructor().getName(); 396 } 397 398 416 public void ifHasConstructor(String template, Properties attributes) throws XDocletException 417 { 418 ifHasConstructor_Impl(template, attributes, true); 419 } 420 421 438 public void ifDoesntHaveConstructor(String template, Properties attributes) throws XDocletException 439 { 440 ifHasConstructor_Impl(template, attributes, false); 441 } 442 443 456 private boolean hasConstructor(XClass clazz, String constructorName, String [] parameters, boolean setCurrentConstructor) 457 throws XDocletException 458 { 459 return hasExecutableMember(clazz, constructorName, parameters, setCurrentConstructor, FOR_CONSTRUCTOR); 460 } 461 462 473 private void ifHasConstructor_Impl(String template, Properties attributes, boolean hasConstructor) throws XDocletException 474 { 475 Log log = LogUtil.getLog(ConstructorTagsHandler.class, "ifHasConstructor_Impl"); 476 477 String constructorName = attributes.getProperty("name"); 478 String parametersStr = attributes.getProperty("parameters"); 479 String delimiter = attributes.getProperty("delimiter"); 480 481 String [] parameters = null; 482 483 if (log.isDebugEnabled()) { 484 log.debug("constructorName=" + constructorName); 485 log.debug("parametersStr=" + parametersStr); 486 log.debug("delimiter=" + delimiter); 487 log.debug("hasConstructor=" + hasConstructor); 488 log.debug("getCurrentClass()=" + getCurrentClass()); 489 } 490 491 if (parametersStr != null) { 492 if (delimiter == null) { 493 delimiter = PARAMETER_DELIMITER; 494 } 495 496 parameters = DocletUtil.tokenizeDelimitedToArray(parametersStr, delimiter); 497 498 if (log.isDebugEnabled()) { 499 log.debug("parameters.length=" + parameters.length); 500 log.debug("parameters[0]=" + parameters[0]); 501 } 502 } 503 if (hasConstructor(getCurrentClass(), constructorName, parameters, false) == hasConstructor) { 504 log.debug("constructor found."); 505 generate(template); 506 } 507 else { 508 log.debug("constructor not found."); 509 } 510 } 511 } 512 | Popular Tags |