1 25 26 package org.objectweb.jonas_ejb.genic; 27 28 import java.io.File ; 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 33 import org.apache.velocity.app.VelocityEngine; 34 35 import org.objectweb.jonas_ejb.deployment.api.BeanDesc; 36 import org.objectweb.jonas_ejb.deployment.api.EntityCmp2Desc; 37 import org.objectweb.jonas_ejb.deployment.api.EntityDesc; 38 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc; 39 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc; 40 import org.objectweb.jonas_ejb.lib.BeanNaming; 41 import org.objectweb.jonas_ejb.lib.RdbMappingBuilder; 42 43 import org.objectweb.jonas.common.Log; 44 45 import org.objectweb.jorm.compiler.api.JormCompilerParameter; 46 import org.objectweb.jorm.compiler.lib.JormCompiler; 47 48 import org.objectweb.util.monolog.api.BasicLevel; 49 import org.objectweb.util.monolog.api.Logger; 50 51 63 public class BeanSources { 64 65 68 private static final String JAVA_SUFFIX = ".java"; 69 70 73 private static final String RDB_PREFIX = "rdb"; 74 75 78 private static final String CLUSTER_SUFFIX = "_Cmi"; 79 80 83 private String wrpRemoteFileName = null; 84 85 88 private String wrpLocalFileName = null; 89 90 93 private String wrpHomeFileName = null; 94 95 98 private String wrpHomeClusterFileName = null; 99 100 103 private String wrpLocalHomeFileName = null; 104 105 108 private String wrpHandleFileName = null; 109 110 113 private String wrpBeanFileName = null; 114 115 118 private String wrpServiceEndpointFileName = null; 119 120 123 private String wrpSEHomeFileName = null; 124 125 128 private String itfCohCmp2Entity = null; 129 130 133 private ArrayList sources; 134 135 138 private ArrayList noRemoteJava; 139 140 143 private String outdir = null; 144 145 148 private BeanDesc dd = null; 149 150 153 private JormCompiler jormCompiler; 154 155 158 private Logger logger = null; 159 160 170 public BeanSources(BeanDesc beanDesc, String dirOutputName, VelocityEngine ve, JormCompiler jormCompiler) 171 throws GenICException { 172 this(beanDesc, dirOutputName, ve); 173 this.jormCompiler = jormCompiler; 174 } 175 176 185 public BeanSources(BeanDesc beanDesc, String dirOutputName, VelocityEngine ve) throws GenICException { 186 187 logger = Log.getLogger(Log.JONAS_GENIC_PREFIX); 188 dd = beanDesc; 189 outdir = dirOutputName; 190 sources = new ArrayList (); 191 noRemoteJava = new ArrayList (); 192 193 if (dd.getHomeClass() != null) { 195 if (outdir.length() > 0) { 196 wrpHomeFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpHomeName()); 197 } else { 198 wrpHomeFileName = dd.getWrpHomeName(); 199 } 200 wrpHomeClusterFileName = wrpHomeFileName.concat(CLUSTER_SUFFIX + JAVA_SUFFIX); 201 noRemoteJava.add(wrpHomeClusterFileName); 202 sources.add(new Source(dd, wrpHomeClusterFileName, Source.CLUSTER_HOME, ve)); 203 204 wrpHomeFileName = wrpHomeFileName.concat(JAVA_SUFFIX); 205 sources.add(new Source(dd, wrpHomeFileName, Source.HOME, ve)); 206 207 if (dd instanceof EntityDesc) { 209 if (outdir.length() > 0) { 210 wrpHandleFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpHandleName()); 211 } else { 212 wrpHandleFileName = dd.getWrpHandleName(); 213 } 214 wrpHandleFileName = wrpHandleFileName.concat(JAVA_SUFFIX); 215 noRemoteJava.add(wrpHandleFileName); 216 sources.add(new Source(dd, wrpHandleFileName, Source.ENTITY_HANDLE, ve)); 217 } 218 } 219 220 if (dd.getRemoteClass() != null) { 222 if (outdir.length() > 0) { 223 wrpRemoteFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpRemoteName()); 224 } else { 225 wrpRemoteFileName = dd.getWrpRemoteName(); 226 } 227 wrpRemoteFileName = wrpRemoteFileName.concat(JAVA_SUFFIX); 228 sources.add(new Source(dd, wrpRemoteFileName, Source.REMOTE, ve)); 229 } 230 231 if (dd.getLocalHomeClass() != null) { 233 if (outdir.length() > 0) { 234 wrpLocalHomeFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpLocalHomeName()); 235 } else { 236 wrpLocalHomeFileName = dd.getWrpLocalHomeName(); 237 } 238 wrpLocalHomeFileName = wrpLocalHomeFileName.concat(JAVA_SUFFIX); 239 noRemoteJava.add(wrpLocalHomeFileName); 240 sources.add(new Source(dd, wrpLocalHomeFileName, Source.LOCAL_HOME, ve)); 241 } 242 243 if (dd.getLocalClass() != null) { 245 if (outdir.length() > 0) { 246 wrpLocalFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpLocalName()); 247 } else { 248 wrpLocalFileName = dd.getWrpLocalName(); 249 } 250 wrpLocalFileName = wrpLocalFileName.concat(JAVA_SUFFIX); 251 noRemoteJava.add(wrpLocalFileName); 252 sources.add(new Source(dd, wrpLocalFileName, Source.LOCAL, ve)); 253 } 254 255 if (dd instanceof SessionStatelessDesc) { 257 SessionStatelessDesc ssd = (SessionStatelessDesc) dd; 258 if (ssd.getServiceEndpointClass() != null) { 259 if (outdir.length() > 0) { 261 wrpServiceEndpointFileName = outdir + File.separatorChar 262 + BeanNaming.getPath(ssd.getFullWrpServiceEndpointName()); 263 } else { 264 wrpServiceEndpointFileName = ssd.getWrpServiceEndpointName(); 265 } 266 wrpServiceEndpointFileName = wrpServiceEndpointFileName.concat(JAVA_SUFFIX); 267 sources.add(new Source(dd, wrpServiceEndpointFileName, Source.SERVICE_ENDPOINT, ve)); 269 if (outdir.length() > 0) { 271 wrpSEHomeFileName = outdir + File.separatorChar + BeanNaming.getPath(ssd.getFullWrpSEHomeName()); 272 } else { 273 wrpSEHomeFileName = ssd.getWrpSEHomeName(); 274 } 275 wrpSEHomeFileName = wrpSEHomeFileName.concat(JAVA_SUFFIX); 276 noRemoteJava.add(wrpSEHomeFileName); sources.add(new Source(dd, wrpSEHomeFileName, Source.SERVICE_ENDPOINT_HOME, ve)); 278 } 279 } 280 281 if (dd instanceof EntityJdbcCmp1Desc) { 283 if (outdir.length() > 0) { 284 wrpBeanFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullDerivedBeanName()); 285 } else { 286 wrpBeanFileName = dd.getDerivedBeanName(); 287 } 288 wrpBeanFileName = wrpBeanFileName.concat(JAVA_SUFFIX); 289 noRemoteJava.add(wrpBeanFileName); 290 sources.add(new Source(dd, wrpBeanFileName, Source.ENTITY_CMP_JDBC, ve)); 291 } 292 if (dd instanceof EntityCmp2Desc) { 293 EntityCmp2Desc ecd = (EntityCmp2Desc) dd; 294 if (outdir.length() > 0) { 295 wrpBeanFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullDerivedBeanName()) 296 + JAVA_SUFFIX; 297 if (ecd.needJormCoherenceHelper()) { 298 itfCohCmp2Entity = outdir + File.separatorChar 299 + BeanNaming.getPath(ecd.getJormCoherenceHelperFQItfName()) + JAVA_SUFFIX; 300 } 301 } else { 302 wrpBeanFileName = BeanNaming.getPath(dd.getDerivedBeanName()) + JAVA_SUFFIX; 303 if (ecd.needJormCoherenceHelper()) { 304 itfCohCmp2Entity = BeanNaming.getPath(ecd.getJormCoherenceHelperItfName()) + JAVA_SUFFIX; 305 } 306 } 307 if (ecd.needJormCoherenceHelper()) { 308 sources.add(new Source(dd, itfCohCmp2Entity, Source.ITF_COH_CMP2_ENTITY, ve)); 309 noRemoteJava.add(itfCohCmp2Entity); 310 } 311 noRemoteJava.add(wrpBeanFileName); 312 sources.add(new Source(dd, wrpBeanFileName, Source.ENTITY_CMP_JDBC, ve)); 313 } 314 } 315 316 320 public void generate() throws GenICException { 321 for (Iterator it = sources.iterator(); it.hasNext();) { 323 Source src = (Source) it.next(); 324 src.generate(); 325 } 326 327 if (dd instanceof EntityCmp2Desc) { 329 EntityCmp2Desc ecd = (EntityCmp2Desc) dd; 330 331 JormCompilerParameter cp = jormCompiler.getCompilerParameter(); 333 cp.setProjectName(RdbMappingBuilder.getProjectName()); 334 cp.setKeepSrc(true); 335 cp.setOutput(outdir); 336 cp.setClassMappingInheritance("org.objectweb.jonas_ejb.container.jorm.RdbFactory"); 337 switch (ecd.getLockPolicy()) { 338 case EntityDesc.LOCK_CONTAINER_READ_UNCOMMITTED: 339 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchCRU"); 340 break; 341 case EntityDesc.LOCK_CONTAINER_SERIALIZED: 342 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchCS"); 343 break; 344 case EntityDesc.LOCK_CONTAINER_READ_COMMITTED: 345 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchCRC"); 346 break; 347 case EntityDesc.LOCK_DATABASE: 348 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchDB"); 349 break; 350 case EntityDesc.LOCK_READ_ONLY: 351 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchRO"); 352 break; 353 default: 354 throw new GenICException("Cannot find JEntitySwitch: Unknown lock policy"); 355 } 356 357 Collection jormflist = null; 359 try { 360 if (Log.getLogger("org.objectweb.jonas_ejb.mijorm").isLoggable(BasicLevel.DEBUG)) { 362 jormCompiler.generateJormFiles(ecd.getJormList()); 363 } 364 jormflist = jormCompiler.generateFiles(ecd.getJormList()); 365 } catch (Exception e) { 366 throw new GenICException("Problem during jorm generation", e); 367 } 368 for (Iterator i = jormflist.iterator(); i.hasNext();) { 370 String file = (String ) i.next(); 371 logger.log(BasicLevel.DEBUG, "Jorm generated file: " + file); 372 noRemoteJava.add(file); 373 } 374 } 375 } 376 377 380 public String getEjbName() { 381 return dd.getEjbName(); 382 } 383 384 388 public String getWrpHomeFileName() { 389 return wrpHomeFileName; 390 } 391 392 396 public String getWrpHomeClusterFileName() { 397 return wrpHomeClusterFileName; 398 } 399 400 404 public String getWrpRemoteFileName() { 405 return wrpRemoteFileName; 406 } 407 408 412 public String getWrpRemoteClassName() { 413 return dd.getFullWrpRemoteName(); 414 } 415 416 420 public String getWrpServiceEndpointFileName() { 421 return wrpServiceEndpointFileName; 422 } 423 424 428 public String getWrpSEHomeFileName() { 429 return wrpSEHomeFileName; 430 } 431 432 436 public String getWrpServiceEndpointClassName() { 437 if (dd instanceof SessionStatelessDesc) { 438 return ((SessionStatelessDesc) dd).getFullWrpServiceEndpointName(); 439 } 440 return null; 441 } 442 443 447 public String getWrpHomeClassName() { 448 return dd.getFullWrpHomeName(); 449 } 450 451 454 public Collection getNoRemoteJavas() { 455 return noRemoteJava; 456 } 457 } | Popular Tags |