You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@locus.apache.org on 2000/11/15 07:38:35 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb DescriptorHandler.java WeblogicDeploymentTool.java
conor 00/11/14 22:38:34
Modified: src/main/org/apache/tools/ant Main.java
src/main/org/apache/tools/ant/taskdefs/optional/ejb
DescriptorHandler.java WeblogicDeploymentTool.java
Log:
Change weblogic element of ejbjar to support including the CMP descriptor based
on parsing the weblogic descriptor rather than using the naming convention. To
access the new behaviour set oldCMP="false" in the weblogic element.
This should allow the ejbjar task to support jars with more than one CMP bean
Submitted by: gayre <gr...@destiny.com>
Some minor changes to Main.java - layout and wording.
Revision Changes Path
1.24 +4 -4 jakarta-ant/src/main/org/apache/tools/ant/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Main.java 2000/11/10 17:07:20 1.23
+++ Main.java 2000/11/15 06:38:34 1.24
@@ -504,7 +504,7 @@
msg.append(" -listener <classname> add an instance of class as a project listener" + lSep);
msg.append(" -buildfile <file> use given buildfile" + lSep);
msg.append(" -D<property>=<value> use value for given property" + lSep);
- msg.append(" -find <file> search for buildfile towards the root of the file" + lSep);
+ msg.append(" -find <file> search for buildfile towards the root of the filesystem" + lSep);
msg.append(" system and use it" + lSep);
System.out.println(msg.toString());
}
@@ -561,10 +561,10 @@
int pos = findTargetPosition(topNames, targetName);
topNames.insertElementAt(targetName, pos);
topDescriptions.insertElementAt(targetDescription, pos);
- if (targetName.length() > maxLength) {
- maxLength = targetName.length();
+ if (targetName.length() > maxLength) {
+ maxLength = targetName.length();
+ }
}
- }
}
printTargets(topNames, topDescriptions, "Main targets:", maxLength);
printTargets(subNames, null, "Subtargets:", 0);
1.2 +5 -5 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DescriptorHandler.java 2000/08/02 14:30:55 1.1
+++ DescriptorHandler.java 2000/11/15 06:38:34 1.2
@@ -84,19 +84,19 @@
* processed by the SAX parser. Accessed by the SAX parser call-back methods
* startElement() and endElement().
*/
- private String currentElement = null;
+ protected String currentElement = null;
/**
* The text of the current element
*/
- private String currentText = null;
+ protected String currentText = null;
/**
* Instance variable that stores the names of the files as they will be
* put into the jar file, mapped to File objects Accessed by the SAX
* parser call-back method characters().
*/
- private Hashtable ejbFiles = null;
+ protected Hashtable ejbFiles = null;
private Hashtable fileDTDs = new Hashtable();
@@ -158,7 +158,7 @@
* instance variables to ensure safe operation.
*/
public void startDocument() throws SAXException {
- this.ejbFiles = new Hashtable(10, 1);
+ this.ejbFiles = new Hashtable(10, 1);
this.currentElement = null;
}
@@ -214,7 +214,7 @@
}
- private void processElement() {
+ protected void processElement() {
if (currentElement.equals(HOME_INTERFACE) ||
currentElement.equals(REMOTE_INTERFACE) ||
currentElement.equals(BEAN_CLASS) ||
1.8 +130 -28 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WeblogicDeploymentTool.java 2000/11/13 00:29:52 1.7
+++ WeblogicDeploymentTool.java 2000/11/15 06:38:34 1.8
@@ -59,22 +59,36 @@
import java.util.*;
import java.net.*;
+import javax.xml.parsers.*;
+import org.xml.sax.*;
+
import org.apache.tools.ant.*;
import org.apache.tools.ant.types.*;
import org.apache.tools.ant.taskdefs.Java;
public class WeblogicDeploymentTool extends GenericDeploymentTool {
- protected static final String WL_DD = "weblogic-ejb-jar.xml";
+ public static final String PUBLICID_EJB
+ = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN";
+ public static final String PUBLICID_WEBLOGIC
+ = "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN";
+
+ protected static final String WL_DD = "weblogic-ejb-jar.xml";
protected static final String WL_CMP_DD = "weblogic-cmp-rdbms-jar.xml";
- protected static final String WL_DTD = "/weblogic/ejb/deployment/xml/ejb-jar.dtd";
- protected static final String WL_HTTP_DTD = "http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd";
+ protected static final String DEFAULT_EJB_DTD_LOCATION
+ = "/weblogic/ejb/deployment/xml/ejb-jar.dtd";
+ protected static final String DEFAULT_WL_DTD_LOCATION
+ = "/weblogic/ejb/deployment/xml/weblogic-ejb-jar.dtd";
+
/** Instance variable that stores the suffix for the weblogic jarfile. */
private String jarSuffix = ".jar";
/** Instance variable that stores the location of the weblogic DTD file. */
private String weblogicDTD;
+ /** Instance variable that stores the location of the generic EJB DTD file. */
+ private String ejbDTD;
+
/** Instance variable that determines whether generic ejb jars are kept. */
private boolean keepgenerated = false;
@@ -86,6 +100,11 @@
private String compiler = null;
private boolean alwaysRebuild = true;
+
+ /**
+ * Indicates if the old CMP location convention is to be used.
+ */
+ private boolean oldCMP = true;
/**
* The compiler (switch <code>-compiler</code>) to use
@@ -124,16 +143,14 @@
* the .java source files are kept).
* @param inValue either 'true' or 'false'
*/
- public void setKeepgenerated(String inValue)
- {
+ public void setKeepgenerated(String inValue) {
this.keepgenerated = Boolean.valueOf(inValue).booleanValue();
}
/**
* sets some additional args to send to ejbc.
*/
- public void setArgs(String args)
- {
+ public void setArgs(String args) {
this.additionalArgs = args;
}
@@ -147,26 +164,73 @@
this.weblogicDTD = inString;
}
+ /**
+ * Setter used to store the location of the Sun's Generic EJB DTD.
+ * This can be a file on the system or a resource on the classpath.
+ * @param inString the string to use as the DTD location.
+ */
+ public void setEJBdtd(String inString) {
+ this.ejbDTD = inString;
+ }
+
+ /**
+ * Set the value of the oldCMP scheme. The oldCMP scheme locates the
+ * weblogic CMP descriptor based on the naming convention where the
+ * weblogic CMP file is expected to be named with the bean name as the prefix.
+ *
+ * Under this scheme the name of the CMP descriptor does not match the name
+ * actually used in the main weblogic EJB descriptor. Also, descriptors which
+ * contain multiple CMP references could not be used.
+ *
+ * The old scheme is currently the default, but is also deprecated.
+ */
+ public void setOldCMP(boolean oldCMP) {
+ this.oldCMP = oldCMP;
+ }
+
+
+ /**
+ * Register the location of the local resource copy of a DTD in a given
+ * handler.
+ */
+ private void registerDTD(DescriptorHandler handler,
+ String publicId, String dtdLocation) {
+ File dtdFile = new File(dtdLocation);
+ if (dtdFile.exists()) {
+ handler.registerFileDTD(publicId, dtdFile);
+ } else {
+ handler.registerResourceDTD(publicId, dtdLocation);
+ }
+ }
+
protected DescriptorHandler getDescriptorHandler(File srcDir) {
DescriptorHandler handler = new DescriptorHandler(srcDir);
- if (weblogicDTD != null) {
- // is the DTD a local file?
- File dtdFile = new File(weblogicDTD);
- if (dtdFile.exists()) {
- handler.registerFileDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN",
- dtdFile);
- } else {
- handler.registerResourceDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN",
- weblogicDTD);
- }
- } else {
- handler.registerResourceDTD("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN",
- WL_DTD);
- }
-
+ registerDTD(handler, PUBLICID_EJB,
+ ejbDTD == null ? DEFAULT_EJB_DTD_LOCATION : ejbDTD);
return handler;
}
+ protected DescriptorHandler getWebglogicDescriptorHandler(File srcDir) {
+ DescriptorHandler handler =
+ new DescriptorHandler(srcDir) {
+ protected void processElement() {
+ if (currentElement.equals("type-storage")) {
+ // Get the filename of vendor specific descriptor
+ String fileNameWithMETA = currentText;
+ //trim the META_INF\ off of the file name
+ String fileName = fileNameWithMETA.substring(META_DIR.length(),
+ fileNameWithMETA.length() );
+ File descriptorFile = new File(getDescriptorDir(), fileName);
+ ejbFiles.put(fileNameWithMETA, descriptorFile);
+ }
+ }
+ };
+
+ registerDTD(handler, PUBLICID_WEBLOGIC,
+ weblogicDTD == null ? DEFAULT_WL_DTD_LOCATION : weblogicDTD);
+ return handler;
+ }
+
/**
* Add any vendor specific files which should be included in the
* EJB Jar.
@@ -180,13 +244,51 @@
ejbFiles.put(META_DIR + WL_DD,
weblogicDD);
}
-
- // The the weblogic cmp deployment descriptor
- File weblogicCMPDD = new File(getDescriptorDir(), ddPrefix + WL_CMP_DD);
+ else {
+ return;
+ }
- if (weblogicCMPDD.exists()) {
- ejbFiles.put(META_DIR + WL_CMP_DD,
- weblogicCMPDD);
+ if (oldCMP) {
+ log("The old method for locating CMP files has been DEPRECATED.", Project.MSG_INFO);
+ log("Please adjust your weblogic descriptor and set oldCMP=\"false\" " +
+ "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_INFO);
+ // The the weblogic cmp deployment descriptor
+ File weblogicCMPDD = new File(getDescriptorDir(), ddPrefix + WL_CMP_DD);
+
+ if (weblogicCMPDD.exists()) {
+ ejbFiles.put(META_DIR + WL_CMP_DD,
+ weblogicCMPDD);
+ }
+ }
+ else {
+ // now that we have the weblogic descriptor, we parse the file
+ // to find other descriptors needed to deploy the bean.
+ // this could be the weblogic-cmp-rdbms.xml or any other O/R
+ // mapping tool descriptors.
+ try
+ {
+ File ejbDescriptor = (File)ejbFiles.get(META_DIR + EJB_DD);
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setValidating(true);
+ SAXParser saxParser = saxParserFactory.newSAXParser();
+ DescriptorHandler handler = getWebglogicDescriptorHandler(ejbDescriptor.getParentFile());
+ saxParser.parse(new InputSource
+ (new FileInputStream
+ (weblogicDD)),
+ handler);
+
+ Hashtable ht = handler.getFiles();
+ Enumeration e = ht.keys();
+ while(e.hasMoreElements()){
+ String key = (String)e.nextElement();
+ ejbFiles.put(key, ht.get(key));
+ }
+ }
+ catch(Exception e)
+ {
+ String msg = "Exception while adding Vendor specific files: " + e.toString();
+ throw new BuildException(msg, e);
+ }
}
}