[jboss-user] [Microcontainer] - What is the correct time to invoke the getProperties on a Be
jaikiran
do-not-reply at jboss.com
Mon Feb 23 03:22:53 EST 2009
I am trying to dynamically create and deploy an MC bean as follows:
// My MC bean
| public class MyBean
| {
|
| // the attributes especially the bean name will be dynamically modified
| @Inject
| private MyOtherBean otherBean;
|
| // other stuff
| }
|
// The code which creates instances of these MyBean and deploys it into MC
|
| BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("someuniquename", "org.myapp.MyBean");
| MyBean bean = new MyBean();
| builder.setConstructorValue(bean);
|
| // Now let's get the PropertyMetadata from the bean (i.e. the @Inject property "otherBean")
| Set<PropertyMetaData> propertiesOnMyBean = builder.getBeanMetaData().getProperties();
|
|
The property metadata is always null. Isn't this the right time to call the builder.getBeanMetaData().getProperties()?
The reason i need this information is that i want to dynamically change some attributes of @Inject for the "otherBean" - something on these lines dynamically :
Set<PropertyMetaData> propertiesOnNoInterfaceMCBean = builder.getBeanMetaData().getProperties();
| for (PropertyMetaData propertyMetadata : propertiesOnNoInterfaceMCBean)
| {
| AnnotationMetaData anm = new AbstractAnnotationMetaData(Inject.class.getName());
| if (propertyMetadata.getAnnotations().contains(anm) && propertyMetadata.getType().equals(MyOtherBean.class.getName()))
| {
| logger.info("Changing Inject " + propertyMetadata.getName());
| // notice the bean name that we are adding to the @Inject is dynamic
| ValueMetaData inject = builder.createInject("dynamicBeanName", null, null, ControllerState.DESCRIBED);
| // addPropertyMetaData replaces the property metadata (if any)
| builder.addPropertyMetaData(propertyMetadata.getName(), inject);
|
| break;
| }
| }
|
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4212148#4212148
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4212148
More information about the jboss-user
mailing list