Search in sources :

Example 1 with InjectionTarget

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

the class EntityManagerInjection method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    addWarningDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    for (EntityManagerReferenceDescriptor emRefDesc : descriptor.getEntityManagerReferenceDescriptors()) {
        Set<InjectionTarget> injectionTargets = emRefDesc.getInjectionTargets();
        if (injectionTargets != null) {
            for (InjectionTarget it : injectionTargets) {
                String itClassName = it.getClassName();
                String errMsg = smh.getLocalString(className + ".warning", "Found a persistence unit by name [ {0} ] injected into [ {1} ].", new Object[] { emRefDesc.getUnitName(), itClassName });
                try {
                    Class c = Class.forName(itClassName, false, getVerifierContext().getClassLoader());
                    if (!(Servlet.class.isAssignableFrom(c))) {
                        result.warning(errMsg);
                    } else if (!(SingleThreadModel.class.isAssignableFrom(c))) {
                        result.warning(errMsg);
                    }
                } catch (Exception ex) {
                    result.warning(errMsg);
                }
            }
        }
    }
    return result;
}
Also used : InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) SingleThreadModel(javax.servlet.SingleThreadModel) Result(com.sun.enterprise.tools.verifier.Result) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 2 with InjectionTarget

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

the class StatefulSessionBeanInjection method check.

public Result check(WebBundleDescriptor descriptor) {
    // initialize the result object
    Result result = getInitializedResult();
    addWarningDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    Set<EjbReference> s = descriptor.getEjbReferenceDescriptors();
    if (s == null)
        return result;
    for (EjbReference ejbRefDesc : s) {
        EjbDescriptor ejbDescriptor = ejbRefDesc.getEjbDescriptor();
        if (ejbDescriptor instanceof EjbSessionDescriptor) {
            // instaceof returns false if ejbDescriptor=null.
            String stateType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType();
            if (EjbSessionDescriptor.STATEFUL.equals(stateType)) {
                Set<InjectionTarget> injectionTargets = ejbRefDesc.getInjectionTargets();
                if (injectionTargets != null) {
                    for (InjectionTarget it : injectionTargets) {
                        String itClassName = it.getClassName();
                        result.warning(smh.getLocalString(className + ".warning", "Found a stateful session bean [ {0} ] injected into [ {1} ].", new Object[] { ejbDescriptor.getEjbClassName(), itClassName }));
                    }
                }
            }
        }
    }
    return result;
}
Also used : EjbReference(com.sun.enterprise.deployment.types.EjbReference) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 3 with InjectionTarget

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

the class EjbDescriptor method addEntityManagerReferenceDescriptor.

@Override
public final void addEntityManagerReferenceDescriptor(EntityManagerReferenceDescriptor reference) {
    try {
        EntityManagerReferenceDescriptor existing = this.getEntityManagerReferenceByName(reference.getName());
        for (InjectionTarget next : reference.getInjectionTargets()) {
            existing.addInjectionTarget(next);
        }
    } catch (IllegalArgumentException e) {
        if (getEjbBundleDescriptor() != null) {
            reference.setReferringBundleDescriptor(getEjbBundleDescriptor());
        }
        if (env != null)
            env.addEntityManagerReferenceDescriptor(reference);
        else
            getEntityManagerReferenceDescriptors().add(reference);
    }
}
Also used : InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 4 with InjectionTarget

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

the class EjbDescriptor method addEntityManagerFactoryReferenceDescriptor.

@Override
public final void addEntityManagerFactoryReferenceDescriptor(EntityManagerFactoryReferenceDescriptor reference) {
    try {
        EntityManagerFactoryReferenceDescriptor existing = getEntityManagerFactoryReferenceByName(reference.getName());
        for (InjectionTarget next : reference.getInjectionTargets()) {
            existing.addInjectionTarget(next);
        }
    } catch (IllegalArgumentException e) {
        if (getEjbBundleDescriptor() != null) {
            reference.setReferringBundleDescriptor(getEjbBundleDescriptor());
        }
        if (env != null)
            env.addEntityManagerFactoryReferenceDescriptor(reference);
        else
            entityManagerFactoryReferences.add(reference);
    }
}
Also used : InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) EntityManagerFactoryReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)

Example 5 with InjectionTarget

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

the class ComponentValidator method acceptWithCL.

// we need to split the accept(InjectionCapable) into two parts:
// one needs classloader and one doesn't. This is needed because
// in the standalone war case, the classloader is not created
// untill the web module is being started.
protected void acceptWithCL(InjectionCapable injectable) {
    // injection method for each injection target
    for (InjectionTarget target : injectable.getInjectionTargets()) {
        if ((target.getFieldName() == null) && (target.getMethodName() == null)) {
            String injectTargetName = target.getTargetName();
            String targetClassName = target.getClassName();
            ClassLoader classLoader = getBundleDescriptor().getClassLoader();
            Class targetClazz = null;
            try {
                targetClazz = classLoader.loadClass(targetClassName);
            } catch (ClassNotFoundException cnfe) {
                // @@@
                // Don't treat this as a fatal error for now.  One known issue
                // is that all .xml, even web.xml, is processed within the
                // appclient container during startup.  In that case, there
                // are issues with finding .classes in .wars due to the
                // structure of the returned client .jar and the way the
                // classloader is formed.
                DOLUtils.getDefaultLogger().fine("Injection class " + targetClassName + " not found for " + injectable);
                return;
            }
            // Spec requires that we attempt to match on method before field.
            boolean matched = false;
            // The only information we have is method name, so iterate
            // through the methods find a match.  There is no overloading
            // allowed for injection methods, so any match is considered
            // the only possible match.
            String setterMethodName = TypeUtil.propertyNameToSetterMethod(injectTargetName);
            // method can have any access type so use getDeclaredMethods()
            for (Method next : targetClazz.getDeclaredMethods()) {
                // has exactly one parameter, we find a match
                if (next.getName().equals(setterMethodName) && next.getParameterTypes().length == 1) {
                    target.setMethodName(next.getName());
                    if (injectable.getInjectResourceType() == null) {
                        Class[] paramTypes = next.getParameterTypes();
                        if (paramTypes.length == 1) {
                            String resourceType = paramTypes[0].getName();
                            injectable.setInjectResourceType(resourceType);
                        }
                    }
                    matched = true;
                    break;
                }
            }
            if (!matched) {
                // field name.  Field can have any access type.
                try {
                    Field f = targetClazz.getDeclaredField(injectTargetName);
                    target.setFieldName(injectTargetName);
                    if (injectable.getInjectResourceType() == null) {
                        String resourceType = f.getType().getName();
                        injectable.setInjectResourceType(resourceType);
                    }
                    matched = true;
                } catch (NoSuchFieldException nsfe) {
                    String msg = "No matching injection setter method or " + "injection field found for injection property " + injectTargetName + " on class " + targetClassName + " for component dependency " + injectable;
                    throw new RuntimeException(msg, nsfe);
                }
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) Method(java.lang.reflect.Method)

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