1 5 package xdoclet.modules.ejb.session; 6 7 import org.apache.commons.logging.Log; 8 9 import xjavadoc.XClass; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XDocletMessages; 13 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 14 import xdoclet.modules.ejb.EjbTagsHandler; 15 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 16 import xdoclet.tagshandler.PackageTagsHandler; 17 import xdoclet.util.LogUtil; 18 19 import xdoclet.util.Translator; 20 21 29 public class SessionSubTask extends AbstractEjbCodeGeneratorSubTask 30 { 31 public final static String DEFAULT_SESSION_CLASS_PATTERN = "{0}Session"; 32 33 protected final static String DEFAULT_TEMPLATE_FILE = "resources/session.xdt"; 34 35 42 protected String sessionClassPattern; 43 44 45 48 public SessionSubTask() 49 { 50 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 51 setDestinationFile(getSessionClassPattern() + ".java"); 52 addOfType("javax.ejb.SessionBean"); 53 setPackageSubstitutionInheritanceSupported(false); 54 } 55 56 65 public String getSessionClassPattern() 66 { 67 if (sessionClassPattern != null) { 68 return sessionClassPattern; 69 } 70 else { 71 return DEFAULT_SESSION_CLASS_PATTERN; 72 } 73 } 74 75 76 81 public void setPattern(String new_pattern) 82 { 83 sessionClassPattern = new_pattern; 84 } 85 86 87 92 public void validateOptions() throws XDocletException 93 { 94 super.validateOptions(); 95 96 if (getSessionClassPattern() == null || getSessionClassPattern().trim().equals("")) { 97 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 98 } 99 100 if (getSessionClassPattern().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(SessionTagsHandler.getSessionClassFor(getCurrentClass())) + ".java"; 116 } 117 118 119 124 protected void engineStarted() throws XDocletException 125 { 126 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_SESSION_FOR, 127 new String []{getCurrentClass().getQualifiedName()})); 128 } 129 130 131 138 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 139 { 140 Log log = LogUtil.getLog(SessionSubTask.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 session 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 |