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:
019: package org.apache.tools.ant.taskdefs.optional.ejb;
020:
021: import java.io.File;
022: import java.util.Hashtable;
023: import org.apache.tools.ant.BuildException;
024: import org.apache.tools.ant.Project;
025:
026: /**
027: * Deployment tool for Weblogic TOPLink.
028: */
029: public class WeblogicTOPLinkDeploymentTool extends
030: WeblogicDeploymentTool {
031:
032: private static final String TL_DTD_LOC = "http://www.objectpeople.com/tlwl/dtd/toplink-cmp_2_5_1.dtd";
033:
034: private String toplinkDescriptor;
035: private String toplinkDTD;
036:
037: /**
038: * Setter used to store the name of the toplink descriptor.
039: * @param inString the string to use as the descriptor name.
040: */
041: public void setToplinkdescriptor(String inString) {
042: this .toplinkDescriptor = inString;
043: }
044:
045: /**
046: * Setter used to store the location of the toplink DTD file.
047: * This is expected to be an URL (file or otherwise). If running
048: * this on NT using a file URL, the safest thing would be to not use a
049: * drive spec in the URL and make sure the file resides on the drive that
050: * ANT is running from. This will keep the setting in the build XML
051: * platform independent.
052: *
053: * @param inString the string to use as the DTD location.
054: */
055: public void setToplinkdtd(String inString) {
056: this .toplinkDTD = inString;
057: }
058:
059: /**
060: * Get the descriptor handler.
061: * @param srcDir the source file.
062: * @return the descriptor handler.
063: */
064: protected DescriptorHandler getDescriptorHandler(File srcDir) {
065: DescriptorHandler handler = super .getDescriptorHandler(srcDir);
066: if (toplinkDTD != null) {
067: handler.registerDTD("-//The Object People, Inc.//"
068: + "DTD TOPLink for WebLogic CMP 2.5.1//EN",
069: toplinkDTD);
070: } else {
071: handler.registerDTD("-//The Object People, Inc.//"
072: + "DTD TOPLink for WebLogic CMP 2.5.1//EN",
073: TL_DTD_LOC);
074: }
075: return handler;
076: }
077:
078: /**
079: * Add any vendor specific files which should be included in the
080: * EJB Jar.
081: * @param ejbFiles the hashtable to add files to.
082: * @param ddPrefix the prefix to use.
083: */
084: protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
085: super .addVendorFiles(ejbFiles, ddPrefix);
086: // Then the toplink deployment descriptor
087:
088: // Setup a naming standard here?.
089:
090: File toplinkDD = new File(getConfig().descriptorDir, ddPrefix
091: + toplinkDescriptor);
092:
093: if (toplinkDD.exists()) {
094: ejbFiles.put(META_DIR + toplinkDescriptor, toplinkDD);
095: } else {
096: log(
097: "Unable to locate toplink deployment descriptor. "
098: + "It was expected to be in "
099: + toplinkDD.getPath(), Project.MSG_WARN);
100: }
101: }
102:
103: /**
104: * Called to validate that the tool parameters have been configured.
105: * @throws BuildException if there is an error.
106: */
107: public void validateConfigured() throws BuildException {
108: super .validateConfigured();
109: if (toplinkDescriptor == null) {
110: throw new BuildException(
111: "The toplinkdescriptor attribute must "
112: + "be specified");
113: }
114: }
115: }
|