Search in sources :

Example 6 with EjbReferenceDescriptor

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

the class WebBundleDescriptorImpl method combineEjbReferenceDescriptors.

@Override
protected void combineEjbReferenceDescriptors(JndiNameEnvironment env) {
    for (Object oejbRef : env.getEjbReferenceDescriptors()) {
        EjbReference ejbRef = (EjbReference) oejbRef;
        EjbReferenceDescriptor ejbRefDesc = (EjbReferenceDescriptor) _getEjbReference(ejbRef.getName());
        if (ejbRefDesc != null) {
            combineInjectionTargets(ejbRefDesc, (EnvironmentProperty) ejbRef);
        } else {
            if (env instanceof WebBundleDescriptor && ((WebBundleDescriptor) env).isConflictEjbReference()) {
                throw new IllegalArgumentException(localStrings.getLocalString("web.deployment.exceptionconflictejbref", "There are more than one ejb references defined in web fragments with the same name, but not overrided in web.xml"));
            } else {
                addEjbReferenceDescriptor(ejbRef);
            }
        }
    }
}
Also used : EjbReference(com.sun.enterprise.deployment.types.EjbReference) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor)

Example 7 with EjbReferenceDescriptor

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

the class EJBHandler method getEjbReferenceDescriptors.

/**
 * Return EjbReferenceDescriptors with given name if exists or a new
 * one without name being set.
 * @param logicalName
 * @param rcContexts
 * @return an array of EjbReferenceDescriptor
 */
private EjbReferenceDescriptor[] getEjbReferenceDescriptors(String logicalName, ResourceContainerContext[] rcContexts) {
    EjbReferenceDescriptor[] ejbRefs = new EjbReferenceDescriptor[rcContexts.length];
    for (int i = 0; i < rcContexts.length; i++) {
        EjbReferenceDescriptor ejbRef = (EjbReferenceDescriptor) rcContexts[i].getEjbReference(logicalName);
        if (ejbRef == null) {
            ejbRef = new EjbReferenceDescriptor();
            rcContexts[i].addEjbReferenceDescriptor(ejbRef);
        }
        ejbRefs[i] = ejbRef;
    }
    return ejbRefs;
}
Also used : EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor)

Example 8 with EjbReferenceDescriptor

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

the class EJBHandler method processEJB.

/**
 * Process a particular annotation whose 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.
 *
 * @param ainfo the annotation information
 * @param rcContexts an array of ResourceContainerContext
 * @param ejbAn
 * @return HandlerProcessingResult
 */
protected HandlerProcessingResult processEJB(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts, EJB ejbAn) throws AnnotationProcessorException {
    EjbReferenceDescriptor[] ejbRefs = null;
    String defaultLogicalName = null;
    Class defaultBeanInterface = null;
    InjectionTarget target = null;
    if (ElementType.FIELD.equals(ainfo.getElementType())) {
        Field f = (Field) ainfo.getAnnotatedElement();
        String targetClassName = f.getDeclaringClass().getName();
        defaultLogicalName = targetClassName + "/" + f.getName();
        defaultBeanInterface = f.getType();
        target = new InjectionTarget();
        target.setClassName(targetClassName);
        target.setFieldName(f.getName());
        target.setMetadataSource(MetadataSource.ANNOTATION);
    } else if (ElementType.METHOD.equals(ainfo.getElementType())) {
        Method m = (Method) ainfo.getAnnotatedElement();
        String targetClassName = m.getDeclaringClass().getName();
        validateInjectionMethod(m, ainfo);
        // Derive javabean property name.
        String propertyName = getInjectionMethodPropertyName(m, ainfo);
        defaultLogicalName = targetClassName + "/" + propertyName;
        defaultBeanInterface = m.getParameterTypes()[0];
        target = new InjectionTarget();
        target.setClassName(targetClassName);
        target.setMethodName(m.getName());
        target.setMetadataSource(MetadataSource.ANNOTATION);
    } else if (ElementType.TYPE.equals(ainfo.getElementType())) {
        // if either of them not set, fail fast.  See issue 17284
        if (ejbAn.name().equals("") || ejbAn.beanInterface() == Object.class) {
            Class c = (Class) ainfo.getAnnotatedElement();
            AnnotationProcessorException fatalException = new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidtypelevelejb", "Invalid TYPE-level @EJB with name() = [{0}] and " + "beanInterface = [{1}] in {2}.  Each TYPE-level @EJB " + "must specify both name() and beanInterface().", new Object[] { ejbAn.name(), ejbAn.beanInterface(), c }), ainfo);
            fatalException.setFatal(true);
            throw fatalException;
        }
    } else {
        // can't happen
        return getDefaultFailedResult();
    }
    // NOTE that default value is Object.class, not null
    Class beanInterface = (ejbAn.beanInterface() == Object.class) ? defaultBeanInterface : ejbAn.beanInterface();
    String logicalName = ejbAn.name().equals("") ? defaultLogicalName : ejbAn.name();
    ejbRefs = getEjbReferenceDescriptors(logicalName, rcContexts);
    for (EjbReferenceDescriptor ejbRef : ejbRefs) {
        if (target != null)
            ejbRef.addInjectionTarget(target);
        if (// a new one
        !ok(ejbRef.getName()))
            ejbRef.setName(logicalName);
        // merge type information
        setEjbType(ejbRef, beanInterface);
        // merge description
        if (!ok(ejbRef.getDescription()) && ok(ejbAn.description()))
            ejbRef.setDescription(ejbAn.description());
        // merge lookup-name and mapped-name
        if (!ejbRef.hasLookupName() && ok(ejbAn.lookup()))
            ejbRef.setLookupName(ejbAn.lookup());
        if (!ok(ejbRef.getMappedName()) && ok(ejbAn.mappedName()))
            ejbRef.setMappedName(ejbAn.mappedName());
        // merge beanName/linkName
        if (!ok(ejbRef.getLinkName()) && ok(ejbAn.beanName()))
            ejbRef.setLinkName(ejbAn.beanName());
    }
    return getDefaultProcessedResult();
}
Also used : Field(java.lang.reflect.Field) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) Method(java.lang.reflect.Method) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException)

Example 9 with EjbReferenceDescriptor

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

the class ASEjbRef method check.

/**
 * @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();
    String ejbName = null, jndiName = null;
    boolean oneFailed = false;
    boolean notApplicable = false;
    boolean oneWarning = false;
    try {
        ejbName = descriptor.getName();
        Set ejbRefs = descriptor.getEjbReferenceDescriptors();
        if (ejbRefs.size() > 0) {
            Iterator it = ejbRefs.iterator();
            while (it.hasNext()) {
                EjbReferenceDescriptor desc = ((EjbReferenceDescriptor) it.next());
                String refJndiName = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb/ejb-ref[ejb-ref-name=\"" + desc.getName() + "\"]/jndi-name");
                String refName = desc.getName();
                String type = desc.getType();
                if (!desc.isLocal()) {
                    if (type == null || !((type.equals(EjbSessionDescriptor.TYPE) || type.equals(EjbEntityDescriptor.TYPE)))) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB ejb-ref] ejb-ref-name has an invalid type in ejb-jar.xml." + " Type should be Session or Entity only"));
                    } else {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB ejb-ref] ejb-ref-name [{0}] is valid", new Object[] { refName }));
                    }
                } else {
                    addNaDetails(result, compName);
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} Does not define any ejb references", new Object[] { ejbName }));
                    return result;
                }
                if (refJndiName != null) {
                    if (refJndiName.length() == 0) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB ejb-ref] : jndi-name cannot be an empty string", new Object[] { refName }));
                    } else {
                        if (!refJndiName.startsWith("ejb/")) {
                            oneWarning = true;
                            addWarningDetails(result, compName);
                            result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb-ref] JNDI name should start with ejb/ for an ejb reference", new Object[] { refName }));
                        }
                    }
                } else {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB ejb-ref] : jndi-name cannot be an empty string", new Object[] { refName }));
                }
                if (!oneFailed) {
                    addGoodDetails(result, compName);
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB ejb-ref] : ejb-ref-Name is {0} and jndi-name is {1}", new Object[] { refName, refJndiName }));
                }
            }
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} Does not define any ejb references", new Object[] { ejbName }));
            return result;
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create descriptor object"));
        return result;
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else if (oneWarning) {
        result.setStatus(Result.WARNING);
    } else {
        addErrorDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB] :  {0} ejb refernce is verified", new Object[] { ejbName, jndiName }));
    }
    return result;
}
Also used : Set(java.util.Set) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 10 with EjbReferenceDescriptor

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

the class EjbRefNamePrefixed method check.

/**
 * The ejb-ref-name element contains the name of an EJB reference. The EJB
 * reference is an entry in the enterprise bean's environment. It is
 * recommended that name is prefixed with "ejb/".
 *
 * @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();
    if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
        for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
            EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
            String ejbRefName = nextEjbReference.getName();
            if (!ejbRefName.startsWith("ejb/")) {
                addWarningDetails(result, compName);
                result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Warning: [ {0} ] is not prefixed with recommended string " + "ejb/ within bean [ {1} ]", new Object[] { ejbRefName, descriptor.getName() }));
            }
        }
    }
    if (result.getStatus() != Result.WARNING) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "ejb-ref-name is properly defined within bean [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)13 Iterator (java.util.Iterator)7 Result (com.sun.enterprise.tools.verifier.Result)6 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)6 Set (java.util.Set)3 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)2 Application (com.sun.enterprise.deployment.Application)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 EjbReference (com.sun.enterprise.deployment.types.EjbReference)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)1 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)1