TypeBinding mapType = schemaBinding.getType(mapTypeQName);
mapType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractMapMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractMapMetaData collection = (AbstractMapMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
collection.setType(attrs.getValue(i));
else if ("keyClass".equals(localName))
collection.setKeyType(attrs.getValue(i));
else if ("valueClass".equals(localName))
collection.setValueType(attrs.getValue(i));
}
}
});
// map has a map entries
mapType.pushInterceptor(entryQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractMapMetaData map = (AbstractMapMetaData) parent;
MapEntry entry = (MapEntry) child;
AbstractValueMetaData entryKey = (AbstractValueMetaData) entry.key;
if (entryKey == null)
throw new IllegalArgumentException("No key in map entry");
AbstractValueMetaData entryValue = (AbstractValueMetaData) entry.value;
if (entryValue == null)
throw new IllegalArgumentException("No value in map entry");
map.put(entryKey.getValue(), entryValue.getValue());
}
});
// entry binding
TypeBinding entryType = schemaBinding.getType(entryTypeQName);