KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > DocletSupport


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

5 package xdoclet;
6
7 import java.util.Stack JavaDoc;
8
9 import xjavadoc.XClass;
10 import xjavadoc.XConstructor;
11 import xjavadoc.XField;
12 import xjavadoc.XMethod;
13 import xjavadoc.XPackage;
14 import xjavadoc.XTag;
15
16 /**
17  * @author Ara Abrahamian (ara_e@email.com)
18  * @created Oct 13, 2001
19  * @version $Revision: 1.16 $
20  */

21 public abstract class DocletSupport
22 {
23     /**
24      * The current Tag. Various template tag implementations set this value, including looping tags such as
25      * forAllClassTags. There's no distinction between class/method/field/constructor/whatever tags, and currentTag can
26      * point to any one them.
27      */

28     protected static XTag currentMethodTag;
29
30     protected static XTag currentClassTag;
31
32     protected static XTag currentFieldTag;
33
34     /**
35      * The current class stack is used for pushing/poping classes to/from it, so that it's possible to work of the
36      * current class while not losing the previous current class since template tags can be nested inside each other and
37      * each may set a new class as the current class (by pushing the class to top of stack).
38      *
39      * @see #setCurrentClass(xjavadoc.XClass)
40      * @see #getCurrentClass()
41      * @see #pushCurrentClass(xjavadoc.XClass)
42      * @see #popCurrentClass()
43      */

44     private transient Stack JavaDoc currentClassStack = null;
45
46     /**
47      * Reference to the current method. Unlike current class stack, there's no stack for methods, because rarely you
48      * need to alter current method reference nestedly.
49      *
50      * @see #getCurrentMethod()
51      * @see #setCurrentMethod(xjavadoc.XMethod)
52      */

53     private transient XMethod currentMethod = null;
54
55     /**
56      * Reference to the current constructor. Unlike current class stack, there's no stack for constructors, because
57      * rarely you need to alter current constructor reference nestedly.
58      *
59      * @see #getCurrentConstructor()
60      * @see #setCurrentConstructor(xjavadoc.XConstructor)
61      */

62     private transient XConstructor currentConstructor = null;
63
64     /**
65      * Reference to the current field. Unlike current class stack, there's no stack for fields, because rarely you need
66      * to alter current field reference nestedly.
67      *
68      * @see #getCurrentField()
69      * @see #setCurrentField(xjavadoc.XField)
70      */

71     private transient XField currentField = null;
72
73     /**
74      * Reference to the current package. Unlike current class stack, there's no stack for methods, because rarely you
75      * need to alter current package reference nestedly.
76      *
77      * @see #getCurrentPackage()
78      * @see #setCurrentPackage(xjavadoc.XPackage)
79      */

80     private transient XPackage currentPackage = null;
81
82     public DocletSupport()
83     {
84         currentClassStack = new Stack JavaDoc();
85     }
86
87     /**
88      * Gets the CurrentMethodTag attribute of the DocletSupport class
89      *
90      * @return The CurrentMethodTag value
91      */

92     public static XTag getCurrentMethodTag()
93     {
94         return currentMethodTag;
95     }
96
97     /**
98      * Gets the CurrentClassTag attribute of the DocletSupport class
99      *
100      * @return The CurrentClassTag value
101      */

102     public static XTag getCurrentClassTag()
103     {
104         return currentClassTag;
105     }
106
107     /**
108      * Gets the CurrentFieldTag attribute of the DocletSupport field
109      *
110      * @return The CurrentFieldTag value
111      */

112     public static XTag getCurrentFieldTag()
113     {
114         return currentFieldTag;
115     }
116
117     /**
118      * This method is for backward compatiblity only. Method or Class Tag getter should be used instead.
119      *
120      * @return The CurrentTag value
121      */

122     public static XTag getCurrentTag()
123     {
124         if (currentMethodTag != null)
125             return currentMethodTag;
126         else
127             return currentClassTag;
128     }
129
130     /**
131      * Returns true if the clazz generated by xdoclet. An xdoclet generated class has a class-level xdoclet-generated
132      * tag.
133      *
134      * @param clazz Description of Parameter
135      * @return The DocletGenerated value
136      */

137     public static boolean isDocletGenerated(XClass clazz)
138     {
139         return clazz.getDoc().hasTag("xdoclet-generated", false);
140     }
141
142     /**
143      * Sets the CurrentMethodTag attribute of the DocletSupport class
144      *
145      * @param currentTag The new CurrentMethodTag value
146      * @ant.ignore
147      */

148     public static void setCurrentMethodTag(XTag currentTag)
149     {
150         DocletSupport.currentMethodTag = currentTag;
151     }
152
153     /**
154      * Sets the CurrentClassTag attribute of the DocletSupport class
155      *
156      * @param currentTag The new CurrentClassTag value
157      * @ant.ignore
158      */

159     public static void setCurrentClassTag(XTag currentTag)
160     {
161         DocletSupport.currentClassTag = currentTag;
162     }
163
164     /**
165      * Sets the CurrentFieldTag attribute of the DocletSupport field
166      *
167      * @param currentTag The new CurrentFieldTag value
168      * @ant.ignore
169      */

170     public static void setCurrentFieldTag(XTag currentTag)
171     {
172         DocletSupport.currentFieldTag = currentTag;
173     }
174
175     /**
176      * Peeks and return the current class from top of currentClassStack stack.
177      *
178      * @return The CurrentClass value
179      * @see #setCurrentClass(xjavadoc.XClass)
180      */

181     public XClass getCurrentClass()
182     {
183         return currentClassStack.empty() ? null : (XClass) currentClassStack.peek();
184     }
185
186     /**
187      * Returns current package.
188      *
189      * @return The CurrentPackage value
190      * @see #setCurrentPackage(xjavadoc.XPackage)
191      */

192     public XPackage getCurrentPackage()
193     {
194         return currentPackage;
195     }
196
197     /**
198      * Returns current method.
199      *
200      * @return The CurrentMethod value
201      * @see #setCurrentMethod(xjavadoc.XMethod)
202      */

203     public XMethod getCurrentMethod()
204     {
205         return currentMethod;
206     }
207
208     /**
209      * Returns current constructor.
210      *
211      * @return The CurrentConstructor value
212      * @see #setCurrentConstructor(xjavadoc.XConstructor)
213      */

214     public XConstructor getCurrentConstructor()
215     {
216         return currentConstructor;
217     }
218
219     /**
220      * Returns current field.
221      *
222      * @return The CurrentField value
223      * @see #setCurrentField(xjavadoc.XField)
224      */

225     public XField getCurrentField()
226     {
227         return currentField;
228     }
229
230     /**
231      * Returns current package.
232      *
233      * @param pakkage The new CurrentPackage value
234      * @see #setCurrentPackage(xjavadoc.XPackage)
235      * @ant.ignore
236      */

237     public void setCurrentPackage(XPackage pakkage)
238     {
239         currentPackage = pakkage;
240
241         // since we're now working on a new package, clear the class stack
242
currentClassStack.clear();
243     }
244
245     /**
246      * Sets the CurrentMethod attribute of the DocletSupport object
247      *
248      * @param method The new CurrentMethod value
249      * @ant.ignore
250      */

251     public void setCurrentMethod(XMethod method)
252     {
253         currentMethod = method;
254     }
255
256     /**
257      * Sets the CurrentConstructor attribute of the DocletSupport object
258      *
259      * @param constructor The new CurrentConstructor value
260      * @ant.ignore
261      */

262     public void setCurrentConstructor(XConstructor constructor)
263     {
264         currentConstructor = constructor;
265     }
266
267     /**
268      * Sets the CurrentField attribute of the DocletSupport object
269      *
270      * @param field The new CurrentField value
271      * @ant.ignore
272      */

273     public void setCurrentField(XField field)
274     {
275         currentField = field;
276     }
277
278     /**
279      * Sets current class to clazz by clearing currentClassStack stack and pushing clazz into top of it.
280      *
281      * @param clazz The new CurrentClass value
282      * @see #getCurrentClass()
283      * @ant.ignore
284      */

285     public void setCurrentClass(XClass clazz)
286     {
287         currentClassStack.clear();
288         currentClassStack.push(clazz);
289     }
290
291     /**
292      * Pushes class clazz to top of currentClassStack stack, making it effectively the current class.
293      *
294      * @param clazz Description of Parameter
295      * @return Description of the Returned Value
296      * @see #getCurrentClass()
297      * @see #setCurrentClass(xjavadoc.XClass)
298      * @see #popCurrentClass()
299      */

300     public XClass pushCurrentClass(XClass clazz)
301     {
302         return (XClass) currentClassStack.push(clazz);
303     }
304
305     /**
306      * Popes current class from top currentClassStack stack. The poped class is no longer the current class.
307      *
308      * @return Description of the Returned Value
309      * @see #getCurrentClass()
310      * @see #setCurrentClass(xjavadoc.XClass)
311      * @see #pushCurrentClass(xjavadoc.XClass)
312      */

313     public XClass popCurrentClass()
314     {
315         return (XClass) currentClassStack.pop();
316     }
317 }
318
Popular Tags