mapType.addElement(QNAME_ENTRY3, entry3Type, 0, true);
mapType.addElement(QNAME_ENTRY4, entry4Type, 0, true);
// sequence as entry
SequenceBinding entrySeq = new SequenceBinding(schema);
ElementBinding keyElement = new ElementBinding(schema, new QName(NS, "key"), new TypeBinding());
entrySeq.addParticle(new ParticleBinding(keyElement));
ElementBinding valueElement = new ElementBinding(schema, new QName(NS, "value"), new TypeBinding());
entrySeq.addParticle(new ParticleBinding(valueElement));
ParticleBinding entryParticle = new ParticleBinding(entrySeq);
entryParticle.setMinOccurs(0);
entryParticle.setMaxOccursUnbounded(true);
mapType.addParticle(entryParticle);
mapType.addElement(QNAME_SUBMAP, mapType, 0, true);
schema.addElement(QNAME_MAP, mapType);
// Handler implementations
mapType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new HashMap();
}
}
);
ElementInterceptor addMapEntryInterceptor = new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
Map map = (Map)parent;
Object[] arr = (Object[])child;
map.put(arr[0], arr[1]);
}
};
mapType.pushInterceptor(QNAME_ENTRY1, addMapEntryInterceptor);
mapType.pushInterceptor(QNAME_ENTRY2, addMapEntryInterceptor);
mapType.pushInterceptor(QNAME_ENTRY3, addMapEntryInterceptor);
mapType.pushInterceptor(QNAME_ENTRY4, addMapEntryInterceptor);
mapType.pushInterceptor(QNAME_SUBMAP, addMapEntryInterceptor);
entry1Type.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new Object[2];
}
}
);
entry1Type.pushInterceptor(QNAME_KEY1, new DefaultElementInterceptor()
{
public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
{
Object[] arr = (Object[])o;
arr[0] = text;
}
}
);
entry1Type.pushInterceptor(QNAME_VALUE1, new DefaultElementInterceptor()
{
public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
{
Object[] arr = (Object[])o;
arr[1] = text;
}
}
);
entry2Type.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new Object[2];
}
public void attributes(Object o,
QName elementName,
ElementBinding element,
Attributes attrs,
NamespaceContext nsCtx)
{
Object[] arr = (Object[])o;
for(int i = 0; i < attrs.getLength(); ++i)
{
String lName = attrs.getLocalName(i);
if("key2".equals(lName))
{
arr[0] = attrs.getValue(i);
}
}
}
}
);
entry2Type.pushInterceptor(QNAME_VALUE2, new DefaultElementInterceptor()
{
public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
{
Object[] arr = (Object[])o;
arr[1] = text;
}
}
);
entry3Type.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new Object[2];
}
public void attributes(Object o,
QName elementName,
ElementBinding element,
Attributes attrs,
NamespaceContext nsCtx)
{
Object[] arr = (Object[])o;
for(int i = 0; i < attrs.getLength(); ++i)
{
String lName = attrs.getLocalName(i);
if("key3".equals(lName))
{
arr[0] = attrs.getValue(i);
}
else if("value3".equals(lName))
{
arr[1] = attrs.getValue(i);
}
}
}
}
);
entry4Type.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new Object[2];
}
public void attributes(Object o,
QName elementName,
ElementBinding element,
Attributes attrs,
NamespaceContext nsCtx)
{
Object[] arr = (Object[])o;
for(int i = 0; i < attrs.getLength(); ++i)
{
String lName = attrs.getLocalName(i);
if("key4".equals(lName))
{
arr[0] = attrs.getValue(i);
}
}
}
}
);
entry4Type.setSimpleType(new CharactersHandler()
{
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
Object[] arr = (Object[])owner;
arr[1] = value;
}
}
);
mapType.pushInterceptor(QNAME_SUBMAP, new DefaultElementInterceptor()
{
public Object startElement(Object parent, QName name, TypeBinding type)
{
return new Object[2];
}
public void attributes(Object o,
QName elementName,
TypeBinding type,
Attributes attrs,
NamespaceContext nsCtx)
{
Object[] arr = (Object[])o;
for(int i = 0; i < attrs.getLength(); ++i)
{
String lName = attrs.getLocalName(i);
if("key".equals(lName))
{
arr[0] = attrs.getValue(i);
}
}
}
public void add(Object parent, Object child, QName qName)
{
Object[] arr = (Object[])parent;
Map submap = (Map)child;
arr[1] = submap;
}
}
);
// sequence entry
entrySeq.setHandler(new ParticleHandler()
{
public Object startParticle(Object parent,
QName elementName,
ParticleBinding particle,
Attributes attrs,
NamespaceContext nsCtx)
{
return new Object[2];
}
public Object endParticle(Object o, QName elementName, ParticleBinding particle)
{
return o;
}
public void setParent(Object parent,
Object o,
QName elementName,
ParticleBinding particle,
ParticleBinding parentParticle)
{
Map map = (Map)parent;
Object[] arr = (Object[])o;
map.put(arr[0], arr[1]);
}
}
);
keyElement.pushInterceptor(new DefaultElementInterceptor()
{
public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
{
Object[] arr = (Object[])o;
arr[0] = text;
}
});
valueElement.pushInterceptor(new DefaultElementInterceptor()
{
public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
{
Object[] arr = (Object[])o;
arr[1] = text;