1 5 package xdoclet.modules.ejb.intf; 6 7 import org.apache.commons.logging.Log; 8 9 import xjavadoc.XClass; 10 import xjavadoc.XTag; 11 12 import xdoclet.XDocletException; 13 import xdoclet.XDocletMessages; 14 15 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 16 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 17 import xdoclet.modules.ejb.intf.InterfaceTagsHandler; 18 import xdoclet.tagshandler.PackageTagsHandler; 19 20 import xdoclet.util.LogUtil; 21 import xdoclet.util.Translator; 22 23 33 public class LocalInterfaceSubTask extends AbstractEjbCodeGeneratorSubTask 34 { 35 public final static String DEFAULT_LOCAL_CLASS_PATTERN = "{0}Local"; 36 37 protected final static String DEFAULT_TEMPLATE_FILE = "resources/local.xdt"; 38 39 46 protected String localClassPattern; 47 48 49 51 public LocalInterfaceSubTask() 52 { 53 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 54 setDestinationFile(getLocalClassPattern() + ".java"); 55 addOfType("javax.ejb.EntityBean"); 56 addOfType("javax.ejb.SessionBean"); 57 } 58 59 67 public String getLocalClassPattern() 68 { 69 if (localClassPattern != null) { 70 return localClassPattern; 71 } 72 else { 73 return DEFAULT_LOCAL_CLASS_PATTERN; 74 } 75 } 76 77 78 84 public void setPattern(String new_pattern) 85 { 86 localClassPattern = new_pattern; 87 } 88 89 90 95 public void validateOptions() throws XDocletException 96 { 97 super.validateOptions(); 98 99 if (getLocalClassPattern() == null || getLocalClassPattern().trim().equals("")) { 100 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 101 } 102 103 if (getLocalClassPattern().indexOf("{0}") == -1) { 104 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 105 } 106 } 107 108 109 116 protected String getGeneratedFileName(XClass clazz) throws XDocletException 117 { 118 return PackageTagsHandler.packageNameAsPathFor(InterfaceTagsHandler.getComponentInterface("local", getCurrentClass())) + ".java"; 119 } 120 121 122 129 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 130 { 131 if (super.matchesGenerationRules(clazz) == false) { 132 return false; 133 } 134 135 Log log = LogUtil.getLog(LocalInterfaceSubTask.class, "matchesGenerationRules"); 136 137 if (!InterfaceTagsHandler.isLocalEjb(getCurrentClass())) { 138 log.debug("Reject file " + clazz.getQualifiedName() + " because of different view-type"); 139 return false; 140 } 141 142 XTag interfaceTag = getCurrentClass().getDoc().getTag("ejb:interface"); 143 144 if (interfaceTag == null) { 145 return true; 146 } 147 148 String generate = interfaceTag.getAttributeValue("generate"); 149 150 if ((generate != null) && (generate.indexOf("local") == -1)) { 151 log.debug("Skip remote interface for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 152 return false; 153 } 154 155 return true; 156 } 157 158 159 162 protected void engineStarted() throws XDocletException 163 { 164 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_LOCAL_FOR, 165 new String []{getCurrentClass().getQualifiedName()})); 166 } 167 168 } 169 | Popular Tags |