Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] XML attributes on the fly? How?

Hi John,

The XmlAnyAttribute will only pick up attributes that aren't otherwise mapped. For each attribute encountered, it will check to see if there's a field on the object that's mapped to that attribute. If there's not, then it's handed off to the XmlAnyAttribute.

The List of objects wouldn't be easy to configure, in part due to the fact that the attribute name (source-0, source-1, source-2) changes for each instance of the Object. I believe the XmlAnyAttribute would be the easiest way to map this, but if you could use a custom accessor method to convert from the map to the list and back.

For example:

public class SourceWrapper {
    public String source;

    public String masterSource;
}


public class Region {
    ...
    private List<SourceWrapper> source;
    ...

@XmlTransient
public List<SourceWrapper> getSource() {
    return source;
}

@XmlAnyAttribute
public Map<QName, String> getSourceMap() {
    HashMap<QName, String> map = new HashMap<QName, String>();
    for(int i = 0; i < channels; i++) {
        Source next = source.get(i);
        map.put(new QName("source-" + i), next.source);
        map.put(new QName("masterSource-" + 1), next.masterSource);
    }
    return map;
}
public void setSourceMap(Map<QName, String> map) {
    //build the list of wrappers from the map
}

Hope the helps,

-Matt
On 2013-04-23 2:53 PM, jdiligence wrote:
Thanks.

That should work as long as XmlAnyAttribute doesn't map any that have other
definitions. Otherwise when I marshall it out again it could have duplicate
attributes. Does XmlAnyAttribute ignore already mapped attributes?

My ideal though would be something like a List of objects each having two
fields: source & masterSource. Is there an easy way to configure that?




--
View this message in context: http://eclipse.1072660.n5.nabble.com/XML-attributes-on-the-fly-How-tp159345p159356.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users





Back to the top