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.modules.ejb.entity.FacadeTagsHandler; 17 18 import xdoclet.tagshandler.PackageTagsHandler; 19 import xdoclet.util.LogUtil; 20 21 import xdoclet.util.Translator; 22 23 31 32 public class RemoteFacadeSubTask extends AbstractEjbCodeGeneratorSubTask 33 { 34 public final static String DEFAULT_REMOTE_FACADE_CLASS_PATTERN = "{0}Remote"; 35 protected final static String DEFAULT_TEMPLATE_FILE = "resources/remotefacade.xdt"; 36 37 42 protected String remoteFacadeClassPattern; 43 44 47 protected String remoteFacadeEjbNamePattern; 48 49 public RemoteFacadeSubTask() 50 { 51 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 52 setDestinationFile(getRemoteFacadeClassPattern() + ".java"); 53 addOfType("javax.ejb.SessionBean"); 54 55 } 56 57 65 public String getRemoteFacadeClassPattern() 66 { 67 if (remoteFacadeClassPattern != null) { 68 return remoteFacadeClassPattern; 69 } 70 else { 71 return DEFAULT_REMOTE_FACADE_CLASS_PATTERN; 72 } 73 } 74 75 80 public void setPattern(String new_pattern) 81 { 82 remoteFacadeClassPattern = new_pattern; 83 } 84 85 90 public void validateOptions() throws XDocletException 91 { 92 super.validateOptions(); 93 94 if (getRemoteFacadeClassPattern() == null || getRemoteFacadeClassPattern().trim().equals("")) { 95 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 96 } 97 98 if (getRemoteFacadeClassPattern().indexOf("{0}") == -1) { 99 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 100 } 101 } 102 103 110 protected String getGeneratedFileName(XClass clazz) throws XDocletException 111 { 112 return PackageTagsHandler.packageNameAsPathFor(FacadeTagsHandler.getRemoteFacadeClassFor(getCurrentClass())) + ".java"; 113 } 114 115 123 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 124 { 125 Log log = LogUtil.getLog(RemoteFacadeSubTask.class, "matchesGenerationRules"); 126 127 System.out.println("remote facade tests: " + clazz.getQualifiedName()); 128 if (super.matchesGenerationRules(clazz) == false) { 129 System.out.println("super failed"); 130 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 131 return false; 132 } 133 134 if (SessionTagsHandler.isSession(getCurrentClass()) == false) { 135 System.out.println("session failed"); 136 137 log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not session bean."); 138 return false; 139 } 140 141 String generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false); 142 143 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 144 System.out.println("generate failed"); 145 log.debug("Skip remote facade for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 146 return false; 147 } 148 149 if (!clazz.getDoc().hasTag("ejb.remote-facade")) { 150 System.out.println("remote-facade failed"); 151 log.debug("Skip facade class for " + clazz.getQualifiedName() + " because ejb.remote-facade is absent"); 152 return false; 153 } 154 155 String facade = clazz.getDoc().getTagAttributeValue("ejb.remote-facade", "generate", false); 156 157 if ((facade != null) && (facade.equals("false") || facade.equals("no"))) { 158 System.out.println("remote-facade generate failed"); 159 log.debug("Skip facade class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 160 return false; 161 } 162 163 if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) { 164 return true; 165 } 166 else { 167 System.out.println("not concrete failed"); 168 log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean."); 169 return false; 170 } 171 } 172 173 178 protected void engineStarted() throws XDocletException 179 { 180 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_REMOTE_FACADE_FOR, 181 new String []{getCurrentClass().getQualifiedName()})); 182 } 183 184 } 185 186 | Popular Tags |