Search in sources :

Example 11 with EjbReference

use of com.sun.enterprise.deployment.types.EjbReference 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 12 with EjbReference

use of com.sun.enterprise.deployment.types.EjbReference in project Payara by payara.

the class EjbDescriptor method addEjbReferenceDescriptor.

/**
 * Adds a reference to another ejb to me.
 * @param ejbReference
 */
@Override
public final void addEjbReferenceDescriptor(EjbReference ejbReference) {
    try {
        EjbReference existing = getEjbReference(ejbReference.getName());
        for (InjectionTarget next : ejbReference.getInjectionTargets()) {
            existing.addInjectionTarget(next);
        }
    } catch (IllegalArgumentException e) {
        if (env != null)
            env.addEjbReferenceDescriptor(ejbReference);
        else
            ejbReferences.add(ejbReference);
        ejbReference.setReferringBundleDescriptor(getEjbBundleDescriptor());
    }
}
Also used : EjbReference(com.sun.enterprise.deployment.types.EjbReference) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget)

Example 13 with EjbReference

use of com.sun.enterprise.deployment.types.EjbReference in project Payara by payara.

the class DeploymentDescriptorNode method writeEjbReferenceDescriptors.

/**
 * write  the ejb references (local or remote) to the DOM tree
 *
 * @param parentNode parent node for the DOM tree
 * @param refs the set of EjbReferenceDescriptor to write
 */
protected void writeEjbReferenceDescriptors(Node parentNode, Iterator refs) {
    if (refs == null || !refs.hasNext())
        return;
    EjbReferenceNode subNode = new EjbReferenceNode();
    // ejb-ref*
    Set localRefDescs = new HashSet();
    for (; refs.hasNext(); ) {
        EjbReference ejbRef = (EjbReference) refs.next();
        if (ejbRef.isLocal()) {
            localRefDescs.add(ejbRef);
        } else {
            subNode.writeDescriptor(parentNode, TagNames.EJB_REFERENCE, ejbRef);
        }
    }
    // ejb-local-ref*
    for (Iterator e = localRefDescs.iterator(); e.hasNext(); ) {
        EjbReference ejbRef = (EjbReference) e.next();
        subNode.writeDescriptor(parentNode, TagNames.EJB_LOCAL_REFERENCE, ejbRef);
    }
}
Also used : EjbReference(com.sun.enterprise.deployment.types.EjbReference)

Aggregations

EjbReference (com.sun.enterprise.deployment.types.EjbReference)13 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)4 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)3 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 Result (com.sun.enterprise.tools.verifier.Result)2 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)2 PersistenceDescriptor (org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor)2 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)1 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)1 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)1 MessageDestinationReferenceDescriptor (com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor)1 MethodPermission (com.sun.enterprise.deployment.MethodPermission)1 RoleReference (com.sun.enterprise.deployment.RoleReference)1