Search in sources :

Example 21 with EjbSessionDescriptor

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

the class EjbSessionNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, String nodeName, EjbSessionDescriptor ejbDesc) {
    Node ejbNode = super.writeDescriptor(parent, nodeName, ejbDesc);
    writeDisplayableComponentInfo(ejbNode, ejbDesc);
    writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc);
    appendTextChild(ejbNode, EjbTagNames.SESSION_TYPE, ejbDesc.getSessionType());
    if (ejbDesc.hasStatefulTimeout()) {
        TimeoutValueNode timeoutValueNode = new TimeoutValueNode();
        TimeoutValueDescriptor timeoutDesc = new TimeoutValueDescriptor();
        timeoutDesc.setValue(ejbDesc.getStatefulTimeoutValue());
        timeoutDesc.setUnit(ejbDesc.getStatefulTimeoutUnit());
        timeoutValueNode.writeDescriptor(ejbNode, EjbTagNames.STATEFUL_TIMEOUT, timeoutDesc);
    }
    MethodNode methodNode = new MethodNode();
    if (ejbDesc.isTimedObject()) {
        if (ejbDesc.getEjbTimeoutMethod() != null) {
            methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.TIMEOUT_METHOD, ejbDesc.getEjbTimeoutMethod());
        }
        for (ScheduledTimerDescriptor timerDesc : ejbDesc.getScheduledTimerDescriptors()) {
            ScheduledTimerNode timerNode = new ScheduledTimerNode();
            timerNode.writeDescriptor(ejbNode, EjbTagNames.TIMER, timerDesc);
        }
    }
    if (ejbDesc.isSingleton()) {
        appendTextChild(ejbNode, EjbTagNames.INIT_ON_STARTUP, Boolean.toString(ejbDesc.getInitOnStartup()));
    }
    if (!ejbDesc.isStateless()) {
        appendTextChild(ejbNode, EjbTagNames.CONCURRENCY_MANAGEMENT_TYPE, ejbDesc.getConcurrencyManagementType().toString());
    }
    for (EjbSessionDescriptor.AccessTimeoutHolder next : ejbDesc.getAccessTimeoutInfo()) {
        ConcurrentMethodDescriptor cDesc = new ConcurrentMethodDescriptor();
        cDesc.setConcurrentMethod(next.method);
        TimeoutValueDescriptor timeoutDesc = new TimeoutValueDescriptor();
        timeoutDesc.setValue(next.value);
        timeoutDesc.setUnit(next.unit);
        cDesc.setAccessTimeout(timeoutDesc);
        ConcurrentMethodNode cNode = new ConcurrentMethodNode();
        cNode.writeDescriptor(ejbNode, EjbTagNames.CONCURRENT_METHOD, cDesc);
    }
    for (MethodDescriptor nextReadLock : ejbDesc.getReadLockMethods()) {
        ConcurrentMethodDescriptor cDesc = new ConcurrentMethodDescriptor();
        cDesc.setConcurrentMethod(nextReadLock);
        cDesc.setWriteLock(false);
        ConcurrentMethodNode cNode = new ConcurrentMethodNode();
        cNode.writeDescriptor(ejbNode, EjbTagNames.CONCURRENT_METHOD, cDesc);
    }
    if (ejbDesc.hasDependsOn()) {
        Node dependsOnNode = appendChild(ejbNode, EjbTagNames.DEPENDS_ON);
        for (String depend : ejbDesc.getDependsOn()) {
            appendTextChild(dependsOnNode, EjbTagNames.EJB_NAME, depend);
        }
    }
    if (ejbDesc.hasInitMethods()) {
        EjbInitNode initNode = new EjbInitNode();
        for (EjbInitInfo next : ejbDesc.getInitMethods()) {
            initNode.writeDescriptor(ejbNode, EjbTagNames.INIT_METHOD, next);
        }
    }
    if (ejbDesc.hasRemoveMethods()) {
        EjbRemoveNode removeNode = new EjbRemoveNode();
        for (EjbRemovalInfo next : ejbDesc.getAllRemovalInfo()) {
            removeNode.writeDescriptor(ejbNode, EjbTagNames.REMOVE_METHOD, next);
        }
    }
    for (MethodDescriptor nextDesc : ejbDesc.getAsynchronousMethods()) {
        methodNode.writeDescriptor(ejbNode, EjbTagNames.ASYNC_METHOD, nextDesc, ejbDesc.getName());
    }
    appendTextChild(ejbNode, EjbTagNames.TRANSACTION_TYPE, ejbDesc.getTransactionType());
    MethodDescriptor afterBeginMethod = ejbDesc.getAfterBeginMethod();
    if (afterBeginMethod != null) {
        methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.AFTER_BEGIN_METHOD, afterBeginMethod);
    }
    MethodDescriptor beforeCompletionMethod = ejbDesc.getBeforeCompletionMethod();
    if (beforeCompletionMethod != null) {
        methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.BEFORE_COMPLETION_METHOD, beforeCompletionMethod);
    }
    MethodDescriptor afterCompletionMethod = ejbDesc.getAfterCompletionMethod();
    if (afterCompletionMethod != null) {
        methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.AFTER_COMPLETION_METHOD, afterCompletionMethod);
    }
    // around-invoke-method
    writeAroundInvokeDescriptors(ejbNode, ejbDesc.getAroundInvokeDescriptors().iterator());
    // around-timeout-method
    writeAroundTimeoutDescriptors(ejbNode, ejbDesc.getAroundTimeoutDescriptors().iterator());
    // env-entry*
    writeEnvEntryDescriptors(ejbNode, ejbDesc.getEnvironmentProperties().iterator());
    // ejb-ref * and ejb-local-ref*
    writeEjbReferenceDescriptors(ejbNode, ejbDesc.getEjbReferenceDescriptors().iterator());
    // service-ref*
    writeServiceReferenceDescriptors(ejbNode, ejbDesc.getServiceReferenceDescriptors().iterator());
    // resource-ref*
    writeResourceRefDescriptors(ejbNode, ejbDesc.getResourceReferenceDescriptors().iterator());
    // resource-env-ref*
    writeResourceEnvRefDescriptors(ejbNode, ejbDesc.getResourceEnvReferenceDescriptors().iterator());
    // message-destination-ref*
    writeMessageDestinationRefDescriptors(ejbNode, ejbDesc.getMessageDestinationReferenceDescriptors().iterator());
    // persistence-context-ref*
    writeEntityManagerReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerReferenceDescriptors().iterator());
    // persistence-unit-ref*
    writeEntityManagerFactoryReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
    // post-construct
    writeLifeCycleCallbackDescriptors(ejbNode, TagNames.POST_CONSTRUCT, ejbDesc.getPostConstructDescriptors());
    // pre-destroy
    writeLifeCycleCallbackDescriptors(ejbNode, TagNames.PRE_DESTROY, ejbDesc.getPreDestroyDescriptors());
    // all descriptors (includes DSD, MSD, JMSCFD, JMSDD,AOD, CFD)*
    writeResourceDescriptors(ejbNode, ejbDesc.getAllResourcesDescriptors().iterator());
    // post-activate-method
    writeLifeCycleCallbackDescriptors(ejbNode, EjbTagNames.POST_ACTIVATE_METHOD, ejbDesc.getPostActivateDescriptors());
    // pre-passivate-method
    writeLifeCycleCallbackDescriptors(ejbNode, EjbTagNames.PRE_PASSIVATE_METHOD, ejbDesc.getPrePassivateDescriptors());
    // security-role-ref*
    writeRoleReferenceDescriptors(ejbNode, ejbDesc.getRoleReferences().iterator());
    // security-identity
    writeSecurityIdentityDescriptor(ejbNode, ejbDesc);
    // passivation-capable
    if (ejbDesc.isStateful()) {
        appendTextChild(ejbNode, EjbTagNames.PASSIVATION_CAPABLE, Boolean.toString(ejbDesc.isPassivationCapable()));
    }
    return ejbNode;
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) MethodNode(com.sun.enterprise.deployment.node.MethodNode) MailSessionNode(com.sun.enterprise.deployment.node.MailSessionNode) Node(org.w3c.dom.Node) LifecycleCallbackNode(com.sun.enterprise.deployment.node.LifecycleCallbackNode) DataSourceDefinitionNode(com.sun.enterprise.deployment.node.DataSourceDefinitionNode) ConcurrentMethodDescriptor(org.glassfish.ejb.deployment.descriptor.ConcurrentMethodDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbInitInfo(org.glassfish.ejb.deployment.descriptor.EjbInitInfo) ConcurrentMethodDescriptor(org.glassfish.ejb.deployment.descriptor.ConcurrentMethodDescriptor) MethodNode(com.sun.enterprise.deployment.node.MethodNode) EjbRemovalInfo(org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo) TimeoutValueDescriptor(org.glassfish.ejb.deployment.descriptor.TimeoutValueDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 22 with EjbSessionDescriptor

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

the class EjbBundleValidator method validateStatefulTimeout.

/**
 * Validates @StatefulTimeout or <stateful-timeout> values.  Any value less than -1
 * is invalid.
 */
private void validateStatefulTimeout(EjbDescriptor ejb) {
    if (ejb instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejb;
        Long statefulTimeoutValue = sessionDesc.getStatefulTimeoutValue();
        if (statefulTimeoutValue != null && statefulTimeoutValue < -1) {
            throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.invalid_stateful_timeout_value", "Invalid value [{0}] for @StatefulTimeout or <stateful-timeout> element in EJB [{1}]. Values less than -1 are not valid.", new Object[] { statefulTimeoutValue, sessionDesc.getName() }));
        }
    }
}
Also used : EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 23 with EjbSessionDescriptor

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

the class EjbBundleValidator method validateConcurrencyMetadata.

private void validateConcurrencyMetadata(EjbDescriptor ejb) {
    if (ejb instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejb;
        List<EjbSessionDescriptor.AccessTimeoutHolder> accessTimeoutInfo = sessionDesc.getAccessTimeoutInfo();
        for (EjbSessionDescriptor.AccessTimeoutHolder accessTimeoutHolder : accessTimeoutInfo) {
            MethodDescriptor accessTimeoutMethodDesc = accessTimeoutHolder.method;
            Method accessTimeoutMethod = accessTimeoutMethodDesc.getMethod(ejb);
            if (accessTimeoutMethod == null) {
                throw new RuntimeException("Invalid AccessTimeout method signature " + accessTimeoutMethodDesc + " . Method could not be resolved to a bean class method for bean " + ejb.getName());
            }
        }
        for (MethodDescriptor lockMethodDesc : sessionDesc.getReadAndWriteLockMethods()) {
            Method readLockMethod = lockMethodDesc.getMethod(sessionDesc);
            if (readLockMethod == null) {
                throw new RuntimeException("Invalid Lock method signature " + lockMethodDesc + " . Method could not be resolved to a bean class method for bean " + ejb.getName());
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 24 with EjbSessionDescriptor

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

the class EjbContainerServicesImpl method isRemoved.

public boolean isRemoved(Object ejbRef) {
    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);
    if (localObjectImpl == null) {
        throw new UnsupportedOperationException("Invalid ejb ref");
    }
    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        isStatefulBean = sessionDesc.isStateful();
    }
    if (!isStatefulBean) {
        // stateless/singleton references via 299 will fail until bug is fixed.
        return false;
    // TODO reenable this per SessionObjectReference.isRemoved SPI
    // throw new UnsupportedOperationException("ejbRef for ejb " +
    // ejbDesc.getName() + " is not a stateful bean ");
    }
    boolean removed = false;
    try {
        ((BaseContainer) container).checkExists(localObjectImpl);
    } catch (Exception e) {
        removed = true;
    }
    return removed;
}
Also used : Container(com.sun.ejb.Container) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException)

Example 25 with EjbSessionDescriptor

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

the class EjbContainerServicesImpl method remove.

public void remove(Object ejbRef) {
    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);
    if (localObjectImpl == null) {
        throw new UnsupportedOperationException("Invalid ejb ref");
    }
    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        isStatefulBean = sessionDesc.isStateful();
    }
    if (!isStatefulBean) {
        // stateless/singleton references via 299 could fail until bug is fixed.
        return;
    // TODO reenable this after bug is fixed
    // throw new UnsupportedOperationException("ejbRef for ejb " +
    // ejbDesc.getName() + " is not a stateful bean ");
    }
    try {
        localObjectImpl.remove();
    } catch (EJBException e) {
        LogFacade.getLogger().log(Level.FINE, "EJBException during remove. ", e);
    } catch (javax.ejb.RemoveException re) {
        throw new NoSuchEJBException(re.getMessage(), re);
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) Container(com.sun.ejb.Container) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

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