public void testDuplicateInterceptor() throws Exception
{
SchemaBinding schema = bind("DuplicateInterceptor.xsd");
schema.setIgnoreUnresolvedFieldOrClass(false);
ClassMetaData classMetaData = new ClassMetaData();
classMetaData.setImpl(Parent1.class.getName());
TypeBinding parent1Type = schema.getType(new QName(NS, "parent1Type"));
assertNotNull(parent1Type);
parent1Type.setClassMetaData(classMetaData);
parent1Type.pushInterceptor(new QName(NS, "child"), new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName qName)
{
Parent1 parent1 = (Parent1) parent;
Child c = (Child) child;
c.string = c.string + "Parent1";
parent1.child = c;
}
});
classMetaData = new ClassMetaData();
classMetaData.setImpl(Parent2.class.getName());
TypeBinding parent2Type = schema.getType(new QName(NS, "parent2Type"));
assertNotNull(parent2Type);
parent2Type.setClassMetaData(classMetaData);
parent2Type.pushInterceptor(new QName(NS, "child"), new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName qName)
{
fail("Should not invoke interceptor added to parent2Type when processing parent1!");
}
});
classMetaData = new ClassMetaData();
classMetaData.setImpl(Child.class.getName());
TypeBinding childType = schema.getType(new QName(NS, "childType"));
assertNotNull(childType);
childType.setClassMetaData(classMetaData);
Parent1 parent1 = (Parent1) unmarshal("DuplicateInterceptor.xml", schema, Parent1.class);