Java – add annotations to JAXB generated classes that depend on information in the XSD

I have a WSDL XSD that needs to be converted to a Java class This is simple – wsimport will handle this problem without any problems However, I also need to be able to add comments to the generated classes, and these comments need to contain the information contained in the XSD (in particular, they need to reference the XSD: MaxLength or XSD: length attribute)

Why? Because I plan to use bindy to convert them into flat files later As a reference, I know that I can use annox to add custom annotations to the generated class, but as far as I know, this will require that all annotations are the same and all parameters are the same, or specify the annotation of each element separately. It is impossible to specify the annotation once and the value of one of the parameters. It should be different for each element (such as XPath)

That is, a similar pattern extraction is given

<xsd:element name="smapleRequest">
    <xsd:sequence>
         <xsd:element name="ELEMENT_ONE">
             <xsd:simpleType>
                 <xsd:restriction base="xsd:string">
                     <xsd:length value="3" />
                 </xsd:restriction>
             </xsd:simpleType>
         </xsd:element>
         <xsd:element name="ELEMENT_TWO">
             <xsd:simpleType>
                 <xsd:restriction base="xsd:string">
                     <xsd:maxLength value="8" />
                 </xsd:restriction>
             </xsd:simpleType>
         </xsd:element>
    </xsd:sequence>
</xsd:element>

I would like to see such a class:

.
.
.
@FixedLengthRecord
public class SampleRequest {

    @XmlElement(name = "ELEMENT_ONE",required = true)
    @datafield(pos = 1,length=3)
    protected String elementOne;


    @XmlElement(name = "ELEMENT_TWO",required = true)
    @datafield(pos = 4,length=8)
    protected String elementTwo;
    .
    .
    .
}

Ideally, I want to be able to do this without having to copy all the information in the XSD to the JAXB binding file I mean, I can, but each web service method may contain hundreds of elements, and many very, very fast methods At that time, I may have to use another tool to generate XSD and JAXB binding files from COBOL!

So, does anyone know if this is possible? Did I just miss something about annox? Or am I just asking too much here?

Solution

You have several choices: xjc plug-in is a route, and annox looks interesting But I'm not an expert, so I'll let others discuss it with you

I suggest you consider another route. If you encounter the first one, post process the JAXB source you generate through annotation processing (formerly apt tool, now part of javac tool) to access XSD and attach your comments in flight I'm not sure if it works in all cases, but in your example, JAXB generated comments should be sufficient to construct XPath expressions to read the corresponding XML element type characteristics Assuming that your requirements are basically near the field length, there should be few use cases and XPath expressions

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>