KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > borland > bes > ejb > BorlandRelationTagsHandler


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

5 package xdoclet.modules.borland.bes.ejb;
6
7 import java.util.*;
8
9 import xjavadoc.*;
10 import xdoclet.XDocletException;
11 import xdoclet.modules.ejb.dd.RelationTagsHandler;
12
13 /**
14  * This tag handler handles tags needed for Web
15  *
16  * @author <a HREF="mailto:mmaczka@cqs.ch">Michal Maczka</a>
17  * @created 12 mei 2002
18  * @xdoclet.taghandler namespace="BesEjbRel"
19  * @version $Revision: 1.4 $
20  */

21 public class BorlandRelationTagsHandler extends RelationTagsHandler
22 {
23
24     private final static String JavaDoc BES_RELATION = "bes.relation";
25
26     /**
27      * Describe what the method does
28      *
29      * @return Describe the return value
30      * @exception XDocletException Describe the exception
31      * @doc.tag type="content"
32      */

33     public String JavaDoc leftTableName() throws XDocletException
34     {
35         // We say mandatory is false (last parameter), so we can provide a more detailed error message.
36
String JavaDoc leftTableName =
37             currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
38             BES_RELATION,
39             "left-table-name",
40             false);
41
42         return leftTableName;
43     }
44
45     /**
46      * Describe what the method does
47      *
48      * @return Describe the return value
49      * @exception XDocletException Describe the exception
50      * @doc.tag type="content"
51      */

52     public String JavaDoc defaultLeftTableName() throws XDocletException
53     {
54         ;
55
56         XClass clazz = currentRelation.getLeft();
57         XTag persistenceTag = clazz.getDoc().getTag("ejb.persistence");
58
59         if (persistenceTag != null) {
60             String JavaDoc tableName = persistenceTag.getAttributeValue("table-name");
61
62             return tableName;
63         }
64         return "??";
65     }
66
67     /**
68      * Describe what the method does
69      *
70      * @param template Describe what the parameter does
71      * @exception XDocletException Describe the exception
72      * @doc.tag type="block"
73      */

74     public void ifHasLeftTableName(String JavaDoc template) throws XDocletException
75     {
76         if (leftTableName() != null) {
77             generate(template);
78         }
79     }
80
81     /**
82      * Describe what the method does
83      *
84      * @param template Describe what the parameter does
85      * @exception XDocletException Describe the exception
86      * @doc.tag type="block"
87      */

88     public void ifDoesntHaveLeftTableName(String JavaDoc template)
89          throws XDocletException
90     {
91         if (leftTableName() == null) {
92             generate(template);
93         }
94     }
95
96     /**
97      * Describe what the method does
98      *
99      * @return Describe the return value
100      * @exception XDocletException Describe the exception
101      * @doc.tag type="content"
102      */

103     public String JavaDoc leftColumnName() throws XDocletException
104     {
105
106         String JavaDoc leftColumnName =
107             currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
108             BES_RELATION,
109             "left-column-name",
110             false);
111
112         return leftColumnName;
113     }
114
115     /**
116      * Describe what the method does
117      *
118      * @param template Describe what the parameter does
119      * @exception XDocletException Describe the exception
120      * @doc.tag type="block"
121      */

122     public void ifHasLeftColumnName(String JavaDoc template) throws XDocletException
123     {
124         if (leftColumnName() != null) {
125             generate(template);
126         }
127     }
128
129     /**
130      * Describe what the method does
131      *
132      * @param template Describe what the parameter does
133      * @exception XDocletException Describe the exception
134      * @doc.tag type="block"
135      */

136     public void ifDoesntHaveLeftColumnName(String JavaDoc template)
137          throws XDocletException
138     {
139         if (leftColumnName() == null) {
140             generate(template);
141         }
142     }
143
144     /**
145      * Describe what the method does
146      *
147      * @return Describe the return value
148      * @exception XDocletException Describe the exception
149      * @doc.tag type="content"
150      */

151     public String JavaDoc defaultLeftColumnName() throws XDocletException
152     {
153         // We say mandatory is false (last parameter), so we can provide a more detailed error message.
154
String JavaDoc defaultLeftColumnName =
155             currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
156             "ejb.persistence",
157             "column-name",
158             false);
159
160         return defaultLeftColumnName;
161     }
162
163     /**
164      * Describe what the method does
165      *
166      * @return Describe the return value
167      * @exception XDocletException Describe the exception
168      * @doc.tag type="content"
169      */

170     public String JavaDoc rightTableName() throws XDocletException
171     {
172
173         String JavaDoc rightTableName =
174             currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
175             BES_RELATION,
176             "right-table-name",
177             false);
178
179         return rightTableName;
180     }
181
182     /**
183      * Describe what the method does
184      *
185      * @return Describe the return value
186      * @exception XDocletException Describe the exception
187      * @doc.tag type="content"
188      */

189     public String JavaDoc defaultRightTableName() throws XDocletException
190     {
191
192         Collection classes = getXJavaDoc().getSourceClasses();
193
194         for (Iterator i = classes.iterator(); i.hasNext(); ) {
195             XClass clazz = (XClass) i.next();
196
197             XTag ejbBeanTag = clazz.getDoc().getTag("ejb.bean");
198
199             if (ejbBeanTag != null) {
200                 String JavaDoc name = ejbBeanTag.getAttributeValue("name");
201
202                 if (
203                     name != null
204                     &&
205                     name.equals(rightEJBName())
206                     ) {
207                     XTag persistenceTag = clazz.getDoc().getTag("ejb.persistence");
208
209                     if (persistenceTag != null) {
210                         String JavaDoc tableName = persistenceTag.getAttributeValue("table-name");
211
212                         return tableName;
213                     }
214                     else {
215                         throw new XDocletException(name + " Bean found, but it it's not having '@ejb.persistence table-name' tag");
216                     }
217
218                 }
219
220             }
221         }
222         throw new XDocletException("Cannot resolve defaultRightTableName. Probably '@ejb.persistence table-name' tag is not existing in right side bean");
223     }
224
225
226     /**
227      * Describe what the method does
228      *
229      * @param template Describe what the parameter does
230      * @exception XDocletException Describe the exception
231      * @doc.tag type="block"
232      */

233     public void ifHasRightTableName(String JavaDoc template)
234          throws XDocletException
235     {
236         if (rightTableName() != null) {
237             generate(template);
238         }
239     }
240
241     /**
242      * Describe what the method does
243      *
244      * @param template Describe what the parameter does
245      * @exception XDocletException Describe the exception
246      * @doc.tag type="block"
247      */

248     public void ifDoesntHaveRightTableName(String JavaDoc template)
249          throws XDocletException
250     {
251         if (rightTableName() == null) {
252             generate(template);
253         }
254     }
255
256     /**
257      * Describe what the method does
258      *
259      * @return Describe the return value
260      * @exception XDocletException Describe the exception
261      * @doc.tag type="content"
262      */

263     public String JavaDoc rightColumnName() throws XDocletException
264     {
265         // We say mandatory is false (last parameter), so we can provide a more detailed error message.
266
String JavaDoc rightColumnName =
267             currentRelation.getLeftMethod()
268             .getDoc()
269             .getTagAttributeValue(
270             BES_RELATION,
271             "right-column-name",
272             false);
273
274         return rightColumnName;
275     }
276
277     /**
278      * Default right colum name is pk field of the right side bean..
279      *
280      * @return Describe the return value
281      * @exception XDocletException Describe the exception
282      * @doc.tag type="content"
283      */

284     public String JavaDoc defaultRightColumnName() throws XDocletException
285     {
286         Collection classes = getXJavaDoc().getSourceClasses();
287
288         for (Iterator i = classes.iterator(); i.hasNext(); ) {
289             XClass clazz = (XClass) i.next();
290
291             XTag ejbBeanTag = clazz.getDoc().getTag("ejb.bean");
292
293             if (ejbBeanTag != null) {
294                 String JavaDoc name = ejbBeanTag.getAttributeValue("name");
295
296                 if (
297                     name != null
298                     &&
299                     name.equals(rightEJBName())
300                     ) {
301                     XTag persistenceTag = clazz.getDoc().getTag("ejb.bean");
302
303                     if (persistenceTag != null) {
304                         String JavaDoc tableName = persistenceTag.getAttributeValue("primkey-field");
305
306                         return tableName;
307                     }
308                     else {
309                         throw new XDocletException("Bean found, but does not have '@ejb.bean primkey-field' tag");
310                     }
311
312                 }
313
314             }
315         }
316         throw new XDocletException("Cannot resolve deafultRightColumnNam. Probably '@ejb.bean primkey-field' tag is not existing in right size bean");
317     }
318
319     /**
320      * Describe what the method does
321      *
322      * @param template Describe what the parameter does
323      * @exception XDocletException Describe the exception
324      * @doc.tag type="block"
325      */

326     public void ifHasRightColumnName(String JavaDoc template)
327          throws XDocletException
328     {
329         if (rightColumnName() != null) {
330             generate(template);
331         }
332     }
333
334     /**
335      * Describe what the method does
336      *
337      * @param template Describe what the parameter does
338      * @exception XDocletException Describe the exception
339      * @doc.tag type="block"
340      */

341     public void ifDoesntHaveRightColumnName(String JavaDoc template)
342          throws XDocletException
343     {
344         if (rightColumnName() == null) {
345             generate(template);
346         }
347     }
348
349 }
350
Popular Tags