use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl 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.EjbBundleDescriptorImpl in project Payara by payara.
the class EjbBundleValidator method checkDependsOn.
private void checkDependsOn(EjbDescriptor ejb) {
if (ejb instanceof EjbSessionDescriptor) {
EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejb;
if (sessionDesc.hasDependsOn()) {
if (!sessionDesc.isSingleton()) {
throw new RuntimeException("Illegal usage of DependsOn for EJB " + ejb.getName() + ". DependsOn is only supported for Singleton beans");
}
String[] dependsOn = sessionDesc.getDependsOn();
for (String next : dependsOn) {
// TODO support new EJB 3.1 syntax
boolean fullyQualified = next.contains("#");
Application app = sessionDesc.getEjbBundleDescriptor().getApplication();
if (fullyQualified) {
int indexOfHash = next.indexOf('#');
String ejbName = next.substring(indexOfHash + 1);
String relativeJarPath = next.substring(0, indexOfHash);
BundleDescriptor bundle = app.getRelativeBundle(sessionDesc.getEjbBundleDescriptor(), relativeJarPath);
if (bundle == null) {
throw new IllegalStateException("Invalid @DependOn value = " + next + " for Singleton " + sessionDesc.getName());
}
EjbBundleDescriptorImpl ejbBundle = (bundle.getModuleType() != null && bundle.getModuleType().equals(DOLUtils.warType())) ? bundle.getExtensionsDescriptors(EjbBundleDescriptorImpl.class).iterator().next() : (EjbBundleDescriptorImpl) bundle;
if (!ejbBundle.hasEjbByName(ejbName)) {
throw new RuntimeException("Invalid DependsOn dependency '" + next + "' for EJB " + ejb.getName());
}
} else {
EjbBundleDescriptorImpl bundle = ejb.getEjbBundleDescriptor();
if (!bundle.hasEjbByName(next)) {
throw new RuntimeException("Invalid DependsOn dependency '" + next + "' for EJB " + ejb.getName());
}
}
}
}
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class CmpResourceNode method postParsing.
@Override
public void postParsing() {
EjbBundleDescriptorImpl bd = (EjbBundleDescriptorImpl) getParentNode().getDescriptor();
if (bd == null) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure", new Object[] { descriptor });
return;
}
bd.setCMPResourceReference(descriptor);
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class ClusteredAnnotationProcessor method isEJB.
private <X> boolean isEJB(ProcessAnnotatedType<X> annotatedType) {
String className = annotatedType.getAnnotatedType().getJavaClass().getName();
Application application = deployment.getCurrentDeploymentContext().getModuleMetaData(Application.class);
for (EjbBundleDescriptorImpl bundleDescriptor : application.getBundleDescriptors(EjbBundleDescriptorImpl.class)) {
if (bundleDescriptor.getEjbByClassName(className).length > 0) {
return true;
}
}
return false;
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class AbstractEjbHandler method processAnnotation.
/**
* Process a particular annotation which type is the same as the one
* returned by @see getAnnotationType().All information pertinent to the
* annotation and its context is encapsulated in the passed AnnotationInfo
* instance.This is a method in interface AnnotationHandler.
*
* @param ainfo the annotation information
* @return
* @throws org.glassfish.apf.AnnotationProcessorException
*/
@Override
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
ApplicationState state = ainfo.getProcessingContext().getArchive().getExtraData(ApplicationState.class);
Class ejbClass = (Class) ainfo.getAnnotatedElement();
Annotation annotation = ainfo.getAnnotation();
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "@ process ejb annotation {0} in {1}", new Object[] { annotation, ejbClass });
}
AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
if (aeHandler != null && aeHandler instanceof EjbContext) {
EjbContext context = (EjbContext) aeHandler;
EjbDescriptor desc = (EjbDescriptor) context.getDescriptor();
if (isValidEjbDescriptor(desc, annotation)) {
return getDefaultProcessedResult();
} else {
log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.notcompsuperclass", "The annotation symbol defined in super-class is not compatible with {0} ejb {1}.", new Object[] { desc.getType(), desc.getName() }));
return getDefaultFailedResult();
}
} else if (aeHandler == null || !(aeHandler instanceof EjbBundleContext)) {
return getInvalidAnnotatedElementHandlerResult(ainfo.getProcessingContext().getHandler(), ainfo);
}
EjbBundleContext ctx = (EjbBundleContext) aeHandler;
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "My context is {0}", ctx);
}
String elementName = getAnnotatedName(annotation);
if (elementName.length() == 0) {
elementName = ejbClass.getSimpleName();
} else {
elementName = TranslatedConfigView.expandValue(elementName);
}
EjbBundleDescriptorImpl currentBundle = (EjbBundleDescriptorImpl) ctx.getDescriptor();
EjbDescriptor ejbDesc = null;
try {
ejbDesc = currentBundle.getEjbByName(elementName);
} catch (IllegalArgumentException ex) {
// getEjbByName throws IllegalArgumentException when no ejb is found
}
if (state != null && ejbDesc != null) {
currentBundle.removeEjb(ejbDesc);
ejbDesc = null;
}
if (ejbDesc != null && !(ejbDesc instanceof DummyEjbDescriptor)) {
// overriding rules applies
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Overriding rules apply for {0}", ejbClass.getName());
}
// don't allow ejb-jar.xml overwrite ejb type
if (!isValidEjbDescriptor(ejbDesc, annotation)) {
// this is an error
log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.wrongejbtype", "Wrong annotation symbol for ejb {0}", new Object[] { ejbDesc }));
return getDefaultFailedResult();
}
// <ejb-class> is optional if a component-defining
// annotation is used. If present, <ejb-class> element
// must match the class on which the component defining annotation
// appears.
String descriptorEjbClass = ejbDesc.getEjbClassName();
if (descriptorEjbClass == null) {
ejbDesc.setEjbClassName(ejbClass.getName());
ejbDesc.applyDefaultClassToLifecycleMethods();
} else if (!descriptorEjbClass.equals(ejbClass.getName())) {
log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.ejbclsmismatch", "", new Object[] { descriptorEjbClass, elementName, ejbClass.getName() }));
return getDefaultFailedResult();
}
} else {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Creating a new descriptor for {0}", ejbClass.getName());
}
EjbDescriptor dummyEjbDesc = ejbDesc;
ejbDesc = createEjbDescriptor(elementName, ainfo);
// the information from dummy ejb descriptor if applicable
if (dummyEjbDesc != null) {
currentBundle.removeEjb(dummyEjbDesc);
ejbDesc.addEjbDescriptor(dummyEjbDesc);
// reset ejbClassName on ejbDesc
ejbDesc.setEjbClassName(ejbClass.getName());
}
// add the actual ejb descriptor to the ejb bundle
currentBundle.addEjb(ejbDesc);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "New {0} bean {1}", new Object[] { getAnnotationType().getName(), elementName });
}
}
// We need to include all ejbs of the same name in the annotation processing context
// in order to handle the case that a bean class has both a component-defining
// annotation and there are other ejb-jar.xml-defined beans with the same bean class.
EjbDescriptor[] ejbDescs = currentBundle.getEjbByClassName(ejbClass.getName());
HandlerProcessingResult procResult = null;
for (EjbDescriptor next : ejbDescs) {
procResult = setEjbDescriptorInfo(next, ainfo);
doTimedObjectProcessing(ejbClass, next);
}
AnnotationContext annContext = null;
if (ejbDescs.length == 1) {
annContext = new EjbContext(ejbDesc, ejbClass);
} else {
annContext = new EjbsContext(ejbDescs, ejbClass);
}
// we push the new context on the stack...
ctx.getProcessingContext().pushHandler(annContext);
return procResult;
}
Aggregations