}
});
// have to override string type's handlers
ElementBinding global = SCHEMA.getElement(new QName("http://jboss.org/ns/test", "global"));
SequenceBinding sequence = (SequenceBinding) global.getType().getParticle().getTerm();
Iterator iter = sequence.getParticles().iterator();
iter.next(); // stringType element
ElementBinding stringElement = (ElementBinding) ((ParticleBinding)iter.next()).getTerm();
stringElement.setBeforeMarshallingCallback(new TermBeforeMarshallingCallback()
{
public Object beforeMarshalling(Object o, MarshallingContext ctx)
{
ParticleBinding particle = ctx.getParticleBinding();
assertNotNull(particle);
assertTrue(particle.getTerm().isElement());
ElementBinding element = (ElementBinding) particle.getTerm();
assertEquals(new QName("http://jboss.org/ns/test", "stringElement"), element.getQName());
TypeBinding type = element.getType();
assertEquals(Constants.QNAME_STRING, type.getQName());
return o == null ? null : (String)o;
}
});
stringElement.setBeforeSetParentCallback(new TermBeforeSetParentCallback()
{
public Object beforeSetParent(Object o, UnmarshallingContext ctx)
{
ParticleBinding particle = ctx.getParticle();
assertNotNull(particle);
assertTrue(particle.getTerm().isElement());
ElementBinding element = (ElementBinding) particle.getTerm();
assertEquals(new QName("http://jboss.org/ns/test", "stringElement"), element.getQName());
assertTrue(ctx.getParentValue() instanceof GlobalElement);
TermBinding parentTerm = ctx.getParentParticle().getTerm();
assertTrue(parentTerm.isElement());
assertEquals("global", ((ElementBinding)parentTerm).getQName().getLocalPart());
assertEquals(String.class, ctx.resolvePropertyType());
return o == null ? null : (String)o;
}
});
// sequence
sequence = (SequenceBinding) ((ParticleBinding)iter.next()).getTerm();
sequence.setBeforeMarshallingCallback(new TermBeforeMarshallingCallback()
{
public Object beforeMarshalling(Object o, MarshallingContext ctx)
{
ParticleBinding particle = ctx.getParticleBinding();
assertNotNull(particle);
assertTrue(particle.getTerm() instanceof SequenceBinding);
if(o != null)
{
GlobalElement.Sequence seq = new GlobalElement.Sequence();
seq.item = (StringType) o;
o = seq;
}
return o;
}
});
sequence.setBeforeSetParentCallback(new TermBeforeSetParentCallback()
{
public Object beforeSetParent(Object o, UnmarshallingContext ctx)
{
ParticleBinding particle = ctx.getParticle();
assertTrue(particle.getTerm() instanceof SequenceBinding);