XJC插件自定义 [英] XJC Plugin customizations

查看:158
本文介绍了XJC插件自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用自定义的XJC插件。问题是我得到了

I'm developing XJC plugin which uses customizations. The problem is I get

[ERROR] compiler was unable to honor this myPlugin:testAnnotation customization. It is attached to a wrong place, or its inconsistent with other bindings.
  line 16 of file:/C:/JaxbPlugin_jar/withInternalBinding/sampleInlineAnnotation.xsd

[ERROR] (the above customization is attached to the following location in the schema)
  line 13 of file:/C:/JaxbPlugin_jar/withInternalBinding/sampleInlineAnnotation.xsd

这是我的架构:

<?xml version='1.0' ?>
<xs:schema 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:myPlugin="http://www.example.org"  
targetNamespace="http://www.books.org"  
xmlns="http://www.books.org" 

xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc myPlugin" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
jaxb:version="2.1">

    <xs:element name="a" type="xs:string">
        <xs:annotation>
            <xs:appinfo>
                <myPlugin:testAnnotation>test</myPlugin:testAnnotation>
            </xs:appinfo>
        </xs:annotation>    
    </xs:element>
</xs:schema>

我没有使用外部绑定配置(没有-b选项)所以

I'm not using external binding configuration (no -b option) so


  1. 它附加到错误的地方

  2. 所以它与其他绑定不一致 - 我只有一个自定义,我不使用外部绑定文件

  1. "It is attached to a wrong place"
  2. "so it is inconsistent with other bindings" - I've got only one customization and I don't use external binding files

所以看起来好像是< myPlugin:testAnnotation> test< / myPlugin:testAnnotation> 位置错误。但它在注释标签内,我不知道为什么它不起作用。

So it seems <myPlugin:testAnnotation>test</myPlugin:testAnnotation> is in the wrong place. But it is inside an annotation tag, and I don't know why it doesn't work.

推荐答案

简短的回答是你可能正在做的一切。您只需要执行插件的下一步,并告诉XJC您已经看到了自定义。

The short answer is that you probably are doing everything correctly. You just have to take the next step in the implementation of your plugin and tell XJC that you saw the customization.

任何时候都没有插件会出现此错误承认定制。要处理自定义,您通常需要覆盖几个Plugin方法,然后在处理自定义时,调用 markAsAcknowledged

You will get this error any time that none of the plugins "acknowledge" the customization. To deal with customizations, you will generally want to override a couple of the Plugin methods and then when you handle the customization, call markAsAcknowledged.

@Override
public List<String> getCustomizationURIs() {
    List<String> uris = new ArrayList<>();
    uris.add(...);
    return uris;
}

@Override
public boolean isCustomizationTagName(String nsUri, String localName) {
    return ...;
}


for (CPluginCustomization customization : propertyInfo.getCustomizations()) {
    if (isCustomizationTagName(customization.element.getNamespaceURI(),
            customization.element.getLocalName())) {
        // Apply the customization.
        ...

        // Tell XJC that the customization was consumed.
        customization.markAsAcknowledged();
    }
}

错误背后的想法place verbiage是插件可能只在属性级别查找自定义,但文档在类级别(例如,在complexType上)。在这种情况下,插件代码会错过它(因为它没有在classInfo上查找它),因此它不会得到确认。

The idea behind the wrong place verbiage is that the plugin might only be looking for the customization at the 'property' level but the document has it at the 'class' level (e.g., on a complexType). In this case, the plugin code would miss it (because it is not looking for it on the classInfo) and therefore it does not get acknowledged.

这篇关于XJC插件自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆