Hi Mark;
Do you try to implement resource injections via XML definitions, right? Below
sketch is the summary of how you can proceed with the current implementation.
For XML defined webbeans, the main entry point is the *WebBeansXMLConfigurator*
class. Java EE Resources are only defined in the xml file, according to the
*9.5.2 Type-Level metadata for a bean*. This part is handled in the
*WebBeansXMLConfigurator#configureTypeLevelMetaData* method.
For injectable resources, you can create another class like
*XMLResourceInjectableField* in the *inject/xml* package and add the
*Map<Field,XMLInjectionPointModel> injectedResources* instance variable into
the *XMLComponentImpl.java* to hold the injectable resource fields.
After that you will have to add the resource injection fields that are declared
in the XML into the resource injection map in the *XMLComponentImpl* class. You
can create another method for this in the *WebBeansXMLConfigurator* class, for
example *configureInjectableResources()*, and call this method from
*configureTypeLevelMetaData()* method.
Skeletons of the codes may like the followings;
WebBeansXMLConfigurator.java
----------------------------------------------
........
//Update this method
public <T> void configureTypeLevelMetaData()
{
//Add this method call
configureInjectableResources();
}
//This is the new method that is responsible for adding resource injection
fields to the component
public <T> void configureInjectableResources()
{
//Find fields from resource decleration in XML
//Create XMLInjectionPointModel for each field
//Add field and related model into the
XMLComponentImpl#Map<Field,XMLInjectionPointModel>
}
XMLComponentImpl.java
---------------------------------
After that in XMLComponentImpl class, update injectFields method to inject
resources,
//Update this method for adding resource injection support
protected void injectFields(T instance)
{
......
//For each resource injection map entry
//Create new *XMLResourceInjectableField* instance
//Set field with calling the AbstractInjectable#inject(....)
}
AbstractInjectable class
---------------------------------
public Object inject()
{
//If resource, create injection object with method injectResource
if (isResource(annotations))
{
return injectResource(type, annotations);
}
}
WDYT?
/Gurkan
________________________________
From: Mark Struberg <[email protected]>
To: [email protected]
Sent: Tuesday, January 27, 2009 12:35:02 PM
Subject: level of resource injection
Gurkan,
another question about resources: where should I actually inject the resources
finally?
This is the stack trace so far:
InjectionResolver.implResolveByType(Class<?>, Type[], Annotation...) line: 94
InjectableField(AbstractInjectable).inject(Class<T>, Type[], Annotation...)
line: 83
InjectableField.doInjection() line: 92
My thoughts:
Resources can be handled in a very high layer, since the 'accessors' already
hide all the underlying complexity of having classloader hierarchies etc, isn't?
So in the
AbstractInjectable#inject
I'd like to add something like:
if (isResource(annotations))
{
return injectResource(type, annotations);
}
LieGrü,
strub