1 5 package xdoclet.modules.jboss.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; 14 import xdoclet.modules.ejb.dd.AbstractEjbDeploymentDescriptorSubTask; 15 import xdoclet.util.Translator; 16 17 66 public class JBossSubTask extends AbstractEjbDeploymentDescriptorSubTask 67 { 68 private final static String DEFAULT_JBOSS_XML_TEMPLATE_FILE = "resources/jboss_xml.xdt"; 69 70 private final static String JBOSS_XML_FILE_NAME = "jboss.xml"; 71 72 private final static String DEFAULT_JAWS_XML_TEMPLATE_FILE = "resources/jboss-jaws_xml.xdt"; 73 74 private final static String JAWS_XML_FILE_NAME = "jaws.xml"; 75 76 private final static String DEFAULT_JBOSSCMP_TEMPLATE_FILE = "resources/jbosscmp-jdbc_xml.xdt"; 77 78 private final static String JBOSSCMP_DD_FILE_NAME = "jbosscmp-jdbc.xml"; 79 80 private final static String JBOSS_DD_PUBLICID_24 = "-//JBoss//DTD JBOSS 2.4//EN"; 81 82 private final static String JBOSS_DD_SYSTEMID_24 = "http://www.jboss.org/j2ee/dtd/jboss_2_4.dtd"; 83 84 private final static String JBOSS_DTD_FILE_NAME_24 = "resources/jboss_2_4.dtd"; 85 86 private final static String JBOSS_DD_PUBLICID_30 = "-//JBoss//DTD JBOSS 3.0//EN"; 87 88 private final static String JBOSS_DD_SYSTEMID_30 = "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd"; 89 90 private final static String JBOSS_DTD_FILE_NAME_30 = "resources/jboss_3_0.dtd"; 91 92 private final static String JBOSS_DD_PUBLICID_32 = "-//JBoss//DTD JBOSS 3.2//EN"; 93 94 private final static String JBOSS_DD_SYSTEMID_32 = "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd"; 95 96 private final static String JBOSS_DTD_FILE_NAME_32 = "resources/jboss_3_2.dtd"; 97 98 private final static String JBOSS_DD_PUBLICID_40 = "-//JBoss//DTD JBOSS 4.0//EN"; 99 100 private final static String JBOSS_DD_SYSTEMID_40 = "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"; 101 102 private final static String JBOSS_DTD_FILE_NAME_40 = "resources/jboss_4_0.dtd"; 103 104 private final static String JAWS_DD_PUBLICID_24 = "-//JBoss//DTD JAWS 2.4//EN"; 105 106 private final static String JAWS_DD_SYSTEMID_24 = "http://www.jboss.org/j2ee/dtd/jaws_2_4.dtd"; 107 108 private final static String JAWS_DTD_FILE_NAME_24 = "resources/jaws_2_4.dtd"; 109 110 private final static String JAWS_DD_PUBLICID_30 = "-//JBoss//DTD JAWS 3.0//EN"; 111 112 private final static String JAWS_DD_SYSTEMID_30 = "http://www.jboss.org/j2ee/dtd/jaws_3_0.dtd"; 113 114 private final static String JAWS_DTD_FILE_NAME_30 = "resources/jaws_3_0.dtd"; 115 116 private final static String JBOSSCMP_DD_PUBLICID_30 = "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"; 117 118 private final static String JBOSSCMP_DD_SYSTEMID_30 = "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd"; 119 120 private final static String JBOSSCMP_DTD_FILE_NAME_30 = "resources/jbosscmp-jdbc_3_0.dtd"; 121 122 private final static String JBOSSCMP_DD_PUBLICID_32 = "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"; 123 124 private final static String JBOSSCMP_DD_SYSTEMID_32 = "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd"; 125 126 private final static String JBOSSCMP_DTD_FILE_NAME_32 = "resources/jbosscmp-jdbc_3_2.dtd"; 127 128 private final static String JBOSSCMP_DD_PUBLICID_40 = "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"; 129 130 private final static String JBOSSCMP_DD_SYSTEMID_40 = "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd"; 131 132 private final static String JBOSSCMP_DTD_FILE_NAME_40 = "resources/jbosscmp-jdbc_4_0.dtd"; 133 134 private String version = JBossVersionTypes.VERSION_2_4; 135 136 private String datasource; 137 138 private String datasourceMapping; 139 140 private String generateRelations = "false"; 141 142 private String preferredRelationMapping; 143 144 private String createTable; 145 146 private String alterTable; 147 148 private String removeTable; 149 150 private String securityDomain = ""; 151 152 private String webServiceContextRoot; 153 154 private String unauthenticatedPrincipal = ""; 155 156 private String debug = "false"; 157 158 private URL jbossTemplateURL = null; 159 160 private URL jawsTemplateURL = null; 161 162 private URL jbosscmpTemplateURL = null; 163 164 169 public String getWebServiceContextRoot() 170 { 171 return webServiceContextRoot; 172 } 173 174 179 public URL getJbossTemplateURL() 180 { 181 return jbossTemplateURL; 182 } 183 184 189 public URL getJawsTemplateURL() 190 { 191 return jawsTemplateURL; 192 } 193 194 199 public URL getJbosscmpTemplateURL() 200 { 201 return jbosscmpTemplateURL; 202 } 203 204 209 public String getDebug() 210 { 211 return debug; 212 } 213 214 219 public String getVersion() 220 { 221 return version; 222 } 223 224 229 public String getSecurityDomain() 230 { 231 return securityDomain; 232 } 233 234 239 public String getUnauthenticatedPrincipal() 240 { 241 return unauthenticatedPrincipal; 242 } 243 244 249 public String getDatasource() 250 { 251 return datasource; 252 } 253 254 259 public String getDatasourceMapping() 260 { 261 return datasourceMapping; 262 } 263 264 269 public String getTypemapping() 270 { 271 return datasourceMapping; 272 } 273 274 279 public String getGenerateRelations() 280 { 281 return generateRelations; 282 } 283 284 289 public String getPreferredRelationMapping() 290 { 291 return preferredRelationMapping; 292 } 293 294 299 public String getCreateTable() 300 { 301 return createTable; 302 } 303 304 309 public String getAlterTable() 310 { 311 return alterTable; 312 } 313 314 319 public String getRemoveTable() 320 { 321 return removeTable; 322 } 323 324 329 public void setWebServiceContextRoot(String webServiceContextRoot) 330 { 331 this.webServiceContextRoot = webServiceContextRoot; 332 } 333 334 340 public void setJbossTemplateFile(File jbossTemplateFile) throws XDocletException 341 { 342 this.jbossTemplateURL = toURL(jbossTemplateFile); 343 } 344 345 351 public void setJawsTemplateFile(File jawsTemplateFile) throws XDocletException 352 { 353 this.jawsTemplateURL = toURL(jawsTemplateFile); 354 } 355 356 362 public void setJbosscmpTemplateFile(File jbosscmpTemplateFile) throws XDocletException 363 { 364 this.jbosscmpTemplateURL = toURL(jbosscmpTemplateFile); 365 } 366 367 372 public void setDebug(String debug) 373 { 374 this.debug = debug; 375 } 376 377 383 public void setVersion(JBossVersionTypes version) 384 { 385 this.version = version.getValue(); 386 } 387 388 393 public void setSecurityDomain(String aSecurityDomain) 394 { 395 securityDomain = aSecurityDomain; 396 } 397 398 403 public void setUnauthenticatedPrincipal(String anUnauthenticatedPrincipal) 404 { 405 unauthenticatedPrincipal = anUnauthenticatedPrincipal; 406 } 407 408 413 public void setDatasource(String datasource) 414 { 415 this.datasource = datasource; 416 } 417 418 421 public void setDatasourceMapping(String datasourceMapping) 422 { 423 this.datasourceMapping = datasourceMapping; 424 } 425 426 429 public void setTypemapping(String typemapping) 430 { 431 datasourceMapping = typemapping; 432 } 433 434 437 public void setGenerateRelations(String generateRelations) 438 { 439 this.generateRelations = generateRelations; 440 } 441 442 445 public void setPreferredRelationMapping(String preferredRelationMapping) 446 { 447 this.preferredRelationMapping = preferredRelationMapping; 448 } 449 450 453 public void setCreateTable(String createTable) 454 { 455 this.createTable = createTable; 456 } 457 458 461 public void setAlterTable(String alterTable) 462 { 463 this.alterTable = alterTable; 464 } 465 466 469 public void setRemoveTable(String removeTable) 470 { 471 this.removeTable = removeTable; 472 } 473 474 479 public void validateOptions() throws XDocletException 480 { 481 if (jbossTemplateURL == null) 482 this.jbossTemplateURL = getClass().getResource(DEFAULT_JBOSS_XML_TEMPLATE_FILE); 483 if (jbosscmpTemplateURL == null) 484 this.jbosscmpTemplateURL = getClass().getResource(DEFAULT_JBOSSCMP_TEMPLATE_FILE); 485 if (jawsTemplateURL == null) 486 this.jawsTemplateURL = getClass().getResource(DEFAULT_JAWS_XML_TEMPLATE_FILE); 487 488 492 if (getVersion().startsWith("3")) { 493 if ((hasDatasource() && !hasDatasourceMapping()) || 495 (!hasDatasource() && hasDatasourceMapping())) { 496 throw new XDocletException(Translator.getString(XDocletModulesJBossEjbMessages.class, XDocletModulesJBossEjbMessages.DATASOURCE_DATASOURCEMAPPING_PARAMETER_MISSING, new String []{hasDatasource() ? "datasource" : "datasourcemapping"})); 497 } 498 } 499 } 500 501 504 public void execute() throws XDocletException 505 { 506 String jbossVersion = getVersion(); 507 508 URL url = getJbossTemplateURL(); 509 510 if (url == null) { 511 throw new XDocletException("can't find template for " + JBOSS_XML_FILE_NAME); 512 } 513 514 setTemplateURL(url); 515 setDestinationFile(JBOSS_XML_FILE_NAME); 516 if (jbossVersion.equals(JBossVersionTypes.VERSION_4_0)) { 517 setPublicId(JBOSS_DD_PUBLICID_40); 518 setSystemId(JBOSS_DD_SYSTEMID_40); 519 setDtdURL(getClass().getResource(JBOSS_DTD_FILE_NAME_40)); 520 } 521 else if (jbossVersion.equals(JBossVersionTypes.VERSION_3_2)) { 522 setPublicId(JBOSS_DD_PUBLICID_32); 523 setSystemId(JBOSS_DD_SYSTEMID_32); 524 setDtdURL(getClass().getResource(JBOSS_DTD_FILE_NAME_32)); 525 } 526 else if (jbossVersion.equals(JBossVersionTypes.VERSION_3_0) || 527 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_1) || 528 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_2) || 529 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_3)) { 530 setPublicId(JBOSS_DD_PUBLICID_30); 531 setSystemId(JBOSS_DD_SYSTEMID_30); 532 setDtdURL(getClass().getResource(JBOSS_DTD_FILE_NAME_30)); 533 } 534 else { 535 setPublicId(JBOSS_DD_PUBLICID_24); 536 setSystemId(JBOSS_DD_SYSTEMID_24); 537 setDtdURL(getClass().getResource(JBOSS_DTD_FILE_NAME_24)); 538 } 539 540 startProcess(); 541 542 String ejbSpec = (String ) getContext().getConfigParam("EjbSpec"); 543 544 if (atLeastOneCmp1EntityBeanExists() || jbossVersion.equals(JBossVersionTypes.VERSION_2_4)) { 547 548 url = getJawsTemplateURL(); 549 if (url == null) { 550 throw new XDocletException("can't find template for " + JAWS_XML_FILE_NAME); 551 } 552 setTemplateURL(url); 553 setDestinationFile(JAWS_XML_FILE_NAME); 554 if (jbossVersion.equals(JBossVersionTypes.VERSION_3_0) || 555 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_1) || 556 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_2) || 557 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_3) || 558 jbossVersion.equals(JBossVersionTypes.VERSION_3_2) || 559 jbossVersion.equals(JBossVersionTypes.VERSION_4_0)) { 560 setPublicId(JAWS_DD_PUBLICID_30); 561 setSystemId(JAWS_DD_SYSTEMID_30); 562 setDtdURL(getClass().getResource(JAWS_DTD_FILE_NAME_30)); 563 } 564 else if (ejbSpec.equals(EjbDocletTask.EjbSpecVersion.EJB_1_1)) { 565 setPublicId(JAWS_DD_PUBLICID_24); 566 setSystemId(JAWS_DD_SYSTEMID_24); 567 setDtdURL(getClass().getResource(JAWS_DTD_FILE_NAME_24)); 568 } 569 startProcess(); 570 } 571 572 if ((ejbSpec.equals(EjbDocletTask.EjbSpecVersion.EJB_2_0) || ejbSpec.equals(EjbDocletTask.EjbSpecVersion.EJB_2_1)) 576 && atLeastOneCmp2EntityBeanExists()) { 577 578 url = getJbosscmpTemplateURL(); 579 if (url == null) { 580 throw new XDocletException("can't find template for " + JBOSSCMP_DD_FILE_NAME); 581 } 582 583 setTemplateURL(url); 584 585 setDestinationFile(JBOSSCMP_DD_FILE_NAME); 586 587 if (jbossVersion.equals(JBossVersionTypes.VERSION_3_0) || 588 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_1) || 589 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_2) || 590 jbossVersion.equals(JBossVersionTypes.VERSION_3_0_3)) { 591 592 setPublicId(JBOSSCMP_DD_PUBLICID_30); 593 setSystemId(JBOSSCMP_DD_SYSTEMID_30); 594 setDtdURL(getClass().getResource(JBOSSCMP_DTD_FILE_NAME_30)); 595 } 596 else if (jbossVersion.equals(JBossVersionTypes.VERSION_3_2)) { 597 598 setPublicId(JBOSSCMP_DD_PUBLICID_32); 599 setSystemId(JBOSSCMP_DD_SYSTEMID_32); 600 setDtdURL(getClass().getResource(JBOSSCMP_DTD_FILE_NAME_32)); 601 } 602 else if (jbossVersion.equals(JBossVersionTypes.VERSION_4_0)) { 603 604 setPublicId(JBOSSCMP_DD_PUBLICID_40); 605 setSystemId(JBOSSCMP_DD_SYSTEMID_40); 606 setDtdURL(getClass().getResource(JBOSSCMP_DTD_FILE_NAME_40)); 607 } 608 else { 610 throw new XDocletException("Unknown jboss version number for cmp2 " + jbossVersion); 611 } 612 614 startProcess(); 615 } 616 } 617 618 621 protected void engineStarted() throws XDocletException 622 { 623 if (getDestinationFile().equals(JBOSS_XML_FILE_NAME)) { 624 System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String []{JBOSS_XML_FILE_NAME})); 625 } 626 else if (getDestinationFile().equals(JAWS_XML_FILE_NAME)) { 627 System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String []{JAWS_XML_FILE_NAME})); 628 } 629 else if (getDestinationFile().equals(JBOSSCMP_DD_FILE_NAME)) { 630 System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String []{JBOSSCMP_DD_FILE_NAME})); 631 } 632 } 633 634 private boolean hasDatasource() 635 { 636 return getDatasource() != null && getDatasource().trim().length() > 0; 637 } 638 639 private boolean hasDatasourceMapping() 640 { 641 return getDatasourceMapping() != null && getDatasourceMapping().trim().length() > 0; 642 } 643 644 645 private URL toURL(File file) throws XDocletException 646 { 647 if (file.exists()) { 648 try { 649 return file.toURL(); 650 } 651 catch (MalformedURLException mue) { 652 throw new XDocletException(mue, "Illegal file url: " + file.getAbsolutePath()); 653 } 654 } 655 else { 656 throw new XDocletException("Couldn't find file: " + file.getAbsolutePath()); 657 } 658 } 659 660 664 public static class JBossVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute 665 { 666 public final static String VERSION_2_4 = "2.4"; 667 public final static String VERSION_3_0 = "3.0"; 668 public final static String VERSION_3_0_1 = "3.0.1"; 669 public final static String VERSION_3_0_2 = "3.0.2"; 670 public final static String VERSION_3_0_3 = "3.0.3"; 671 public final static String VERSION_3_2 = "3.2"; 672 public final static String VERSION_4_0 = "4.0"; 673 674 679 public String [] getValues() 680 { 681 return new String []{VERSION_2_4, VERSION_3_0, VERSION_3_0_1, VERSION_3_0_2, VERSION_3_0_3, VERSION_3_2, VERSION_4_0}; 682 } 683 } 684 } 685 | Popular Tags |