KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > lookup > LookupUtilTagsHandler


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

5 package xdoclet.modules.ejb.lookup;
6
7 import java.text.MessageFormat JavaDoc;
8 import java.util.Properties JavaDoc;
9 import org.apache.commons.logging.Log;
10
11 import xjavadoc.XClass;
12 import xdoclet.DocletContext;
13 import xdoclet.DocletTask;
14 import xdoclet.XDocletException;
15 import xdoclet.modules.ejb.EjbTagsHandler;
16
17 import xdoclet.modules.ejb.lookup.LookupObjectSubTask;
18 import xdoclet.util.LogUtil;
19
20 /**
21  * @author Ara Abrahamian (ara_e@email.com)
22  * @created Oct 15, 2001
23  * @xdoclet.taghandler namespace="EjbUtilObj"
24  * @version $Revision: 1.11 $
25  */

26 public class LookupUtilTagsHandler extends EjbTagsHandler
27 {
28     /**
29      * Similar to {@link xdoclet.modules.ejb.intf.InterfaceTagsHandler#getComponentInterface}. Relies on the ejb:home
30      * tag, which has the following relevant properties:
31      * <ul>
32      * <li> remote-class: The fully qualified name of the remote class - overrides all set patterns
33      * <li> local-class: The fully qualified name of the local class - overrides all set patterns
34      * <li> remote-pattern: The pattern to be used to determine the unqualified name of the remote class
35      * <li> local-pattern: The pattern to be used to determine the unqualified name of the local class
36      * <li> pattern: The pattern to be used in determining the unqualified remote and/or local home interface name -
37      * used where remote- or local- pattern are not specified.
38      * <li> remote-package: The package the remote home interface is to be placed in
39      * <li> local-package: The package the local home interface is to be placed in
40      * <li> package: The package the remote and/or local home interface is to be placed in - used where remote- or
41      * local- package are not specified.
42      * </ul>
43      *
44      *
45      * @param clazz Description of Parameter
46      * @return The HomeInterface value
47      */

48     public static String JavaDoc getUtilClassFor(XClass clazz)
49     {
50         Log log = LogUtil.getLog(LookupUtilTagsHandler.class, "utilClassName");
51
52         String JavaDoc fileName = clazz.getContainingPackage().getName();
53         String JavaDoc utilPattern = null;
54
55         if (log.isDebugEnabled()) {
56             log.debug("utility object for " + clazz.getQualifiedName());
57         }
58
59         utilPattern = getUtilClassPattern();
60
61         String JavaDoc ejbName = null;
62         String JavaDoc packagePattern = null;
63
64         if (utilPattern.indexOf("{0}") != -1) {
65             ejbName = MessageFormat.format(utilPattern, new Object JavaDoc[]{getShortEjbNameFor(clazz)});
66         }
67         else {
68             ejbName = utilPattern;
69         }
70
71         // Fix package name
72
fileName = choosePackage(fileName, packagePattern, DocletTask.getSubTaskName(LookupObjectSubTask.class));
73         fileName += '.' + ejbName;
74
75         return fileName;
76     }
77
78     /**
79      * Gets the UtilClassPattern attribute of the UtilTagsHandler class
80      *
81      * @return The UtilClassPattern value
82      */

83     protected static String JavaDoc getUtilClassPattern()
84     {
85         LookupObjectSubTask utilSubtask = ((LookupObjectSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(LookupObjectSubTask.class)));
86
87         if (utilSubtask != null) {
88             return utilSubtask.getUtilClassPattern();
89         }
90         else {
91             return LookupObjectSubTask.DEFAULT_UTIL_CLASS_PATTERN;
92         }
93     }
94
95     /**
96      * Describe what the method does
97      *
98      * @return Describe the return value
99      * @exception XDocletException
100      */

101     public String JavaDoc lookupKind() throws XDocletException
102     {
103         String JavaDoc kind = getTagValue(
104             FOR_CLASS,
105             getCurrentClass().getDoc(),
106             "ejb:util",
107             "generate",
108             "physical,logical",
109             null,
110             true,
111             false
112             );
113
114         //if explicitly specified then use it, otherwise use the kind config param of <utilobject/>
115
if (kind == null) {
116             kind = (String JavaDoc) getDocletContext().getConfigParam(DocletTask.getSubTaskName(LookupObjectSubTask.class) + ".kind");
117         }
118
119         if (kind.equals("physical")) {
120             return "JNDI_NAME";
121         }
122         else {
123             return "COMP_NAME";
124         }
125     }
126
127     /**
128      * Returns the full qualified utility class name for the bean
129      *
130      * @param attributes The attributes of the template tag
131      * @return Utility class name
132      * @exception XDocletException
133      * @doc.tag type="content"
134      */

135     public String JavaDoc utilClass(Properties JavaDoc attributes) throws XDocletException
136     {
137         return getUtilClassFor(getCurrentClass());
138     }
139
140 }
141
142
Popular Tags