KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > mockobjects > MockObjectSubTask


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.mockobjects;
6
7
8 // Apache commons import
9
import org.apache.commons.logging.Log;
10
11 // XJavadoc import
12
import xjavadoc.XClass;
13
14 // XDoclet import
15
import xdoclet.TemplateSubTask;
16 import xdoclet.XDocletException;
17 import xdoclet.util.LogUtil;
18
19 /**
20  * Subtask for mockobject.
21  *
22  * @author Joe Walnes
23  * @author Stig Jørgensen
24  * @created 5. februar 2003
25  * @ant.element name="mockobjects" display-name="Mockmaker" parent="xdoclet.modules.mockobjects.MockObjectDocletTask"
26  */

27 public class MockObjectSubTask extends TemplateSubTask
28 {
29     static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/mockobject.xdt";
30     static String JavaDoc DEFAULT_MOCKCLASS_PATTERN = "{0}Mock";
31
32     String JavaDoc mockClassPattern = DEFAULT_MOCKCLASS_PATTERN;
33
34     /**
35      * Initialize the default behaviour.
36      */

37     public MockObjectSubTask()
38     {
39         setAcceptAbstractClasses(true);
40         setAcceptInterfaces(true);
41
42         // If the templates is not set in the Ant task, use the default ones
43
setDestinationFile(DEFAULT_MOCKCLASS_PATTERN + ".java");
44         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
45     }
46
47     /**
48      * Returns the mockClassPattern.
49      *
50      * @return String the mockClassPattern.
51      */

52     public String JavaDoc getMockClassPattern()
53     {
54         return mockClassPattern;
55     }
56
57     /**
58      * Sets the mockClassPattern.
59      *
60      * @param mockClassPattern The mockClassPattern to set
61      */

62     public void setMockClassPattern(String JavaDoc mockClassPattern)
63     {
64         this.mockClassPattern = mockClassPattern;
65     }
66
67     /**
68      * Gets the GeneratedFileName attribute of the DaoSubTask object
69      *
70      * @param clazz Describe what the parameter does
71      * @return The GeneratedFileName value
72      * @exception XDocletException
73      */

74     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
75     {
76         return javaFile(MockObjectTagsHandler.getMockClassFor(getCurrentClass()));
77     }
78
79     /**
80      * @param clazz
81      * @return
82      * @exception XDocletException
83      * @see xdoclet.TemplateSubTask#matchesGenerationRules(xjavadoc.XClass)
84      */

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