[jboss-cvs] JBossAS SVN: r82312 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/injection.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 16 08:37:46 EST 2008
Author: adrian at jboss.org
Date: 2008-12-16 08:37:46 -0500 (Tue, 16 Dec 2008)
New Revision: 82312
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/injection/WebResourceHandler.java
Log:
Source code tidyup
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/injection/WebResourceHandler.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/injection/WebResourceHandler.java 2008-12-16 13:37:24 UTC (rev 82311)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/injection/WebResourceHandler.java 2008-12-16 13:37:46 UTC (rev 82312)
@@ -64,425 +64,443 @@
/**
* RemoteEnvironment InjectionHandler for web components
*
+ * @param <X> the remote environment type
* @author Scott.Stark at jboss.org
* @version $Revision:$
*/
public class WebResourceHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
{
-private static final Logger log = Logger.getLogger(WebResourceHandler.class);
-
- private boolean checkEncInjectors;
+ private static final Logger log = Logger.getLogger(WebResourceHandler.class);
- public WebResourceHandler()
+ private boolean checkEncInjectors;
+
+ public WebResourceHandler()
+ {
+ this(true);
+ }
+
+ public WebResourceHandler(boolean checkEncInjectors)
+ {
+ this.checkEncInjectors = checkEncInjectors;
+ }
+
+ private static void createURLInjector(String encName, String mappedName, InjectionContainer container)
+ {
+ assert encName.length() > 0 : "encName is empty";
+ assert mappedName.length() > 0 : "mappedName is empty";
+
+ // Create a URL from the mappedName
+ try
{
- this(true);
+ URL url = new URL(mappedName.trim());
+ container.getEncInjectors().put(encName, new ValueEncInjector(encName, url, "@Resource"));
}
-
- public WebResourceHandler(boolean checkEncInjectors)
+ catch (MalformedURLException e)
{
- this.checkEncInjectors = checkEncInjectors;
+ throw new RuntimeException("failed to create url injector for: " + encName, e);
}
-
- private static void createURLInjector(String encName, String mappedName, InjectionContainer container)
+ }
+
+ private static void loadEnvEntry(InjectionContainer container, Collection<EnvironmentEntryMetaData> envEntries)
+ {
+ for (EnvironmentEntryMetaData envEntry : envEntries)
{
- assert encName.length() > 0 : "encName is empty";
- assert mappedName.length() > 0 : "mappedName is empty";
-
- // Create a URL from the mappedName
- try
+ String encName = "env/" + envEntry.getEnvEntryName();
+ // 16.4.1.3: If the env-entry-value is not specified, no value will be injected and it
+ // will not be initialized into the naming context.
+ if (envEntry.getValue() == null)
{
- URL url = new URL(mappedName.trim());
- container.getEncInjectors().put(encName, new ValueEncInjector(encName, url, "@Resource"));
+ log.debug("ignoring env-entry " + envEntry);
+ continue;
}
- catch (MalformedURLException e)
- {
- throw new RuntimeException("failed to create url injector for: "+ encName, e);
- }
+ InjectionUtil.injectionTarget(encName, envEntry, container, container.getEncInjections());
+ if (container.getEncInjectors().containsKey(encName))
+ continue;
+ log.trace("adding env-entry injector " + encName);
+ container.getEncInjectors().put(encName,
+ new EnvEntryEncInjector(encName, envEntry.getType(), envEntry.getValue()));
}
-
- private static void loadEnvEntry(InjectionContainer container, Collection<EnvironmentEntryMetaData> envEntries)
+ }
+
+ private static void loadXmlResourceRefs(InjectionContainer container, Collection<ResourceReferenceMetaData> refs)
+ {
+ for (ResourceReferenceMetaData envRef : refs)
{
- for (EnvironmentEntryMetaData envEntry : envEntries)
+ String encName = "env/" + envRef.getResourceRefName();
+ if (container.getEncInjectors().containsKey(encName))
+ continue;
+
+ String mappedName = envRef.getMappedName();
+ if (mappedName == null || mappedName.length() == 0)
+ mappedName = envRef.getResolvedJndiName();
+ if (mappedName == null || mappedName.length() == 0)
{
- String encName = "env/" + envEntry.getEnvEntryName();
- // 16.4.1.3: If the env-entry-value is not specified, no value will be injected and it
- // will not be initialized into the naming context.
- if(envEntry.getValue() == null)
+ if (envRef.getResUrl() != null)
{
- log.debug("ignoring env-entry " + envEntry);
- continue;
+ try
+ {
+ container.getEncInjectors().put(encName,
+ new ValueEncInjector(encName, new URL(envRef.getResUrl().trim()), "<resource-ref>"));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
}
- InjectionUtil.injectionTarget(encName, envEntry, container, container.getEncInjections());
- if (container.getEncInjectors().containsKey(encName)) continue;
- log.trace("adding env-entry injector " + encName);
- container.getEncInjectors().put(encName, new EnvEntryEncInjector(encName, envEntry.getType(), envEntry.getValue()));
- }
- }
-
- private static void loadXmlResourceRefs(InjectionContainer container, Collection<ResourceReferenceMetaData> refs)
- {
- for (ResourceReferenceMetaData envRef : refs)
- {
- String encName = "env/" + envRef.getResourceRefName();
- if (container.getEncInjectors().containsKey(encName))
- continue;
-
- String mappedName = envRef.getMappedName();
- if(mappedName == null || mappedName.length() == 0)
- mappedName = envRef.getResolvedJndiName();
- if (mappedName == null || mappedName.length() == 0)
+ else if (UserTransaction.class.getName().equals(envRef.getType()))
{
- if (envRef.getResUrl() != null)
+ final InjectionContainer ic = container;
+ InjectorFactory<?> factory = new InjectorFactory<UserTransactionPropertyInjector>()
{
- try
+ public UserTransactionPropertyInjector create(BeanProperty property)
{
- container.getEncInjectors().put(encName, new ValueEncInjector(encName, new URL(envRef.getResUrl().trim()), "<resource-ref>"));
+ return new UserTransactionPropertyInjector(property, ic);
}
- catch (MalformedURLException e)
- {
- throw new RuntimeException(e);
- }
- }
- else if (UserTransaction.class.getName().equals(envRef.getType()))
+ };
+ if (envRef.getInjectionTargets() != null)
{
- final InjectionContainer ic = container;
- InjectorFactory<?> factory = new InjectorFactory<UserTransactionPropertyInjector>()
- {
- public UserTransactionPropertyInjector create(BeanProperty property)
- {
- return new UserTransactionPropertyInjector(property, ic);
- }
- };
- if(envRef.getInjectionTargets() != null)
- {
- TomcatInjectionUtils.createInjectors(container.getEncInjections(), container.getClassloader(), factory, envRef.getInjectionTargets());
- continue;
- }
- else
- {
- encName = "java:comp/UserTransaction";
- }
+ TomcatInjectionUtils.createInjectors(container.getEncInjections(), container.getClassloader(),
+ factory, envRef.getInjectionTargets());
+ continue;
}
- else if (ORB.class.getName().equals(envRef.getType()))
- {
- encName = "java:comp/ORB";
- }
else
{
- throw new RuntimeException("mapped-name is required for " + envRef.getResourceRefName() + " of deployment " + container.getIdentifier());
+ encName = "java:comp/UserTransaction";
}
}
- else if(URL.class.getName().equals(envRef.getType()) && ! mappedName.startsWith("java:") )
+ else if (ORB.class.getName().equals(envRef.getType()))
{
- createURLInjector(encName, mappedName, container);
- InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
- continue;
+ encName = "java:comp/ORB";
}
- else if(envRef.getResUrl() != null)
- {
- try
- {
- container.getEncInjectors().put(encName, new ValueEncInjector(encName, new URL(envRef.getResUrl().trim()), "<resource-ref>"));
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException(e);
- }
- }
else
{
- container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, mappedName, "<resource-ref>"));
+ throw new RuntimeException("mapped-name is required for " + envRef.getResourceRefName()
+ + " of deployment " + container.getIdentifier());
}
+ }
+ else if (URL.class.getName().equals(envRef.getType()) && !mappedName.startsWith("java:"))
+ {
+ createURLInjector(encName, mappedName, container);
InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
+ continue;
}
+ else if (envRef.getResUrl() != null)
+ {
+ try
+ {
+ container.getEncInjectors().put(encName,
+ new ValueEncInjector(encName, new URL(envRef.getResUrl().trim()), "<resource-ref>"));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ else
+ {
+ container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, mappedName, "<resource-ref>"));
+ }
+ InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
}
+ }
- private static void loadXmlResourceEnvRefs(InjectionContainer container, Collection<ResourceEnvironmentReferenceMetaData> refs)
+ private static void loadXmlResourceEnvRefs(InjectionContainer container,
+ Collection<ResourceEnvironmentReferenceMetaData> refs)
+ {
+ for (ResourceEnvironmentReferenceMetaData envRef : refs)
{
- for (ResourceEnvironmentReferenceMetaData envRef : refs)
+ String resTypeName = envRef.getType();
+ String mappedName = envRef.getMappedName();
+ if (mappedName == null || mappedName.length() == 0)
+ mappedName = envRef.getResolvedJndiName();
+ try
{
- String resTypeName = envRef.getType();
- String mappedName = envRef.getMappedName();
- if(mappedName == null || mappedName.length() == 0)
- mappedName = envRef.getResolvedJndiName();
- try
+ if (resTypeName != null)
{
- if(resTypeName != null)
+ Class<?> resType = Class.forName(resTypeName);
+ if (TimerService.class.isAssignableFrom(resType))
{
- Class<?> resType = Class.forName(resTypeName);
- if(TimerService.class.isAssignableFrom(resType))
+ log.warn("Ignoring invalid TimerService resource-env-ref");
+ continue;
+ }
+ else if (SessionContext.class.isAssignableFrom(resType))
+ {
+ log.warn("Ignoring invalid SessionContext resource-env-ref");
+ continue;
+ }
+ else if (resType.equals(UserTransaction.class))
+ {
+ final InjectionContainer ic = container;
+ InjectorFactory<?> factory = new InjectorFactory<UserTransactionPropertyInjector>()
{
- log.warn("Ignoring invalid TimerService resource-env-ref");
+ public UserTransactionPropertyInjector create(BeanProperty property)
+ {
+ return new UserTransactionPropertyInjector(property, ic);
+ }
+ };
+ if (envRef.getInjectionTargets() != null)
+ {
+ TomcatInjectionUtils.createInjectors(container.getEncInjections(), container.getClassloader(),
+ factory, envRef.getInjectionTargets());
continue;
}
- else if(SessionContext.class.isAssignableFrom(resType))
+ else
{
- log.warn("Ignoring invalid SessionContext resource-env-ref");
- continue;
+ mappedName = "java:comp/UserTransaction";
}
- else if (resType.equals(UserTransaction.class))
+ }
+ else if (resType.equals(ORB.class))
+ {
+ mappedName = "java:comp/ORB";
+ continue;
+ }
+ else if (WebServiceContext.class.getName().equals(envRef.getType()))
+ {
+ // JBAS-5359
+ InjectorFactory<?> factory = new InjectorFactory<WebServiceContextPropertyInjector>()
{
- final InjectionContainer ic = container;
- InjectorFactory<?> factory = new InjectorFactory<UserTransactionPropertyInjector>()
+ public WebServiceContextPropertyInjector create(BeanProperty property)
{
- public UserTransactionPropertyInjector create(BeanProperty property)
- {
- return new UserTransactionPropertyInjector(property, ic);
- }
- };
- if(envRef.getInjectionTargets() != null)
- {
- TomcatInjectionUtils.createInjectors(container.getEncInjections(), container.getClassloader(), factory, envRef.getInjectionTargets());
- continue;
+ return new WebServiceContextPropertyInjector(property);
}
- else
- {
- mappedName = "java:comp/UserTransaction";
- }
- }
- else if (resType.equals(ORB.class))
+ };
+ if (envRef.getInjectionTargets() != null)
{
- mappedName = "java:comp/ORB";
+ TomcatInjectionUtils.createInjectors(container.getEncInjections(), container.getClassloader(),
+ factory, envRef.getInjectionTargets());
continue;
}
- else if(WebServiceContext.class.getName().equals(envRef.getType()))
- {
- // JBAS-5359
- InjectorFactory<?> factory = new InjectorFactory<WebServiceContextPropertyInjector>()
- { public WebServiceContextPropertyInjector create(BeanProperty property)
- {
- return new WebServiceContextPropertyInjector(property);
- }
- };
- if(envRef.getInjectionTargets() != null)
- {
- TomcatInjectionUtils.createInjectors(container.getEncInjections(), container.getClassloader(), factory, envRef.getInjectionTargets());
- continue;
- }
- }
}
}
- catch(ClassNotFoundException e)
- {
- throw new EJBException(e);
- }
-
- String encName = "env/" + envRef.getResourceEnvRefName();
- if (container.getEncInjectors().containsKey(encName))
- continue;
- if (mappedName == null || mappedName.equals(""))
- {
- throw new RuntimeException("mapped-name is required for " + envRef.getResourceEnvRefName() + " of deployment " + container.getIdentifier());
- }
- container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
- InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
}
+ catch (ClassNotFoundException e)
+ {
+ throw new EJBException(e);
+ }
+
+ String encName = "env/" + envRef.getResourceEnvRefName();
+ if (container.getEncInjectors().containsKey(encName))
+ continue;
+ if (mappedName == null || mappedName.equals(""))
+ {
+ throw new RuntimeException("mapped-name is required for " + envRef.getResourceEnvRefName()
+ + " of deployment " + container.getIdentifier());
+ }
+ container.getEncInjectors().put(encName,
+ new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
+ InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
}
+ }
- private static void loadXmlMessageDestinationRefs(InjectionContainer container, Collection<MessageDestinationReferenceMetaData> refs)
+ private static void loadXmlMessageDestinationRefs(InjectionContainer container,
+ Collection<MessageDestinationReferenceMetaData> refs)
+ {
+ for (MessageDestinationReferenceMetaData envRef : refs)
{
- for (MessageDestinationReferenceMetaData envRef : refs)
+ String encName = "env/" + envRef.getMessageDestinationRefName();
+ if (container.getEncInjectors().containsKey(encName))
+ continue;
+ String jndiName = envRef.getMappedName();
+ if (jndiName == null || jndiName.equals(""))
{
- String encName = "env/" + envRef.getMessageDestinationRefName();
- if (container.getEncInjectors().containsKey(encName)) continue;
- String jndiName = envRef.getMappedName();
+ jndiName = envRef.getResolvedJndiName();
if (jndiName == null || jndiName.equals(""))
- {
- jndiName = envRef.getResolvedJndiName();
- if (jndiName == null || jndiName.equals(""))
- throw new RuntimeException("mapped-name is required for " + envRef.getMessageDestinationRefName() + " of deployment " + container.getIdentifier());
- }
- container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, jndiName, "<message-destination-ref>"));
- InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
+ throw new RuntimeException("mapped-name is required for " + envRef.getMessageDestinationRefName()
+ + " of deployment " + container.getIdentifier());
}
+ container.getEncInjectors().put(encName,
+ new LinkRefEncInjector(encName, jndiName, "<message-destination-ref>"));
+ InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
}
+ }
- public void loadXml(X xml, InjectionContainer container)
- {
- if (xml == null)
- return;
- if (xml.getMessageDestinationReferences() != null)
- loadXmlMessageDestinationRefs(container, xml.getMessageDestinationReferences());
- if (xml.getResourceEnvironmentReferences() != null)
- loadXmlResourceEnvRefs(container, xml.getResourceEnvironmentReferences());
- if (xml.getResourceReferences() != null)
- loadXmlResourceRefs(container, xml.getResourceReferences());
- if (xml.getEnvironmentEntries() != null)
- loadEnvEntry(container, xml.getEnvironmentEntries());
- }
+ public void loadXml(X xml, InjectionContainer container)
+ {
+ if (xml == null)
+ return;
+ if (xml.getMessageDestinationReferences() != null)
+ loadXmlMessageDestinationRefs(container, xml.getMessageDestinationReferences());
+ if (xml.getResourceEnvironmentReferences() != null)
+ loadXmlResourceEnvRefs(container, xml.getResourceEnvironmentReferences());
+ if (xml.getResourceReferences() != null)
+ loadXmlResourceRefs(container, xml.getResourceReferences());
+ if (xml.getEnvironmentEntries() != null)
+ loadEnvEntry(container, xml.getEnvironmentEntries());
+ }
- public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+ public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+ {
+ Resources resources = container.getAnnotation(Resources.class, clazz);
+ if (resources != null)
{
- Resources resources = container.getAnnotation(Resources.class, clazz);
- if (resources != null)
- {
for (Resource ref : resources.value())
{
handleClassAnnotation(ref, container, clazz);
}
- }
- Resource res = container.getAnnotation(Resource.class, clazz);
- if (res != null) handleClassAnnotation(res, container, clazz);
}
+ Resource res = container.getAnnotation(Resource.class, clazz);
+ if (res != null)
+ handleClassAnnotation(res, container, clazz);
+ }
- private void handleClassAnnotation(Resource ref, InjectionContainer container, Class<?> clazz)
+ private void handleClassAnnotation(Resource ref, InjectionContainer container, Class<?> clazz)
+ {
+ String encName = ref.name();
+ if (encName == null || encName.equals(""))
{
- String encName = ref.name();
- if (encName == null || encName.equals(""))
- {
- throw new RuntimeException("JBoss requires name() for class level @Resource");
- }
- encName = "env/" + ref.name();
- if (container.getEncInjectors().containsKey(encName)) return;
+ throw new RuntimeException("JBoss requires name() for class level @Resource");
+ }
+ encName = "env/" + ref.name();
+ if (container.getEncInjectors().containsKey(encName))
+ return;
- String mappedName = ref.mappedName();
- if (mappedName == null || mappedName.equals(""))
+ String mappedName = ref.mappedName();
+ if (mappedName == null || mappedName.equals(""))
+ {
+ // Handle class level @Resource(type=ORB.class)
+ if (ORB.class.isAssignableFrom(ref.type()))
{
- // Handle class level @Resource(type=ORB.class)
- if(ORB.class.isAssignableFrom(ref.type()))
- {
- mappedName = "java:comp/ORB";
- }
- else if(UserTransaction.class.isAssignableFrom(ref.type()))
- {
- mappedName = "java:comp/UserTransaction";
- }
- else
- {
- throw new RuntimeException("You did not specify a @Resource.mappedName() for name: "
- +ref.name()+", class: " + clazz.getName() + " and there is no binding for that enc name in XML");
- }
+ mappedName = "java:comp/ORB";
}
-
- if (ref.type() == URL.class)
+ else if (UserTransaction.class.isAssignableFrom(ref.type()))
{
- createURLInjector(encName, mappedName, container);
+ mappedName = "java:comp/UserTransaction";
}
else
{
- container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+ throw new RuntimeException("You did not specify a @Resource.mappedName() for name: " + ref.name()
+ + ", class: " + clazz.getName() + " and there is no binding for that enc name in XML");
}
}
- public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+ if (ref.type() == URL.class)
{
- Resource ref = container.getAnnotation(Resource.class, method);
- if (ref == null) return;
+ createURLInjector(encName, mappedName, container);
+ }
+ else
+ {
+ container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+ }
+ }
- log.trace("method " + method + " has @Resource");
-
- handlePropertyAnnotation(ref, new MethodBeanProperty(method), container, injectors);
+ public void handleMethodAnnotations(Method method, InjectionContainer container,
+ Map<AccessibleObject, Injector> injectors)
+ {
+ Resource ref = container.getAnnotation(Resource.class, method);
+ if (ref == null)
+ return;
+
+ log.trace("method " + method + " has @Resource");
+
+ handlePropertyAnnotation(ref, new MethodBeanProperty(method), container, injectors);
+ }
+
+ public void handleFieldAnnotations(Field field, InjectionContainer container,
+ Map<AccessibleObject, Injector> injectors)
+ {
+ Resource ref = container.getAnnotation(Resource.class, field);
+ if (ref == null)
+ return;
+
+ log.trace("field " + field + " has @Resource");
+
+ handlePropertyAnnotation(ref, new FieldBeanProperty(field), container, injectors);
+ }
+
+ private void handlePropertyAnnotation(Resource ref, BeanProperty property, InjectionContainer container,
+ Map<AccessibleObject, Injector> injectors)
+ {
+ assert ref != null;
+ assert property != null;
+ assert container != null;
+ assert injectors != null;
+
+ String encName = ref.name();
+ if (encName == null || encName.equals(""))
+ {
+ //encName = InjectionUtil.getEncName(field);
+ encName = property.getDeclaringClass().getName() + "/" + property.getName();
}
-
- public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+ if (!encName.startsWith("env/"))
{
- Resource ref = container.getAnnotation(Resource.class, field);
- if (ref == null) return;
+ encName = "env/" + encName;
+ }
- log.trace("field " + field + " has @Resource");
-
- handlePropertyAnnotation(ref, new FieldBeanProperty(field), container, injectors);
+ AccessibleObject accObj = property.getAccessibleObject();
+
+ Class<?> type = property.getType();
+ if (!ref.type().equals(Object.class))
+ {
+ type = ref.type();
}
- private void handlePropertyAnnotation(Resource ref, BeanProperty property, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+ if (type.equals(UserTransaction.class))
{
- assert ref != null;
- assert property != null;
- assert container != null;
- assert injectors != null;
-
- String encName = ref.name();
- if (encName == null || encName.equals(""))
+ injectors.put(accObj, new UserTransactionPropertyInjector(property, container));
+ }
+ else if (type.equals(TimerService.class))
+ {
+ injectors.put(accObj, new TimerServicePropertyInjector(property, (Container) container)); // only EJBs
+ }
+ else if (type.equals(URL.class) && ref.mappedName() != null && ref.mappedName().length() > 0)
+ {
+ createURLInjector(encName, ref.mappedName(), container);
+ injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
+ }
+ else if (type.equals(String.class) || type.equals(Character.class) || type.equals(Byte.class)
+ || type.equals(Short.class) || type.equals(Integer.class) || type.equals(Long.class)
+ || type.equals(Boolean.class) || type.equals(Double.class) || type.equals(Float.class)
+ || type.isPrimitive())
+ {
+ // don't add an injector if no XML <env-entry is present as there will be no value to inject
+ if (container.getEncInjectors().containsKey(encName))
{
- //encName = InjectionUtil.getEncName(field);
- encName = property.getDeclaringClass().getName() + "/" + property.getName();
- }
- if (!encName.startsWith("env/"))
- {
- encName = "env/" + encName;
- }
-
- AccessibleObject accObj = property.getAccessibleObject();
-
- Class<?> type = property.getType();
- if (!ref.type().equals(Object.class))
- {
- type = ref.type();
- }
-
- if (type.equals(UserTransaction.class))
- {
- injectors.put(accObj, new UserTransactionPropertyInjector(property, container));
- }
- else if (type.equals(TimerService.class))
- {
- injectors.put(accObj, new TimerServicePropertyInjector(property, (Container) container)); // only EJBs
- }
- else if(type.equals(URL.class) && ref.mappedName() != null && ref.mappedName().length() > 0)
- {
- createURLInjector(encName, ref.mappedName(), container);
injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
}
- else if (type.equals(String.class)
- || type.equals(Character.class)
- || type.equals(Byte.class)
- || type.equals(Short.class)
- || type.equals(Integer.class)
- || type.equals(Long.class)
- || type.equals(Boolean.class)
- || type.equals(Double.class)
- || type.equals(Float.class)
- || type.isPrimitive()
- )
+ else if (ref.mappedName() != null && ref.mappedName().length() > 0)
{
- // don't add an injector if no XML <env-entry is present as there will be no value to inject
- if (container.getEncInjectors().containsKey(encName))
+ // Use the mappedName as the string value
+ String s = ref.mappedName().trim();
+ try
{
+ Object value = ValueConvertor.convertValue(type, s);
+ container.getEncInjectors().put(encName, new ValueEncInjector(encName, value, "@Resource"));
injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
}
- else if (ref.mappedName() != null && ref.mappedName().length() > 0)
+ catch (Throwable t)
{
- // Use the mappedName as the string value
- String s = ref.mappedName().trim();
- try
- {
- Object value = ValueConvertor.convertValue(type, s);
- container.getEncInjectors().put(encName, new ValueEncInjector(encName, value, "@Resource"));
- injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
- }
- catch(Throwable t)
- {
- throw new RuntimeException("Failed to convert: "+ref.mappedName()+" to type:"+type, t);
- }
+ throw new RuntimeException("Failed to convert: " + ref.mappedName() + " to type:" + type, t);
}
- else
- {
- log.warn("Not injecting " + property.getName() + ", no matching enc injector " + encName + " found");
- }
}
else
{
- if (checkEncInjectors && !container.getEncInjectors().containsKey(encName))
+ log.warn("Not injecting " + property.getName() + ", no matching enc injector " + encName + " found");
+ }
+ }
+ else
+ {
+ if (checkEncInjectors && !container.getEncInjectors().containsKey(encName))
+ {
+ String mappedName = ref.mappedName();
+ if (mappedName == null || mappedName.equals(""))
{
- String mappedName = ref.mappedName();
- if (mappedName == null || mappedName.equals(""))
- {
- // TODO: is this a nice trick?
-// if(ConnectionFactory.class.isAssignableFrom(type))
-// {
-// // neat little trick
-// mappedName = "java:/ConnectionFactory";
-// }
-// else
- if(ORB.class.isAssignableFrom(type))
- mappedName = "java:comp/ORB";
- else
- throw new RuntimeException("You did not specify a @Resource.mappedName() on " + accObj + " and there is no binding for enc name " + encName + " in XML");
- }
- container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, mappedName, "@Resource"));
+ // TODO: is this a nice trick?
+ // if(ConnectionFactory.class.isAssignableFrom(type))
+ // {
+ // // neat little trick
+ // mappedName = "java:/ConnectionFactory";
+ // }
+ // else
+ if (ORB.class.isAssignableFrom(type))
+ mappedName = "java:comp/ORB";
+ else
+ throw new RuntimeException("You did not specify a @Resource.mappedName() on " + accObj
+ + " and there is no binding for enc name " + encName + " in XML");
}
- injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
- }
+ container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, mappedName, "@Resource"));
+ }
+ injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
}
-
}
+
+}
More information about the jboss-cvs-commits
mailing list