Search in sources :

Example 31 with EjbDescriptor

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

the class ExcludeDefaultInterceptorsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    EjbBundleDescriptorImpl ejbBundle = ((EjbDescriptor) ejbContexts[0].getDescriptor()).getEjbBundleDescriptor();
    for (EjbContext next : ejbContexts) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();
        // Create binding information.
        InterceptorBindingDescriptor binding = new InterceptorBindingDescriptor();
        binding.setEjbName(ejbDescriptor.getName());
        binding.setExcludeDefaultInterceptors(true);
        if (ElementType.METHOD.equals(ainfo.getElementType())) {
            Method m = (Method) ainfo.getAnnotatedElement();
            MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
            binding.setBusinessMethod(md);
        } else if (ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
            Constructor c = (Constructor) ainfo.getAnnotatedElement();
            Class cl = c.getDeclaringClass();
            Class[] ctorParamTypes = c.getParameterTypes();
            String[] parameterClassNames = (new MethodDescriptor()).getParameterClassNamesFor(null, ctorParamTypes);
            MethodDescriptor md = new MethodDescriptor(cl.getSimpleName(), null, parameterClassNames, MethodDescriptor.EJB_BEAN);
            binding.setBusinessMethod(md);
        }
        ejbBundle.prependInterceptorBinding(binding);
    }
    return getDefaultProcessedResult();
}
Also used : EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 32 with EjbDescriptor

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

the class ScheduleHandler method processSchedule.

protected HandlerProcessingResult processSchedule(Schedule sch, AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        if (ElementType.METHOD.equals(ainfo.getElementType())) {
            Method annMethod = (Method) ainfo.getAnnotatedElement();
            // .xml-defined timer method overrides @Schedule
            if (!ejbDesc.hasScheduledTimerMethodFromDD(annMethod)) {
                ScheduledTimerDescriptor sd = new ScheduledTimerDescriptor();
                sd.setSecond(sch.second());
                sd.setMinute(sch.minute());
                sd.setHour(sch.hour());
                sd.setDayOfMonth(sch.dayOfMonth());
                sd.setMonth(sch.month());
                sd.setDayOfWeek(sch.dayOfWeek());
                sd.setYear(sch.year());
                sd.setTimezone(sch.timezone());
                sd.setPersistent(sch.persistent());
                sd.setInfo(sch.info());
                sd.setTimeoutMethod(new MethodDescriptor(annMethod));
                ejbDesc.addScheduledTimerDescriptor(sd);
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("@@@ Found Schedule on " + annMethod);
                    logger.fine("@@@ TimerConfig : " + ((sd.getInfo() != null && !sd.getInfo().equals("")) ? sd.getInfo() : null) + " # " + sd.getPersistent());
                }
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 33 with EjbDescriptor

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

the class TransactionAttributeHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
        if (ElementType.TYPE.equals(ainfo.getElementType())) {
            ejbContext.addPostProcessInfo(ainfo, this);
        } else {
            Method annMethod = (Method) ainfo.getAnnotatedElement();
            Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
            for (Object next : txBusMethods) {
                MethodDescriptor nextDesc = (MethodDescriptor) next;
                Method m = nextDesc.getMethod(ejbDesc);
                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(nextDesc) == null) {
                    // override by xml
                    ejbDesc.setContainerTransactionFor(nextDesc, containerTransaction);
                }
            }
            if (ejbDesc instanceof EjbSessionDescriptor) {
                EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDesc;
                if (sd.isStateful() || sd.isSingleton()) {
                    ClassLoader loader = ejbDesc.getEjbBundleDescriptor().getClassLoader();
                    Set<LifecycleCallbackDescriptor> lcds = ejbDesc.getLifecycleCallbackDescriptors();
                    for (LifecycleCallbackDescriptor lcd : lcds) {
                        if (lcd.getLifecycleCallbackClass().equals(ejbDesc.getEjbClassName()) && lcd.getLifecycleCallbackMethod().equals(annMethod.getName())) {
                            try {
                                Method m = lcd.getLifecycleCallbackMethodObject(loader);
                                MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(md) == null) {
                                    // stateful lifecycle callback txn attr type EJB spec
                                    if (sd.isStateful() && containerTransaction != null) {
                                        String txAttr = containerTransaction.getTransactionAttribute();
                                        if (txAttr != null && !txAttr.equals(ContainerTransaction.REQUIRES_NEW) && !txAttr.equals(ContainerTransaction.NOT_SUPPORTED)) {
                                            logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.annotation.handlers.sfsblifecycletxnattrtypewarn", "Stateful session bean {0} lifecycle callback method {1} has transaction " + "attribute {2} with container-managed transaction demarcation. " + "The transaction attribute should be either REQUIRES_NEW or NOT_SUPPORTED", new Object[] { (sd.getName() == null ? "" : sd.getName()), m.getName(), txAttr }));
                                        }
                                    }
                                    // override by xml
                                    ejbDesc.setContainerTransactionFor(md, containerTransaction);
                                    if (logger.isLoggable(Level.FINE)) {
                                        logger.log(Level.FINE, "Found matching callback method {0}<>{1} : {2}", new Object[] { ejbDesc.getEjbClassName(), md, containerTransaction });
                                    }
                                }
                            } catch (Exception e) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, "Transaction attribute for a lifecycle callback annotation processing error", e);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 34 with EjbDescriptor

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

the class TransactionManagementHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    TransactionManagement tmAn = (TransactionManagement) ainfo.getAnnotation();
    String tmType = TransactionManagementType.CONTAINER.equals(tmAn.value()) ? EjbDescriptor.CONTAINER_TRANSACTION_TYPE : EjbDescriptor.BEAN_TRANSACTION_TYPE;
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        // override by xml
        if (ejbDesc.getTransactionType() == null) {
            ejbDesc.setTransactionType(tmType);
        }
    }
    return getDefaultProcessedResult();
}
Also used : EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) TransactionManagement(javax.ejb.TransactionManagement)

Example 35 with EjbDescriptor

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

the class PrimekeyFieldPersistentFields method check.

/**
 * The primkey-field must be one of the fields declared in the cmp-field
 * elements.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // cmp-field elements
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
            try {
                // do i need to use this to help determine single vs. multiple
                // object finders, etc.
                String primkey = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
                if (primkey.equals("java.lang.String")) {
                    try {
                        FieldDescriptor primField = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
                        // primField must exist in order to be valid & pass test
                        Descriptor persistentField;
                        Field field;
                        Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
                        Iterator iterator = persistentFields.iterator();
                        boolean foundMatch = false;
                        while (iterator.hasNext()) {
                            persistentField = (Descriptor) iterator.next();
                            if (primField != null) {
                                if (primField.getName().equals(persistentField.getName())) {
                                    foundMatch = true;
                                    break;
                                } else {
                                    continue;
                                }
                            } else {
                                // should already be set, can't ever be in cmp
                                // fields if primField doesn't exist
                                foundMatch = false;
                                break;
                            }
                        }
                        if (foundMatch) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "Primary key field [ {0} ] is defined within set of container managed fields for bean [ {1} ]", new Object[] { primField.getName(), descriptor.getName() }));
                        } else {
                            if (primField != null) {
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Primary key field [ {0} ] is not defined within set of container managed fields for bean [ {1} ]", new Object[] { primField.getName(), descriptor.getName() }));
                            } else {
                                // not failed
                                try {
                                    if (((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName().equals("java.lang.Object")) {
                                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
                                    } else {
                                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                        result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Primary key field is not defined within set of container managed fields for bean [ {0} ]", new Object[] { descriptor.getName() }));
                                    }
                                } catch (NullPointerException e) {
                                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
                                }
                            }
                        }
                    } catch (NullPointerException e) {
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error: Primary Key Field must be defined for bean [ {0} ] with primary key class set to [ {1} ]", new Object[] { descriptor.getName(), primkey }));
                    }
                } else {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable3", "primkey [ {0} ] is not java.lang.String for bean [ {1} ]", new Object[] { primkey, descriptor.getName() }));
                }
            } catch (NullPointerException e) {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
            }
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistence }));
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected \n {1} bean, but called with {2} bean", new Object[] { getClass(), "Entity", "Session" }));
    }
    return result;
}
Also used : Set(java.util.Set) Result(com.sun.enterprise.tools.verifier.Result) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Field(java.lang.reflect.Field) Iterator(java.util.Iterator) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) Descriptor(org.glassfish.deployment.common.Descriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Aggregations

EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)48 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)19 Iterator (java.util.Iterator)18 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)16 Result (com.sun.enterprise.tools.verifier.Result)14 Method (java.lang.reflect.Method)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 Set (java.util.Set)8 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)6 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)5 Container (com.sun.ejb.Container)4 Field (java.lang.reflect.Field)4 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)4 DummyEjbDescriptor (org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor)4 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)3 Constructor (java.lang.reflect.Constructor)3 Descriptor (org.glassfish.deployment.common.Descriptor)3 InterceptorBindingDescriptor (org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor)3