This content has been marked as final.
Show 7 replies
-
1. Re: What is the correct time to invoke the getProperties on
alesj Feb 23, 2009 5:29 AM (in response to jaikiran)The builder just builds metadata.
Annotation's metadata population happens only in Describe state,
as we know there that our CL exists == can do class info inspection.
I looks like you're actually trying to do what AnnotationToBeanMetaDataFactory is meant for. -
2. Re: What is the correct time to invoke the getProperties on
jaikiran Feb 24, 2009 9:13 AM (in response to jaikiran)"alesj" wrote:
The builder just builds metadata.
Annotation's metadata population happens only in Describe state,
as we know there that our CL exists == can do class info inspection.
Makes sense."alesj" wrote:
I looks like you're actually trying to do what AnnotationToBeanMetaDataFactory is meant for.
After looking at the AnnotationToBeanMetadatFactory, i don't think that's what i am after. So to give you an exact idea of what i am trying to do:
I am dynamically building a bean MyBean which needs another bean MyOtherBean to be injected in it:public class MyBean { // Inject information will be dynamically added, including the bean name // to be injected @Inject private MyOtherBean otherBean; ... }
The easy way to dynamically build this bean and add the injection attributes is this:MyBean mybean = new MyBean(); BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("blah", mybean.getClass().getName()); builder.setConstructorValue(mybean); // create the inject attributes ValueMetaData inject = builder.createInject("beanNameOftheDependency", null, null, ControllerState.DESCRIBED); builder.addPropertyMetaData("otherBean", inject);
Works fine. However, the thing that i want to avoid is this line:builder.addPropertyMetaData("otherBean", inject)
I was trying to avoid adding the inject/depends on a "field name" and instead was trying to see if i could create the metadata based on the "type" to inject. Something like:builder.addPropertyMetadata(MyOtherBean.class.getName(),inject);
The MC would then look for a field of type MyOtherBean and create the injection on MyBean.
So if tomorrow, someone dislikes the field name and changes it to:public class MyBean { // Inject information will be dynamically added, including the bean name // to be injected @Inject private MyOtherBean iDontLikeTheEarlierName; ... }
then i could still have this entire thing working.
Maybe MC already has something to achieve this and i am not finding the correct API? -
3. Re: What is the correct time to invoke the getProperties on
alesj Feb 25, 2009 4:46 AM (in response to jaikiran)"jaikiran" wrote:
Maybe MC already has something to achieve this and i am not finding the correct API?
BeanMetaDataBuilder::createContextualInject is the closest you can get.
But your example is different.
Current contextual injection would still need the property name,
it just wouldn't care about what exact bean maps to that property,
it would be determined via type matching.
In your case you would have to "examine" the bean/class,
to find the actual property/field name,
as I don't see how else MC's IoC could know where to inject the matching bean.
But this is "weird" custom behavior. :-) -
4. Re: What is the correct time to invoke the getProperties on
jaikiran Feb 25, 2009 5:09 AM (in response to jaikiran)"alesj" wrote:
But this is "weird" custom behavior. :-)
Custom - yes. Weird - maybe not :-)
But i'll think a bit more to see if whatever i am trying to do is worth the efforts :) -
5. Re: What is the correct time to invoke the getProperties on
alesj Feb 25, 2009 5:14 AM (in response to jaikiran)"jaikiran" wrote:
Weird - maybe not :-)
If you bother to change the field name,
I think you can bother to change it as well in MC's xml descriptor. ;-) -
6. Re: What is the correct time to invoke the getProperties on
jaikiran Feb 25, 2009 5:16 AM (in response to jaikiran)"alesj" wrote:
.. as well in MC's xml descriptor. ;-)
That's the whole point, this is a dynamic MC bean created on the fly with no xml configuration :) -
7. Re: What is the correct time to invoke the getProperties on
alesj Feb 25, 2009 6:01 AM (in response to jaikiran)"jaikiran" wrote:
That's the whole point, this is a dynamic MC bean created on the fly with no xml configuration :)
OK, I still don't consider this a valid use case to make MC changes. :-)
But keeps us informed on how you achieved this. ;-)