Search in sources :

Example 21 with InjectionTarget

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

the class EntityManagerReferenceHandler method processEmRef.

/**
 * Process a particular annotation which 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.
 */
protected HandlerProcessingResult processEmRef(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts, PersistenceContext emRefAn) throws AnnotationProcessorException {
    EntityManagerReferenceDescriptor[] emRefs = null;
    if (ElementType.FIELD.equals(ainfo.getElementType())) {
        Field f = (Field) ainfo.getAnnotatedElement();
        String targetClassName = f.getDeclaringClass().getName();
        String logicalName = emRefAn.name();
        // applying with default
        if (logicalName.equals("")) {
            logicalName = targetClassName + "/" + f.getName();
        }
        emRefs = getEmReferenceDescriptors(logicalName, rcContexts);
        InjectionTarget target = new InjectionTarget();
        target.setFieldName(f.getName());
        target.setClassName(targetClassName);
        target.setMetadataSource(MetadataSource.ANNOTATION);
        for (EntityManagerReferenceDescriptor emRef : emRefs) {
            emRef.addInjectionTarget(target);
            if (emRef.getName().length() == 0) {
                // a new one
                processNewEmRefAnnotation(emRef, logicalName, emRefAn);
            }
        }
    } else if (ElementType.METHOD.equals(ainfo.getElementType())) {
        Method m = (Method) ainfo.getAnnotatedElement();
        String targetClassName = m.getDeclaringClass().getName();
        String logicalName = emRefAn.name();
        if (logicalName.equals("")) {
            // Derive javabean property name.
            String propertyName = getInjectionMethodPropertyName(m, ainfo);
            // prefixing with fully qualified type name
            logicalName = targetClassName + "/" + propertyName;
        }
        validateInjectionMethod(m, ainfo);
        emRefs = getEmReferenceDescriptors(logicalName, rcContexts);
        InjectionTarget target = new InjectionTarget();
        target.setMethodName(m.getName());
        target.setClassName(targetClassName);
        target.setMetadataSource(MetadataSource.ANNOTATION);
        for (EntityManagerReferenceDescriptor emRef : emRefs) {
            emRef.addInjectionTarget(target);
            if (emRef.getName().length() == 0) {
                // a new one
                processNewEmRefAnnotation(emRef, logicalName, emRefAn);
            }
        }
    } else if (ElementType.TYPE.equals(ainfo.getElementType())) {
        // name() is required for TYPE-level usage
        String logicalName = emRefAn.name();
        if ("".equals(logicalName)) {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.nonametypelevel", "TYPE-Level annotation symbol on class must specify name."));
            return getDefaultFailedResult();
        }
        emRefs = getEmReferenceDescriptors(logicalName, rcContexts);
        for (EntityManagerReferenceDescriptor emRef : emRefs) {
            if (emRef.getName().length() == 0) {
                // a new one
                processNewEmRefAnnotation(emRef, logicalName, emRefAn);
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : Field(java.lang.reflect.Field) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) Method(java.lang.reflect.Method) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 22 with InjectionTarget

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

the class InjectionTargetTest method check.

public Result check(Descriptor descriptor) {
    this.descriptor = descriptor;
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    ClassLoader cl = getVerifierContext().getClassLoader();
    List<InjectionCapable> injectables = getInjectables(getClassName());
    for (InjectionCapable injectionCapable : injectables) {
        Set<InjectionTarget> iTargets = injectionCapable.getInjectionTargets();
        for (InjectionTarget target : iTargets) {
            try {
                if (target.isFieldInjectable()) {
                    Class classObj = Class.forName(getClassName(), false, cl);
                    Field field = classObj.getDeclaredField(target.getFieldName());
                    testMethodModifiers(field.getModifiers(), "field", field);
                }
                if (target.isMethodInjectable()) {
                    Class classObj = Class.forName(getClassName(), false, cl);
                    Method method = getInjectedMethod(classObj, target.getMethodName());
                    if (method == null)
                        continue;
                    testMethodModifiers(method.getModifiers(), "method", method);
                }
            }// ignore as it will be caught in other tests
             catch (Exception e) {
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid injection method(s)."));
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) InjectionCapable(com.sun.enterprise.deployment.InjectionCapable) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) Method(java.lang.reflect.Method)

Example 23 with InjectionTarget

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

the class MessageDestinationRefNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, String nodeName, MessageDestinationReferenceDescriptor desc) {
    Node msgDestRefNode = appendChild(parent, nodeName);
    writeLocalizedDescriptions(msgDestRefNode, desc);
    appendTextChild(msgDestRefNode, TagNames.MESSAGE_DESTINATION_REFERENCE_NAME, desc.getName());
    appendTextChild(msgDestRefNode, TagNames.MESSAGE_DESTINATION_TYPE, desc.getDestinationType());
    appendTextChild(msgDestRefNode, TagNames.MESSAGE_DESTINATION_USAGE, desc.getUsage());
    appendTextChild(msgDestRefNode, TagNames.MESSAGE_DESTINATION_LINK, desc.getMessageDestinationLinkName());
    appendTextChild(msgDestRefNode, TagNames.MAPPED_NAME, desc.getMappedName());
    if (desc.isInjectable()) {
        InjectionTargetNode ijNode = new InjectionTargetNode();
        for (InjectionTarget target : desc.getInjectionTargets()) {
            ijNode.writeDescriptor(msgDestRefNode, TagNames.INJECTION_TARGET, target);
        }
    }
    appendTextChild(msgDestRefNode, TagNames.LOOKUP_NAME, desc.getLookupName());
    return msgDestRefNode;
}
Also used : Node(org.w3c.dom.Node) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget)

Example 24 with InjectionTarget

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

the class ResourceEnvRefNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, String nodeName, ResourceEnvReferenceDescriptor descriptor) {
    Node ejbResNode = appendChild(parent, nodeName);
    writeLocalizedDescriptions(ejbResNode, descriptor);
    appendTextChild(ejbResNode, TagNames.RESOURCE_ENV_REFERENCE_NAME, descriptor.getName());
    appendTextChild(ejbResNode, TagNames.RESOURCE_ENV_REFERENCE_TYPE, descriptor.getRefType());
    appendTextChild(ejbResNode, TagNames.MAPPED_NAME, descriptor.getMappedName());
    if (descriptor.isInjectable()) {
        InjectionTargetNode ijNode = new InjectionTargetNode();
        for (InjectionTarget target : descriptor.getInjectionTargets()) {
            ijNode.writeDescriptor(ejbResNode, TagNames.INJECTION_TARGET, target);
        }
    }
    appendTextChild(ejbResNode, TagNames.LOOKUP_NAME, descriptor.getLookupName());
    return ejbResNode;
}
Also used : Node(org.w3c.dom.Node) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget)

Aggregations

InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)24 Node (org.w3c.dom.Node)8 Field (java.lang.reflect.Field)6 Method (java.lang.reflect.Method)6 EntityManagerReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)3 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)2 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)2 EntityManagerFactoryReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)2 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)2 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)2 EjbReference (com.sun.enterprise.deployment.types.EjbReference)2 Result (com.sun.enterprise.tools.verifier.Result)2 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)1 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 MessageDestinationReferenceDescriptor (com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ServiceRefPortInfo (com.sun.enterprise.deployment.ServiceRefPortInfo)1 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)1