Giter Club home page Giter Club logo

Comments (3)

whummer avatar whummer commented on July 3, 2024

Hi, it's always better to give a concrete example of what you're trying to achieve. As far as I understand, you want to start from an XSD schema that contains <xs:annotation> tags, and then generate Java source code classes which contain the corresponding @Annotation annotations.

Java classes can currently only be generated from WSDL files which contain embedded XML Schemas, using the utility script bin/wsimport.sh. Create a bare minimum WSDL file with your schema as follows. Replace the MySchemaType complex type definition with your own type definition(s) and store the file as /tmp/tmpservice.wsdl .

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/service/TestService" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="TestService" targetNamespace="http://example.com/service/TestService">
  <wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.com/service/TestService" elementFormDefault="unqualified" targetNamespace="http://example.com/service/TestService" version="1.0">
  <xs:element name="testIn" type="xs:anyType"/>
  <xs:element name="testOut" type="xs:anyType"/>

  <xs:complexType name="MySchemaType">
    <xs:annotation>
      <xs:documentation>Your documentation goes here...!</xs:documentation>
    </xs:annotation>
    <xs:sequence/>
  </xs:complexType>

</xs:schema>
  </wsdl:types>
  <wsdl:message name="testOut">
    <wsdl:part element="tns:testOut" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="testIn">
    <wsdl:part element="tns:testIn" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="TestService">
    <wsdl:operation name="test">
      <wsdl:input message="tns:testIn" name="testIn">
    </wsdl:input>
      <wsdl:output message="tns:testOut" name="testOut">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="TestServiceSoapBinding" type="tns:TestService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="test">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="testIn">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="testOut">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="TestService">
    <wsdl:port binding="tns:TestServiceSoapBinding" name="TestServiceImplPort">
      <soap:address location="http://localhost:9001/TestService"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Next, run these commands (from the directory where you cloned the jaxb-facets repository). I'm assuming that you are running a Unix operating system (e.g., Mac OS, Linux) and that you have Apache Maven (mvn) installed.

mvn install # to compile and install the code in this repo
mkdir /tmp/tmpservice
./bin/wsimport.sh -keep -B-jaxb-facets -d /tmp/tmpservice /tmp/tmpservice.wsdl

This will generate (among other files, which you can ignore), the following file:

/tmp/tmpservice/com/example/service/testservice/MySchemaType.java

Take a look at the file and you will find the desired XSD annotations:

@XmlType(name = "MySchemaType")
@Annotation(documentation = @Documentation("Your documentation goes here...!"))
public class MySchemaType {
}

Good luck, and let me know how it goes... :)

from jaxb-facets.

red-hood avatar red-hood commented on July 3, 2024

Hi,

thanks for your answer. What I would like is to be able to add any type of annotation to a field of a class when generating the .java files from the xsd. The schema files are actually generated from a proprietary description of a binary format, which should then be parsed and serialized with preon (https://github.com/preon/preon).

So, for example, the original class with annotations would look like:

public class FooTest {
    @BoundNumber(size="16", byteOrder = BigEndian)
    public int foo;
    @BoundString
    public String world = "Hello World!";
}

The schema, including the annotations, could then be something along these lines:

  <xs:complexType name="fooTest">
    <xs:sequence>
      <xs:element name="foo" type="xs:int">
         <xs:annotation>
           <xs:jannotation type=BoundNumber>
             <param name="size" type="xs:string" value="16"/>
             <param name="byteOrder" value="java:org.codehaus.preon.buffer.ByteOrder.BigEndian"/>
           <xs:jannotation/>
         </xs:annotation>
      </xs:element>
      <xs:element name="world" type="xs:string" minOccurs="0">
         <xs:annotation>
           <xs:jannotation type=BoundString/>
         </xs:annotation>
    </xs:sequence>
  </xs:complexType>

Additionally, I would also like to add annotations for JPA mappings for each field of a class. As there is no webservice involved, a WSDL would not make much sense it that case.

In the meantime, I think I found what i was looking for: https://github.com/highsource/jaxb2-annotate-plugin

It seems this xjc plugin allows to define arbitrary annotations on Classe/Types and Fields/Elements, by using the xsd:appinfo tag. I will try it and report back on success.

Thank you a lot for your answer so far :)

from jaxb-facets.

whummer avatar whummer commented on July 3, 2024

Thanks for your detailed answer. jaxb2-annotate-plugin seems to provide what you're looking for. Feel free to come back here if it doesn't, then we can try to work something out... Closing this for now.

from jaxb-facets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.