KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > tagshandler > FieldTagsHandler


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

5 package xdoclet.tagshandler;
6
7 import java.util.Properties JavaDoc;
8
9 import xjavadoc.*;
10 import xdoclet.ConfigParamIntrospector;
11
12 import xdoclet.XDocletException;
13
14 /**
15  * @author <a HREF="mailto:aslak.nospam@users.sf.net">Aslak Hellesøy</a>
16  * @created 13. januar 2002
17  * @xdoclet.taghandler namespace="Field"
18  * @version $Revision: 1.16 $
19  */

20 public class FieldTagsHandler extends AbstractProgramElementTagsHandler
21 {
22
23     /**
24      * Gets the FieldTypeFor attribute of the FieldTagsHandler class
25      *
26      * @param field Describe what the parameter does
27      * @return The FieldTypeFor value
28      * @exception XDocletException Describe the exception
29      */

30     public static String JavaDoc getFieldTypeFor(XField field) throws XDocletException
31     {
32         return field.getType().getQualifiedName() + field.getDimensionAsString();
33     }
34
35     /**
36      * Returns the capitalized name of the current field.
37      *
38      * @return Description of the Returned Value
39      * @exception XDocletException Description of Exception
40      * @doc.tag type="content"
41      */

42     public String JavaDoc getCapitalizedFieldName() throws XDocletException
43     {
44         return ConfigParamIntrospector.capitalize(getCurrentField().getName());
45     }
46
47     /**
48      * Iterates over all fields of current class and evaluates the body of the tag for each field.
49      *
50      * @param template The body of the block tag
51      * @param attributes The attributes of the template tag
52      * @exception XDocletException Description of Exception
53      * @doc.tag type="block"
54      * @doc.param name="superclasses" optional="true" values="true,false" description="If true then
55      * traverse superclasses also, otherwise look up the tag in current concrete class only."
56      * @doc.param name="sort" optional="true" values="true,false" description="If true then sort the
57      * fields list."
58      */

59     public void forAllFields(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
60     {
61         forAllMembers(template, attributes, FOR_FIELD);
62     }
63
64     /**
65      * Describe what the method does
66      *
67      * @return Describe the return value
68      * @exception XDocletException Describe the exception
69      */

70     public String JavaDoc modifiers() throws XDocletException
71     {
72         return modifiers(FOR_FIELD);
73     }
74
75     /**
76      * Return standard javadoc of current field.
77      *
78      * @return Description of the Returned Value
79      * @exception XDocletException Description of Exception
80      * @doc.tag type="content"
81      */

82     public String JavaDoc firstSentenceDescriptionOfCurrentField() throws XDocletException
83     {
84         return firstSentenceDescriptionOfCurrentMember(getCurrentField());
85     }
86
87     /**
88      * Returns the name of the current field.
89      *
90      * @return Description of the Returned Value
91      * @exception XDocletException Description of Exception
92      * @doc.tag type="content"
93      */

94     public String JavaDoc fieldName() throws XDocletException
95     {
96         return getCurrentField().getName();
97     }
98
99     /**
100      * The comment for the current field.
101      *
102      * @param attributes The attributes of the template tag
103      * @return Description of the Returned Value
104      * @exception XDocletException Description of Exception
105      * @see ClassTagsHandler#classComment(java.util.Properties)
106      * @doc.tag type="content"
107      * @doc.param name="no-comment-signs" optional="true" values="true,false" description="If true
108      * then don't decorate the comment with comment signs."
109      * @doc.param name="indent" optional="true" description="Number of spaces to indent the comment.
110      * Default is 0."
111      */

112     public String JavaDoc fieldComment(Properties JavaDoc attributes) throws XDocletException
113     {
114         return memberComment(attributes, FOR_FIELD);
115     }
116
117     /**
118      * Iterates over all tags of current field and evaluates the body of the tag for each field.
119      *
120      * @param template The body of the block tag
121      * @param attributes The attributes of the template tag
122      * @exception XDocletException Description of Exception
123      * @doc.tag type="block"
124      * @doc.param name="tagName" optional="false" description="The tag name."
125      * @doc.param name="superclasses" optional="true" values="true,false" description="If true then
126      * traverse superclasses also, otherwise look up the tag in current concrete class only. Default is true."
127      */

128     public void forAllFieldTags(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
129     {
130         forAllMemberTags(template, attributes, FOR_FIELD, XDocletTagshandlerMessages.ONLY_CALL_FIELD_NOT_NULL, new String JavaDoc[]{"forAllFieldTags"});
131     }
132
133     /**
134      * Iterates over all tokens in current field tag with the name tagName and evaluates the body for every token.
135      *
136      * @param template The body of the block tag
137      * @param attributes The attributes of the template tag
138      * @exception XDocletException Description of Exception
139      * @doc.tag type="block"
140      * @doc.param name="tagName" optional="false" description="The tag name."
141      * @doc.param name="delimiter" description="delimiter for the StringTokenizer. consult javadoc for
142      * java.util.StringTokenizer default is ','"
143      * @doc.param name="skip" description="how many tokens to skip on start"
144      */

145     public void forAllFieldTagTokens(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
146     {
147         forAllMemberTagTokens(template, attributes, FOR_FIELD);
148     }
149
150     /**
151      * Iterates over all field tags with the specified tagName for the current field probably inside of a
152      * forAllFieldTags body.
153      *
154      * @param attributes The attributes of the template tag
155      * @return Description of the Returned Value
156      * @exception XDocletException Description of Exception
157      * @doc.tag type="content"
158      * @doc.param name="tagName" optional="false" description="The tag name."
159      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
160      * content of the tag is returned."
161      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
162      * used the space-separated format for specifying parameters."
163      * @doc.param name="values" description="The valid values for the parameter, comma separated. An
164      * error message is printed if the parameter value is not one of the values."
165      * @doc.param name="default" description="The default value is returned if parameter not specified
166      * by user for the tag."
167      */

168     public String JavaDoc fieldTagValue(Properties JavaDoc attributes) throws XDocletException
169     {
170         // setting field to true will override the for_class value.
171
attributes.setProperty("field", "true");
172         return getExpandedDelimitedTagValue(attributes, FOR_FIELD);
173     }
174
175     /**
176      * Returns the type of the current field.
177      *
178      * @return Description of the Returned Value
179      * @exception XDocletException Description of Exception
180      * @doc.tag type="content"
181      */

182     public String JavaDoc fieldType() throws XDocletException
183     {
184         return getFieldTypeFor(getCurrentField());
185     }
186
187     /**
188      * Evaluates the body if current field has at least one tag with the specified name.
189      *
190      * @param template The body of the block tag
191      * @param attributes The attributes of the template tag
192      * @exception XDocletException Description of Exception
193      * @doc.tag type="block"
194      * @doc.param name="tagName" optional="false" description="The tag name."
195      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
196      * content of the tag is returned."
197      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
198      * used the space-separated format for specifying parameters."
199      * @doc.param name="superclasses" optional="true" values="true,false" description="If true then
200      * traverse superclasses also, otherwise look up the tag in current concrete class only. Default is true."
201      * @doc.param name="error" description="Show this error message if no tag found."
202      */

203     public void ifHasFieldTag(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
204     {
205         if (hasTag(attributes, FOR_FIELD)) {
206             generate(template);
207         }
208         else {
209             String JavaDoc error = attributes.getProperty("error");
210
211             if (error != null) {
212                 getEngine().print(error);
213             }
214         }
215     }
216
217     /**
218      * Evaluates the body if current field doesnt have any tags with the specified name.
219      *
220      * @param template The body of the block tag
221      * @param attributes The attributes of the template tag
222      * @exception XDocletException Description of Exception
223      * @doc.tag type="block"
224      * @doc.param name="tagName" optional="false" description="The tag name."
225      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
226      * content of the tag is returned."
227      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
228      * used the space-separated format for specifying parameters."
229      * @doc.param name="error" description="Show this error message if no tag found."
230      */

231     public void ifDoesntHaveFieldTag(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
232     {
233         if (!hasTag(attributes, FOR_FIELD)) {
234             generate(template);
235         }
236         else {
237             String JavaDoc error = attributes.getProperty("error");
238
239             if (error != null) {
240                 getEngine().print(error);
241             }
242         }
243     }
244
245     /**
246      * Evaluates the body if value for the field tag equals the specified value.
247      *
248      * @param template The body of the block tag
249      * @param attributes The attributes of the template tag
250      * @exception XDocletException Description of Exception
251      * @doc.tag type="block"
252      * @doc.param name="tagName" optional="false" description="The tag name."
253      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
254      * content of the tag is returned."
255      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
256      * used the space-separated format for specifying parameters."
257      * @doc.param name="value" optional="false" description="The desired value."
258      */

259     public void ifFieldTagValueEquals(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
260     {
261         if (isTagValueEqual(attributes, FOR_FIELD)) {
262             generate(template);
263         }
264     }
265
266 }
267
Popular Tags