1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.ejb;
  18. import java.io.File;
  19. import java.util.Hashtable;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.Project;
  22. /**
  23. * The deployment tool to add the jboss specific deployment descriptor to the ejb jar file.
  24. * Jboss only requires one additional file jboss.xml and does not require any additional
  25. * compilation.
  26. *
  27. * @version 1.0
  28. * @see EjbJar#createJboss
  29. */
  30. public class JbossDeploymentTool extends GenericDeploymentTool {
  31. protected static final String JBOSS_DD = "jboss.xml";
  32. protected static final String JBOSS_CMP10D = "jaws.xml";
  33. protected static final String JBOSS_CMP20D = "jbosscmp-jdbc.xml";
  34. /** Instance variable that stores the suffix for the jboss jarfile. */
  35. private String jarSuffix = ".jar";
  36. /**
  37. * Setter used to store the suffix for the generated JBoss jar file.
  38. * @param inString the string to use as the suffix.
  39. */
  40. public void setSuffix(String inString) {
  41. jarSuffix = inString;
  42. }
  43. /**
  44. * Add any vendor specific files which should be included in the
  45. * EJB Jar.
  46. */
  47. protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
  48. File jbossDD = new File(getConfig().descriptorDir, ddPrefix + JBOSS_DD);
  49. if (jbossDD.exists()) {
  50. ejbFiles.put(META_DIR + JBOSS_DD, jbossDD);
  51. } else {
  52. log("Unable to locate jboss deployment descriptor. "
  53. + "It was expected to be in " + jbossDD.getPath(),
  54. Project.MSG_WARN);
  55. return;
  56. }
  57. String descriptorFileName = JBOSS_CMP10D;
  58. if (EjbJar.CMPVersion.CMP2_0.equals(getParent().getCmpversion())) {
  59. descriptorFileName = JBOSS_CMP20D;
  60. }
  61. File jbossCMPD
  62. = new File(getConfig().descriptorDir, ddPrefix + descriptorFileName);
  63. if (jbossCMPD.exists()) {
  64. ejbFiles.put(META_DIR + descriptorFileName, jbossCMPD);
  65. } else {
  66. log("Unable to locate jboss cmp descriptor. "
  67. + "It was expected to be in "
  68. + jbossCMPD.getPath(), Project.MSG_VERBOSE);
  69. return;
  70. }
  71. }
  72. /**
  73. * Get the vendor specific name of the Jar that will be output. The modification date
  74. * of this jar will be checked against the dependent bean classes.
  75. */
  76. File getVendorOutputJarFile(String baseName) {
  77. if (getDestDir() == null && getParent().getDestdir() == null) {
  78. throw new BuildException("DestDir not specified");
  79. }
  80. if (getDestDir() == null) {
  81. return new File(getParent().getDestdir(), baseName + jarSuffix);
  82. } else {
  83. return new File(getDestDir(), baseName + jarSuffix);
  84. }
  85. }
  86. /**
  87. * Called to validate that the tool parameters have been configured.
  88. *
  89. * @throws BuildException If the Deployment Tool's configuration isn't
  90. * valid
  91. * @since ant 1.6
  92. */
  93. public void validateConfigured() throws BuildException {
  94. }
  95. private EjbJar getParent() {
  96. return (EjbJar) this.getTask();
  97. }
  98. }