3

The JAXB RI source code contains:

public void setProperty(String name, Object value) throws PropertyException {

    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }

I'm invoking it like so:

        Class c = Class.forName("org.docx4j.jaxb.ri.NamespacePrefixMapper");
        prefixMapper = c.newInstance();         
        m.setProperty("com.sun.xml.bind.namespacePrefixMapper", prefixMapper );

where my Class c is declared as follows:

public class NamespacePrefixMapper extends com.sun.xml.bind.marshaller.NamespacePrefixMapper 
    implements NamespacePrefixMapperInterface, McIgnorableNamespaceDeclarator 

This usually works fine (including in Karaf 4.2.4, ServiceMix 7.0.1), but I'm having problems with ServiceMix 5.4.1.

In ServiceMix 5.4.1, I get:

javax.xml.bind.PropertyException: property "com.sun.xml.bind.namespacePrefixMapper" must be an instance of type com.sun.xml.bind.marshaller.NamespacePrefixMapper, not org.docx4j.jaxb.ri.NamespacePrefixMapper
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:502)

which is mystifying, since it extends com.sun.xml.bind.marshaller.NamespacePrefixMapper

Is instanceof expected to behave differently in an OSGi environment?

Thoughts welcome, thanks!

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • You've the right Java-Environment? http://servicemix.apache.org/docs/5.x/quickstart/quickstart.pdf , http://servicemix.apache.org/docs/5.x/index.html – David Apr 26 '19 at 21:08

0 Answers0