conor 01/06/25 08:17:48
Modified: src/main/org/apache/tools/ant/taskdefs/optional/ejb
BorlandDeploymentTool.java DescriptorHandler.java
EjbJar.java GenericDeploymentTool.java
IPlanetDeploymentTool.java JbossDeploymentTool.java
WeblogicDeploymentTool.java
WeblogicTOPLinkDeploymentTool.java
Log:
2nd Installment of the ejb-jar naming convention changes. This
introduces a namign attribnute which can take one of four values
ejb-name - use the ejb-name in the deployment descriptor to name the jar
descriptor - name the jar based on the name of the deployment descriptor file
basejarname - name the jars based on the given basejarname attribute
directory - the directory containing the deployment descriptor is used
ejb-name handling based on code submitted by Trevor Stewart <[EMAIL
PROTECTED]>
Revision Changes Path
1.5 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java
Index: BorlandDeploymentTool.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BorlandDeploymentTool.java 2001/06/24 13:26:51 1.4
+++ BorlandDeploymentTool.java 2001/06/25 15:17:26 1.5
@@ -240,7 +240,7 @@
* Add any vendor specific files which should be included in the
* EJB Jar.
*/
- protected void addVendorFiles(Hashtable ejbFiles, String baseName,
String descriptorFileName) {
+ protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
File borlandDD = new File(getConfig().descriptorDir,META_DIR+BAS_DD);
if (borlandDD.exists()) {
1.9 +58 -9
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
Index: DescriptorHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DescriptorHandler.java 2001/06/24 13:26:52 1.8
+++ DescriptorHandler.java 2001/06/25 15:17:28 1.9
@@ -72,6 +72,12 @@
* list can then be accessed through the getFiles() method.
*/
public class DescriptorHandler extends org.xml.sax.HandlerBase {
+ static private final int STATE_LOOKING_EJBJAR = 1;
+ static private final int STATE_IN_EJBJAR = 2;
+ static private final int STATE_IN_BEANS = 3;
+ static private final int STATE_IN_SESSION = 4;
+ static private final int STATE_IN_ENTITY = 5;
+
private Task owningTask;
private String publicId = null;
@@ -80,13 +86,22 @@
* Bunch of constants used for storing entries in a hashtable, and for
* constructing the filenames of various parts of the ejb jar.
*/
- private static final String EJB_REF = "ejb-ref";
private static final String HOME_INTERFACE = "home";
private static final String REMOTE_INTERFACE = "remote";
private static final String BEAN_CLASS = "ejb-class";
private static final String PK_CLASS = "prim-key-class";
+ private static final String EJB_NAME = "ejb-name";
+ private static final String EJB_JAR = "ejb-jar";
+ private static final String ENTERPRISE_BEANS = "enterprise-beans";
+ private static final String ENTITY_BEAN = "entity";
+ private static final String SESSION_BEAN = "session";
/**
+ * The state of the parsing
+ */
+ private int parseState = STATE_LOOKING_EJBJAR;
+
+ /**
* Instance variable used to store the name of the current element being
* processed by the SAX parser. Accessed by the SAX parser call-back
methods
* startElement() and endElement().
@@ -105,12 +120,15 @@
*/
protected Hashtable ejbFiles = null;
+ /**
+ * Instance variable that stores the value found in the <ejb-name>
element
+ */
+ protected String ejbName = null;
+
private Hashtable fileDTDs = new Hashtable();
private Hashtable resourceDTDs = new Hashtable();
- private boolean inEJBRef = false;
-
/**
* The directory containing the bean classes and interfaces. This is
* used for performing dependency file lookups.
@@ -188,6 +206,13 @@
return publicId;
}
+ /**
+ * Getter method that returns the value of the <ejb-name> element.
+ */
+ public String getEjbName() {
+ return ejbName;
+ }
+
/**
* SAX parser call-back method that is used to initialize the values of
some
* instance variables to ensure safe operation.
@@ -195,7 +220,6 @@
public void startDocument() throws SAXException {
this.ejbFiles = new Hashtable(10, 1);
this.currentElement = null;
- inEJBRef = false;
}
@@ -210,9 +234,18 @@
throws SAXException {
this.currentElement = name;
currentText = "";
- if (name.equals(EJB_REF)) {
- inEJBRef = true;
+ if (parseState == STATE_LOOKING_EJBJAR && name.equals(EJB_JAR)) {
+ parseState = STATE_IN_EJBJAR;
+ }
+ else if (parseState == STATE_IN_EJBJAR &&
name.equals(ENTERPRISE_BEANS)) {
+ parseState = STATE_IN_BEANS;
+ }
+ else if (parseState == STATE_IN_BEANS && name.equals(SESSION_BEAN)) {
+ parseState = STATE_IN_SESSION;
}
+ else if (parseState == STATE_IN_BEANS && name.equals(ENTITY_BEAN )) {
+ parseState = STATE_IN_ENTITY;
+ }
}
@@ -229,9 +262,18 @@
processElement();
currentText = "";
this.currentElement = "";
- if (name.equals(EJB_REF)) {
- inEJBRef = false;
+ if (parseState == STATE_IN_ENTITY && name.equals(ENTITY_BEAN )) {
+ parseState = STATE_IN_BEANS;
+ }
+ else if (parseState == STATE_IN_SESSION &&
name.equals(SESSION_BEAN)) {
+ parseState = STATE_IN_BEANS;
}
+ else if (parseState == STATE_IN_BEANS &&
name.equals(ENTERPRISE_BEANS)) {
+ parseState = STATE_IN_EJBJAR;
+ }
+ else if (parseState == STATE_IN_EJBJAR && name.equals(EJB_JAR)) {
+ parseState = STATE_LOOKING_EJBJAR;
+ }
}
/**
@@ -257,7 +299,7 @@
protected void processElement() {
- if (inEJBRef) {
+ if (parseState != STATE_IN_ENTITY && parseState != STATE_IN_SESSION)
{
return;
}
@@ -279,6 +321,13 @@
className += ".class";
classFile = new File(srcDir, className);
ejbFiles.put(className, classFile);
+ }
+ }
+
+ // Get the value of the <ejb-name> tag. Only the first occurence.
+ if (currentElement.equals(EJB_NAME)) {
+ if ( ejbName == null ) {
+ ejbName = currentText.trim();
}
}
}
1.20 +51 -7
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java
Index: EjbJar.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- EjbJar.java 2001/06/24 13:26:52 1.19
+++ EjbJar.java 2001/06/25 15:17:30 1.20
@@ -161,8 +161,25 @@
* 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;
};
+
+ public static class NamingScheme extends EnumeratedAttribute {
+ static public final String EJB_NAME = "ejb-name";
+ static public final String DIRECTORY = "directory";
+ static public final String DESCRIPTOR = "descriptor";
+ static public final String BASEJARNAME = "basejarname";
+ public String[] getValues() {
+ return new String[] {EJB_NAME, DIRECTORY, DESCRIPTOR,
BASEJARNAME};
+ }
+ }
+
private Config config = new Config();
@@ -321,9 +338,33 @@
*/
public void setBasejarname(String inValue) {
config.baseJarName = inValue;
+ if (config.namingScheme == null) {
+ config.namingScheme = new NamingScheme();
+ config.namingScheme.setValue(NamingScheme.BASEJARNAME);
+ }
+ else if
(!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)) {
+ throw new BuildException("The basejarname attribute is not
compatible with the " +
+ config.namingScheme.getValue() + "
naming scheme");
+ }
}
/**
+ * Set the naming scheme used to determine the name of the generated jars
+ * from the deployment descriptor
+ *
+ * @param NamingScheme the namign scheme to be used
+ */
+ public void setNaming(NamingScheme namingScheme) {
+ config.namingScheme = namingScheme;
+ if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)
&&
+ config.baseJarName != null) {
+ throw new BuildException("The basejarname attribute is not
compatible with the " +
+ config.namingScheme.getValue() + "
naming scheme");
+ }
+ }
+
+
+ /**
* Set the destination directory.
*
* The EJB jar files will be written into this directory. The jar files
that exist in
@@ -399,6 +440,16 @@
if (config.descriptorDir == null) {
config.descriptorDir = config.srcDir;
}
+
+ if (config.namingScheme == null) {
+ config.namingScheme = new NamingScheme();
+ config.namingScheme.setValue(NamingScheme.DESCRIPTOR);
+ }
+ else if
(config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) &&
+ config.baseJarName == null) {
+ throw new BuildException("The basejarname attribute must be
specified " +
+ "with the basejarname naming scheme");
+ }
}
/**
@@ -469,13 +520,6 @@
throw new BuildException(msg, pce);
}
} // end of execute()
-
- public static class NamignScheme extends EnumeratedAttribute {
- public String[] getValues() {
- return new String[] {"ejb-name", "directory", "descriptor"};
- }
- }
-
}
1.19 +44 -6
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
Index: GenericDeploymentTool.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- GenericDeploymentTool.java 2001/06/24 13:26:52 1.18
+++ GenericDeploymentTool.java 2001/06/25 15:17:31 1.19
@@ -306,6 +306,8 @@
checkConfiguration(descriptorFileName, saxParser);
try {
+ handler = getDescriptorHandler(config.srcDir);
+
// Retrive the files to be added to JAR from EJB descriptor
Hashtable ejbFiles = parseEjbFiles(descriptorFileName,
saxParser);
@@ -315,12 +317,14 @@
// Determine the JAR filename (without filename extension)
String baseName = getJarBaseName(descriptorFileName);
+ String ddPrefix = getVendorDDPrefix(baseName,
descriptorFileName);
+
// First the regular deployment descriptor
ejbFiles.put(META_DIR + EJB_DD,
new File(config.descriptorDir, descriptorFileName));
// now the vendor specific files, if any
- addVendorFiles(ejbFiles, baseName, descriptorFileName);
+ addVendorFiles(ejbFiles, ddPrefix);
// add any inherited files
checkAndAddInherited(ejbFiles);
@@ -423,7 +427,6 @@
Hashtable ejbFiles = null;
try {
- handler = getDescriptorHandler(config.srcDir);
/* Parse the ejb deployment descriptor. While it may not
* look like much, we use a SAXParser and an inner class to
@@ -484,14 +487,14 @@
String baseName = "";
// Work out what the base name is
- if (config.baseJarName != null) {
+ if
(config.namingScheme.getValue().equals(EjbJar.NamingScheme.BASEJARNAME)) {
String canonicalDescriptor = descriptorFileName.replace('\\',
'/');
int index = canonicalDescriptor.lastIndexOf('/');
if (index != -1) {
baseName = descriptorFileName.substring(0, index + 1);
}
baseName += config.baseJarName;
- } else {
+ } else if
(config.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) {
int lastSeparatorIndex =
descriptorFileName.lastIndexOf(File.separator);
int endBaseName = -1;
if (lastSeparatorIndex != -1) {
@@ -505,17 +508,52 @@
baseName = descriptorFileName.substring(0, endBaseName);
}
baseName = descriptorFileName.substring(0, endBaseName);
+ } else if
(config.namingScheme.getValue().equals(EjbJar.NamingScheme.DIRECTORY)) {
+ int lastSeparatorIndex =
descriptorFileName.lastIndexOf(File.separator);
+ String dirName = descriptorFileName.substring(0,
lastSeparatorIndex);
+ int dirSeparatorIndex = dirName.lastIndexOf(File.separator);
+ if (dirSeparatorIndex != -1) {
+ dirName = dirName.substring(dirSeparatorIndex + 1);
+ }
+
+ baseName = dirName;
+ } else if
(config.namingScheme.getValue().equals(EjbJar.NamingScheme.EJB_NAME)) {
+ baseName = handler.getEjbName();
}
-
return baseName;
}
+ /**
+ * Get the prefix for vendor deployment descriptors.
+ *
+ * This will contain the path and the start of the descriptor name,
+ * depending on the naming scheme
+ */
+ public String getVendorDDPrefix(String baseName, String
descriptorFileName) {
+ String ddPrefix = null;
+
+ if
(config.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) {
+ ddPrefix = baseName + config.baseNameTerminator;
+ } else if
(config.namingScheme.getValue().equals(EjbJar.NamingScheme.BASEJARNAME) ||
+
config.namingScheme.getValue().equals(EjbJar.NamingScheme.EJB_NAME) ||
+
config.namingScheme.getValue().equals(EjbJar.NamingScheme.DIRECTORY)) {
+ String canonicalDescriptor = descriptorFileName.replace('\\',
'/');
+ int index = canonicalDescriptor.lastIndexOf('/');
+ if (index == -1) {
+ ddPrefix = "";
+ }
+ else {
+ ddPrefix = descriptorFileName.substring(0, index + 1);
+ }
+ }
+ return ddPrefix;
+ }
/**
* Add any vendor specific files which should be included in the
* EJB Jar.
*/
- protected void addVendorFiles(Hashtable ejbFiles, String baseName,
String descriptorFileName) {
+ protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
// nothing to add for generic tool.
}
1.3 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java
Index: IPlanetDeploymentTool.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IPlanetDeploymentTool.java 2001/06/24 13:26:53 1.2
+++ IPlanetDeploymentTool.java 2001/06/25 15:17:32 1.3
@@ -334,7 +334,7 @@
* @param baseName String name of the EJB JAR file to be written (without
* a filename extension).
*/
- protected void addVendorFiles(Hashtable ejbFiles, String baseName,
String descriptorFileName) {
+ protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
ejbFiles.put(META_DIR + IAS_DD, new File(getConfig().descriptorDir,
getIasDescriptorName()));
}
1.3 +1 -3
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java
Index: JbossDeploymentTool.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JbossDeploymentTool.java 2001/06/24 13:26:53 1.2
+++ JbossDeploymentTool.java 2001/06/25 15:17:33 1.3
@@ -77,9 +77,7 @@
* Add any vendor specific files which should be included in the
* EJB Jar.
*/
- protected void addVendorFiles(Hashtable ejbFiles, String baseName,
String descriptorFileName) {
- String ddPrefix = (usingBaseJarName() ? "" : baseName +
getConfig().baseNameTerminator);
-
+ protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
File jbossDD = new File(getConfig().descriptorDir, ddPrefix +
JBOSS_DD);
if (jbossDD.exists()) {
ejbFiles.put(META_DIR + JBOSS_DD, jbossDD);
1.24 +1 -15
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
Index: WeblogicDeploymentTool.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- WeblogicDeploymentTool.java 2001/06/24 13:26:53 1.23
+++ WeblogicDeploymentTool.java 2001/06/25 15:17:36 1.24
@@ -297,21 +297,7 @@
* Add any vendor specific files which should be included in the
* EJB Jar.
*/
- protected void addVendorFiles(Hashtable ejbFiles, String baseName,
String descriptorFileName) {
- String ddPrefix = null;
- if (!usingBaseJarName()) {
- ddPrefix = baseName + getConfig().baseNameTerminator;
- }
- else {
- String canonicalDescriptor = descriptorFileName.replace('\\',
'/');
- int index = canonicalDescriptor.lastIndexOf('/');
- if (index == -1) {
- ddPrefix = "";
- }
- else {
- ddPrefix = descriptorFileName.substring(0, index + 1);
- }
- }
+ protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
File weblogicDD = new File(getConfig().descriptorDir, ddPrefix +
WL_DD);
if (weblogicDD.exists()) {
1.7 +3 -11
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java
Index: WeblogicTOPLinkDeploymentTool.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WeblogicTOPLinkDeploymentTool.java 2001/06/24 13:26:53 1.6
+++ WeblogicTOPLinkDeploymentTool.java 2001/06/25 15:17:37 1.7
@@ -102,22 +102,14 @@
* Add any vendor specific files which should be included in the
* EJB Jar.
*/
- protected void addVendorFiles(Hashtable ejbFiles, String baseName,
String descriptorFileName) {
- super.addVendorFiles(ejbFiles, baseName, descriptorFileName);
+ protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) {
+ super.addVendorFiles(ejbFiles, ddPrefix);
// Then the toplink deployment descriptor
// Setup a naming standard here?.
- File toplinkDD = null;
- if (usingBaseJarName()) {
- toplinkDD = new File(getConfig().descriptorDir,
toplinkDescriptor);
- }
- else {
- String ddPrefix = baseName + getConfig().baseNameTerminator;
- File actualDir = (new File(getConfig().descriptorDir,
ddPrefix)).getParentFile();
- toplinkDD = new File(actualDir, toplinkDescriptor);
- }
+ File toplinkDD = new File(getConfig().descriptorDir, ddPrefix +
toplinkDescriptor);
if (toplinkDD.exists()) {
ejbFiles.put(META_DIR + toplinkDescriptor,