[jboss-cvs] JBossAS SVN: r108618 - projects/ejb3/trunk/core/src/main/java/org/jboss/injection.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Oct 17 04:39:02 EDT 2010
Author: jaikiran
Date: 2010-10-17 04:39:00 -0400 (Sun, 17 Oct 2010)
New Revision: 108618
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java
Log:
EJBTHREE-2168 Similar to env-entry-type, the resource-evn-ref-type too should be inferred from injection-target (if present), in the absence of explicit resource-env-ref-type
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java 2010-10-17 04:22:21 UTC (rev 108617)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java 2010-10-17 08:39:00 UTC (rev 108618)
@@ -182,7 +182,7 @@
{
// EJBTHREE-712
// TODO: refactor with handlePropertyAnnotation
- String resTypeName = envRef.getType();
+ String resTypeName = getResourceEnvRefType(container, envRef);
String mappedName = envRef.getMappedName();
String encName = "env/" + envRef.getResourceEnvRefName();
if (resTypeName != null)
@@ -313,6 +313,57 @@
// TODO: Check for injection targets and if there's a mismatch in the types between
// different injection targets, then throw an error
ResourceInjectionTargetMetaData injectionTarget = injectionTargets.iterator().next();
+ return getTargetType(container, injectionTarget);
+ }
+
+ /**
+ * Returns the resource-env-ref-type for the passed {@link ResourceEnvironmentReferenceMetaData}.
+ * <p>
+ * If the passed resource-env-ref has the resource-env-entry-type explicitly specified, then
+ * that value is returned. Else, this method checks for the presence of any
+ * injection targets for this resource-env-ref. If there's a injection target, then
+ * the resource-env-entry-type is deduced based on the field/method of the injection target.
+ * </p>
+ * <p>
+ * This method returns null if the resource-env-entry-type isn't explicitly specified and
+ * if the resource-env-entry-type could not be deduced from the injection targets of this
+ * resource-env-ref.
+ * </p>
+ * @param container The container to which this env-entry belongs
+ * @param resourceEnvRef The resource-env-ref metadata
+ * @return
+ */
+ private static String getResourceEnvRefType(InjectionContainer container, ResourceEnvironmentReferenceMetaData resourceEnvRef)
+ {
+ // first check whether the type is explicitly specified
+ String explicitType = resourceEnvRef.getType();
+ if (explicitType != null)
+ {
+ return explicitType;
+ }
+ // check if this env-entry has an injection-target. If yes, then
+ // fetch the type from the injection target's field/method type
+ Set<ResourceInjectionTargetMetaData> injectionTargets = resourceEnvRef.getInjectionTargets();
+ if (injectionTargets == null || injectionTargets.isEmpty())
+ {
+ return null;
+ }
+ // even if there are multiple injection targets, we just check for the first one
+ // TODO: Check for injection targets and if there's a mismatch in the types between
+ // different injection targets, then throw an error
+ ResourceInjectionTargetMetaData injectionTarget = injectionTargets.iterator().next();
+ return getTargetType(container, injectionTarget);
+ }
+
+ /**
+ * Returns the fully qualified classname of the type of the injection target (field/method).
+ *
+ * @param container The container
+ * @param injectionTargets The injection target
+ * @return
+ */
+ private static String getTargetType(InjectionContainer container, ResourceInjectionTargetMetaData injectionTarget)
+ {
AccessibleObject accessibleObject = InjectionUtil.findInjectionTarget(container.getClassloader(), injectionTarget);
if (accessibleObject instanceof Field)
{
More information about the jboss-cvs-commits
mailing list