KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > maven > MavenpluginTagsHandler


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

5 package xdoclet.modules.maven;
6
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9 import xjavadoc.XClass;
10 import xjavadoc.XParameter;
11
12 import xdoclet.XDocletException;
13 import xdoclet.modules.doc.AntdocSubTask;
14 import xdoclet.modules.doc.AntdocTagsHandler;
15 import xdoclet.tagshandler.TypeTagsHandler;
16
17 /**
18  * This tag handler is used to generate xdoclet Maven plugin.
19  *
20  * @author Ara Abrahamian
21  * @created 21 September 2002
22  * @xdoclet.taghandler namespace="Mavenplugin"
23  * @version $Revision: 1.4 $
24  */

25 public class MavenpluginTagsHandler extends AntdocTagsHandler
26 {
27     private List JavaDoc tasks;
28
29     private static boolean isNestedElementParameter(XParameter parameter)
30     {
31         return TypeTagsHandler.isPrimitiveType(parameter.getType().getQualifiedName()) == false &&
32             parameter.getType().getQualifiedName().startsWith("xjavadoc") == false &&
33             parameter.getType().getQualifiedName().startsWith("java") == false;
34     }
35
36     public List JavaDoc getTasks()
37     {
38         return tasks;
39     }
40
41     public void setTasks(List JavaDoc tasks)
42     {
43         this.tasks = tasks;
44     }
45
46     public void forAllTasks(String JavaDoc template) throws XDocletException
47     {
48         XClass old_cur_class = getCurrentClass();
49
50         for (Iterator JavaDoc i = getTasks().iterator(); i.hasNext(); ) {
51             docElement = (AntdocSubTask.Element) i.next();
52
53             setCurrentClass(docElement.getXClass());
54
55             generate(template);
56         }
57
58         setCurrentClass(old_cur_class);
59     }
60
61     public void ifIsASubTask(String JavaDoc template) throws XDocletException
62     {
63         ifIsASubTask_Impl(template, true);
64     }
65
66     public void ifIsNotASubTask(String JavaDoc template) throws XDocletException
67     {
68         ifIsASubTask_Impl(template, false);
69     }
70
71     public void ifIsAFileSet(String JavaDoc template) throws XDocletException
72     {
73         ifIsAFileSet_Impl(template, true);
74     }
75
76     public void ifIsNotAFileSet(String JavaDoc template) throws XDocletException
77     {
78         ifIsAFileSet_Impl(template, false);
79     }
80
81     public void ifIsAConfigParam(String JavaDoc template) throws XDocletException
82     {
83         if (subElement.getXClass().isA("xdoclet.ConfigParameter"))
84             generate(template);
85     }
86
87     public void ifIsANestedElement(String JavaDoc template) throws XDocletException
88     {
89         ifIsANestedElement_Impl(template, true);
90     }
91
92     public String JavaDoc nestedElementName() throws XDocletException
93     {
94         return getCurrentMethod().getName().substring(3);
95     }
96
97     public String JavaDoc nestedElementType() throws XDocletException
98     {
99         for (Iterator JavaDoc i = getCurrentMethod().getParameters().iterator(); i.hasNext(); ) {
100             XParameter parameter = (XParameter) i.next();
101
102             return parameter.getType().getQualifiedName();
103         }
104
105         return "";
106     }
107
108     public String JavaDoc moduleName() throws XDocletException
109     {
110         String JavaDoc elementName = elementName();
111
112         return elementName.substring(0, elementName.indexOf("doclet"));
113     }
114
115     public void ifIsNotANestedElement(String JavaDoc template) throws XDocletException
116     {
117         ifIsANestedElement_Impl(template, false);
118     }
119
120     private void ifIsASubTask_Impl(String JavaDoc template, boolean condition) throws XDocletException
121     {
122         if (subElement.isDynamicSubElement() == condition)
123             generate(template);
124     }
125
126     private void ifIsAFileSet_Impl(String JavaDoc template, boolean condition) throws XDocletException
127     {
128         if (subElement.getXClass().isA("org.apache.tools.ant.types.FileSet") == condition)
129             generate(template);
130     }
131
132     private void ifIsANestedElement_Impl(String JavaDoc template, boolean condition) throws XDocletException
133     {
134         if ((getCurrentMethod().getName().startsWith("set") || getCurrentMethod().getName().startsWith("add")) && getCurrentMethod().getParameters().size() == 1) {
135
136             for (Iterator JavaDoc i = getCurrentMethod().getParameters().iterator(); i.hasNext(); ) {
137                 XParameter parameter = (XParameter) i.next();
138
139                 if (isNestedElementParameter(parameter) == condition) {
140                     generate(template);
141                 }
142             }
143         }
144     }
145 }
146
Popular Tags