KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > caucho > ResinEjbTagsHandler


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

5 package xdoclet.modules.caucho;
6
7 import xjavadoc.XMethod;
8
9 import xdoclet.XDocletException;
10 import xdoclet.modules.ejb.dd.RelationTagsHandler;
11
12 /**
13  * Template tags handler used by resin-ejb.j and resin-relationships.j to add resin cmp-specific configuration
14  * (resin.ejb) to the standard deployment descriptor.
15  *
16  * @author Yoritaka Sakakura (yori@teardrop.org)
17  * @created June 5, 2002
18  * @see <a HREF="http://caucho.com/products/resin-ejb/ejb-ref/resin-ejb-config.xtp">Resin CMP
19  * Configuration</a>
20  * @xdoclet.taghandler namespace="ResinEjb"
21  */

22 public class ResinEjbTagsHandler extends RelationTagsHandler
23 {
24     private final static String JavaDoc RELATION_TAG = "resin-ejb:relation";
25
26     /**
27      * Evaluates the body if the left side of the relationship is many and the order-by parameter of the
28      * resinejb:relation method-level tag is defined.
29      *
30      * @param template
31      * @exception XDocletException
32      * @doc.tag type="block"
33      */

34     public void ifHasLeftOrderBy(String JavaDoc template)
35          throws XDocletException
36     {
37         if (leftOrderBy() != null)
38             generate(template);
39     }
40
41     /**
42      * Evaluates the body if the left side of the relationship is single and the sql-column parameter of the
43      * resinejb:relation method-level tag is defined.
44      *
45      * @param template
46      * @exception XDocletException
47      * @doc.tag type="block"
48      */

49     public void ifHasLeftSqlColumn(String JavaDoc template)
50          throws XDocletException
51     {
52         if (leftSqlColumn() != null)
53             generate(template);
54     }
55
56     /**
57      * Evaluates the body if the right side of the relationship is many and the order-by parameter of the
58      * resinejb:relation method-level tag is defined.
59      *
60      * @param template
61      * @exception XDocletException
62      * @doc.tag type="block"
63      */

64     public void ifHasRightOrderBy(String JavaDoc template)
65          throws XDocletException
66     {
67         if (rightOrderBy() != null)
68             generate(template);
69     }
70
71     /**
72      * Evaluates the body if the right side of the relationship is single and the sql-column parameter of the
73      * resinejb:relation method-level tag is defined.
74      *
75      * @param template
76      * @exception XDocletException
77      * @doc.tag type="block"
78      */

79     public void ifHasRightSqlColumn(String JavaDoc template)
80          throws XDocletException
81     {
82         if (rightSqlColumn() != null)
83             generate(template);
84     }
85
86     /**
87      * Evaluates the body if either side of the current relation is many and the sql-table parameter of the
88      * resinejb:relation method-level tag is defined.
89      *
90      * @param template
91      * @exception XDocletException
92      * @doc.tag type="block"
93      */

94     public void ifHasSqlTable(String JavaDoc template)
95          throws XDocletException
96     {
97         if (sqlTable() != null)
98             generate(template);
99     }
100
101     /**
102      * Returns the order-by for the left side of the current relation, if applicable.
103      *
104      * @return
105      * @exception XDocletException
106      * @see #ifHasLeftOrderBy(String)
107      * @doc.tag type="content"
108      */

109     public String JavaDoc leftOrderBy()
110          throws XDocletException
111     {
112         if (!currentRelation.isLeftMany())
113             return null;
114         else
115             return getMethodTagValue(RELATION_TAG, "order-by", true);
116     }
117
118     /**
119      * Returns the sql-column for the left side of the current relation, if applicable.
120      *
121      * @return
122      * @exception XDocletException
123      * @see #ifHasLeftSqlColumn(String)
124      * @doc.tag type="content"
125      */

126     public String JavaDoc leftSqlColumn()
127          throws XDocletException
128     {
129         return getMethodTagValue(RELATION_TAG, "sql-column", true);
130     }
131
132     /**
133      * Returns the order-by for the right side of the current relation, if applicable.
134      *
135      * @return
136      * @exception XDocletException
137      * @see #ifHasRightOrderBy(String)
138      * @doc.tag type="content"
139      */

140     public String JavaDoc rightOrderBy()
141          throws XDocletException
142     {
143         if (!currentRelation.isRightMany())
144             return null;
145         else
146             return getMethodTagValue(RELATION_TAG, "order-by", false);
147     }
148
149     /**
150      * Returns the sql-column for the right side of the current relation, if applicable.
151      *
152      * @return
153      * @exception XDocletException
154      * @see #ifHasRightSqlColumn(String)
155      * @doc.tag type="content"
156      */

157     public String JavaDoc rightSqlColumn()
158          throws XDocletException
159     {
160         String JavaDoc rightValue = getMethodTagValue(RELATION_TAG, "sql-column", false);
161
162         if (rightValue != null)
163             return rightValue;
164         else
165             return getMethodTagValue(RELATION_TAG, "target-sql-column", true);
166     }
167
168     /**
169      * Returns the signature of the current method in a form suitable for the
170      * /resinejb/enterprise-beans/entity/method/signature element.
171      *
172      * @return
173      * @exception XDocletException
174      * @doc.tag type="content"
175      */

176     public String JavaDoc signatureFromMethod()
177          throws XDocletException
178     {
179         XMethod method = getCurrentMethod();
180
181         if (method == null)
182             throw L.error(L.NO_CURRENT_METHOD);
183         else
184             return method.getNameWithSignature(false);
185     }
186
187     /**
188      * Returns the sql-table of the current relationship, if any.
189      *
190      * @return
191      * @exception XDocletException
192      * @see #ifHasSqlTable(String)
193      * @doc.tag type="content"
194      */

195     public String JavaDoc sqlTable()
196          throws XDocletException
197     {
198         String JavaDoc sqlTable = null;
199
200         if (currentRelation.isLeftMany())
201             sqlTable = getMethodTagValue(RELATION_TAG, "sql-table", true);
202         if (sqlTable == null && currentRelation.isRightMany())
203             sqlTable = getMethodTagValue(RELATION_TAG, "sql-table", false);
204
205         return sqlTable;
206     }
207
208
209     private String JavaDoc getMethodTagValue(String JavaDoc tagName, String JavaDoc paramName, boolean left)
210          throws XDocletException
211     {
212         XMethod method = left ? currentRelation.getLeftMethod() : currentRelation.getRightMethod();
213
214         if (method == null)
215             return null;
216         else
217             return getTagValue(FOR_METHOD, method.getDoc(), tagName, paramName, null, null, false, false);
218     }
219 }
220
Popular Tags