1 5 package xdoclet.modules.hibernate; 6 7 import java.text.MessageFormat ; 8 9 import xjavadoc.XClass; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XmlSubTask; 13 import xdoclet.util.Translator; 14 15 29 public class HibernateSubTask 30 extends XmlSubTask 31 { 32 public final static String DEFAULT_HIBERNATE_CLASS_PATTERN = "{0}"; 33 34 36 private final static String HIBERNATE_PUBLICID_11 = "-//Hibernate/Hibernate Mapping DTD 1.1//EN"; 37 38 private final static String HIBERNATE_SYSTEMID_11 = "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd"; 39 40 private final static String DTD_FILE_NAME_11 = "resources/hibernate-mapping_1_1.dtd"; 41 42 private final static String HIBERNATE_PUBLICID_20 = "-//Hibernate/Hibernate Mapping DTD 2.0//EN"; 43 44 private final static String HIBERNATE_SYSTEMID_20 = "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"; 45 46 private final static String DTD_FILE_NAME_20 = "resources/hibernate-mapping_2_0.dtd"; 47 48 private final static String HIBERNATE_PUBLICID_30 = "-//Hibernate/Hibernate Mapping DTD 3.0//EN"; 49 50 private final static String HIBERNATE_SYSTEMID_30 = "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"; 51 52 private final static String DTD_FILE_NAME_30 = "resources/hibernate-mapping_3_0.dtd"; 53 54 57 private static String DEFAULT_HIBERNATE_TEMPLATE_FILE = "resources/hibernate.xdt"; 58 59 62 private static String GENERATED_HIBERNATE_FILE_NAME = "{0}.hbm.xml"; 63 64 67 private String hibernateVersion = HibernateVersion.HIBERNATE_1_1; 68 69 71 74 public HibernateSubTask() 75 { 76 setHavingClassTag("hibernate.class"); 77 setTemplateURL(getClass().getResource(DEFAULT_HIBERNATE_TEMPLATE_FILE)); 78 setDestinationFile(GENERATED_HIBERNATE_FILE_NAME); 79 } 80 81 public String getGeneratedFileName(XClass clazz) throws XDocletException 82 { 83 return super.getGeneratedFileName(clazz); 84 } 85 86 public String getMappingURL(XClass clazz) 87 { 88 return MessageFormat.format(getDestinationFile(), new Object []{clazz.getTransformedQualifiedName().replace('.', '/'), ""}); 89 } 90 91 96 public String getVersion() 97 { 98 return hibernateVersion; 99 } 100 101 107 public void setVersion(HibernateVersion version) 108 { 109 hibernateVersion = version.getValue(); 110 } 111 112 117 public void execute() throws XDocletException 118 { 119 120 if (hibernateVersion.equals(HibernateVersion.HIBERNATE_1_1)) { 121 setPublicId(HIBERNATE_PUBLICID_11); 122 setSystemId(HIBERNATE_SYSTEMID_11); 123 setDtdURL(getClass().getResource(DTD_FILE_NAME_11)); 124 } 125 if (hibernateVersion.equals(HibernateVersion.HIBERNATE_2_0) || 126 hibernateVersion.equals(HibernateVersion.HIBERNATE_2_1)) { 127 setPublicId(HIBERNATE_PUBLICID_20); 128 setSystemId(HIBERNATE_SYSTEMID_20); 129 setDtdURL(getClass().getResource(DTD_FILE_NAME_20)); 130 } 131 else { 132 setPublicId(HIBERNATE_PUBLICID_30); 133 setSystemId(HIBERNATE_SYSTEMID_30); 134 setDtdURL(getClass().getResource(DTD_FILE_NAME_30)); 135 } 136 startProcess(); 137 } 138 139 141 146 protected void engineStarted() 147 throws XDocletException 148 { 149 System.out.println(Translator.getString(XDocletModulesHibernateMessages.class, 150 XDocletModulesHibernateMessages.GENERATING_HIBERNATE_FOR, 151 new String []{getCurrentClass().getQualifiedName()})); 152 } 153 154 159 protected boolean processInnerClasses() 160 { 161 return true; 162 } 163 164 168 public static class HibernateVersion extends org.apache.tools.ant.types.EnumeratedAttribute 169 { 170 public final static String HIBERNATE_1_1 = "1.1"; 171 public final static String HIBERNATE_2_0 = "2.0"; 172 public final static String HIBERNATE_2_1 = "2.1"; 173 public final static String HIBERNATE_3_0 = "3.0"; 174 175 180 public java.lang.String [] getValues() 181 { 182 return (new java.lang.String []{ 183 HIBERNATE_1_1, HIBERNATE_2_0, HIBERNATE_2_1, HIBERNATE_3_0 184 }); 185 } 186 } 187 } 188 | Popular Tags |