001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.ejb;
019:
020: import java.io.File;
021: import java.util.Hashtable;
022: import org.apache.tools.ant.BuildException;
023: import org.apache.tools.ant.Project;
024:
025: /**
026: * The deployment tool to add the jboss specific deployment descriptor to the ejb jar file.
027: * Jboss only requires one additional file jboss.xml and does not require any additional
028: * compilation.
029: *
030: * @version 1.0
031: * @see EjbJar#createJboss
032: */
033: public class JbossDeploymentTool extends GenericDeploymentTool {
034: protected static final String JBOSS_DD = "jboss.xml";
035: protected static final String JBOSS_CMP10D = "jaws.xml";
036: protected static final String JBOSS_CMP20D = "jbosscmp-jdbc.xml";
037:
038: /** Instance variable that stores the suffix for the jboss jarfile. */
039: private String jarSuffix = ".jar";
040:
041: /**
042: * Setter used to store the suffix for the generated JBoss jar file.
043: * @param inString the string to use as the suffix.
044: */
045: public void setSuffix(String inString) {
046: jarSuffix = inString;
047: }
048:
049: /**
050: * Add any vendor specific files which should be included in the
051: * EJB Jar.
052: * @param ejbFiles the hashtable of files to populate.
053: * @param ddPrefix the prefix to use.
054: */
055: protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
056: File jbossDD = new File(getConfig().descriptorDir, ddPrefix
057: + JBOSS_DD);
058: if (jbossDD.exists()) {
059: ejbFiles.put(META_DIR + JBOSS_DD, jbossDD);
060: } else {
061: log("Unable to locate jboss deployment descriptor. "
062: + "It was expected to be in " + jbossDD.getPath(),
063: Project.MSG_WARN);
064: return;
065: }
066: String descriptorFileName = JBOSS_CMP10D;
067: if (EjbJar.CMPVersion.CMP2_0
068: .equals(getParent().getCmpversion())) {
069: descriptorFileName = JBOSS_CMP20D;
070: }
071: File jbossCMPD = new File(getConfig().descriptorDir, ddPrefix
072: + descriptorFileName);
073:
074: if (jbossCMPD.exists()) {
075: ejbFiles.put(META_DIR + descriptorFileName, jbossCMPD);
076: } else {
077: log(
078: "Unable to locate jboss cmp descriptor. "
079: + "It was expected to be in "
080: + jbossCMPD.getPath(), Project.MSG_VERBOSE);
081: return;
082: }
083: }
084:
085: /**
086: * Get the vendor specific name of the Jar that will be output. The modification date
087: * of this jar will be checked against the dependent bean classes.
088: */
089: File getVendorOutputJarFile(String baseName) {
090: if (getDestDir() == null && getParent().getDestdir() == null) {
091: throw new BuildException("DestDir not specified");
092: }
093: if (getDestDir() == null) {
094: return new File(getParent().getDestdir(), baseName
095: + jarSuffix);
096: } else {
097: return new File(getDestDir(), baseName + jarSuffix);
098: }
099: }
100:
101: /**
102: * Called to validate that the tool parameters have been configured.
103: *
104: * @throws BuildException If the Deployment Tool's configuration isn't
105: * valid
106: * @since ant 1.6
107: */
108: public void validateConfigured() throws BuildException {
109: }
110:
111: private EjbJar getParent() {
112: return (EjbJar) this.getTask();
113: }
114: }
|