1 23 24 33 34 package com.sun.enterprise.deployment.backend; 35 36 import java.io.File ; 37 import java.util.List ; 38 import java.util.ArrayList ; 39 import java.util.Iterator ; 40 import java.util.logging.Level ; 41 import java.util.logging.Logger ; 42 import javax.enterprise.deploy.shared.ModuleType ; 43 44 import com.sun.enterprise.util.io.FileUtils; 45 import com.sun.enterprise.util.StringUtils; 46 import com.sun.enterprise.util.zip.ZipItem; 47 48 import com.sun.enterprise.instance.BaseManager; 49 import com.sun.enterprise.instance.AppsManager; 50 import com.sun.enterprise.instance.EjbModulesManager; 51 import com.sun.enterprise.instance.WebModulesManager; 52 import com.sun.enterprise.instance.ModulesManager; 53 import com.sun.enterprise.instance.UniqueIdGenerator; 54 55 import com.sun.enterprise.loader.EJBClassPathUtils; 56 import com.sun.ejb.codegen.IASEJBC; 57 import com.sun.ejb.codegen.IASEJBCTimes; 58 import com.sun.enterprise.util.i18n.StringManager; 59 import com.sun.enterprise.loader.EJBClassLoader; 60 61 62 import com.sun.enterprise.security.acl.RoleMapper; 63 import com.sun.enterprise.deployment.Application; 64 import com.sun.enterprise.deployment.Descriptor; 65 import com.sun.enterprise.deployment.EjbBundleDescriptor; 66 import com.sun.enterprise.deployment.EjbDescriptor; 67 import com.sun.enterprise.deployment.BundleDescriptor; 68 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 69 import com.sun.enterprise.deployment.util.ModuleDescriptor; 70 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 71 import com.sun.enterprise.security.application.EJBSecurityManager; 72 73 import java.io.IOException ; 74 import org.xml.sax.SAXParseException ; 75 import com.sun.enterprise.config.ConfigException; 76 77 116 public class EJBCompiler 117 { 118 123 public EJBCompiler 124 ( 125 String name, 126 File srcDir, 127 File oldSrcDir, 128 File stubsDir, 129 File oldStubsDir, 130 BaseManager manager, 131 DeploymentRequest request, 132 IASEJBCTimes timing 133 134 ) throws IASDeploymentException 135 136 { 137 this(name, srcDir, oldSrcDir, stubsDir, oldStubsDir, manager, request, timing, request.getCompleteClasspath()); 138 } 139 140 146 public EJBCompiler 147 ( 148 String name, 149 File srcDir, 150 File oldSrcDir, 151 File stubsDir, 152 File oldStubsDir, 153 BaseManager manager, 154 DeploymentRequest request, 155 IASEJBCTimes timing, 156 java.util.List classpathForCompilation 157 158 ) throws IASDeploymentException 159 160 { 161 assert StringUtils.ok(name); 162 assert FileUtils.safeIsDirectory(srcDir); 163 assert FileUtils.safeIsDirectory(oldSrcDir); 164 assert FileUtils.safeIsDirectory(stubsDir); 165 assert FileUtils.safeIsDirectory(oldStubsDir); 166 assert manager != null; 167 assert request != null; 168 assert timing != null; 169 170 try 171 { 172 this.name = name; 173 this.request = request; 174 this.classpathForCompilation = classpathForCompilation; 175 176 this.ejbcContext = new EjbcContextImpl(); 178 ejbcContext.setSrcDir(srcDir); 179 ejbcContext.setOldSrcDir(oldSrcDir); 180 ejbcContext.setStubsDir(stubsDir); 181 ejbcContext.setOldStubsDir(oldStubsDir); 182 ejbcContext.setTiming(timing); 183 ejbcContext.setRmicOptions( manager.getRmicOptions() ); 184 ejbcContext.setJavacOptions( manager.getJavacOptions() ); 185 ejbcContext.setOptionalArguments(this.request.getOptionalArguments()); 186 ejbcContext.setDeploymentRequest(request); 187 188 if(manager instanceof ModulesManager) 189 { 190 moduleManager = (ModulesManager)manager; 191 appManager = null; 192 } 193 else if(manager instanceof AppsManager) 194 { 195 appManager = (AppsManager)manager; 196 moduleManager = null; 197 } 198 else 199 assert (false); 200 } 201 catch(Throwable t) 202 { 203 throw wrapException(t); 204 } 205 } 206 207 209 public ZipItem[] compile() throws IASDeploymentException 210 { 211 ZipItem[] clientStubs = null; 212 try 213 { 214 if(request.getNoEJBC()) 215 { 216 _logger.info( "********** EJBC Skipped! ************" ); 217 return new ZipItem[] {}; 218 } 219 220 if(appManager != null) 221 { 222 clientStubs = preDeployApp(); 223 } 224 else 225 { 226 clientStubs = preDeployModule(); 227 } 228 229 Application app = ejbcContext.getDescriptor(); 230 if (app != null) 231 { 232 for (Iterator iter = app.getEjbDescriptors().iterator(); 233 iter.hasNext();) 234 { 235 EJBSecurityManager.loadPolicyConfiguration((EjbDescriptor)iter.next()); 237 } 238 } 239 } 240 catch(Throwable t) 241 { 242 throw wrapException(t); 243 } finally { 244 this.ejbcContext.cleanup(); 245 } 246 247 return clientStubs; 248 } 249 250 281 private ZipItem[] preDeployApp() throws Exception 282 { 283 ZipItem[] clientStubs = null; 284 285 Application application = request.getDescriptor(); 286 287 String appRoot = ejbcContext.getSrcDir().getCanonicalPath(); 288 setEjbClasspath(request.getModuleClasspath()); 289 ejbcContext.setDescriptor(application); 290 291 297 String [] classPathUrls = new String [this.classpathForCompilation.size()]; 299 classPathUrls = (String []) this.classpathForCompilation.toArray(classPathUrls); 300 301 ejbcContext.setClasspathUrls(classPathUrls); 302 303 verifyContext(); 305 306 if ( this.ejbcContext.isRedeploy() ) { 308 309 String oldAppRoot = ejbcContext.getOldSrcDir().getCanonicalPath(); 310 311 List oldEjbClassPath = new ArrayList (); 318 String newStubsDir = ejbcContext.getStubsDir().getCanonicalPath(); 319 for(int i = 0; i < classPathUrls.length; i++) { 320 String nextNew = classPathUrls[i]; 321 if( nextNew.startsWith(appRoot) ) { 322 StringBuffer sb = new StringBuffer (nextNew); 323 StringBuffer nextOld = sb.replace(0, appRoot.length(), 324 oldAppRoot); 325 oldEjbClassPath.add(nextOld.toString()); 326 } else if(!nextNew.equals(newStubsDir)) { 327 oldEjbClassPath.add(nextNew); 328 } 329 } 330 331 final ClassLoader oldEjbClassLoader = 332 DeploymentUtils.getClassLoader(oldEjbClassPath, 333 request.getParentClassLoader(), this.ejbcContext.getOldStubsDir()); 334 this.ejbcContext.setOldClassLoader(oldEjbClassLoader); 335 336 } 337 338 clientStubs = IASEJBC.ejbc(this.ejbcContext); 340 341 UniqueIdGenerator uidGenerator = UniqueIdGenerator.getInstance(); 342 long uid = uidGenerator.getNextUniqueId(); 343 344 application.setUniqueId(uid); 345 346 this.appManager.saveAppDescriptor(this.name, application, 347 request.getDeployedDirectory().getCanonicalPath(), 348 request.getGeneratedXMLDirectory().getCanonicalPath(), false); 349 350 return clientStubs; 351 } 352 353 358 private void setEjbClasspath(List ejbClassPath) { 359 360 String [] ejbClassPathUrls = new String [ejbClassPath.size()]; 361 ejbClassPathUrls = (String []) ejbClassPath.toArray(ejbClassPathUrls); 362 this.ejbcContext.setEjbClasspathUrls(ejbClassPathUrls); 363 } 364 365 373 private ZipItem[] preDeployModule() throws Exception 374 { 375 ZipItem[] clientStubs = null; 376 377 Application application = request.getDescriptor(); 378 ejbcContext.setDescriptor(application); 379 380 386 String [] classPathUrls = new String [this.classpathForCompilation.size()]; 388 classPathUrls = (String []) this.classpathForCompilation.toArray(classPathUrls); 389 390 ejbcContext.setClasspathUrls(classPathUrls); 391 392 verifyContext(); 394 395 if ( this.ejbcContext.isRedeploy() ) { 397 398 String oldModRoot = ejbcContext.getOldSrcDir().getCanonicalPath(); 399 400 List oldEjbClassPath = new ArrayList (); 402 oldEjbClassPath.add(oldModRoot); 403 404 final ClassLoader oldEjbClassLoader = 405 DeploymentUtils.getClassLoader(oldEjbClassPath, 406 request.getParentClassLoader(), this.ejbcContext.getOldStubsDir()); 407 this.ejbcContext.setOldClassLoader(oldEjbClassLoader); 408 409 } 410 411 412 clientStubs = IASEJBC.ejbc(this.ejbcContext); 414 415 416 417 UniqueIdGenerator uidGenerator = UniqueIdGenerator.getInstance(); 418 long uid = uidGenerator.getNextUniqueId(); 419 420 for (Iterator itr = application.getEjbBundleDescriptors().iterator(); 421 itr.hasNext();) 422 { 423 424 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) itr.next(); 427 428 bundleDesc.setUniqueId(uid); 430 } 431 this.moduleManager.saveAppDescriptor(this.name, application, 432 request.getDeployedDirectory().getCanonicalPath(), 433 request.getGeneratedXMLDirectory().getCanonicalPath(), true); 434 435 return clientStubs; 436 } 437 438 441 void verifyContext() throws IASDeploymentException 442 { 443 if ( (this.ejbcContext.getSrcDir() == null) 444 || (this.ejbcContext.getStubsDir() == null) 445 || (this.ejbcContext.getDescriptor() == null) 446 || (this.ejbcContext.getRmicOptions() == null) 447 || (this.ejbcContext.getJavacOptions() == null) 448 || (this.ejbcContext.getTiming() == null)) 449 { 450 String msg = localStrings.getString( 452 "enterprise.deployment.backend.bad_ejbc_ctx"); 453 throw new IASDeploymentException(msg); 454 } 455 } 456 457 459 IASDeploymentException wrapException(Throwable t) 460 { 461 String msg = localStrings.getString( 462 "enterprise.deployment.backend.fatal_ejbc_error" ); 463 464 if(t instanceof java.rmi.RemoteException ) 465 { 466 msg += localStrings.getString( 467 "enterprise.deployment.backend.ejbc_remoteexception", t ); 468 } 469 470 return new IASDeploymentException(msg, t); 471 } 472 473 474 476 private String name; 477 private ModulesManager moduleManager; 478 private AppsManager appManager; 479 private DeploymentRequest request; 480 private EjbcContextImpl ejbcContext; 481 482 483 private java.util.List classpathForCompilation; 484 485 private static final Logger _logger = DeploymentLogger.get(); 486 private static StringManager localStrings = 487 StringManager.getManager( EJBCompiler.class ); 488 } 489 | Popular Tags |