JAXB RI源代码包含:
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;
}
我正在这样调用它:
Class c = Class.forName("org.docx4j.jaxb.ri.NamespacePrefixMapper");
prefixMapper = c.newInstance();
m.setProperty("com.sun.xml.bind.namespacePrefixMapper", prefixMapper );
我的Class c声明如下:
public class NamespacePrefixMapper extends com.sun.xml.bind.marshaller.NamespacePrefixMapper
implements NamespacePrefixMapperInterface, McIgnorableNamespaceDeclarator
这通常可以正常工作(包括在Karaf 4.2.4,ServiceMix 7.0.1中),但是ServiceMix 5.4.1出现问题。
在ServiceMix 5.4.1中,我得到:
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)
这很神秘,因为它扩展了com.sun.xml.bind.marshaller.NamespacePrefixMapper
instanceof是否应在OSGi环境中表现不同?
欢迎您,谢谢!