Methods Summary |
---|
private java.lang.String[] | buildArgumentList(org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbc$EjbInfo ejb)Based on this object's instance variables as well as the EJB to be
processed, the correct flags and parameters are set for the ejbc
command-line utility.
List arguments = new ArrayList();
/* OPTIONAL COMMAND LINE PARAMETERS */
if (debugOutput) {
arguments.add("-debug");
}
/* No beantype flag is needed for an entity bean */
if (ejb.getBeantype().equals(STATELESS_SESSION)) {
arguments.add("-sl");
} else if (ejb.getBeantype().equals(STATEFUL_SESSION)) {
arguments.add("-sf");
}
if (ejb.getIiop()) {
arguments.add("-iiop");
}
if (ejb.getCmp()) {
arguments.add("-cmp");
}
if (retainSource) {
arguments.add("-gs");
}
if (ejb.getHasession()) {
arguments.add("-fo");
}
/* REQUIRED COMMAND LINE PARAMETERS */
arguments.add("-classpath");
arguments.add(classpath);
arguments.add("-d");
arguments.add(destDirectory.toString());
arguments.add(ejb.getHome().getQualifiedClassName());
arguments.add(ejb.getRemote().getQualifiedClassName());
arguments.add(ejb.getImplementation().getQualifiedClassName());
/* Convert the List into an Array and return it */
return (String[]) arguments.toArray(new String[arguments.size()]);
|
private void | callEjbc(java.lang.String[] arguments)Executes the iPlanet Application Server ejbc command-line utility.
/* Concatenate all of the command line arguments into a single String */
StringBuffer args = new StringBuffer();
for (int i = 0; i < arguments.length; i++) {
args.append(arguments[i]).append(" ");
}
/* If an iAS home directory is specified, prepend it to the commmand */
String command;
if (iasHomeDir == null) {
command = "";
} else {
command = iasHomeDir.toString() + File.separator + "bin"
+ File.separator;
}
command += "ejbc ";
log(command + args);
/*
* Use the Runtime object to execute an external command. Use the
* RedirectOutput inner class to direct the standard and error output
* from the command to the JRE's standard output
*/
try {
Process p = Runtime.getRuntime().exec(command + args);
RedirectOutput output = new RedirectOutput(p.getInputStream());
RedirectOutput error = new RedirectOutput(p.getErrorStream());
output.start();
error.start();
p.waitFor();
p.destroy();
} catch (IOException e) {
log("An IOException has occurred while trying to execute ejbc.");
e.printStackTrace();
} catch (InterruptedException e) {
// Do nothing
}
|
protected void | checkConfiguration()Verifies that the user selections are valid.
String msg = "";
if (stdDescriptor == null) {
msg += "A standard XML descriptor file must be specified. ";
}
if (iasDescriptor == null) {
msg += "An iAS-specific XML descriptor file must be specified. ";
}
if (classpath == null) {
msg += "A classpath must be specified. ";
}
if (parser == null) {
msg += "An XML parser must be specified. ";
}
if (destDirectory == null) {
msg += "A destination directory must be specified. ";
} else if (!destDirectory.exists()) {
msg += "The destination directory specified does not exist. ";
} else if (!destDirectory.isDirectory()) {
msg += "The destination specified is not a directory. ";
}
if (msg.length() > 0) {
throw new EjbcException(msg);
}
|
public void | execute()Compiles the stub and skeletons for the specified EJBs, if they need to
be updated.
checkConfiguration(); // Throws EjbcException if unsuccessful
EjbInfo[] ejbs = getEjbs(); // Returns list of EJBs for processing
for (int i = 0; i < ejbs.length; i++) {
log("EJBInfo...");
log(ejbs[i].toString());
}
for (int i = 0; i < ejbs.length; i++) {
EjbInfo ejb = ejbs[i];
ejb.checkConfiguration(destDirectory); // Throws EjbcException
if (ejb.mustBeRecompiled(destDirectory)) {
log(ejb.getName() + " must be recompiled using ejbc.");
String[] arguments = buildArgumentList(ejb);
callEjbc(arguments);
} else {
log(ejb.getName() + " is up to date.");
}
}
|
public java.lang.String[] | getCmpDescriptors()Returns the list of CMP descriptors referenced in the EJB descriptors.
List returnList = new ArrayList();
EjbInfo[] ejbs = handler.getEjbs();
for (int i = 0; i < ejbs.length; i++) {
List descriptors = (List) ejbs[i].getCmpDescriptors();
returnList.addAll(descriptors);
}
return (String[]) returnList.toArray(new String[returnList.size()]);
|
public java.lang.String | getDisplayName()Returns the display-name element read from the standard EJB descriptor.
return displayName;
|
public java.util.Hashtable | getEjbFiles()Returns a Hashtable which contains a list of EJB class files processed by
the ejbc utility (both "source" class files as well as stubs and
skeletons). The key for the Hashtable is a String representing the path
to the class file (relative to the destination directory). The value for
the Hashtable is a File object which reference the actual class file.
return ejbFiles;
|
private org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbc$EjbInfo[] | getEjbs()Parses the EJB descriptors and returns a list of EJBs which may need to
be compiled.
EjbInfo[] ejbs = null;
/*
* The EJB information is gathered from the standard XML EJB descriptor
* and the iAS-specific XML EJB descriptor using a SAX parser.
*/
parser.parse(stdDescriptor, handler);
parser.parse(iasDescriptor, handler);
ejbs = handler.getEjbs();
return ejbs;
|
private void | log(java.lang.String msg)Convenience method used to print messages to the user if debugging
messages are enabled.
if (debugOutput) {
System.out.println(msg);
}
|
public static void | main(java.lang.String[] args)Main application method for the iPlanet Application Server ejbc utility.
If the application is run with no commandline arguments, a usage
statement is printed for the user.
File stdDescriptor;
File iasDescriptor;
File destDirectory = null;
String classpath = null;
SAXParser parser = null;
boolean debug = false;
boolean retainSource = false;
IPlanetEjbc ejbc;
if ((args.length < MIN_NUM_ARGS) || (args.length > MAX_NUM_ARGS)) {
usage();
return;
}
stdDescriptor = new File(args[args.length - 2]);
iasDescriptor = new File(args[args.length - 1]);
for (int i = 0; i < args.length - 2; i++) {
if (args[i].equals("-classpath")) {
classpath = args[++i];
} else if (args[i].equals("-d")) {
destDirectory = new File(args[++i]);
} else if (args[i].equals("-debug")) {
debug = true;
} else if (args[i].equals("-keepsource")) {
retainSource = true;
} else {
usage();
return;
}
}
/* If the -classpath flag isn't specified, use the system classpath */
if (classpath == null) {
Properties props = System.getProperties();
classpath = props.getProperty("java.class.path");
}
/*
* If the -d flag isn't specified, use the working directory as the
* destination directory
*/
if (destDirectory == null) {
Properties props = System.getProperties();
destDirectory = new File(props.getProperty("user.dir"));
}
/* Construct a SAXParser used to process the descriptors */
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(true);
try {
parser = parserFactory.newSAXParser();
} catch (Exception e) {
// SAXException or ParserConfigurationException may be thrown
System.out.println("An exception was generated while trying to ");
System.out.println("create a new SAXParser.");
e.printStackTrace();
return;
}
/* Build and populate an instance of the ejbc utility */
ejbc = new IPlanetEjbc(stdDescriptor, iasDescriptor, destDirectory,
classpath, parser);
ejbc.setDebugOutput(debug);
ejbc.setRetainSource(retainSource);
/* Execute the ejbc utility -- stubs/skeletons are rebuilt, if needed */
try {
ejbc.execute();
} catch (IOException e) {
System.out.println("An IOException has occurred while reading the "
+ "XML descriptors (" + e.getMessage() + ").");
return;
} catch (SAXException e) {
System.out.println("A SAXException has occurred while reading the "
+ "XML descriptors (" + e.getMessage() + ").");
return;
} catch (IPlanetEjbc.EjbcException e) {
System.out.println("An error has occurred while executing the ejbc "
+ "utility (" + e.getMessage() + ").");
return;
}
|
public void | registerDTD(java.lang.String publicID, java.lang.String location)Registers the location of a local DTD file or resource. By registering
a local DTD, EJB descriptors can be parsed even when the remote servers
which contain the "public" DTDs cannot be accessed.
handler.registerDTD(publicID, location);
|
public void | setDebugOutput(boolean debugOutput)If true, enables debugging output when ejbc is executed.
this.debugOutput = debugOutput;
|
public void | setIasHomeDir(java.io.File iasHomeDir)May be used to specify the "home" directory for this iAS installation.
The directory specified should typically be
[install-location]/iplanet/ias6/ias .
this.iasHomeDir = iasHomeDir;
|
public void | setRetainSource(boolean retainSource)If true, the Java source files which are generated by the
ejbc process are retained.
this.retainSource = retainSource;
|
private static void | usage()Print a usage statement.
System.out.println("java org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbc \\");
System.out.println(" [OPTIONS] [EJB 1.1 descriptor] [iAS EJB descriptor]");
System.out.println("");
System.out.println("Where OPTIONS are:");
System.out.println(" -debug -- for additional debugging output");
System.out.println(" -keepsource -- to retain Java source files generated");
System.out.println(" -classpath [classpath] -- classpath used for compilation");
System.out.println(" -d [destination directory] -- directory for compiled classes");
System.out.println("");
System.out.println("If a classpath is not specified, the system classpath");
System.out.println("will be used. If a destination directory is not specified,");
System.out.println("the current working directory will be used (classes will");
System.out.println("still be placed in subfolders which correspond to their");
System.out.println("package name).");
System.out.println("");
System.out.println("The EJB home interface, remote interface, and implementation");
System.out.println("class must be found in the destination directory. In");
System.out.println("addition, the destination will look for the stubs and skeletons");
System.out.println("in the destination directory to ensure they are up to date.");
|