protected void updateEJBJar(ControlAssemblyContext.EJBModule ejbAssemblyContext,
EJBInfo ejbInfo,
String ejbLinkValue)
throws ControlAssemblyException {
ControlAssemblyContext cac = (ControlAssemblyContext)ejbAssemblyContext;
cac.getMessager().printNotice("EJBControlAssembler.updateEJBJar() called");
cac.getMessager().printNotice(" ejbInfo=" + ejbInfo );
cac.getMessager().printNotice(" ejbLinkValue=" + ejbLinkValue );
File ejbJarFile = ejbAssemblyContext.getEjbJarXml();
FileInputStream ejbJarStream;
try {
ejbJarStream = new FileInputStream( ejbJarFile );
}
catch (FileNotFoundException fnfe) {
String msg = "EJBControlAssembler aborted: " +
"caught FileNotFoundException attempting to read file " +
ejbJarFile.getAbsolutePath() +
". Message: " +
fnfe.getMessage();
cac.getMessager().printWarning(msg);
return;
}
try
{
// get the existing <ejb-jar> XBean from the stream
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document ejbDoc = db.parse(ejbJarStream);
ejbJarStream.close();
ejbJarStream = null;
EJBJarDescriptorHandler ejbHandler = EJBJarDescriptorHandler.getInstance();
ejbHandler.assemble(ejbDoc, ejbInfo, ejbLinkValue);
// overwrite existing ejb-jar.xml file with new document
writeXML(cac, ejbDoc, ejbJarFile);
}
catch(IOException ioe) {
String msg = "EJBControlAssembler: caught IOException " +
"attempting to write to file " +
ejbJarFile.getAbsolutePath() +
". Message: " +
ioe.getMessage();
cac.getMessager().printError(msg);
}
catch (ParserConfigurationException e) {
String msg = "EJBControlAssembler: caught ParserConfigurationException " +
"attempting to read to file " +
ejbJarFile.getAbsolutePath() +
". Message: " +
e.getMessage();
cac.getMessager().printError(msg);
}
catch (SAXException e) {
String msg = "EJBControlAssembler: caught SAXException " +
"attempting to read to file " +
ejbJarFile.getAbsolutePath() +
". Message: " +
e.getMessage();
cac.getMessager().printError(msg);
}
finally {
try {
if (ejbJarStream != null)
ejbJarStream.close();