configureValueBindings(valueType);
valueType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractValueMetaData(new StringValueMetaData());
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractValueMetaData value = (AbstractValueMetaData) o;
StringValueMetaData string = (StringValueMetaData) value.getValue();
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
string.setType(attrs.getValue(i));
}
}
});
// value can take a value
valueType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return value;
}
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
AbstractValueMetaData valueMetaData = (AbstractValueMetaData) owner;
StringValueMetaData string = (StringValueMetaData) valueMetaData.getValue();
string.setValue(value);
}
});
// collection binding
configureCollection(collectionTypeQName);
// list binding
configureCollection(listTypeQName);
// set binding
configureCollection(setTypeQName);
// array binding
configureCollection(arrayTypeQName);
// map binding
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);