开发者

JAXB generated classes serializable with JAX-WS binding

Having JAXB-RI and CXF. WSDL first. I want a generated class of mine to implement Serializable. I now have the following binding xml, which works (the SEI class name gets changed)

<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
    <bindings node="wsdl:definitions/wsdl:portType[@name='Foo']">
   开发者_如何学编程     <!-- change the generated SEI class -->
        <class name="IFooService" />
    </bindings>
</jaxws:bindings>

No, in this context, where and what should I add. I tried:

<xsd:annotation>
    <xsd:appinfo>
        <jaxb:globalBindings>
            <xjc:serializable uid="12343" />
        </jaxb:globalBindings>
    </xsd:appinfo>
</xsd:annotation>

and

<jxb:globalBindings>
    <jxb:serializable/>
</jxb:globalBindings> 

both inside and outside the <bindings> tag - either Serializable is not added, or classes are not generated at all (without any error).

See also this thread

So, how exactly to do that


I made it work in two ways:

  1. Using a second binding file, which is JAXB-only, as the one Pascal showed in his answer

  2. By specifying another <bindings> tag that handles the whole namespace:

    <bindings
        node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://www.yoursite.com/services/mynamespace']">
        <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <jxb:serializable />
        </jxb:globalBindings>
    </bindings>
    


You can implement an XJC plugin to do that:

public class SerializablePlugin extends Plugin
{

  @Override
  public boolean run(Outline outline, Options options, ErrorHandler errorHandler) throws SAXException
  {
   for (ClassOutline classOutline : outline.getClasses())
   {
    JDefinedClass definedClass = classOutline.implClass;
    definedClass._implements(codeModel.ref(Serializable.class));
   }
   return true;
  }

 ...
}

Then, you can add the plugin to the SchemaCompiler options:

WsimportOptions wsimportOptions = new WsimportOptions();
wsimportOptions.getSchemaCompiler().getOptions().activePlugins.add(new SerializablePlugin());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜