org.apache.tools.ant.taskdefs.optional.ejb
Class GenericDeploymentTool

java.lang.Object
  |
  +--org.apache.tools.ant.taskdefs.optional.ejb.GenericDeploymentTool
All Implemented Interfaces:
EJBDeploymentTool
Direct Known Subclasses:
BorlandDeploymentTool, IPlanetDeploymentTool, JbossDeploymentTool, WeblogicDeploymentTool

public class GenericDeploymentTool
extends java.lang.Object
implements EJBDeploymentTool

A deployment tool which creates generic EJB jars. Generic jars contains only those classes and META-INF entries specified in the EJB 1.1 standard This class is also used as a framework for the creation of vendor specific deployment tools. A number of template methods are provided through which the vendor specific tool can hook into the EJB creation process.


Field Summary
protected static java.lang.String EJB_DD
           
protected static java.lang.String META_DIR
          Private constants that are used when constructing the standard jarfile
 
Constructor Summary
GenericDeploymentTool()
           
 
Method Summary
protected  void addFileToJar(java.util.jar.JarOutputStream jStream, java.io.File inputFile, java.lang.String logicalFilename)
          Utility method that encapsulates the logic of adding a file entry to a .jar file.
protected  void addSupportClasses(java.util.Hashtable ejbFiles)
          Adds any classes the user specifies using support nested elements to the ejbFiles Hashtable.
protected  void addVendorFiles(java.util.Hashtable ejbFiles, java.lang.String ddPrefix)
          Add any vendor specific files which should be included in the EJB Jar.
protected  void checkAndAddInherited(java.util.Hashtable checkEntries)
          Check if a EJB Class Inherits from a Superclass, and if a Remote Interface extends an interface other then javax.ejb.EJBObject directly.
protected  void checkConfiguration(java.lang.String descriptorFileName, javax.xml.parsers.SAXParser saxParser)
          This method is called as the first step in the processDescriptor method to allow vendor-specific subclasses to validate the task configuration prior to processing the descriptor.
 void configure(org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.Config config)
          Configure this tool for use in the ejbjar task.
 Path createClasspath()
          Add the classpath for the user classes
protected  java.lang.ClassLoader getClassLoaderForBuild()
          Returns a Classloader object which parses the passed in generic EjbJar classpath.
protected  Path getCombinedClasspath()
          Get the classpath by combining the one from the surrounding task, if any and the one from tis tool.
protected  org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.Config getConfig()
          Get the basename terminator.
protected  DescriptorHandler getDescriptorHandler(java.io.File srcDir)
           
protected  java.io.File getDestDir()
          Get the desitination directory.
protected  java.lang.String getJarBaseName(java.lang.String descriptorFileName)
          Using the EJB descriptor file name passed from the ejbjar task, this method returns the "basename" which will be used to name the completed JAR file.
protected  Location getLocation()
           
protected  java.lang.String getPublicId()
          Returns the Public ID of the DTD specified in the EJB descriptor.
protected  Task getTask()
          Get the task for this tool.
 java.lang.String getVendorDDPrefix(java.lang.String baseName, java.lang.String descriptorFileName)
          Get the prefix for vendor deployment descriptors.
protected  void log(java.lang.String message, int level)
           
protected  boolean needToRebuild(java.util.Hashtable ejbFiles, java.io.File jarFile)
          This method checks the timestamp on each file listed in the ejbFiles and compares them to the timestamp on the jarFile .
protected  java.util.Hashtable parseEjbFiles(java.lang.String descriptorFileName, javax.xml.parsers.SAXParser saxParser)
          This method returns a list of EJB files found when the specified EJB descriptor is parsed and processed.
 void processDescriptor(java.lang.String descriptorFileName, javax.xml.parsers.SAXParser saxParser)
          Process a deployment descriptor, generating the necessary vendor specific deployment files.
protected  void registerKnownDTDs(DescriptorHandler handler)
          Register the locations of all known DTDs. vendor-specific subclasses should override this method to define the vendor-specific locations of the EJB DTDs
 void setClasspath(Path classpath)
          Set the classpath to be used for this compilation.
 void setDestdir(java.io.File inDir)
          Setter used to store the value of destination directory prior to execute() being called.
 void setGenericJarSuffix(java.lang.String inString)
          Setter used to store the suffix for the generated jar file.
 void setTask(Task task)
          Set the task which owns this tool
protected  boolean usingBaseJarName()
          Returns true, if the meta-inf dir is being explicitly set, false otherwise.
 void validateConfigured()
          Called to validate that the tool parameters have been configured.
protected  void writeJar(java.lang.String baseName, java.io.File jarfile, java.util.Hashtable files, java.lang.String publicId)
          Method used to encapsulate the writing of the JAR file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

META_DIR

protected static final java.lang.String META_DIR
Private constants that are used when constructing the standard jarfile

EJB_DD

protected static final java.lang.String EJB_DD
Constructor Detail

GenericDeploymentTool

public GenericDeploymentTool()
Method Detail

setDestdir

public void setDestdir(java.io.File inDir)
Setter used to store the value of destination directory prior to execute() being called.
Parameters:
inDir - the destination directory.

getDestDir

protected java.io.File getDestDir()
Get the desitination directory.

setTask

public void setTask(Task task)
Set the task which owns this tool
Specified by:
setTask in interface EJBDeploymentTool

getTask

protected Task getTask()
Get the task for this tool.

getConfig

protected org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.Config getConfig()
Get the basename terminator.

usingBaseJarName

protected boolean usingBaseJarName()
Returns true, if the meta-inf dir is being explicitly set, false otherwise.

setGenericJarSuffix

public void setGenericJarSuffix(java.lang.String inString)
Setter used to store the suffix for the generated jar file.
Parameters:
inString - the string to use as the suffix.

createClasspath

public Path createClasspath()
Add the classpath for the user classes

setClasspath

public void setClasspath(Path classpath)
Set the classpath to be used for this compilation.

getCombinedClasspath

protected Path getCombinedClasspath()
Get the classpath by combining the one from the surrounding task, if any and the one from tis tool.

log

protected void log(java.lang.String message,
                   int level)

getLocation

protected Location getLocation()

configure

public void configure(org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.Config config)
Configure this tool for use in the ejbjar task.
Specified by:
configure in interface EJBDeploymentTool

addFileToJar

protected void addFileToJar(java.util.jar.JarOutputStream jStream,
                            java.io.File inputFile,
                            java.lang.String logicalFilename)
                     throws BuildException
Utility method that encapsulates the logic of adding a file entry to a .jar file. Used by execute() to add entries to the jar file as it is constructed.
Parameters:
jStream - A JarOutputStream into which to write the jar entry.
inputFile - A File from which to read the contents the file being added.
logicalFilename - A String representing the name, including all relevant path information, that should be stored for the entry being added.

getDescriptorHandler

protected DescriptorHandler getDescriptorHandler(java.io.File srcDir)

registerKnownDTDs

protected void registerKnownDTDs(DescriptorHandler handler)
Register the locations of all known DTDs. vendor-specific subclasses should override this method to define the vendor-specific locations of the EJB DTDs

processDescriptor

public void processDescriptor(java.lang.String descriptorFileName,
                              javax.xml.parsers.SAXParser saxParser)
Description copied from interface: EJBDeploymentTool
Process a deployment descriptor, generating the necessary vendor specific deployment files.
Specified by:
processDescriptor in interface EJBDeploymentTool
Following copied from interface: org.apache.tools.ant.taskdefs.optional.ejb.EJBDeploymentTool
Parameters:
descriptorFilename - the name of the deployment descriptor
saxParser - a SAX parser which can be used to parse the deployment descriptor.

checkConfiguration

protected void checkConfiguration(java.lang.String descriptorFileName,
                                  javax.xml.parsers.SAXParser saxParser)
                           throws BuildException
This method is called as the first step in the processDescriptor method to allow vendor-specific subclasses to validate the task configuration prior to processing the descriptor. If the configuration is invalid, a BuildException should be thrown.
Parameters:
descriptorFileName - String representing the file name of an EJB descriptor to be processed
saxParser - SAXParser which may be used to parse the XML descriptor

parseEjbFiles

protected java.util.Hashtable parseEjbFiles(java.lang.String descriptorFileName,
                                            javax.xml.parsers.SAXParser saxParser)
                                     throws java.io.IOException,
                                            org.xml.sax.SAXException
This method returns a list of EJB files found when the specified EJB descriptor is parsed and processed.
Parameters:
descriptorFileName - String representing the file name of an EJB descriptor to be processed
saxParser - SAXParser which may be used to parse the XML descriptor
Returns:
Hashtable of EJB class (and other) files to be added to the completed JAR file
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception
java.io.IOException - An IOException from the parser, possibly from a the byte stream or character stream

addSupportClasses

protected void addSupportClasses(java.util.Hashtable ejbFiles)
Adds any classes the user specifies using support nested elements to the ejbFiles Hashtable.
Parameters:
ejbFiles - Hashtable of EJB classes (and other) files that will be added to the completed JAR file

getJarBaseName

protected java.lang.String getJarBaseName(java.lang.String descriptorFileName)
Using the EJB descriptor file name passed from the ejbjar task, this method returns the "basename" which will be used to name the completed JAR file.
Parameters:
descriptorFileName - String representing the file name of an EJB descriptor to be processed
Returns:
The "basename" which will be used to name the completed JAR file

getVendorDDPrefix

public java.lang.String getVendorDDPrefix(java.lang.String baseName,
                                          java.lang.String descriptorFileName)
Get the prefix for vendor deployment descriptors. This will contain the path and the start of the descriptor name, depending on the naming scheme

addVendorFiles

protected void addVendorFiles(java.util.Hashtable ejbFiles,
                              java.lang.String ddPrefix)
Add any vendor specific files which should be included in the EJB Jar.

needToRebuild

protected boolean needToRebuild(java.util.Hashtable ejbFiles,
                                java.io.File jarFile)
This method checks the timestamp on each file listed in the ejbFiles and compares them to the timestamp on the jarFile . If the jarFile's timestamp is more recent than each EJB file, true is returned. Otherwise, false is returned.
Parameters:
ejbFiles - Hashtable of EJB classes (and other) files that will be added to the completed JAR file
jarFile - JAR file which will contain all of the EJB classes (and other) files
Returns:
boolean indicating whether or not the jarFile is up to date

getPublicId

protected java.lang.String getPublicId()
Returns the Public ID of the DTD specified in the EJB descriptor. Not every vendor-specific DeploymentTool will need to reference this value or may want to determine this value in a vendor-specific way.
Returns:
Public ID of the DTD specified in the EJB descriptor.

writeJar

protected void writeJar(java.lang.String baseName,
                        java.io.File jarfile,
                        java.util.Hashtable files,
                        java.lang.String publicId)
                 throws BuildException
Method used to encapsulate the writing of the JAR file. Iterates over the filenames/java.io.Files in the Hashtable stored on the instance variable ejbFiles.

checkAndAddInherited

protected void checkAndAddInherited(java.util.Hashtable checkEntries)
                             throws BuildException
Check if a EJB Class Inherits from a Superclass, and if a Remote Interface extends an interface other then javax.ejb.EJBObject directly. Then add those classes to the generic-jar so they dont have to added elsewhere.

getClassLoaderForBuild

protected java.lang.ClassLoader getClassLoaderForBuild()
Returns a Classloader object which parses the passed in generic EjbJar classpath. The loader is used to dynamically load classes from javax.ejb.* and the classes being added to the jar.

validateConfigured

public void validateConfigured()
                        throws BuildException
Called to validate that the tool parameters have been configured.
Specified by:
validateConfigured in interface EJBDeploymentTool
Throws:
BuildException - If the Deployment Tool's configuration isn't valid


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.