Browse Source

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 <greg.ayre@destiny.com>

Some minor changes to Main.java - layout and wording.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268186 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 25 years ago
parent
commit
d97f4f390c
3 changed files with 139 additions and 37 deletions
  1. +4
    -4
      src/main/org/apache/tools/ant/Main.java
  2. +5
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
  3. +130
    -28
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java

+ 4
- 4
src/main/org/apache/tools/ant/Main.java View File

@@ -504,7 +504,7 @@ public class Main {
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,11 +561,11 @@ public class Main {
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);
}


+ 5
- 5
src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java View File

@@ -84,19 +84,19 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
* 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 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
* 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 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
}
private void processElement() {
protected void processElement() {
if (currentElement.equals(HOME_INTERFACE) ||
currentElement.equals(REMOTE_INTERFACE) ||
currentElement.equals(BEAN_CLASS) ||


+ 130
- 28
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java View File

@@ -59,15 +59,26 @@ import java.util.jar.*;
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";
@@ -75,6 +86,9 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
/** 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 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
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 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
* 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,23 +164,70 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
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;
}

@@ -180,13 +244,51 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
ejbFiles.put(META_DIR + WL_DD,
weblogicDD);
}
else {
return;
}

// 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);
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);
}
}
}


Loading…
Cancel
Save