1 5 package xdoclet.modules.ejb.mdb; 6 7 8 import org.apache.commons.logging.Log; 9 10 import xjavadoc.XClass; 11 12 import xdoclet.XDocletException; 13 import xdoclet.XDocletMessages; 14 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 15 import xdoclet.modules.ejb.EjbTagsHandler; 16 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 17 import xdoclet.tagshandler.PackageTagsHandler; 18 import xdoclet.util.LogUtil; 19 20 import xdoclet.util.Translator; 21 22 30 public class MdbSubTask extends AbstractEjbCodeGeneratorSubTask 31 { 32 public final static String DEFAULT_MESSAGE_DRIVEN_CLASS_PATTERN = "{0}Mdb"; 33 34 protected final static String DEFAULT_TEMPLATE_FILE = "resources/mdb.xdt"; 35 36 43 protected String mdbClassPattern; 44 45 46 49 public MdbSubTask() 50 { 51 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 52 setDestinationFile(getMessageDrivenClassPattern() + ".java"); 53 addOfType("javax.ejb.MessageDrivenBean"); 54 setPackageSubstitutionInheritanceSupported(false); 55 } 56 57 65 public String getMessageDrivenClassPattern() 66 { 67 if (mdbClassPattern != null) { 68 return mdbClassPattern; 69 } 70 else { 71 return DEFAULT_MESSAGE_DRIVEN_CLASS_PATTERN; 72 } 73 } 74 75 76 81 public void setPattern(String new_pattern) 82 { 83 mdbClassPattern = new_pattern; 84 } 85 86 87 92 public void validateOptions() throws XDocletException 93 { 94 super.validateOptions(); 95 96 if (getMessageDrivenClassPattern() == null || getMessageDrivenClassPattern().trim().equals("")) { 97 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 98 } 99 100 if (getMessageDrivenClassPattern().indexOf("{0}") == -1) { 101 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 102 } 103 } 104 105 106 113 protected String getGeneratedFileName(XClass clazz) throws XDocletException 114 { 115 return PackageTagsHandler.packageNameAsPathFor(MdbTagsHandler.getMessageDrivenClassFor(getCurrentClass())) + ".java"; 116 } 117 118 119 124 protected void engineStarted() throws XDocletException 125 { 126 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_MDB_FOR, 127 new String []{getCurrentClass().getQualifiedName()})); 128 } 129 130 131 138 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 139 { 140 Log log = LogUtil.getLog(MdbSubTask.class, "matchesGenerationRules"); 141 142 if (super.matchesGenerationRules(clazz) == false) { 143 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 144 return false; 145 } 146 147 String generate = getCurrentClass().getDoc().getTagAttributeValue("ejb:bean", "generate", false); 148 149 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 150 log.debug("Skip mdb class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 151 return false; 152 } 153 154 if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) { 155 return true; 156 } 157 else { 158 log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean."); 159 return false; 160 } 161 } 162 163 } 164 | Popular Tags |