1. /*
  2. * Copyright 2000-2002,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. public class WeblogicTOPLinkDeploymentTool extends WeblogicDeploymentTool {
  23. private static final String TL_DTD_LOC
  24. = "http://www.objectpeople.com/tlwl/dtd/toplink-cmp_2_5_1.dtd";
  25. private String toplinkDescriptor;
  26. private String toplinkDTD;
  27. /**
  28. * Setter used to store the name of the toplink descriptor.
  29. * @param inString the string to use as the descriptor name.
  30. */
  31. public void setToplinkdescriptor(String inString) {
  32. this.toplinkDescriptor = inString;
  33. }
  34. /**
  35. * Setter used to store the location of the toplink DTD file.
  36. * This is expected to be an URL (file or otherwise). If running
  37. * this on NT using a file URL, the safest thing would be to not use a
  38. * drive spec in the URL and make sure the file resides on the drive that
  39. * ANT is running from. This will keep the setting in the build XML
  40. * platform independent.
  41. *
  42. * @param inString the string to use as the DTD location.
  43. */
  44. public void setToplinkdtd(String inString) {
  45. this.toplinkDTD = inString;
  46. }
  47. protected DescriptorHandler getDescriptorHandler(File srcDir) {
  48. DescriptorHandler handler = super.getDescriptorHandler(srcDir);
  49. if (toplinkDTD != null) {
  50. handler.registerDTD("-//The Object People, Inc.//"
  51. + "DTD TOPLink for WebLogic CMP 2.5.1//EN", toplinkDTD);
  52. } else {
  53. handler.registerDTD("-//The Object People, Inc.//"
  54. + "DTD TOPLink for WebLogic CMP 2.5.1//EN", TL_DTD_LOC);
  55. }
  56. return handler;
  57. }
  58. /**
  59. * Add any vendor specific files which should be included in the
  60. * EJB Jar.
  61. */
  62. protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
  63. super.addVendorFiles(ejbFiles, ddPrefix);
  64. // Then the toplink deployment descriptor
  65. // Setup a naming standard here?.
  66. File toplinkDD = new File(getConfig().descriptorDir, ddPrefix + toplinkDescriptor);
  67. if (toplinkDD.exists()) {
  68. ejbFiles.put(META_DIR + toplinkDescriptor,
  69. toplinkDD);
  70. } else {
  71. log("Unable to locate toplink deployment descriptor. "
  72. + "It was expected to be in "
  73. + toplinkDD.getPath(), Project.MSG_WARN);
  74. }
  75. }
  76. /**
  77. * Called to validate that the tool parameters have been configured.
  78. *
  79. */
  80. public void validateConfigured() throws BuildException {
  81. super.validateConfigured();
  82. if (toplinkDescriptor == null) {
  83. throw new BuildException("The toplinkdescriptor attribute must "
  84. + "be specified");
  85. }
  86. }
  87. }