1 5 package xdoclet.modules.hibernate; 6 7 import java.util.Collection ; 8 9 import xjavadoc.XClass; 10 11 import xdoclet.TemplateSubTask; 12 import xdoclet.XDocletException; 13 import xdoclet.tagshandler.PackageTagsHandler; 14 import xdoclet.util.Translator; 15 27 public class FactoryClassSubTask extends TemplateSubTask implements HibernateProperties 28 { 29 30 33 private static String DEFAULT_TEMPLATE_FILE = "resources/hibernate-factory.xdt"; 34 private static String GENERATED_FILE_NAME = "HibernateFactory.java"; 35 36 private String dataSource; 37 private String dialect; 38 private String driver; 39 private String username; 40 private String password; 41 private String factoryClass; 42 private boolean useJndiFactory = false; 43 private String jndiName; 44 private String jdbcUrl; 45 private String poolSize; 46 47 50 public FactoryClassSubTask() 51 { 52 setSubTaskName("factoryclass"); 53 setHavingClassTag("hibernate.class"); 54 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 55 setDestinationFile(GENERATED_FILE_NAME); 56 } 57 58 public String getDataSource() 59 { 60 return dataSource; 61 } 62 63 public String getDialect() 64 { 65 return dialect; 66 } 67 68 public String getDriver() 69 { 70 return driver; 71 } 72 73 public String getPassword() 74 { 75 return password; 76 } 77 78 public String getUsername() 79 { 80 return username; 81 } 82 83 public String getFactoryClass() 84 { 85 return factoryClass; 86 } 87 88 public boolean isUseJndiFactory() 89 { 90 return useJndiFactory; 91 } 92 93 public Collection getJndiProperties() 94 { 95 throw new UnsupportedOperationException ("FactoryClassSubTask does not have a jndiProperties attribute."); 96 } 97 98 102 public Collection getOtherMappings() { 103 throw new UnsupportedOperationException ("FactoryClassSubTask doesn't have other mappings"); 104 } 105 106 public Collection getOtherProperties() 107 { 108 throw new UnsupportedOperationException ("FactoryClassSubTask does not have an otherProperties attribute."); 109 } 110 111 public String getTransactionManagerStrategy() 112 { 113 throw new UnsupportedOperationException ("FactoryClassSubTask does not have a transactionManagerStrategy attribute."); 114 } 115 116 public String getUserTransactionName() 117 { 118 throw new UnsupportedOperationException ("FactoryClassSubTask does not have a userTransactionName attribute."); 119 } 120 121 public String getUserName() 122 { 123 return username; 124 } 125 126 public boolean getUseOuterJoin() 127 { 128 throw new UnsupportedOperationException ("FactoryClassSubTask does not have a useOuterJoin attribute."); 129 } 130 131 public boolean getShowSql() 132 { 133 throw new UnsupportedOperationException ("FactoryClassSubTask does not have a showSql attribute."); 134 } 135 136 public String getJndiName() 137 { 138 return jndiName; 139 } 140 141 public String getJdbcUrl() 142 { 143 return jdbcUrl; 144 } 145 146 public String getPoolSize() 147 { 148 return poolSize; 149 } 150 151 155 public void setJndiName(String jndiName) 156 { 157 this.jndiName = jndiName; 158 } 159 160 163 public void setJdbcUrl(String jdbcUrl) 164 { 165 this.jdbcUrl = jdbcUrl; 166 } 167 168 171 public void setPoolSize(String poolSize) 172 { 173 this.poolSize = poolSize; 174 } 175 176 181 public void setDataSource(String dataSource) 182 { 183 this.dataSource = dataSource; 184 } 185 186 191 public void setDialect(String dialect) 192 { 193 this.dialect = dialect; 194 } 195 196 201 public void setDriver(String driver) 202 { 203 this.driver = driver; 204 } 205 206 211 public void setPassword(String password) 212 { 213 this.password = password; 214 } 215 216 221 public void setUsername(String username) 222 { 223 this.username = username; 224 } 225 226 231 public void setFactoryClass(String factoryClass) 232 { 233 this.factoryClass = factoryClass; 234 } 235 236 240 public void setUseJndiFactory(boolean useJndiFactory) 241 { 242 this.useJndiFactory = useJndiFactory; 243 } 244 245 246 public void validateOptions() throws XDocletException 247 { 248 super.validateOptions(); 249 250 if (getFactoryClass() == null) { 251 throw new XDocletException(Translator.getString(XDocletModulesHibernateMessages.class, 252 XDocletModulesHibernateMessages.FACTORY_NAME_REQUIRED)); 253 } 254 } 255 256 261 public void execute() throws XDocletException 262 { 263 setDestinationFile(PackageTagsHandler.packageNameAsPathFor(factoryClass) + ".java"); 264 startProcess(); 265 } 266 267 274 protected String getGeneratedFileName(XClass clazz) throws XDocletException 275 { 276 return PackageTagsHandler.packageNameAsPathFor(factoryClass) + ".java"; 277 } 278 279 284 protected void engineStarted() throws XDocletException 285 { 286 System.out.println(Translator.getString(XDocletModulesHibernateMessages.class, 287 XDocletModulesHibernateMessages.GENERATING_HIBERNATE_FACTORY_CLASS)); 288 } 289 } 290 291 | Popular Tags |