1 5 package xdoclet.modules.ejb.dao; 6 7 import java.text.MessageFormat ; 8 import java.util.Properties ; 9 10 import org.apache.commons.logging.Log; 11 12 import xjavadoc.XClass; 13 import xjavadoc.XMethod; 14 15 import xdoclet.DocletContext; 16 import xdoclet.DocletTask; 17 import xdoclet.XDocletException; 18 import xdoclet.modules.ejb.EjbTagsHandler; 19 import xdoclet.modules.ejb.home.HomeTagsHandler; 20 import xdoclet.util.LogUtil; 21 22 28 public class DaoTagsHandler extends EjbTagsHandler 29 { 30 43 public static String getDaoClassFor(XClass clazz) 44 { 45 Log log = LogUtil.getLog(DaoTagsHandler.class, "getDaoClassFor"); 46 47 String fileName = clazz.getContainingPackage().getName(); 48 String daoPattern = null; 49 50 if (log.isDebugEnabled()) { 51 log.debug("dao for " + clazz.getQualifiedName()); 52 } 53 54 daoPattern = getDaoClassPattern(); 55 56 String daoClass = clazz.getDoc().getTagAttributeValue("ejb.dao", "class", false); 57 58 if (daoClass != null) { 59 return daoClass; 60 } 61 62 String ejbName = null; 63 String packagePattern = null; 64 65 if (daoPattern.indexOf("{0}") != -1) { 66 ejbName = MessageFormat.format(daoPattern, new Object []{getShortEjbNameFor(clazz)}); 67 } 68 else { 69 ejbName = daoPattern; 70 } 71 72 fileName = choosePackage(fileName, packagePattern, DocletTask.getSubTaskName(DaoSubTask.class)); 74 fileName += "." + ejbName; 75 76 return fileName; 77 } 78 79 87 public static boolean isDaoMethod(XMethod method) throws XDocletException 88 { 89 boolean include; 90 Log log = LogUtil.getLog(DaoTagsHandler.class, "isDaoMethod"); 91 92 include = method.getDoc().hasTag("dao.call"); 93 if (log.isDebugEnabled()) { 94 log.debug("method " + method.getName() + " has " + (include ? "a" : "no") + " dao.call tag"); 95 } 96 if (HomeTagsHandler.isCreateMethod(method)) { 97 String createMethods = getTagValue(FOR_CLASS, "ejb.dao", "create-methods", null, "true", false, false); 98 99 log.debug("createMethods=" + createMethods); 100 if ("true".equals(createMethods)) { 101 include = false; 102 } 103 } 104 if (HomeTagsHandler.isFinderMethod(method)) { 105 String finderMethods = getTagValue(FOR_CLASS, "ejb.dao", "finder-methods", null, "true", false, false); 106 107 log.debug("finderMethods=" + finderMethods); 108 if ("true".equals(finderMethods)) { 109 include = false; 110 } 111 } 112 return include; 113 } 114 115 120 protected static String getDaoClassPattern() 121 { 122 DaoSubTask daoSubtask = ((DaoSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(DaoSubTask.class))); 123 124 if (daoSubtask != null) { 125 return daoSubtask.getDaoClassPattern(); 126 } 127 else { 128 return DaoSubTask.DEFAULT_DAO_CLASS_PATTERN; 129 } 130 } 131 132 137 private static boolean isDaoSubTaskActive() 138 { 139 return DocletContext.getInstance().isSubTaskDefined(DocletTask.getSubTaskName(DaoSubTask.class)); 140 } 141 142 150 public String daoClass(Properties attributes) throws XDocletException 151 { 152 return getDaoClassFor(getCurrentClass()); 153 } 154 155 162 public void ifUsingDao(String template) throws XDocletException 163 { 164 if (isDaoSubTaskActive() && getCurrentClass().getDoc().hasTag("ejb.dao", false)) { 165 generate(template); 166 } 167 } 168 169 177 public void ifDaoMethod(String template) throws XDocletException 178 { 179 if (isDaoMethod(getCurrentMethod())) { 180 generate(template); 181 } 182 } 183 184 } 185 | Popular Tags |