Search in sources :

Example 1 with DummyEjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor in project Payara by payara.

the class EjbBundleValidator method accept.

/**
 * visits an ejb descriptor
 * @param ejb descriptor
 */
@Override
public void accept(EjbDescriptor ejb) {
    // application
    if (ejb instanceof DummyEjbDescriptor) {
        throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.exceptionbeanbundle", "Referencing error: this bundle has no bean of name: {0}", new Object[] { ejb.getName() }));
    }
    this.ejb = ejb;
    setDOLDefault(ejb);
    computeRuntimeDefault(ejb);
    checkDependsOn(ejb);
    validateConcurrencyMetadata(ejb);
    validateStatefulTimeout(ejb);
    validatePassivationConfiguration(ejb);
    try {
        ClassLoader cl = ejb.getEjbBundleDescriptor().getClassLoader();
        Class ejbClass = cl.loadClass(ejb.getEjbClassName());
        if (Globals.getDefaultHabitat() == null) {
            return;
        }
        if (ejb instanceof EjbSessionDescriptor) {
            EjbSessionDescriptor desc = (EjbSessionDescriptor) ejb;
            if (desc.isClustered()) {
                if (!desc.isSingleton()) {
                    throw new IllegalArgumentException("Only Sinlgeton beans can be Clustered: " + desc.getName());
                }
                if (!Serializable.class.isAssignableFrom(ejbClass)) {
                    throw new IllegalStateException(String.format("Clustered Singleton %s must be Serializable", desc.getName()));
                }
                if (desc.getClusteredLockType() == DistributedLockType.LOCK) {
                    throw new IllegalStateException(String.format("Clustered Singleton %s - incompatible lock type LOCK", desc.getName()));
                }
            }
        }
        // Perform 2.x style TimedObject processing if the class
        // hasn't already been identified as a timed object.
        AnnotationTypesProvider provider = Globals.getDefaultHabitat().getService(AnnotationTypesProvider.class, "EJB");
        if (provider == null) {
            throw new RuntimeException("Cannot find AnnotationTypesProvider named 'EJB'");
        }
        if (ejb.getEjbTimeoutMethod() == null && provider.getType("javax.ejb.TimedObject").isAssignableFrom(ejbClass)) {
            MethodDescriptor timedObjectMethod = new MethodDescriptor("ejbTimeout", "TimedObject timeout method", new String[] { "javax.ejb.Timer" }, MethodDescriptor.TIMER_METHOD);
            ejb.setEjbTimeoutMethod(timedObjectMethod);
        } else if (ejb.getEjbTimeoutMethod() != null) {
            // If timeout-method was only processed from the descriptor,
            // we need to create a MethodDescriptor using the actual
            // Method object corresponding to the timeout method.  The
            // timeout method can have any access type and be anywhere
            // in the bean class hierarchy.
            MethodDescriptor timeoutMethodDescOrig = ejb.getEjbTimeoutMethod();
            MethodDescriptor timeoutMethodDesc = processTimeoutMethod(ejb, timeoutMethodDescOrig, provider, ejbClass);
            ejb.setEjbTimeoutMethod(timeoutMethodDesc);
        }
        for (ScheduledTimerDescriptor sd : ejb.getScheduledTimerDescriptors()) {
            try {
                // This method creates new schedule and attempts to calculate next timeout.
                // The second part ensures that all values that are not verified up-front
                // are also validated.
                // It does not check that such timeout date is a valid date.
                EJBTimerSchedule.isValid(sd);
            } catch (Exception e) {
                throw new RuntimeException(ejb.getName() + ": Invalid schedule " + "defined on method " + sd.getTimeoutMethod().getFormattedString() + ": " + e.getMessage());
            }
            MethodDescriptor timeoutMethodDescOrig = sd.getTimeoutMethod();
            MethodDescriptor timeoutMethodDesc = processTimeoutMethod(ejb, timeoutMethodDescOrig, provider, ejbClass);
            sd.setTimeoutMethod(timeoutMethodDesc);
        }
    } catch (Exception e) {
        RuntimeException re = new RuntimeException("Error processing EjbDescriptor");
        re.initCause(e);
        throw re;
    }
    // has to be derived from target inject method or inject field.
    for (InjectionCapable injectable : ejb.getEjbBundleDescriptor().getInjectableResources(ejb)) {
        accept(injectable);
    }
    for (Iterator itr = ejb.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
        EjbReference aRef = (EjbReference) itr.next();
        accept(aRef);
    }
    for (Iterator it = ejb.getResourceReferenceDescriptors().iterator(); it.hasNext(); ) {
        ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) it.next();
        accept(next);
    }
    for (Iterator it = ejb.getResourceEnvReferenceDescriptors().iterator(); it.hasNext(); ) {
        ResourceEnvReferenceDescriptor next = (ResourceEnvReferenceDescriptor) it.next();
        accept(next);
    }
    for (Iterator it = ejb.getMessageDestinationReferenceDescriptors().iterator(); it.hasNext(); ) {
        MessageDestinationReferencer next = (MessageDestinationReferencer) it.next();
        accept(next);
    }
    // referencer as well.
    if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
        if (ejb instanceof MessageDestinationReferencer) {
            MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
            if (msgDestReferencer.getMessageDestinationLinkName() != null) {
                accept(msgDestReferencer);
            }
        }
    }
    Set serviceRefs = ejb.getServiceReferenceDescriptors();
    for (Iterator itr = serviceRefs.iterator(); itr.hasNext(); ) {
        accept((ServiceReferenceDescriptor) itr.next());
    }
    if (ejb instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
        PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
        for (Iterator e = persistenceDesc.getCMPFields().iterator(); e.hasNext(); ) {
            FieldDescriptor fd = (FieldDescriptor) e.next();
            accept(fd);
        }
    }
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbReference(com.sun.enterprise.deployment.types.EjbReference) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) MessageDestinationReferencer(com.sun.enterprise.deployment.types.MessageDestinationReferencer) InjectionCapable(com.sun.enterprise.deployment.InjectionCapable) Iterator(java.util.Iterator) ResourceEnvReferenceDescriptor(com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) AnnotationTypesProvider(org.glassfish.internal.deployment.AnnotationTypesProvider)

Example 2 with DummyEjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor 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
 */
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("@ process ejb annotation " + annotation + " in " + 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.fine("My context is " + ctx);
    }
    String elementName = getAnnotatedName(annotation);
    if (elementName.length() == 0) {
        elementName = ejbClass.getSimpleName();
    } else {
        elementName = (String) TranslatedConfigView.getTranslatedValue(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 (ejbDesc != null && !(ejbDesc instanceof DummyEjbDescriptor)) {
        // overriding rules applies
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Overriding rules apply for " + 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.fine("Creating a new descriptor for " + 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.fine("New " + getAnnotationType().getName() + " bean " + 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;
}
Also used : DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotationContext(org.glassfish.apf.context.AnnotationContext) Annotation(java.lang.annotation.Annotation) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Aggregations

DummyEjbDescriptor (org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor)2 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)1 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)1 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)1 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)1 EjbReference (com.sun.enterprise.deployment.types.EjbReference)1 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)1 HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)1 AnnotationContext (org.glassfish.apf.context.AnnotationContext)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)1 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)1