📄 ejbjar.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package org.apache.tools.ant.taskdefs.optional.ejb;// Standard java importsimport java.io.File;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.Project;import org.apache.tools.ant.taskdefs.MatchingTask;import org.apache.tools.ant.types.EnumeratedAttribute;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.Path;import org.xml.sax.SAXException;/** * Provides automated EJB JAR file creation. * <p> * Extends the * MatchingTask class provided in the default ant distribution to provide a * directory scanning EJB jarfile generator. * </p> * * <p> * The task works by taking the deployment descriptors one at a time and * parsing them to locate the names of the classes which should be placed in * the jar. The classnames are translated to java.io.Files by replacing * periods with File.separatorChar and resolving the generated filename as a * relative path under the srcDir attribute. All necessary files are then * assembled into a jarfile. One jarfile is constructed for each deployment * descriptor found. * </p> * * */public class EjbJar extends MatchingTask { /** * Inner class used to record information about the location of a local DTD */ public static class DTDLocation extends org.apache.tools.ant.types.DTDLocation { } /** * A class which contains the configuration state of the ejbjar task. * This state is passed to the deployment tools for configuration */ static class Config { // CheckStyle:VisibilityModifier OFF - bc /** * Stores a handle to the directory under which to search for class * files */ public File srcDir; /** * Stores a handle to the directory under which to search for * deployment descriptors */ public File descriptorDir; /** Instance variable that marks the end of the 'basename' */ public String baseNameTerminator = "-"; /** Stores a handle to the destination EJB Jar file */ public String baseJarName; /** * Instance variable that determines whether to use a package structure * of a flat directory as the destination for the jar files. */ public boolean flatDestDir = false; /** * The classpath to use when loading classes */ public Path classpath; /** * A Fileset of support classes */ public List supportFileSets = new ArrayList(); /** * The list of configured DTD locations */ public ArrayList dtdLocations = new ArrayList(); /** * The naming scheme used to determine the generated jar name * from the descriptor information */ public NamingScheme namingScheme; /** * The Manifest file */ public File manifest; /** * The dependency analyzer to use to add additional classes to the jar */ public String analyzer; // CheckStyle:VisibilityModifier ON } /** * An EnumeratedAttribute class for handling different EJB jar naming * schemes */ public static class NamingScheme extends EnumeratedAttribute { /** * Naming scheme where generated jar is determined from the ejb-name in * the deployment descripor */ public static final String EJB_NAME = "ejb-name"; /** * Naming scheme where the generated jar name is based on the * name of the directory containing the deployment descriptor */ public static final String DIRECTORY = "directory"; /** * Naming scheme where the generated jar name is based on the name of * the deployment descriptor file */ public static final String DESCRIPTOR = "descriptor"; /** * Naming scheme where the generated jar is named by the basejarname * attribute */ public static final String BASEJARNAME = "basejarname"; /** * Gets the values of the NamingScheme * * @return an array of the values of this attribute class. */ public String[] getValues() { return new String[] {EJB_NAME, DIRECTORY, DESCRIPTOR, BASEJARNAME}; } } /** * CMP versions supported * valid CMP versions are 1.0 and 2.0 * @since ant 1.6 */ public static class CMPVersion extends EnumeratedAttribute { /** 1.0 value */ public static final String CMP1_0 = "1.0"; /** 2.0 value */ public static final String CMP2_0 = "2.0"; /** {@inheritDoc}. */ public String[] getValues() { return new String[]{ CMP1_0, CMP2_0, }; } } /** * The config which is built by this task and used by the various deployment * tools to access the configuration of the ejbjar task */ private Config config = new Config(); /** * Stores a handle to the directory to put the Jar files in. This is * only used by the generic deployment descriptor tool which is created * if no other deployment descriptor tools are provided. Normally each * deployment tool will specify the desitination dir itself. */ private File destDir; /** Instance variable that stores the suffix for the generated jarfile. */ private String genericJarSuffix = "-generic.jar"; /** Instance variable that stores the CMP version for the jboss jarfile. */ private String cmpVersion = CMPVersion.CMP1_0; /** The list of deployment tools we are going to run. */ private ArrayList deploymentTools = new ArrayList(); /** * Add a deployment tool to the list of deployment tools that will be * processed * * @param deploymentTool a deployment tool instance to which descriptors * will be passed for processing. */ protected void addDeploymentTool(EJBDeploymentTool deploymentTool) { deploymentTool.setTask(this); deploymentTools.add(deploymentTool); } /** * Adds a deployment tool for Weblogic server. * * @return the deployment tool instance to be configured. */ public WeblogicDeploymentTool createWeblogic() { WeblogicDeploymentTool tool = new WeblogicDeploymentTool(); addDeploymentTool(tool); return tool; } /** * Adds a deployment tool for Websphere 4.0 server. * * @return the deployment tool instance to be configured. */ public WebsphereDeploymentTool createWebsphere() { WebsphereDeploymentTool tool = new WebsphereDeploymentTool(); addDeploymentTool(tool); return tool; } /** * Adds a deployment tool for Borland server. * * @return the deployment tool instance to be configured. */ public BorlandDeploymentTool createBorland() { log("Borland deployment tools", Project.MSG_VERBOSE); BorlandDeploymentTool tool = new BorlandDeploymentTool(); tool.setTask(this); deploymentTools.add(tool); return tool; } /** * Adds a deployment tool for iPlanet Application Server. * * @return the deployment tool instance to be configured. */ public IPlanetDeploymentTool createIplanet() { log("iPlanet Application Server deployment tools", Project.MSG_VERBOSE); IPlanetDeploymentTool tool = new IPlanetDeploymentTool(); addDeploymentTool(tool); return tool; } /** * Adds a deployment tool for JBoss server. * * @return the deployment tool instance to be configured. */ public JbossDeploymentTool createJboss() { JbossDeploymentTool tool = new JbossDeploymentTool(); addDeploymentTool(tool); return tool; } /** * Adds a deployment tool for JOnAS server. * * @return the deployment tool instance to be configured. */ public JonasDeploymentTool createJonas() { log("JOnAS deployment tools", Project.MSG_VERBOSE); JonasDeploymentTool tool = new JonasDeploymentTool(); addDeploymentTool(tool); return tool; } /** * Adds a deployment tool for Weblogic when using the Toplink * Object-Relational mapping. * * @return the deployment tool instance to be configured. */ public WeblogicTOPLinkDeploymentTool createWeblogictoplink() { log("The <weblogictoplink> element is no longer required. Please use " + "the <weblogic> element and set newCMP=\"true\"", Project.MSG_INFO); WeblogicTOPLinkDeploymentTool tool = new WeblogicTOPLinkDeploymentTool(); addDeploymentTool(tool); return tool; } /** * Adds to the classpath used to locate the super classes and * interfaces of the classes that will make up the EJB JAR. * * @return the path to be configured.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -