Search in sources :

Example 41 with EjbSessionDescriptor

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

the class SingletonLifeCycleManager method addSingletonContainer.

void addSingletonContainer(EjbApplication ejbApp, AbstractSingletonContainer c) {
    c.setSingletonLifeCycleManager(this);
    EjbSessionDescriptor sdesc = (EjbSessionDescriptor) c.getEjbDescriptor();
    String src = normalizeSingletonName(sdesc.getName(), sdesc);
    String[] depends = sdesc.getDependsOn();
    String[] newDepends = new String[depends.length];
    StringBuilder sb = new StringBuilder("Partial order of dependent(s). " + src + " => {");
    for (int i = 0; i < depends.length; i++) {
        newDepends[i] = normalizeSingletonName(depends[i], sdesc);
        sb.append(newDepends[i] + " ");
    }
    sb.append("}");
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, sb.toString());
    }
    this.addDependency(src, newDepends);
    name2Container.put(src, c);
    name2EjbApp.put(src, ejbApp);
}
Also used : EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 42 with EjbSessionDescriptor

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

the class EjbSessionNode method getEjbDescriptor.

@Override
public EjbSessionDescriptor getEjbDescriptor() {
    if (descriptor == null) {
        descriptor = new EjbSessionDescriptor();
        descriptor.setEjbBundleDescriptor((EjbBundleDescriptorImpl) getParentNode().getDescriptor());
    }
    return descriptor;
}
Also used : EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 43 with EjbSessionDescriptor

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

the class EjbBundleValidator method validatePassivationConfiguration.

/**
 * Check when passivation-capable of sfsb is false, PrePassivate and PostActivate configurations
 * are not recommended.
 */
private void validatePassivationConfiguration(EjbDescriptor ejb) {
    if (ejb instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejb;
        if (!sessionDesc.isStateful() || sessionDesc.isPassivationCapable()) {
            return;
        }
        String callbackInfo = getAllPrePassivatePostActivateCallbackInfo(sessionDesc);
        if (callbackInfo.length() > 0) {
            _logger.log(Level.WARNING, REDUNDANT_PASSIVATION_CALLBACK_METADATA, new Object[] { ejb.getName(), callbackInfo });
        }
    }
}
Also used : EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 44 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor 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());
                    }
                }
            }
        }
    }
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) Application(com.sun.enterprise.deployment.Application) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 45 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor 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)

Aggregations

EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)78 Result (com.sun.enterprise.tools.verifier.Result)28 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)28 Method (java.lang.reflect.Method)25 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)23 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)18 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)7 Iterator (java.util.Iterator)6 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)6 Set (java.util.Set)5 EJBException (javax.ejb.EJBException)4 Container (com.sun.ejb.Container)3 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)3 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)3 NoSuchEJBException (javax.ejb.NoSuchEJBException)3