1 18 19 package org.apache.tools.ant.taskdefs.optional.ejb; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.Hashtable ; 24 import javax.xml.parsers.SAXParser ; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Project; 27 import org.xml.sax.SAXException ; 28 29 84 public class IPlanetDeploymentTool extends GenericDeploymentTool { 85 86 87 private File iashome; 88 private String jarSuffix = ".jar"; 89 private boolean keepgenerated = false; 90 private boolean debug = false; 91 92 98 private String descriptorName; 99 private String iasDescriptorName; 100 101 107 private String displayName; 108 109 114 private static final String IAS_DD = "ias-ejb-jar.xml"; 115 116 123 public void setIashome(File iashome) { 124 this.iashome = iashome; 125 } 126 127 135 public void setKeepgenerated(boolean keepgenerated) { 136 this.keepgenerated = keepgenerated; 137 } 138 139 145 public void setDebug(boolean debug) { 146 this.debug = debug; 147 } 148 149 155 public void setSuffix(String jarSuffix) { 156 this.jarSuffix = jarSuffix; 157 } 158 159 166 public void setGenericJarSuffix(String inString) { 167 log("Since a generic JAR file is not created during processing, the " 168 + "iPlanet Deployment Tool does not support the " 169 + "\"genericjarsuffix\" attribute. It will be ignored.", 170 Project.MSG_WARN); 171 } 172 173 174 public void processDescriptor(String descriptorName, SAXParser saxParser) { 175 this.descriptorName = descriptorName; 176 this.iasDescriptorName = null; 177 178 log("iPlanet Deployment Tool processing: " + descriptorName + " (and " 179 + getIasDescriptorName() + ")", Project.MSG_VERBOSE); 180 181 super.processDescriptor(descriptorName, saxParser); 182 } 183 184 193 protected void checkConfiguration(String descriptorFileName, 194 SAXParser saxParser) throws BuildException { 195 196 int startOfName = descriptorFileName.lastIndexOf(File.separatorChar) + 1; 197 String stdXml = descriptorFileName.substring(startOfName); 198 if (stdXml.equals(EJB_DD) && (getConfig().baseJarName == null)) { 199 String msg = "No name specified for the completed JAR file. The EJB" 200 + " descriptor should be prepended with the JAR " 201 + "name or it should be specified using the " 202 + "attribute \"basejarname\" in the \"ejbjar\" task."; 203 throw new BuildException(msg, getLocation()); 204 } 205 206 File iasDescriptor = new File (getConfig().descriptorDir, 207 getIasDescriptorName()); 208 if ((!iasDescriptor.exists()) || (!iasDescriptor.isFile())) { 209 String msg = "The iAS-specific EJB descriptor (" 210 + iasDescriptor + ") was not found."; 211 throw new BuildException(msg, getLocation()); 212 } 213 214 if ((iashome != null) && (!iashome.isDirectory())) { 215 String msg = "If \"iashome\" is specified, it must be a valid " 216 + "directory (it was set to " + iashome + ")."; 217 throw new BuildException(msg, getLocation()); 218 } 219 } 220 221 236 protected Hashtable parseEjbFiles(String descriptorFileName, 237 SAXParser saxParser) throws IOException , SAXException { 238 239 Hashtable files; 240 241 242 IPlanetEjbc ejbc = new IPlanetEjbc( 243 new File (getConfig().descriptorDir, 244 descriptorFileName), 245 new File (getConfig().descriptorDir, 246 getIasDescriptorName()), 247 getConfig().srcDir, 248 getCombinedClasspath().toString(), 249 saxParser); 250 ejbc.setRetainSource(keepgenerated); 251 ejbc.setDebugOutput(debug); 252 if (iashome != null) { 253 ejbc.setIasHomeDir(iashome); 254 } 255 256 257 try { 258 ejbc.execute(); 259 } catch (IPlanetEjbc.EjbcException e) { 260 throw new BuildException("An error has occurred while trying to " 261 + "execute the iAS ejbc utility", e, getLocation()); 262 } 263 264 displayName = ejbc.getDisplayName(); 265 files = ejbc.getEjbFiles(); 266 267 268 String [] cmpDescriptors = ejbc.getCmpDescriptors(); 269 if (cmpDescriptors.length > 0) { 270 File baseDir = getConfig().descriptorDir; 271 272 int endOfPath = descriptorFileName.lastIndexOf(File.separator); 273 String relativePath = descriptorFileName.substring(0, endOfPath + 1); 274 275 for (int i = 0; i < cmpDescriptors.length; i++) { 276 int endOfCmp = cmpDescriptors[i].lastIndexOf('/'); 277 String cmpDescriptor = cmpDescriptors[i].substring(endOfCmp + 1); 278 279 File cmpFile = new File (baseDir, relativePath + cmpDescriptor); 280 if (!cmpFile.exists()) { 281 throw new BuildException("The CMP descriptor file (" 282 + cmpFile + ") could not be found.", getLocation()); 283 } 284 files.put(cmpDescriptors[i], cmpFile); 285 } 286 } 287 288 return files; 289 } 290 291 299 protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { 300 ejbFiles.put(META_DIR + IAS_DD, new File (getConfig().descriptorDir, 301 getIasDescriptorName())); 302 } 303 304 313 File getVendorOutputJarFile(String baseName) { 314 File jarFile = new File (getDestDir(), baseName + jarSuffix); 315 log("JAR file name: " + jarFile.toString(), Project.MSG_VERBOSE); 316 return jarFile; 317 } 318 319 326 protected String getPublicId() { 327 return null; 328 } 329 330 338 private String getIasDescriptorName() { 339 340 341 if (iasDescriptorName != null) { 342 return iasDescriptorName; 343 } 344 345 String path = ""; String basename; String remainder; 349 350 int startOfFileName = descriptorName.lastIndexOf(File.separatorChar); 351 if (startOfFileName != -1) { 352 path = descriptorName.substring(0, startOfFileName + 1); 353 } 354 355 356 if (descriptorName.substring(startOfFileName + 1).equals(EJB_DD)) { 357 basename = ""; 358 remainder = EJB_DD; 359 360 } else { 361 int endOfBaseName = descriptorName.indexOf( 362 getConfig().baseNameTerminator, 363 startOfFileName); 364 369 if (endOfBaseName < 0) { 370 endOfBaseName = descriptorName.lastIndexOf('.') - 1; 371 if (endOfBaseName < 0) { 372 endOfBaseName = descriptorName.length() - 1; 373 } 374 } 375 376 basename = descriptorName.substring(startOfFileName + 1, 377 endOfBaseName + 1); 378 remainder = descriptorName.substring(endOfBaseName + 1); 379 } 380 381 iasDescriptorName = path + basename + "ias-" + remainder; 382 return iasDescriptorName; 383 } 384 } 385 | Popular Tags |