use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class CMPDeployerImpl method deploy.
/**
* Generates the concrete impls for all CMPs in the application.
*
* @throws DeploymentException if this exception was thrown while generating concrete impls
*/
public void deploy(DeploymentContext ctx) throws DeploymentException {
// deployment descriptor object representation for the archive
Application application = null;
// deployment descriptor object representation for each module
EjbBundleDescriptorImpl bundle = null;
// ejb name
String beanName = null;
// GeneratorException message if any
StringBuffer generatorExceptionMsg = null;
try {
CMPGenerator gen = new JDOCodeGenerator();
// stubs dir for the current deployment (generated/ejb)
// NOI18N
File stubsDir = ctx.getScratchDir("ejb");
application = ctx.getModuleMetaData(Application.class);
if (_logger.isLoggable(Logger.FINE)) {
// NOI18N
_logger.fine(// NOI18N
"cmpc.processing_cmp", application.getRegistrationName());
}
List<File> cmpFiles = new ArrayList<File>();
final ClassLoader jcl = application.getClassLoader();
bundle = ctx.getModuleMetaData(EjbBundleDescriptorImpl.class);
// This gives the dir where application is exploded
String archiveUri = ctx.getSource().getURI().getSchemeSpecificPart();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Module Dir name is " + archiveUri);
}
// xml dir for the current deployment (generated/xml)
String generatedXmlsPath = ctx.getScratchDir("xml").getCanonicalPath();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Generated XML Dir name is " + generatedXmlsPath);
}
try {
long start = System.currentTimeMillis();
gen.init(bundle, ctx, archiveUri, generatedXmlsPath);
Iterator ejbs = bundle.getEjbs().iterator();
while (ejbs.hasNext()) {
EjbDescriptor desc = (EjbDescriptor) ejbs.next();
beanName = desc.getName();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Ejb Class Name: " + desc.getEjbClassName());
}
if (desc instanceof IASEjbCMPEntityDescriptor) {
// generate concrete CMP class implementation
IASEjbCMPEntityDescriptor entd = (IASEjbCMPEntityDescriptor) desc;
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Home Object Impl name is " + entd.getLocalHomeImplClassName());
}
// The classloader needs to be set else we fail down the road.
ClassLoader ocl = entd.getClassLoader();
entd.setClassLoader(jcl);
try {
gen.generate(entd, stubsDir, stubsDir);
} catch (GeneratorException e) {
String msg = e.getMessage();
_logger.warning(msg);
generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
} finally {
entd.setClassLoader(ocl);
}
/* WARNING: IASRI 4683195
* JDO Code failed when there was a relationship involved
* because it depends upon the orginal ejbclasname and hence
* this code is shifted to just before the Remote Impl is
* generated.Remote/Home Impl generation depends upon this
* value
*/
}
}
// end while ejbs.hasNext()
beanName = null;
cmpFiles.addAll(gen.cleanup());
long end = System.currentTimeMillis();
_logger.fine("CMP Generation: " + (end - start) + " msec");
} catch (GeneratorException e) {
String msg = e.getMessage();
_logger.warning(msg);
generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
}
// Used in exception processing
bundle = null;
// Compile the generated classes
if (generatorExceptionMsg == null) {
long start = System.currentTimeMillis();
compileClasses(ctx, cmpFiles, stubsDir);
long end = System.currentTimeMillis();
_logger.fine("Java Compilation: " + (end - start) + " msec");
// Do Java2DB if needed
start = System.currentTimeMillis();
CMPProcessor processor = new CMPProcessor(ctx);
processor.process();
end = System.currentTimeMillis();
_logger.fine("Java2DB processing: " + (end - start) + " msec");
_logger.fine("cmpc.done_processing_cmp", application.getRegistrationName());
}
} catch (GeneratorException e) {
_logger.warning(e.getMessage());
throw new DeploymentException(e);
} catch (Throwable e) {
String eType = e.getClass().getName();
String appName = application.getRegistrationName();
String exMsg = e.getMessage();
String msg = null;
if (bundle == null) {
// Application or compilation error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_app_error", eType, appName, exMsg);
} else {
String bundleName = bundle.getModuleDescriptor().getArchiveUri();
if (beanName == null) {
// Module processing error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_module_error", new Object[] { eType, appName, bundleName, exMsg });
} else {
// CMP bean generation error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_bean_error", new Object[] { eType, beanName, appName, bundleName, exMsg });
}
}
_logger.log(Logger.SEVERE, msg, e);
throw new DeploymentException(msg);
}
if (generatorExceptionMsg != null) {
// We already logged each separate part.
throw new DeploymentException(generatorExceptionMsg.toString());
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class EjbBundleValidator method accept.
@Override
public void accept(com.sun.enterprise.deployment.EjbBundleDescriptor bundleDesc) {
this.application = bundleDesc.getApplication();
EjbBundleDescriptorImpl bundleDescriptor = (EjbBundleDescriptorImpl) bundleDesc;
if (bundleDescriptor.getEjbs().size() == 0) {
throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.util.no_ejb_in_ejb_jar", "Invalid ejb jar {0}: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean.", new Object[] { bundleDescriptor.getModuleDescriptor().getArchiveUri() }));
}
if (!bundleDescriptor.areResourceReferencesValid()) {
throw new RuntimeException("Incorrectly resolved role references");
}
this.ejbBundleDescriptor = bundleDescriptor;
// Now that we have a classloader, we have to check for any
// interceptor bindings that were specified in .xml to use
// the syntax that refers to all overloaded methods with a
// given name.
handleOverloadedInterceptorMethodBindings(bundleDescriptor);
InterceptorBindingTranslator bindingTranslator = new InterceptorBindingTranslator(bundleDescriptor);
for (Iterator<EjbDescriptor> iter = bundleDescriptor.getEjbs().iterator(); iter.hasNext(); ) {
EjbDescriptor ejb0 = iter.next();
if (ejb0.isRemoteInterfacesSupported() && (ejb0.getRemoteClassName() == null || ejb0.getRemoteClassName().trim().isEmpty())) {
throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.util.componentInterfaceMissing", "{0} Component interface is missing in EJB [{1}]", "Remote", ejb0.getName()));
}
if (ejb0.isLocalInterfacesSupported() && (ejb0.getLocalClassName() == null || ejb0.getLocalClassName().trim().isEmpty())) {
throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.util.componentInterfaceMissing", "{0} Component interface is missing in EJB [{1}]", "Local", ejb0.getName()));
}
if (!EjbEntityDescriptor.TYPE.equals(ejb0.getType())) {
ejb0.applyInterceptors(bindingTranslator);
}
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class AroundInvokeHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
for (EjbContext next : ejbContexts) {
EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();
ejbDescriptor.addAroundInvokeDescriptor(getAroundInvocationDescriptor(ainfo));
}
return getDefaultProcessedResult();
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class AsynchronousHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
for (EjbContext ejbContext : ejbContexts) {
EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
if (ElementType.TYPE.equals(ainfo.getElementType())) {
ejbContext.addPostProcessInfo(ainfo, this);
} else {
Method annMethod = (Method) ainfo.getAnnotatedElement();
setAsynchronous(annMethod, ejbDesc);
}
}
return getDefaultProcessedResult();
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class AsynchronousHandler method postProcessAnnotation.
/**
* Set the default value (from class type annotation) on all
* methods that don't have a value.
* Class type annotation applies to all EJB 3.x Local/Remote/no-interface
* views in which that business method is exposed for that bean.
*/
public void postProcessAnnotation(AnnotationInfo ainfo, EjbContext ejbContext) throws AnnotationProcessorException {
EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
Class classAn = (Class) ainfo.getAnnotatedElement();
Method[] methods = classAn.getDeclaredMethods();
for (Method m0 : methods) {
setAsynchronous(m0, ejbDesc);
}
}
Aggregations