@@ -1,7 +1,7 @@
/*
/*
* The Apache Software License, Version 1.1
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
* reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
@@ -74,26 +74,26 @@ import javax.ejb.deployment.EntityDescriptor;
*/
*/
public class EjbcHelper {
public class EjbcHelper {
/**
/**
* The root directory of the tree containing the serialised deployment desciptors.
* The root directory of the tree containing the serialised deployment desciptors.
*/
*/
private File descriptorDirectory;
private File descriptorDirectory;
/**
/**
* The directory where generated files are placed.
* The directory where generated files are placed.
*/
*/
private File generatedFilesDirectory;
private File generatedFilesDirectory;
/**
/**
* The name of the manifest file generated for the EJB jar.
* The name of the manifest file generated for the EJB jar.
*/
*/
private File manifestFile;
private File manifestFile;
/**
/**
* The source directory for the home and remote interfaces. This is used to determine if
* The source directory for the home and remote interfaces. This is used to determine if
* the generated deployment classes are out of date.
* the generated deployment classes are out of date.
*/
*/
private File sourceDirectory;
private File sourceDirectory;
/**
/**
* The names of the serialised deployment descriptors
* The names of the serialised deployment descriptors
*/
*/
@@ -103,15 +103,15 @@ public class EjbcHelper {
/**
/**
* Command line interface for the ejbc helper task.
* Command line interface for the ejbc helper task.
*/
*/
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws Exception {
EjbcHelper helper = new EjbcHelper(args);
EjbcHelper helper = new EjbcHelper(args);
helper.process();
helper.process();
}
}
/**
/**
* Initialise the EjbcHelper by reading the command arguments.
* Initialise the EjbcHelper by reading the command arguments.
*/
*/
private EjbcHelper(String[] args) {
private EjbcHelper(String[] args) {
int index = 0;
int index = 0;
descriptorDirectory = new File(args[index++]);
descriptorDirectory = new File(args[index++]);
@@ -119,25 +119,25 @@ public class EjbcHelper {
sourceDirectory = new File(args[index++]);
sourceDirectory = new File(args[index++]);
manifestFile = new File(args[index++]);
manifestFile = new File(args[index++]);
keepGenerated = Boolean.valueOf(args[index++]).booleanValue();
keepGenerated = Boolean.valueOf(args[index++]).booleanValue();
descriptors = new String[args.length - index];
descriptors = new String[args.length - index];
for (int i = 0; index < args.length; ++i) {
for (int i = 0; index < args.length; ++i) {
descriptors[i] = args[index++];
descriptors[i] = args[index++];
}
}
}
}
private String[] getCommandLine(boolean debug, File descriptorFile) {
private String[] getCommandLine(boolean debug, File descriptorFile) {
Vector v = new Vector();
Vector v = new Vector();
if (!debug) {
if (!debug) {
v.addElement("-noexit");
v.addElement("-noexit");
}
}
if (keepGenerated) {
if (keepGenerated) {
v.addElement("-keepgenerated");
v.addElement("-keepgenerated");
}
}
v.addElement("-d");
v.addElement("-d");
v.addElement(generatedFilesDirectory.getPath());
v.addElement(generatedFilesDirectory.getPath());
v.addElement(descriptorFile.getPath());
v.addElement(descriptorFile.getPath());
String[] args = new String[v.size()];
String[] args = new String[v.size()];
v.copyInto(args);
v.copyInto(args);
return args;
return args;
@@ -148,7 +148,7 @@ public class EjbcHelper {
* for a given deployment descriptor.
* for a given deployment descriptor.
*
*
* This process attempts to determine if the support classes need to be
* This process attempts to determine if the support classes need to be
* rebuilt. It does this by examining only some of the support classes
* rebuilt. It does this by examining only some of the support classes
* which are typically generated. If the ejbc task is interrupted generating
* which are typically generated. If the ejbc task is interrupted generating
* the support classes for a bean, all of the support classes should be removed
* the support classes for a bean, all of the support classes should be removed
* to force regeneration of the support classes.
* to force regeneration of the support classes.
@@ -170,38 +170,38 @@ public class EjbcHelper {
ObjectInputStream ois = new ObjectInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(fis);
DeploymentDescriptor dd = (DeploymentDescriptor) ois.readObject();
DeploymentDescriptor dd = (DeploymentDescriptor) ois.readObject();
fis.close();
fis.close();
String homeInterfacePath = dd.getHomeInterfaceClassName().replace('.', '/') + ".java";
String homeInterfacePath = dd.getHomeInterfaceClassName().replace('.', '/') + ".java";
String remoteInterfacePath = dd.getRemoteInterfaceClassName().replace('.', '/') + ".java";
String remoteInterfacePath = dd.getRemoteInterfaceClassName().replace('.', '/') + ".java";
String primaryKeyClassPath = null;
String primaryKeyClassPath = null;
if (dd instanceof EntityDescriptor) {
if (dd instanceof EntityDescriptor) {
primaryKeyClassPath = ((EntityDescriptor) dd).getPrimaryKeyClassName().replace('.', '/') + ".java";;
primaryKeyClassPath = ((EntityDescriptor) dd).getPrimaryKeyClassName().replace('.', '/') + ".java";;
}
}
File homeInterfaceSource = new File(sourceDirectory, homeInterfacePath);
File homeInterfaceSource = new File(sourceDirectory, homeInterfacePath);
File remoteInterfaceSource = new File(sourceDirectory, remoteInterfacePath);
File remoteInterfaceSource = new File(sourceDirectory, remoteInterfacePath);
File primaryKeyClassSource = null;
File primaryKeyClassSource = null;
if (primaryKeyClassPath != null) {
if (primaryKeyClassPath != null) {
primaryKeyClassSource = new File(sourceDirectory, remoteInterfacePath);
primaryKeyClassSource = new File(sourceDirectory, remoteInterfacePath);
}
}
// are any of the above out of date.
// are any of the above out of date.
// we find the implementation classes and see if they are older than any
// we find the implementation classes and see if they are older than any
// of the above or the .ser file itself.
// of the above or the .ser file itself.
String beanClassBase = dd.getEnterpriseBeanClassName().replace('.', '/');
String beanClassBase = dd.getEnterpriseBeanClassName().replace('.', '/');
File ejbImplentationClass
File ejbImplentationClass
= new File(generatedFilesDirectory, beanClassBase + "EOImpl.class");
= new File(generatedFilesDirectory, beanClassBase + "EOImpl.class");
File homeImplementationClass
File homeImplementationClass
= new File(generatedFilesDirectory, beanClassBase + "HomeImpl.class");
= new File(generatedFilesDirectory, beanClassBase + "HomeImpl.class");
File beanStubClass
File beanStubClass
= new File(generatedFilesDirectory, beanClassBase + "EOImpl_WLStub.class");
= new File(generatedFilesDirectory, beanClassBase + "EOImpl_WLStub.class");
// if the implementation classes don;t exist regenerate
// if the implementation classes don;t exist regenerate
if (!ejbImplentationClass.exists() || !homeImplementationClass.exists() ||
if (!ejbImplentationClass.exists() || !homeImplementationClass.exists() ||
!beanStubClass.exists()) {
!beanStubClass.exists()) {
return true;
return true;
}
}
// Is the ser file or any of the source files newer then the class files.
// Is the ser file or any of the source files newer then the class files.
// firstly find the oldest of the two class files.
// firstly find the oldest of the two class files.
long classModificationTime = ejbImplentationClass.lastModified();
long classModificationTime = ejbImplentationClass.lastModified();
@@ -211,14 +211,14 @@ public class EjbcHelper {
if (beanStubClass.lastModified() < classModificationTime) {
if (beanStubClass.lastModified() < classModificationTime) {
classModificationTime = beanStubClass.lastModified();
classModificationTime = beanStubClass.lastModified();
}
}
if (descriptorFile.lastModified() > classModificationTime ||
if (descriptorFile.lastModified() > classModificationTime ||
homeInterfaceSource.lastModified() > classModificationTime ||
homeInterfaceSource.lastModified() > classModificationTime ||
remoteInterfaceSource.lastModified() > classModificationTime) {
remoteInterfaceSource.lastModified() > classModificationTime) {
return true;
return true;
}
}
if (primaryKeyClassSource != null &&
if (primaryKeyClassSource != null &&
primaryKeyClassSource.lastModified() > classModificationTime) {
primaryKeyClassSource.lastModified() > classModificationTime) {
return true;
return true;
}
}
@@ -231,20 +231,20 @@ public class EjbcHelper {
fis.close();
fis.close();
}
}
}
}
return false;
return false;
}
}
/**
/**
* Process the descriptors in turn generating support classes for each and a manifest
* Process the descriptors in turn generating support classes for each and a manifest
* file for all of the beans.
* file for all of the beans.
*/
*/
private void process() throws Exception {
private void process() throws Exception {
String manifest = "Manifest-Version: 1.0\n\n";
String manifest = "Manifest-Version: 1.0\n\n";
for (int i = 0; i < descriptors.length; ++i) {
for (int i = 0; i < descriptors.length; ++i) {
String descriptorName = descriptors[i];
String descriptorName = descriptors[i];
File descriptorFile = new File(descriptorDirectory, descriptorName);
File descriptorFile = new File(descriptorDirectory, descriptorName);
if (isRegenRequired(descriptorFile)) {
if (isRegenRequired(descriptorFile)) {
System.out.println("Running ejbc for " + descriptorFile.getName());
System.out.println("Running ejbc for " + descriptorFile.getName());
regenerateSupportClasses(descriptorFile);
regenerateSupportClasses(descriptorFile);
@@ -253,26 +253,26 @@ public class EjbcHelper {
}
}
manifest += "Name: " + descriptorName.replace('\\', '/') + "\nEnterprise-Bean: True\n\n";
manifest += "Name: " + descriptorName.replace('\\', '/') + "\nEnterprise-Bean: True\n\n";
}
}
FileWriter fw = new FileWriter(manifestFile);
FileWriter fw = new FileWriter(manifestFile);
PrintWriter pw = new PrintWriter(fw);
PrintWriter pw = new PrintWriter(fw);
pw.print(manifest);
pw.print(manifest);
fw.flush();
fw.flush();
fw.close();
fw.close();
}
}
/**
/**
* Perform the weblogic.ejbc call to regenerate the support classes.
* Perform the weblogic.ejbc call to regenerate the support classes.
*
*
* Note that this method relies on an undocumented -noexit option to the
* Note that this method relies on an undocumented -noexit option to the
* ejbc tool to stop the ejbc tool exiting the VM altogether.
* ejbc tool to stop the ejbc tool exiting the VM altogether.
*/
*/
private void regenerateSupportClasses(File descriptorFile) throws Exception {
private void regenerateSupportClasses(File descriptorFile) throws Exception {
// create a Java task to do the rebuild
// create a Java task to do the rebuild
String[] args = getCommandLine(false, descriptorFile);
String[] args = getCommandLine(false, descriptorFile);
try {
try {
weblogic.ejbc.main(args);
weblogic.ejbc.main(args);
} catch (Exception e) {
} catch (Exception e) {