KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > entity > FacadeTagsHandler


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

5 package xdoclet.modules.ejb.entity;
6
7 import java.text.MessageFormat JavaDoc;
8 import java.util.*;
9
10 import xjavadoc.*;
11 import xdoclet.DocletContext;
12
13 import xdoclet.DocletTask;
14 import xdoclet.XDocletException;
15 import xdoclet.XDocletTagSupport;
16 import xdoclet.modules.ejb.EjbTagsHandler;
17 import xdoclet.modules.ejb.entity.EntityFacadeSubTask;
18 import xdoclet.modules.ejb.session.RemoteFacadeSubTask;
19
20 /**
21  * @author Konstantin Pribluda (kpriblouda@yahoo.com)
22  * @created September 8, 2002
23  * @xdoclet.taghandler namespace="EjbFacade"
24  * @version $Revision: 1.3 $
25  */

26 public class FacadeTagsHandler extends EntityTagsHandler
27 {
28
29     public static String JavaDoc getEntityFacadeClassFor(XClass clazz)
30     {
31         String JavaDoc fileName = clazz.getContainingPackage().getName();
32         String JavaDoc entityName = MessageFormat.format(getEntityFacadeClassPattern(), new Object JavaDoc[]{EjbTagsHandler.getShortEjbNameFor(clazz)});
33
34
35         // Fix package name
36
fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(EntityFacadeSubTask.class));
37         if (fileName.length() > 0) {
38             fileName += ".";
39         }
40
41         fileName += entityName;
42
43         return fileName;
44     }
45
46     public static String JavaDoc getRemoteFacadeClassFor(XClass clazz)
47     {
48         String JavaDoc fileName = clazz.getContainingPackage().getName();
49         String JavaDoc entityName = MessageFormat.format(getRemoteFacadeClassPattern(), new Object JavaDoc[]{EjbTagsHandler.getShortEjbNameFor(clazz)});
50
51
52         // Fix package name
53
fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(RemoteFacadeSubTask.class));
54         if (fileName.length() > 0) {
55             fileName += ".";
56         }
57
58         fileName += entityName;
59
60         return fileName;
61     }
62
63     /**
64      * Gets the EntityFacadeClassPattern attribute of the CmpTagsHandler class
65      *
66      * @return The EntityFacadeClassPattern value
67      */

68     protected static String JavaDoc getRemoteFacadeClassPattern()
69     {
70         RemoteFacadeSubTask remoteFacadeSubtask = ((RemoteFacadeSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(RemoteFacadeSubTask.class)));
71
72         if (remoteFacadeSubtask != null) {
73             return remoteFacadeSubtask.getRemoteFacadeClassPattern();
74         }
75         else {
76             return RemoteFacadeSubTask.DEFAULT_REMOTE_FACADE_CLASS_PATTERN;
77         }
78     }
79
80
81     protected static String JavaDoc getEntityFacadeClassPattern()
82     {
83         EntityFacadeSubTask entityFacadeSubtask = ((EntityFacadeSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(EntityFacadeSubTask.class)));
84
85         if (entityFacadeSubtask != null) {
86             return entityFacadeSubtask.getEntityFacadeClassPattern();
87         }
88         else {
89             return EntityFacadeSubTask.DEFAULT_ENTITY_FACADE_CLASS_PATTERN;
90         }
91     }
92
93
94     /**
95      * Gets the EntityFacadeEjbNamePattern attribute of the FacadeTagsHandler class
96      *
97      * @return The EntityFacadeEjbNamePattern value
98      */

99     protected static String JavaDoc getEntityFacadeEjbNamePattern()
100     {
101         EntityFacadeSubTask entityFacadeSubtask = ((EntityFacadeSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(EntityFacadeSubTask.class)));
102
103         if (entityFacadeSubtask != null) {
104             return entityFacadeSubtask.getEntityFacadeEjbNamePattern();
105         }
106         else {
107             return EntityFacadeSubTask.DEFAULT_FACADE_EJB_NAME_PATTERN;
108         }
109     }
110
111     public String JavaDoc getFacadeEjbNameFor(XClass clazz) throws XDocletException
112     {
113         // do we have name specified?
114
String JavaDoc name = clazz.getDoc().getTagAttributeValue("ejb.facade", "name", false);
115
116         if (name != null && !"".equals(name)) {
117             return name;
118         }
119         else {
120             return MessageFormat.format(getEntityFacadeEjbNamePattern(), new Object JavaDoc[]{EjbTagsHandler.getShortEjbNameFor(clazz)});
121         }
122
123     }
124
125     /**
126      * produce class name for ejb facade
127      *
128      * @return
129      * @exception XDocletException
130      * @doc.tag type="content"
131      */

132     public String JavaDoc entityFacadeClass() throws XDocletException
133     {
134         return getEntityFacadeClassFor(XDocletTagSupport.getCurrentClass());
135     }
136
137     /**
138      * @return
139      * @exception XDocletException
140      * @doc.tag type="content"
141      */

142     public String JavaDoc remoteFacadeClass() throws XDocletException
143     {
144         return getRemoteFacadeClassFor(XDocletTagSupport.getCurrentClass());
145     }
146
147
148     /**
149      * prodice facade ejb name. Default would be
150      *
151      * @return
152      * @exception XDocletException
153      * @doc.tag type="content"
154      */

155     public String JavaDoc facadeEjbName() throws XDocletException
156     {
157         return getFacadeEjbNameFor(XDocletTagSupport.getCurrentClass());
158     }
159
160     public boolean canUseLocal() throws XDocletException
161     {
162         XClass clazz = XDocletTagSupport.getCurrentClass();
163
164         return !EjbTagsHandler.isOnlyRemoteEjb(clazz);
165     }
166
167     /**
168      * decide whether we have to use local interface of the bean
169      *
170      * @param template
171      * @param attributes
172      * @exception XDocletException
173      * @doc.tag type="block"
174      */

175     public void ifUseLocalInterface(String JavaDoc template, Properties attributes) throws XDocletException
176     {
177         if (canUseLocal()) {
178             generate(template);
179         }
180     }
181
182     /**
183      * decide whether we have to use remote interface of the bean
184      *
185      * @param template
186      * @param attributes
187      * @exception XDocletException
188      * @doc.tag type="block"
189      */

190     public void ifUseRemoteInterface(String JavaDoc template, Properties attributes) throws XDocletException
191     {
192         if (!canUseLocal()) {
193             generate(template);
194         }
195     }
196
197     /**
198      * provide session type
199      *
200      * @return
201      * @exception XDocletException
202      * @doc.tag type="content"
203      */

204     public String JavaDoc sessionType() throws XDocletException
205     {
206         XClass clazz = XDocletTagSupport.getCurrentClass();
207         String JavaDoc type = clazz.getDoc().getTagAttributeValue("ejb.facade", "type", false);
208
209         if ("Statefull".equals(type)) {
210             return "Statefull";
211         }
212         else {
213             return "Stateless";
214         }
215     }
216
217     /**
218      * provide view type for facade bean - inherit from class if not specified
219      *
220      * @return
221      * @exception XDocletException
222      * @doc.tag type="content"
223      */

224     public String JavaDoc viewType() throws XDocletException
225     {
226         XClass clazz = XDocletTagSupport.getCurrentClass();
227         String JavaDoc type = clazz.getDoc().getTagAttributeValue("ejb.bean", "view-type", false);
228         String JavaDoc facadeType = clazz.getDoc().getTagAttributeValue("ejb.facade", "view-type", false);
229
230         if (facadeType != null) {
231             return facadeType;
232         }
233
234         if (type != null) {
235             return type;
236         }
237
238         return "remote";
239     }
240
241     /**
242      * local jndi name if any
243      *
244      * @return
245      * @exception XDocletException
246      * @doc.tag type="content"
247      */

248     public String JavaDoc localJndiName() throws XDocletException
249     {
250         XClass clazz = XDocletTagSupport.getCurrentClass();
251         String JavaDoc jndi = clazz.getDoc().getTagAttributeValue("ejb.facade", "local-jndi-name", false);
252
253         if (jndi != null) {
254             return jndi;
255         }
256
257         return facadeEjbName() + "Local";
258     }
259
260     /**
261      * jndi name if any or default
262      *
263      * @return
264      * @exception XDocletException
265      * @doc.tag type="content"
266      */

267     public String JavaDoc jndiName() throws XDocletException
268     {
269         XClass clazz = XDocletTagSupport.getCurrentClass();
270         String JavaDoc jndi = clazz.getDoc().getTagAttributeValue("ejb.facade", "jndi-name", false);
271
272         if (jndi != null) {
273             return jndi;
274         }
275
276         return "ejb/" + facadeEjbName();
277     }
278
279     /**
280      * generate permission spec - inherit from bean
281      *
282      * @return
283      * @exception XDocletException
284      * @doc.tag type="content"
285      */

286
287     public String JavaDoc beanPermission() throws XDocletException
288     {
289         XClass clazz = XDocletTagSupport.getCurrentClass();
290
291         String JavaDoc permission = clazz.getDoc().getTagAttributeValue("ejb.facade", "permission", false);
292
293         if (permission != null) {
294             // explicit spec, return it
295
return "* @ejb.permission role-name=\"" + permission + "\"";
296         }
297
298         String JavaDoc unchecked = clazz.getDoc().getTagAttributeValue("ejb.facade", "unchecked", false);
299
300         if (unchecked != null) {
301             // unchecked perm
302
return "* @ejb.permission unchecked=\"true\"";
303         }
304
305         // the same from bean...
306
permission = clazz.getDoc().getTagAttributeValue("ejb.permission", "role-name", true);
307
308         if (permission != null) {
309             // explicit spec, return it
310
return "* @ejb.permission role-name=\"" + permission + "\"";
311         }
312
313         unchecked = clazz.getDoc().getTagAttributeValue("ejb.permission", "unchecked", true);
314
315         if (unchecked != null) {
316             // unchecked perm
317
return "* @ejb.permission unchecked=\"true\"";
318         }
319
320         return "*";
321     }
322
323     /**
324      * generate bean reference
325      *
326      * @return
327      * @exception XDocletException
328      * @doc.tag type="content"
329      */

330
331     public String JavaDoc beanRef() throws XDocletException
332     {
333         XClass clazz = XDocletTagSupport.getCurrentClass();
334
335         if (canUseLocal()) {
336             return "* @ejb.ejb-ref ejb-name=\"" + EjbTagsHandler.getEjbNameFor(clazz) + "\" view-type=\"local\"";
337         }
338         else {
339             return "* @ejb.ejb-ref ejb-name=\"" + EjbTagsHandler.getEjbNameFor(clazz) + "\"view-type=\"remote\"";
340         }
341     }
342 }
343
Popular Tags