00001
00026 package org.objectweb.jonas_ejb.genic;
00027
00028 import java.io.File;
00029 import java.util.ArrayList;
00030 import java.util.Collection;
00031 import java.util.Iterator;
00032
00033 import org.apache.velocity.app.VelocityEngine;
00034
00035 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
00036 import org.objectweb.jonas_ejb.deployment.api.EntityCmp2Desc;
00037 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
00038 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc;
00039 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
00040 import org.objectweb.jonas_ejb.lib.BeanNaming;
00041 import org.objectweb.jonas_ejb.lib.RdbMappingBuilder;
00042
00043 import org.objectweb.jonas.common.Log;
00044
00045 import org.objectweb.jorm.compiler.api.JormCompilerParameter;
00046 import org.objectweb.jorm.compiler.lib.JormCompiler;
00047
00048 import org.objectweb.util.monolog.api.BasicLevel;
00049 import org.objectweb.util.monolog.api.Logger;
00050
00063 public class BeanSources {
00064
00068 private static final String JAVA_SUFFIX = ".java";
00069
00073 private static final String RDB_PREFIX = "rdb";
00074
00078 private static final String CLUSTER_SUFFIX = "_Cluster.xml";
00079
00083 private String wrpRemoteFileName = null;
00084
00088 private String wrpLocalFileName = null;
00089
00093 private String wrpHomeFileName = null;
00094
00098 private String wrpHomeClusterConfFileName = null;
00099
00103 private String wrpLocalHomeFileName = null;
00104
00108 private String wrpHandleFileName = null;
00109
00113 private String wrpBeanFileName = null;
00114
00118 private String wrpServiceEndpointFileName = null;
00119
00123 private String wrpSEHomeFileName = null;
00124
00128 private String itfCohCmp2Entity = null;
00129
00133 private ArrayList sources;
00134
00138 private ArrayList noRemoteJava;
00139
00143 private String outdir = null;
00144
00148 private BeanDesc dd = null;
00149
00153 private JormCompiler jormCompiler;
00154
00158 private Logger logger = null;
00159
00170 public BeanSources(BeanDesc beanDesc, String dirOutputName, VelocityEngine ve, JormCompiler jormCompiler)
00171 throws GenICException {
00172 this(beanDesc, dirOutputName, ve);
00173 this.jormCompiler = jormCompiler;
00174 }
00175
00185 public BeanSources(BeanDesc beanDesc, String dirOutputName, VelocityEngine ve) throws GenICException {
00186
00187 logger = Log.getLogger(Log.JONAS_GENIC_PREFIX);
00188 dd = beanDesc;
00189 outdir = dirOutputName;
00190 sources = new ArrayList();
00191 noRemoteJava = new ArrayList();
00192
00193
00194 if (dd.getHomeClass() != null) {
00195 if (outdir.length() > 0) {
00196 wrpHomeFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpHomeName());
00197 } else {
00198 wrpHomeFileName = dd.getWrpHomeName();
00199 }
00200 wrpHomeClusterConfFileName = wrpHomeFileName.concat(CLUSTER_SUFFIX);
00201 sources.add(new Source(dd, wrpHomeClusterConfFileName, Source.CLUSTER_HOME, ve));
00202 wrpHomeFileName = wrpHomeFileName.concat(JAVA_SUFFIX);
00203 sources.add(new Source(dd, wrpHomeFileName, Source.HOME, ve));
00204
00205 if (dd instanceof EntityDesc) {
00206 if (outdir.length() > 0) {
00207 wrpHandleFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpHandleName());
00208 } else {
00209 wrpHandleFileName = dd.getWrpHandleName();
00210 }
00211 wrpHandleFileName = wrpHandleFileName.concat(JAVA_SUFFIX);
00212 noRemoteJava.add(wrpHandleFileName);
00213 sources.add(new Source(dd, wrpHandleFileName, Source.ENTITY_HANDLE, ve));
00214 }
00215 }
00216
00217
00218 if (dd.getRemoteClass() != null) {
00219 if (outdir.length() > 0) {
00220 wrpRemoteFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpRemoteName());
00221 } else {
00222 wrpRemoteFileName = dd.getWrpRemoteName();
00223 }
00224 wrpRemoteFileName = wrpRemoteFileName.concat(JAVA_SUFFIX);
00225 sources.add(new Source(dd, wrpRemoteFileName, Source.REMOTE, ve));
00226 }
00227
00228
00229 if (dd.getLocalHomeClass() != null) {
00230 if (outdir.length() > 0) {
00231 wrpLocalHomeFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpLocalHomeName());
00232 } else {
00233 wrpLocalHomeFileName = dd.getWrpLocalHomeName();
00234 }
00235 wrpLocalHomeFileName = wrpLocalHomeFileName.concat(JAVA_SUFFIX);
00236 noRemoteJava.add(wrpLocalHomeFileName);
00237 sources.add(new Source(dd, wrpLocalHomeFileName, Source.LOCAL_HOME, ve));
00238 }
00239
00240
00241 if (dd.getLocalClass() != null) {
00242 if (outdir.length() > 0) {
00243 wrpLocalFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullWrpLocalName());
00244 } else {
00245 wrpLocalFileName = dd.getWrpLocalName();
00246 }
00247 wrpLocalFileName = wrpLocalFileName.concat(JAVA_SUFFIX);
00248 noRemoteJava.add(wrpLocalFileName);
00249 sources.add(new Source(dd, wrpLocalFileName, Source.LOCAL, ve));
00250 }
00251
00252
00253 if (dd instanceof SessionStatelessDesc) {
00254 SessionStatelessDesc ssd = (SessionStatelessDesc) dd;
00255 if (ssd.getServiceEndpointClass() != null) {
00256
00257 if (outdir.length() > 0) {
00258 wrpServiceEndpointFileName = outdir + File.separatorChar
00259 + BeanNaming.getPath(ssd.getFullWrpServiceEndpointName());
00260 } else {
00261 wrpServiceEndpointFileName = ssd.getWrpServiceEndpointName();
00262 }
00263 wrpServiceEndpointFileName = wrpServiceEndpointFileName.concat(JAVA_SUFFIX);
00264
00265 sources.add(new Source(dd, wrpServiceEndpointFileName, Source.SERVICE_ENDPOINT, ve));
00266
00267 if (outdir.length() > 0) {
00268 wrpSEHomeFileName = outdir + File.separatorChar
00269 + BeanNaming.getPath(ssd.getFullWrpSEHomeName());
00270 } else {
00271 wrpSEHomeFileName = ssd.getWrpSEHomeName();
00272 }
00273 wrpSEHomeFileName = wrpSEHomeFileName.concat(JAVA_SUFFIX);
00274 noRemoteJava.add(wrpSEHomeFileName);
00275 sources.add(new Source(dd, wrpSEHomeFileName, Source.SERVICE_ENDPOINT_HOME, ve));
00276 }
00277 }
00278
00279
00280 if (dd instanceof EntityJdbcCmp1Desc) {
00281 if (outdir.length() > 0) {
00282 wrpBeanFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullDerivedBeanName());
00283 } else {
00284 wrpBeanFileName = dd.getDerivedBeanName();
00285 }
00286 wrpBeanFileName = wrpBeanFileName.concat(JAVA_SUFFIX);
00287 noRemoteJava.add(wrpBeanFileName);
00288 sources.add(new Source(dd, wrpBeanFileName, Source.ENTITY_CMP_JDBC, ve));
00289 }
00290 if (dd instanceof EntityCmp2Desc) {
00291 EntityCmp2Desc ecd = (EntityCmp2Desc) dd;
00292 if (outdir.length() > 0) {
00293 wrpBeanFileName = outdir + File.separatorChar + BeanNaming.getPath(dd.getFullDerivedBeanName())
00294 + JAVA_SUFFIX;
00295 if (ecd.needJormCoherenceHelper()) {
00296 itfCohCmp2Entity = outdir + File.separatorChar
00297 + BeanNaming.getPath(ecd.getJormCoherenceHelperFQItfName()) + JAVA_SUFFIX;
00298 }
00299 } else {
00300 wrpBeanFileName = BeanNaming.getPath(dd.getDerivedBeanName()) + JAVA_SUFFIX;
00301 if (ecd.needJormCoherenceHelper()) {
00302 itfCohCmp2Entity = BeanNaming.getPath(ecd.getJormCoherenceHelperItfName()) + JAVA_SUFFIX;
00303 }
00304 }
00305 if (ecd.needJormCoherenceHelper()) {
00306 sources.add(new Source(dd, itfCohCmp2Entity, Source.ITF_COH_CMP2_ENTITY, ve));
00307 noRemoteJava.add(itfCohCmp2Entity);
00308 }
00309 noRemoteJava.add(wrpBeanFileName);
00310 sources.add(new Source(dd, wrpBeanFileName, Source.ENTITY_CMP_JDBC, ve));
00311 }
00312 }
00313
00318 public void generate() throws GenICException {
00319
00320 for (Iterator it = sources.iterator(); it.hasNext();) {
00321 Source src = (Source) it.next();
00322 src.generate();
00323 }
00324
00325
00326 if (dd instanceof EntityCmp2Desc) {
00327 EntityCmp2Desc ecd = (EntityCmp2Desc) dd;
00328
00329
00330 JormCompilerParameter cp = jormCompiler.getCompilerParameter();
00331 cp.setProjectName(RdbMappingBuilder.getProjectName());
00332 cp.setKeepSrc(true);
00333 cp.setOutput(outdir);
00334 cp.setClassMappingInheritance("org.objectweb.jonas_ejb.container.jorm.RdbFactory");
00335 switch (ecd.getLockPolicy()) {
00336 case EntityDesc.LOCK_CONTAINER_READ_UNCOMMITTED:
00337 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchCRU");
00338 break;
00339 case EntityDesc.LOCK_CONTAINER_SERIALIZED:
00340 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchCS");
00341 break;
00342 case EntityDesc.LOCK_CONTAINER_READ_COMMITTED:
00343 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchCRC");
00344 break;
00345 case EntityDesc.LOCK_DATABASE:
00346 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchDB");
00347 break;
00348 case EntityDesc.LOCK_READ_ONLY:
00349 cp.setBindingInheritance("org.objectweb.jonas_ejb.container.JEntitySwitchRO");
00350 break;
00351 default:
00352 throw new GenICException("Cannot find JEntitySwitch: Unknown lock policy");
00353 }
00354
00355
00356 Collection jormflist = null;
00357 try {
00358
00359 if (Log.getLogger("org.objectweb.jonas_ejb.mijorm").isLoggable(BasicLevel.DEBUG)) {
00360 jormCompiler.generateJormFiles(ecd.getJormList());
00361 }
00362 jormflist = jormCompiler.generateFiles(ecd.getJormList());
00363 } catch (Exception e) {
00364 throw new GenICException("Problem during jorm generation", e);
00365 }
00366
00367 for (Iterator i = jormflist.iterator(); i.hasNext();) {
00368 String file = (String) i.next();
00369 logger.log(BasicLevel.DEBUG, "Jorm generated file: " + file);
00370 noRemoteJava.add(file);
00371 }
00372 }
00373 }
00374
00378 public String getEjbName() {
00379 return dd.getEjbName();
00380 }
00381
00386 public String getWrpHomeFileName() {
00387 return wrpHomeFileName;
00388 }
00389
00394 public String getWrpHomeClusterConfFileName() {
00395 return wrpHomeClusterConfFileName;
00396 }
00397
00402 public String getWrpRemoteFileName() {
00403 return wrpRemoteFileName;
00404 }
00405
00410 public String getWrpRemoteClassName() {
00411 return dd.getFullWrpRemoteName();
00412 }
00413
00418 public String getWrpServiceEndpointFileName() {
00419 return wrpServiceEndpointFileName;
00420 }
00421
00426 public String getWrpSEHomeFileName() {
00427 return wrpSEHomeFileName;
00428 }
00429
00434 public String getWrpServiceEndpointClassName() {
00435 if (dd instanceof SessionStatelessDesc) {
00436 return ((SessionStatelessDesc) dd).getFullWrpServiceEndpointName();
00437 }
00438 return null;
00439 }
00440
00445 public String getWrpHomeClassName() {
00446 return dd.getFullWrpHomeName();
00447 }
00448
00452 public Collection getNoRemoteJavas() {
00453 return noRemoteJava;
00454 }
00455 }