[jboss-dev-forums] [Design of JBossXB] - Re: Attributes problem
adrian@jboss.org
do-not-reply at jboss.com
Fri Mar 7 04:20:40 EST 2008
I've fixed this by creating a WrapperBeanAdapter.
It's not very clean though. I think it shows we need better support
for being able to bind to a group and know how the group is processed.
The strategy I've used is to "steal" the BeanAdapter
(and other information) from the xml type
of the wrapping class then delegate to it from a WrapperBeanAdapter
| if (groupText != null && groupText.wrapper() != Object.class)
| {
| BeanInfo wrapperInfo = JBossXBBuilder.configuration.getBeanInfo(groupText.wrapper());
| TypeBinding wrapperTypeBinding = resolveTypeBinding(wrapperInfo.getClassInfo());
| // Steal the attributes
| Collection<AttributeBinding> otherAttributes = wrapperTypeBinding.getAttributes();
| if (otherAttributes != null)
| {
| for (AttributeBinding other : otherAttributes)
| elementTypeBinding.addAttribute(other);
| }
| ParticleHandler particleHandler = wrapperTypeBinding.getHandler();
| if (particleHandler instanceof BeanHandler == false)
| throw new IllegalStateException("Cannot wrap " + wrapperInfo.getName() + " not a bean type " + particleHandler);
| BeanHandler beanHandler = (BeanHandler) particleHandler;
| WrapperBeanAdapterFactory wrapperFactory = new WrapperBeanAdapterFactory(beanHandler.getBeanAdapterFactory(), propertyType.getType());
| elementTypeBinding.setHandler(new BeanHandler(wrapperInfo.getName(), wrapperFactory));
| elementTypeBinding.setSimpleType(wrapperTypeBinding.getSimpleType());
| }
|
The idea of the wrapper is that it will delegate requests to the wrapped BeanAdapter
until it spots an element from some other part of the group
then it will just return that element's object.
| @Override
| public Object getValue()
| {
| if (notWrapped != null)
| return notWrapped;
| else
| return wrapped.getValue();
| }
|
| @Override
| public void set(PropertyInfo propertyInfo, Object child) throws Throwable
| {
| Class<?> stopWrapping = getBeanAdapterFactory().getStopWrapping();
| if (child != null && stopWrapping != null && stopWrapping.isInstance(child))
| notWrapped = child;
| else
| wrapped.set(propertyInfo, child);
| }
|
Of course, it isn't really doing that. It's just using the property type
(the stopWrapping) to detect when it is another element from the group
which is obviously a kludge that could be fixed by knowing more
about the group.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4134774#4134774
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4134774
More information about the jboss-dev-forums
mailing list