KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > jdo > JdoTagsHandler


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

5 package xdoclet.modules.jdo;
6
7 import java.util.ArrayList JavaDoc;
8
9 import java.util.Collection JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 import xjavadoc.*;
14
15 import xdoclet.SubTask;
16 import xdoclet.XDocletException;
17 import xdoclet.XDocletTagSupport;
18
19 /**
20  * @author Ludovic Claude (ludovicc@users.sourceforge.net)
21  * @author David Jencks (d_jencks@users.sourceforge.net)
22  * @created June 11, 20012
23  * @xdoclet.taghandler namespace="Jdo"
24  * @version $Revision: 1.10 $
25  */

26 public class JdoTagsHandler extends XDocletTagSupport
27 {
28
29     private Collection JavaDoc _extensions;
30     private VendorExtension _currentExtension;
31
32     /**
33      * The <code>forAllPackages</code> iterates through all packages, and generates the template if the
34      * jdo.persistence-capable tag is present in at least one class in the package.
35      *
36      * @param template a <code>String</code> value
37      * @param attributes a <code>Properties</code> value
38      * @exception XDocletException if an error occurs
39      * @doc:tag type="block"
40      * @doc:param name="tagName" optional="false" description="The tag name that must be present in at
41      * least one class in the package in order that the template be generated."
42      */

43     public void forAllPackages(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
44     {
45         if (getCurrentPackage() == null) {
46             Collection JavaDoc packages = getXJavaDoc().getSourcePackages();
47
48             for (Iterator JavaDoc i = packages.iterator(); i.hasNext(); ) {
49                 XPackage pakkage = (XPackage) i.next();
50
51                 setCurrentPackage(pakkage);
52
53                 Collection JavaDoc classes = getCurrentPackage().getClasses();
54
55                 for (Iterator JavaDoc j = classes.iterator(); j.hasNext(); ) {
56                     XDoc doc = ((XClass) j.next()).getDoc();
57
58                     if (doc.hasTag("jdo.persistence-capable")) {
59                         generate(template);
60                         break;
61                     }
62                 }
63                 setCurrentPackage(null);
64             }
65         }
66         else {
67             Collection JavaDoc classes = getCurrentPackage().getClasses();
68
69             for (Iterator JavaDoc j = classes.iterator(); j.hasNext(); ) {
70                 XDoc doc = ((XClass) j.next()).getDoc();
71
72                 if (doc.hasTag("jdo.persistence-capable")) {
73                     generate(template);
74                     break;
75                 }
76             }
77         }
78     }
79
80     /**
81      * The <code>forAllClassesInPackage</code> method iterates through all the classes in the current package.
82      *
83      * @param template a <code>String</code> value
84      * @param attributes a <code>Properties</code> value
85      * @exception XDocletException if an error occurs
86      * @doc:tag type="block"
87      */

88     public void forAllClassesInPackage(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
89     {
90         if (getCurrentClass() == null) {
91
92             Collection JavaDoc classes = getCurrentPackage().getClasses();
93
94             for (Iterator JavaDoc i = classes.iterator(); i.hasNext(); ) {
95                 setCurrentClass((XClass) i.next());
96                 generate(template);
97             }
98         }
99         else {
100             generate(template);
101         }
102
103     }
104
105     /**
106      * Generates the tag body for each vendor extension at the specified level.
107      *
108      * @param attributes
109      * @param template
110      * @exception XDocletException
111      * @doc.tag type="block"
112      * @doc.param name="level" optional="false" values="class,field,collection,array,map"
113      * description="The level to generate the extension tags for."
114      */

115     public void forAllVendorExtensions(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
116     {
117         String JavaDoc level = attributes.getProperty("level");
118         SubTask[] subtasks = getDocletContext().getSubTasks();
119
120         _extensions = new ArrayList JavaDoc();
121         for (int i = 0; i < subtasks.length; i++) {
122             if (subtasks[i] instanceof VendorExtensionsSubTask) {
123                 VendorExtensionsSubTask vendorExtensionsTask = (VendorExtensionsSubTask) subtasks[i];
124
125                 _extensions.addAll(vendorExtensionsTask.getExtensions(level));
126             }
127         }
128
129         for (Iterator JavaDoc i = _extensions.iterator(); i.hasNext(); ) {
130             setCurrentVendorExtension((VendorExtension) i.next());
131             generate(template);
132         }
133     }
134
135     /**
136      * Generates the extension element for the current vendor extension.
137      *
138      * @param attributes
139      * @return Current &lt;extension&gt; element.
140      * @doc.tag type="content"
141      */

142     public String JavaDoc vendorExtension(Properties JavaDoc attributes)
143     {
144         StringBuffer JavaDoc tags = new StringBuffer JavaDoc();
145
146         tags.append("<extension vendor-name=\"");
147         tags.append(_currentExtension.getVendor());
148         tags.append("\" key=\"");
149         tags.append(_currentExtension.getKey());
150         tags.append("\" value=\"");
151         tags.append(_currentExtension.getValue());
152         tags.append("\"");
153         if (_currentExtension.hasNestedExtensions()) {
154             tags.append(">");
155             for (Iterator JavaDoc i = _currentExtension.nestedExtensionsIterator(); i.hasNext(); ) {
156                 VendorExtension popVendorExtension = _currentExtension;
157
158                 setCurrentVendorExtension((VendorExtension) i.next());
159                 tags.append(vendorExtension(attributes));
160                 setCurrentVendorExtension(popVendorExtension);
161             }
162             tags.append("</extension>");
163         }
164         else {
165             tags.append("/>");
166         }
167         return tags.toString();
168     }
169
170     protected void setCurrentVendorExtension(VendorExtension vendorExtension)
171     {
172         _currentExtension = vendorExtension;
173     }
174
175 }
176
Popular Tags