1 5 package xdoclet.modules.ejb.session; 6 7 import java.text.MessageFormat ; 8 import java.util.*; 9 10 import xjavadoc.*; 11 import xdoclet.DocletContext; 12 import xdoclet.DocletSupport; 13 14 import xdoclet.DocletTask; 15 import xdoclet.XDocletException; 16 import xdoclet.modules.ejb.EjbTagsHandler; 17 import xdoclet.modules.ejb.session.SessionSubTask; 18 19 25 public class SessionTagsHandler extends EjbTagsHandler 26 { 27 33 public static String getSessionClassFor(XClass clazz) 34 { 35 String fileName = clazz.getContainingPackage().getName(); 36 String sessionName = MessageFormat.format(getSessionClassPattern(), new Object []{getShortEjbNameFor(clazz)}); 37 38 fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(SessionSubTask.class)); 40 if (fileName.length() > 0) { 41 fileName += "."; 42 } 43 44 fileName += sessionName; 45 46 return fileName; 47 } 48 49 55 public static boolean isSession(XClass clazz) 56 { 57 return clazz.isA("javax.ejb.SessionBean"); 58 } 59 60 65 protected static String getSessionClassPattern() 66 { 67 SessionSubTask sessionSubtask = ((SessionSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(SessionSubTask.class))); 68 69 if (sessionSubtask != null) { 70 return sessionSubtask.getSessionClassPattern(); 71 } 72 else { 73 return SessionSubTask.DEFAULT_SESSION_CLASS_PATTERN; 74 } 75 } 76 77 85 public boolean isStatefulSession(XClass clazz) throws XDocletException 86 { 87 if (isSession(clazz) == false) { 88 return false; 89 } 90 91 String value = getCurrentClass().getDoc().getTagAttributeValue("ejb:bean", "type", false); 92 93 if (value != null && value.equals("Stateful")) { 94 return true; 95 } 96 else { 97 return false; 98 } 99 } 100 101 109 public boolean isStatelessSession(XClass clazz) throws XDocletException 110 { 111 if (isSession(clazz) == false) { 112 return false; 113 } 114 115 String value = getCurrentClass().getDoc().getTagAttributeValue("ejb:bean", "type", false); 116 117 if (value != null) { 118 return value.equals("Stateless"); 119 } 120 else { 121 if (clazz.isA("javax.ejb.SessionSynchronization")) { 123 return false; 124 } 125 126 Collection methods = clazz.getMethods(); 129 boolean hasEmptyCreateMethod = false; 130 boolean hasOtherCreateMethods = false; 131 132 for (Iterator i = methods.iterator(); i.hasNext(); ) { 133 XMethod method = (XMethod) i.next(); 134 135 if (method.getName().equals("ejbCreate") && method.getParameters().size() == 0) { 137 hasEmptyCreateMethod = true; 138 } 139 else if (method.getName().startsWith("ejbCreate") && 140 method.getParameters().size() > 0 && 141 method.getReturnType().getType().getQualifiedName().equals("void")) { 142 hasOtherCreateMethods = true; 143 } 144 } 145 146 if (hasEmptyCreateMethod == true && hasOtherCreateMethods == false) { 147 return true; 148 } 149 else { 150 return false; 151 } 152 } 153 } 154 155 162 public String sessionClass() throws XDocletException 163 { 164 return getSessionClassFor(getCurrentClass()); 165 } 166 167 175 public void ifStatelessSession(String template) throws XDocletException 176 { 177 if (isStatelessSession(getCurrentClass())) { 178 generate(template); 179 } 180 } 181 182 190 public void ifNotStatelessSession(String template) throws XDocletException 191 { 192 if (!isStatelessSession(getCurrentClass())) { 193 generate(template); 194 } 195 } 196 197 205 public void ifStatefulSession(String template) throws XDocletException 206 { 207 if (isStatefulSession(getCurrentClass())) { 208 generate(template); 209 } 210 } 211 212 220 public void ifNotStatefulSession(String template) throws XDocletException 221 { 222 if (!isStatefulSession(getCurrentClass())) { 223 generate(template); 224 } 225 } 226 227 235 public void forAllSessionBeans(String template) throws XDocletException 236 { 237 Collection classes = getXJavaDoc().getSourceClasses(); 238 239 for (Iterator i = classes.iterator(); i.hasNext(); ) { 240 XClass clazz = (XClass) i.next(); 241 242 setCurrentClass(clazz); 243 244 if (DocletSupport.isDocletGenerated(getCurrentClass())) { 245 continue; 246 } 247 248 if (!hasHavingClassTag(getCurrentClass())) { 249 continue; 250 } 251 252 if (isSession(getCurrentClass())) { 253 generate(template); 254 } 255 } 256 } 257 258 266 public void forAllStatefulSessionBeans(String template) throws XDocletException 267 { 268 Collection classes = getXJavaDoc().getSourceClasses(); 269 270 for (Iterator i = classes.iterator(); i.hasNext(); ) { 271 XClass clazz = (XClass) i.next(); 272 273 setCurrentClass(clazz); 274 275 if (DocletSupport.isDocletGenerated(getCurrentClass())) { 276 continue; 277 } 278 279 if (!hasHavingClassTag(getCurrentClass())) { 280 continue; 281 } 282 283 if (isStatefulSession(getCurrentClass())) { 284 generate(template); 285 } 286 } 287 } 288 289 297 public void forAllStatelessSessionBeans(String template) throws XDocletException 298 { 299 Collection classes = getXJavaDoc().getSourceClasses(); 300 301 for (Iterator i = classes.iterator(); i.hasNext(); ) { 302 XClass clazz = (XClass) i.next(); 303 304 setCurrentClass(clazz); 305 306 if (DocletSupport.isDocletGenerated(getCurrentClass())) { 307 continue; 308 } 309 310 if (!hasHavingClassTag(getCurrentClass())) { 311 continue; 312 } 313 314 if (isStatelessSession(getCurrentClass())) { 315 generate(template); 316 } 317 } 318 } 319 } 320 | Popular Tags |