1 5 package xdoclet.tagshandler; 6 7 import java.util.Properties ; 8 9 import org.apache.commons.logging.Log; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XDocletMessages; 13 import xdoclet.XDocletTagSupport; 14 import xdoclet.template.TemplateException; 15 import xdoclet.template.TemplateTagHandler; 16 import xdoclet.util.LogUtil; 17 import xdoclet.util.Translator; 18 19 28 public class TagDefTagsHandler extends XDocletTagSupport 29 { 30 43 public String tagDef(Properties attributes) throws XDocletException 44 { 45 Log log = LogUtil.getLog(TagDefTagsHandler.class, "tagDef"); 46 47 String namespace = attributes.getProperty("namespace"); 48 String handlerFullClassName = attributes.getProperty("handler"); 49 50 if (log.isDebugEnabled()) { 51 log.debug("namespace=" + namespace); 52 log.debug("handler=" + handlerFullClassName); 53 } 54 55 if (namespace == null) { 56 mandatoryTemplateTagParamNotFound("tagDef", "namespace"); 57 } 58 59 if (handlerFullClassName == null) { 60 mandatoryTemplateTagParamNotFound("tagDef", "handler"); 61 } 62 63 Class handlerClass = null; 64 65 try { 66 handlerClass = getClass().getClassLoader().loadClass(handlerFullClassName); 67 68 Object handlerInstance = handlerClass.newInstance(); 69 70 getEngine().setTagHandlerFor(namespace, (TemplateTagHandler) handlerInstance); 71 } 72 catch (ClassNotFoundException e) { 73 String msg = Translator.getString(XDocletMessages.class, XDocletMessages.CLASS_NOT_FOUND, 74 new String []{handlerFullClassName}); 75 76 log.error(msg, e); 77 throw new XDocletException(e, msg); 78 } 79 catch (InstantiationException e) { 80 String msg = Translator.getString(XDocletMessages.class, XDocletTagshandlerMessages.TAGDEF_INSTANTIATION_EXCEPTION, 81 new String []{handlerClass.toString()}); 82 83 log.error(msg, e); 84 throw new XDocletException(e, msg); 85 } 86 catch (IllegalAccessException e) { 87 String msg = Translator.getString(XDocletMessages.class, XDocletTagshandlerMessages.TAGDEF_ILLEGALACCESS_EXCEPTION, 88 new String []{handlerClass.toString()}); 89 90 log.error(msg, e); 91 throw new XDocletException(e, msg); 92 } 93 catch (TemplateException e) { 94 String msg = Translator.getString(XDocletMessages.class, XDocletTagshandlerMessages.TAGDEF_COULDNT_DEF_HANDLER, 95 new String []{handlerFullClassName, namespace}); 96 97 log.error(msg, e); 98 throw new XDocletException(e, msg); 99 } 100 101 return ""; 102 } 103 } 104 | Popular Tags |