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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
}
}
}
Aggregations