1 5 package xdoclet.modules.bea.wls.ejb; 6 7 import java.io.File ; 8 import java.net.MalformedURLException ; 9 import java.net.URL ; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XDocletMessages; 13 import xdoclet.modules.ejb.EjbDocletTask.EjbSpecVersion; 14 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 15 import xdoclet.modules.ejb.dd.AbstractEjbDeploymentDescriptorSubTask; 16 import xdoclet.util.LogUtil; 17 import xdoclet.util.Translator; 18 19 40 public class WebLogicSubTask extends AbstractEjbDeploymentDescriptorSubTask 41 { 42 private final static String WEBLOGIC_DEFAULT_TEMPLATE_FILE = "resources/weblogic-ejb-jar-xml.xdt"; 43 44 private final static String WEBLOGIC_DD_FILE_NAME = "weblogic-ejb-jar.xml"; 45 46 private final static String WEBLOGIC_DD_PUBLICID_61 = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"; 47 48 private final static String WEBLOGIC_DD_PUBLICID_70 = "-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN"; 49 50 private final static String WEBLOGIC_DD_PUBLICID_81 = "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN"; 51 52 private final static String WEBLOGIC_DD_SYSTEMID_61 = "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd"; 53 54 private final static String WEBLOGIC_DD_SYSTEMID_70 = "http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd"; 55 56 private final static String WEBLOGIC_DD_SYSTEMID_81 = "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd"; 57 58 private final static String WEBLOGIC_DTD_FILE_NAME_61 = "resources/weblogic600-ejb-jar.dtd"; 59 60 private final static String WEBLOGIC_DTD_FILE_NAME_70 = "resources/weblogic700-ejb-jar.dtd"; 61 62 private final static String WEBLOGIC_DTD_FILE_NAME_81 = "resources/weblogic810-ejb-jar.dtd"; 63 64 private final static String WEBLOGIC_CMP_DEFAULT_TEMPLATE_FILE = "resources/weblogic-cmp-rdbms-jar-xml.xdt"; 65 66 private final static String WEBLOGIC_CMP_DD_FILE_NAME = "weblogic-cmp-rdbms-jar.xml"; 67 68 private final static String WEBLOGIC_CMP11_PUBLICID_61 = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB 1.1 RDBMS Persistence//EN"; 69 70 private final static String WEBLOGIC_CMP11_PUBLICID_70 = "-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB 1.1 RDBMS Persistence//EN"; 71 72 private final static String WEBLOGIC_CMP20_PUBLICID_61 = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB RDBMS Persistence//EN"; 73 74 private final static String WEBLOGIC_CMP20_PUBLICID_70 = "-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB RDBMS Persistence//EN"; 75 76 private final static String WEBLOGIC_CMP20_PUBLICID_81 = "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB RDBMS Persistence//EN"; 77 78 private final static String WEBLOGIC_CMP11_SYSTEMID_61 = "http://www.bea.com/servers/wls600/dtd/weblogic-rdbms11-persistence-600.dtd"; 79 80 private final static String WEBLOGIC_CMP11_SYSTEMID_70 = "http://www.bea.com/servers/wls700/dtd/weblogic-rdbms11-persistence-700.dtd"; 81 82 private final static String WEBLOGIC_CMP20_SYSTEMID_61 = "http://www.bea.com/servers/wls600/dtd/weblogic-rdbms20-persistence-600.dtd"; 83 84 private final static String WEBLOGIC_CMP20_SYSTEMID_70 = "http://www.bea.com/servers/wls700/dtd/weblogic-rdbms20-persistence-700.dtd"; 85 86 private final static String WEBLOGIC_CMP20_SYSTEMID_81 = "http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd"; 87 88 private final static String WEBLOGIC_CMP11_DTD_FILE_NAME_61 = "resources/weblogic-rdbms11-persistence-600.dtd"; 89 90 private final static String WEBLOGIC_CMP11_DTD_FILE_NAME_70 = "resources/weblogic-rdbms11-persistence-700.dtd"; 91 92 private final static String WEBLOGIC_CMP20_DTD_FILE_NAME_61 = "resources/weblogic-rdbms20-persistence-600.dtd"; 93 94 private final static String WEBLOGIC_CMP20_DTD_FILE_NAME_70 = "resources/weblogic-rdbms20-persistence-700.dtd"; 95 96 private final static String WEBLOGIC_CMP20_DTD_FILE_NAME_81 = "resources/weblogic-rdbms20-persistence-810.dtd"; 97 98 private final static String DEFAULT_PERSISTENCE = "weblogic"; 99 100 private String version = Version.VERSION_6_1; 101 102 private String dataSource = ""; 103 private String poolName = ""; 104 105 private String createTables = ""; 106 private String persistence = DEFAULT_PERSISTENCE; 107 108 private String validateDbSchemaWith = ""; 109 110 private String databaseType = ""; 111 112 private boolean orderDatabaseOperations = true; 113 private boolean enableBatchOperations = true; 114 private boolean enableBeanClassRedeploy = false; 115 116 private URL ejbJarXml = null; 117 private URL cmpRdbmsJarXml = null; 118 119 public WebLogicSubTask() 120 { 121 ejbJarXml = getClass().getResource(WEBLOGIC_DEFAULT_TEMPLATE_FILE); 123 cmpRdbmsJarXml = getClass().getResource(WEBLOGIC_CMP_DEFAULT_TEMPLATE_FILE); 124 } 125 126 132 public String getDatabaseType() 133 { 134 return databaseType; 135 } 136 137 142 public String getDatasource() 143 { 144 return dataSource; 145 } 146 147 public String getPoolname() 148 { 149 return poolName; 150 } 151 152 157 public String getVersion() 158 { 159 return version; 160 } 161 162 167 public String getCreatetables() 168 { 169 return createTables; 170 } 171 172 public String getPersistence() 173 { 174 return persistence; 175 } 176 177 public String getValidateDbSchemaWith() 178 { 179 return validateDbSchemaWith; 180 } 181 182 public String getOrderDatabaseOperations() 183 { 184 return orderDatabaseOperations ? "True" : "False"; 185 } 186 187 public String getEnableBatchOperations() 188 { 189 return enableBatchOperations ? "True" : "False"; 190 } 191 192 public String getEnableBeanClassRedeploy() 193 { 194 return enableBeanClassRedeploy ? "True" : "False"; 195 } 196 197 204 public void setTemplateFile(File templateFile) throws XDocletException 205 { 206 if (templateFile.exists()) { 207 try { 208 ejbJarXml = templateFile.toURL(); 209 } 210 catch (MalformedURLException e) { 211 throw new XDocletException(e.getMessage()); 212 } 213 } 214 else { 215 throw new XDocletException("Couldn't find template for weblogic-ejb-jar.xml: " + templateFile.getAbsolutePath()); 216 } 217 } 218 219 226 public void setCmpTemplateFile(File templateFile) throws XDocletException 227 { 228 if (templateFile.exists()) { 229 try { 230 cmpRdbmsJarXml = templateFile.toURL(); 231 } 232 catch (MalformedURLException e) { 233 throw new XDocletException(e.getMessage()); 234 } 235 } 236 else { 237 throw new XDocletException("Couldn't find template: " + templateFile.getAbsolutePath()); 238 } 239 } 240 241 public void setOrderDatabaseOperations(boolean flag) 242 { 243 this.orderDatabaseOperations = flag; 244 } 245 246 public void setEnableBatchOperations(boolean flag) 247 { 248 this.enableBatchOperations = flag; 249 } 250 251 public void setEnableBeanClassRedeploy(boolean flag) 252 { 253 this.enableBeanClassRedeploy = flag; 254 } 255 256 263 public void setDatabaseType(DatabaseTypes databaseType) 264 { 265 this.databaseType = databaseType.getValue(); 266 } 267 268 275 public void setPoolname(String s) 276 { 277 poolName = s; 278 } 279 280 287 public void setDatasource(String dataSource) 288 { 289 this.dataSource = dataSource; 290 } 291 292 298 public void setVersion(Version version) 299 { 300 this.version = version.getValue(); 301 } 302 303 309 public void setPersistence(String persistence) 310 { 311 this.persistence = persistence; 312 } 313 314 324 public void setCreatetables(CreateTablesType flag) 325 { 326 this.createTables = flag.getValue(); 327 } 328 329 337 public void setValidateDbSchemaWith(ValidateDbSchemaWithTypes type) 338 { 339 validateDbSchemaWith = type.getValue(); 340 } 341 342 347 public void validateOptions() throws XDocletException 348 { 349 CreateTablesType tblType = new CreateTablesType(); 353 354 String versionStr = getVersion(); 355 int index = tblType.indexOfValue(getCreatetables()); 356 357 int index_lo_8_1 = tblType.indexOfValue(CreateTablesType.TRUE); 358 int index_hi_8_1 = tblType.indexOfValue(CreateTablesType.ALTER_OR_CREATE); 359 360 if (versionStr.compareTo(Version.VERSION_8_1) < 0) { 361 if (index > index_lo_8_1) { 363 throw new XDocletException("Argument for createtables must be one of (" + 364 CreateTablesType.TRUE + "|" + 365 CreateTablesType.FALSE + 366 ") if version attribute is < 8.1"); 367 } 368 } 369 else { 370 if ((index <= index_lo_8_1) || (index > index_hi_8_1)) { 372 throw new XDocletException("Argument for createtables must be one of (" + 373 CreateTablesType.DISABLED + "|" + 374 CreateTablesType.CREATE_ONLY + "|" + 375 CreateTablesType.DROP_AND_CREATE + "|" + 376 CreateTablesType.DROP_AND_CREATE_ALWAYS + "|" + 377 CreateTablesType.ALTER_OR_CREATE + 378 ") if version attribute is >= 8.1"); 379 } 380 } 381 } 382 383 387 public void execute() throws XDocletException 388 { 389 setDestinationFile(WEBLOGIC_DD_FILE_NAME); 390 setTemplateURL(ejbJarXml); 391 392 if (getVersion().equals(Version.VERSION_6_1) || getVersion().equals(Version.VERSION_6_0)) { 393 setPublicId(WEBLOGIC_DD_PUBLICID_61); 394 setSystemId(WEBLOGIC_DD_SYSTEMID_61); 395 setDtdURL(getClass().getResource(WEBLOGIC_DTD_FILE_NAME_61)); 396 } 397 else if (getVersion().equals(Version.VERSION_7_0)) { 398 setPublicId(WEBLOGIC_DD_PUBLICID_70); 399 setSystemId(WEBLOGIC_DD_SYSTEMID_70); 400 setDtdURL(getClass().getResource(WEBLOGIC_DTD_FILE_NAME_70)); 401 } 402 else { 403 setPublicId(WEBLOGIC_DD_PUBLICID_81); 404 setSystemId(WEBLOGIC_DD_SYSTEMID_81); 405 setDtdURL(getClass().getResource(WEBLOGIC_DTD_FILE_NAME_81)); 406 } 407 408 startProcess(); 409 410 if (atLeastOneCmpEntityBeanExists()) { 411 if (DEFAULT_PERSISTENCE.equals(getPersistence())) { 412 setDestinationFile(WEBLOGIC_CMP_DD_FILE_NAME); 413 setTemplateURL(cmpRdbmsJarXml); 414 415 String specVers = (String ) getContext().getConfigParam("EjbSpec"); 416 417 if (specVers.equals(EjbSpecVersion.EJB_2_1)) { 418 specVers = EjbSpecVersion.EJB_2_0; 419 LogUtil.getLog(getClass(), "execute").warn("EJB spec version 2.1 unknown for WLS subtask. Falling back to 2.0"); 420 } 421 if (specVers.equals(EjbSpecVersion.EJB_1_1)) { 422 if (getVersion().equals(Version.VERSION_6_1) || getVersion().equals(Version.VERSION_6_0)) { 423 setPublicId(WEBLOGIC_CMP11_PUBLICID_61); 424 setSystemId(WEBLOGIC_CMP11_SYSTEMID_61); 425 setDtdURL(getClass().getResource(WEBLOGIC_CMP11_DTD_FILE_NAME_61)); 426 } 427 else { 428 setPublicId(WEBLOGIC_CMP11_PUBLICID_70); 429 setSystemId(WEBLOGIC_CMP11_SYSTEMID_70); 430 setDtdURL(getClass().getResource(WEBLOGIC_CMP11_DTD_FILE_NAME_70)); 431 } 432 } 433 else if (specVers.equals(EjbSpecVersion.EJB_2_0)) { 434 if (getVersion().equals(Version.VERSION_6_1) || getVersion().equals(Version.VERSION_6_0)) { 435 setPublicId(WEBLOGIC_CMP20_PUBLICID_61); 436 setSystemId(WEBLOGIC_CMP20_SYSTEMID_61); 437 setDtdURL(getClass().getResource(WEBLOGIC_CMP20_DTD_FILE_NAME_61)); 438 } 439 else if (getVersion().equals(Version.VERSION_7_0)) { 440 setPublicId(WEBLOGIC_CMP20_PUBLICID_70); 441 setSystemId(WEBLOGIC_CMP20_SYSTEMID_70); 442 setDtdURL(getClass().getResource(WEBLOGIC_CMP20_DTD_FILE_NAME_70)); 443 } 444 else { 445 setPublicId(WEBLOGIC_CMP20_PUBLICID_81); 446 setSystemId(WEBLOGIC_CMP20_SYSTEMID_81); 447 setDtdURL(getClass().getResource(WEBLOGIC_CMP20_DTD_FILE_NAME_81)); 448 } 449 } 450 else { 451 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.UNSUPPORTED_EJB_SPEC, new String []{getContext().getConfigParam("EjbSpec").toString()})); 452 } 453 } 454 else { 455 LogUtil.getLog(getClass(), "execute").warn(Translator.getString(XDocletModulesBeaWlsEjbMessages.class, XDocletModulesBeaWlsEjbMessages.NON_WEBLOGIC_PERSISTENCE, new String []{getPersistence()})); 456 } 457 458 startProcess(); 459 } 460 } 461 462 467 protected void engineStarted() throws XDocletException 468 { 469 if (getDestinationFile().equals(WEBLOGIC_DD_FILE_NAME)) { 470 System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String []{WEBLOGIC_DD_FILE_NAME})); 471 } 472 else if (getDestinationFile().equals(WEBLOGIC_CMP_DD_FILE_NAME)) { 473 System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String []{WEBLOGIC_CMP_DD_FILE_NAME})); 474 } 475 } 476 477 482 public static class ValidateDbSchemaWithTypes extends org.apache.tools.ant.types.EnumeratedAttribute 483 { 484 public final static String META_DATA = "MetaData"; 485 486 public final static String TABLE_QUERY = "TableQuery"; 487 488 493 public java.lang.String [] getValues() 494 { 495 return (new java.lang.String []{ 496 META_DATA, TABLE_QUERY 497 }); 498 } 499 } 500 501 506 public static class DatabaseTypes extends org.apache.tools.ant.types.EnumeratedAttribute 507 { 508 public final static String DB2 = "DB2"; 509 public final static String INFORMIX = "INFORMIX"; 510 public final static String ORACLE = "ORACLE"; 511 public final static String SQL_SERVER = "SQL_SERVER"; 512 public final static String SYBASE = "SYBASE"; 513 public final static String POINTBASE = "POINTBASE"; 514 515 520 public java.lang.String [] getValues() 521 { 522 return (new java.lang.String []{ 523 DB2, INFORMIX, ORACLE, SQL_SERVER, SYBASE, POINTBASE 524 }); 525 } 526 } 527 528 533 public static class Version extends org.apache.tools.ant.types.EnumeratedAttribute 534 { 535 public final static String VERSION_6_0 = "6.0"; 536 public final static String VERSION_6_1 = "6.1"; 537 public final static String VERSION_7_0 = "7.0"; 541 public final static String VERSION_8_1 = "8.1"; 542 543 548 public java.lang.String [] getValues() 549 { 550 return (new java.lang.String []{ 551 VERSION_6_0, VERSION_6_1, VERSION_7_0, VERSION_8_1 552 }); 553 } 554 } 555 556 559 public static class CreateTablesType extends org.apache.tools.ant.types.EnumeratedAttribute 560 { 561 public final static String FALSE = "False"; 563 public final static String TRUE = "True"; 564 565 public final static String DISABLED = "Disabled"; 567 public final static String CREATE_ONLY = "CreateOnly"; 568 public final static String DROP_AND_CREATE = "DropAndCreate"; 569 public final static String DROP_AND_CREATE_ALWAYS = "DropAndCreateAlways"; 570 public final static String ALTER_OR_CREATE = "AlterOrCreate"; 571 572 577 public java.lang.String [] getValues() 578 { 579 return (new java.lang.String []{ 580 FALSE, TRUE, 581 DISABLED, CREATE_ONLY, DROP_AND_CREATE, DROP_AND_CREATE_ALWAYS, ALTER_OR_CREATE, 582 }); 583 } 584 } 585 } 586 | Popular Tags |