1 5 package xdoclet.modules.mockobjects; 6 7 8 import org.apache.commons.logging.Log; 10 11 import xjavadoc.XClass; 13 14 import xdoclet.TemplateSubTask; 16 import xdoclet.XDocletException; 17 import xdoclet.util.LogUtil; 18 19 27 public class MockObjectSubTask extends TemplateSubTask 28 { 29 static String DEFAULT_TEMPLATE_FILE = "resources/mockobject.xdt"; 30 static String DEFAULT_MOCKCLASS_PATTERN = "{0}Mock"; 31 32 String mockClassPattern = DEFAULT_MOCKCLASS_PATTERN; 33 34 37 public MockObjectSubTask() 38 { 39 setAcceptAbstractClasses(true); 40 setAcceptInterfaces(true); 41 42 setDestinationFile(DEFAULT_MOCKCLASS_PATTERN + ".java"); 44 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 45 } 46 47 52 public String getMockClassPattern() 53 { 54 return mockClassPattern; 55 } 56 57 62 public void setMockClassPattern(String mockClassPattern) 63 { 64 this.mockClassPattern = mockClassPattern; 65 } 66 67 74 protected String getGeneratedFileName(XClass clazz) throws XDocletException 75 { 76 return javaFile(MockObjectTagsHandler.getMockClassFor(getCurrentClass())); 77 } 78 79 85 protected boolean matchesGenerationRules(XClass clazz) 86 throws XDocletException 87 { 88 89 Log log = LogUtil.getLog(MockObjectSubTask.class, "matchesGenerationRules"); 90 91 if (super.matchesGenerationRules(clazz) == false) { 92 log.debug("Skip class " + clazz.getQualifiedName() + 93 " because super.matchesGenerationRules() returned false."); 94 95 return false; 96 } 97 98 if (!getCurrentClass().isInterface()) { 99 log.debug("Skip class " + clazz.getQualifiedName() + 100 " because it is not an interface."); 101 102 return false; 103 } 104 105 if (!getCurrentClass().getDoc().hasTag("mock:generate")) { 106 log.debug("Skip class " + clazz.getQualifiedName() + 107 " because the mock:generate tag does not exist."); 108 109 return false; 110 } 111 return true; 112 } 113 } 114 | Popular Tags |