1 5 package xdoclet.modules.ejb.mdb; 6 7 import java.text.MessageFormat ; 8 9 import java.util.*; 10 11 import xjavadoc.*; 12 13 import xdoclet.DocletContext; 14 import xdoclet.DocletSupport; 15 import xdoclet.DocletTask; 16 import xdoclet.XDocletException; 17 import xdoclet.modules.ejb.EjbTagsHandler; 18 19 25 public class MdbTagsHandler extends EjbTagsHandler 26 { 27 28 private XTag currentDestination; 29 30 36 public static String getMessageDrivenClassFor(XClass clazz) 37 { 38 String fileName = clazz.getContainingPackage().getName(); 39 String mdbName = MessageFormat.format(getMessageDrivenClassPattern(), new Object []{getShortEjbNameFor(clazz)}); 40 41 fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(MdbSubTask.class)); 43 if (fileName.length() > 0) { 44 fileName += "."; 45 } 46 47 fileName += mdbName; 48 49 return fileName; 50 } 51 52 58 public static boolean isMessageDriven(XClass clazz) 59 { 60 return clazz.isA("javax.ejb.MessageDrivenBean"); 61 } 62 63 68 protected static String getMessageDrivenClassPattern() 69 { 70 MdbSubTask mdbSubtask = ((MdbSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(MdbSubTask.class))); 71 72 if (mdbSubtask != null) { 73 return mdbSubtask.getMessageDrivenClassPattern(); 74 } 75 else { 76 return MdbSubTask.DEFAULT_MESSAGE_DRIVEN_CLASS_PATTERN; 77 } 78 } 79 80 88 public void forAllMDBeans(String template) throws XDocletException 89 { 90 Collection classes = getXJavaDoc().getSourceClasses(); 91 92 for (Iterator i = classes.iterator(); i.hasNext(); ) { 93 XClass clazz = (XClass) i.next(); 94 95 setCurrentClass(clazz); 96 97 if (DocletSupport.isDocletGenerated(getCurrentClass())) { 98 continue; 99 } 100 101 if (!hasHavingClassTag(getCurrentClass())) { 102 continue; 103 } 104 105 if (isMessageDriven(getCurrentClass())) { 106 generate(template); 107 } 108 } 109 } 110 111 118 public void ifMessageDriven(String template) throws XDocletException 119 { 120 if (isMessageDriven(getCurrentClass())) { 121 generate(template); 122 } 123 } 124 125 132 public void ifNotMessageDriven(String template) throws XDocletException 133 { 134 if (!isMessageDriven(getCurrentClass())) { 135 generate(template); 136 } 137 } 138 139 146 public String messageDrivenClass() throws XDocletException 147 { 148 return getMessageDrivenClassFor(getCurrentClass()); 149 } 150 151 158 public String mdbClass() throws XDocletException 159 { 160 return getMessageDrivenClassFor(getCurrentClass()); 161 } 162 163 164 172 public void ifHasActivationConfig(String template, Properties attributes) throws XDocletException 173 { 174 if (hasActivationConfig()) { 175 generate(template); 176 } 177 } 178 179 189 public void forAllDestinations(String template) throws XDocletException 190 { 191 Collection classes = getXJavaDoc().getSourceClasses(); 192 193 Map dests = new HashMap(); 194 195 for (Iterator i = classes.iterator(); i.hasNext(); ) { 196 XClass clazz = (XClass) i.next(); 197 198 setCurrentClass(clazz); 199 200 if (getCurrentClass().getDoc().hasTag("ejb.message-destination")) { 201 XTag tag = getCurrentClass().getDoc().getTag("ejb.message-destination"); 202 String destName = tag.getAttributeValue("name"); 203 204 if (destName != null) { 205 dests.put(destName, tag); 206 } 207 } 208 } 209 210 for (Iterator it = dests.values().iterator(); it.hasNext(); ) { 212 currentDestination = (XTag) it.next(); 213 214 generate(template); 215 } 216 } 217 218 226 public String destinationName() throws XDocletException 227 { 228 return currentDestination.getAttributeValue("name"); 229 } 230 231 239 public String destinationDisplayName() throws XDocletException 240 { 241 return currentDestination.getAttributeValue("display-name"); 242 } 243 244 251 public void ifDestinationHasDisplayName(String template) throws XDocletException 252 { 253 if (destinationDisplayName() != null) { 254 generate(template); 255 } 256 } 257 258 266 public String destinationJndiName() throws XDocletException 267 { 268 return currentDestination.getAttributeValue("jndi-name"); 269 } 270 271 278 public void ifDestinationHasJndiName(String template) throws XDocletException 279 { 280 if (destinationJndiName() != null) { 281 generate(template); 282 } 283 } 284 285 293 public String destinationDescription() throws XDocletException 294 { 295 return currentDestination.getAttributeValue("description"); 296 } 297 298 305 public void ifDestinationHasDescription(String template) throws XDocletException 306 { 307 if (destinationDescription() != null) { 308 generate(template); 309 } 310 } 311 312 318 private boolean hasActivationConfig() throws XDocletException 319 { 320 Properties props = new Properties(); 321 322 props.setProperty("tagName", "ejb.bean"); 323 props.setProperty("paramName", "destination-type"); 324 if (hasTag(props, FOR_CLASS)) { 325 return true; 326 } 327 328 props.setProperty("paramName", "acknowledge-mode"); 329 if (hasTag(props, FOR_CLASS)) { 330 return true; 331 } 332 333 props.setProperty("paramName", "subscription-durability"); 334 if (hasTag(props, FOR_CLASS)) { 335 return true; 336 } 337 338 props.setProperty("paramName", "message-selector"); 339 if (hasTag(props, FOR_CLASS)) { 340 return true; 341 } 342 343 props.setProperty("tagName", "ejb.activation-config-property"); 344 props.setProperty("paramName", ""); 345 return hasTag(props, FOR_CLASS); 346 } 347 348 } 349 350 | Popular Tags |