> > . Suppose i have
> > class A
> > ..
> > Map getFooMap()
> > void addFoo(B foo)
> >
> > Can i map A into
> > <a>
> > <foo name="name1" value="value1"/>
> > <foo name="name2" value="value2"/>
> > <foo name="name3" value="value3"/>
> > </a>
>
> (at the moment) betwixt always outputs map entries using the following
> format:
>
> <entry>
> <key>xxx</key>
>      <value>yyy</value>
> <entry>
> it might be more difficult for object values maps since you'll need
> appropriate object->value conversion. it would make round tripping complex
> since you'd need a string -> object factory. it's not impossible but it'd
> need some thinking about. i'd be interested to hear other people views on

I solve this problem in the following way:
1. I create the following implementation of the Expression
  public class MapValuesExpression implements Expression{
    Expression expression;

    public Object evaluate(Context context){
      Object value = expression.evaluate(context);
      if(value instanceof Map){
        Map map = (Map)value;
        value = map.values().iterator();
      }
      return value;
    }
    .....
  }
2. In the main method
      // Init
      BeanWriter beanWriter = new BeanWriter(outputWriter);
      XMLIntrospector introspector = beanWriter.getXMLIntrospector();
      XMLBeanInfoRegistry registry = introspector.getRegistry();
      // Take ElementDesciptor object
      introspector.introspect(A.class);
      ElementDescriptor fooMapProperty =
registry.get(A.class).getElementDescriptor().getElementDescriptors()[0];
      ElementDescriptor fooProperty =
fooMapProperty.getElementDescriptors()[0];
     fieldProperty.setContextExpression(
                                               new MapValuesExpression(
                                                  new MethodExpression(

A.class.getMethod("getFooMap",new Class[]{})
                                                  )
                                                ) );
      // Init a object and write it
      A a = new A();
      .......
      beanWriter.write(a);





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to